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."
229 (equal '("Subtree Title")
230 (org-test-with-temp-text "#+TITLE: Title
233 :EXPORT_TITLE: Subtree Title
236 (plist-get (org-export-get-environment nil t
) :title
))))
240 (org-test-with-temp-text "#+OPTIONS: H:1
246 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
249 (equal '("29-03-2012")
250 (org-test-with-temp-text "#+DATE: today
253 :EXPORT_DATE: 29-03-2012
256 (plist-get (org-export-get-environment nil t
) :date
))))
257 ;; Properties with `split' behaviour are stored as a list of
261 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
264 :EXPORT_EXCLUDE_TAGS: a b
267 (plist-get (org-export-get-environment nil t
) :exclude-tags
))))
268 ;; Handle :PROPERTY+: syntax.
271 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
274 :EXPORT_EXCLUDE_TAGS: a
275 :EXPORT_EXCLUDE_TAGS+: b
278 (plist-get (org-export-get-environment nil t
) :exclude-tags
))))
279 ;; Export properties are case-insensitive.
281 (equal '("29-03-2012")
282 (org-test-with-temp-text "* Headline
284 :EXPORT_Date: 29-03-2012
287 (plist-get (org-export-get-environment nil t
) :date
))))
288 ;; Still grab correct options when section above is empty.
291 (org-test-with-temp-text "* H1\n** H11\n** H12<point>"
292 (plist-get (org-export-get-environment nil t
) :title
))))
293 ;; More than one property can refer to the same node property.
296 (org-test-with-temp-text
297 "* H\n:PROPERTIES:\n:EXPORT_A: 1\n:END:\n<point>"
298 (let* ((backend (org-export-create-backend
301 (options (org-export-get-environment backend t
)))
302 (list (plist-get options
:k1
) (plist-get options
:k2
)))))))
304 (ert-deftest test-org-export
/set-title
()
305 "Test title setting."
306 ;; Without TITLE keyword.
310 (let (org-export-filter-body-functions
311 org-export-filter-final-output-functions
)
312 (org-test-with-temp-text "Test"
314 (org-export-create-backend
316 '((template .
(lambda (text info
)
317 (org-element-interpret-data
318 (plist-get info
:title
)))))))))))
319 ;; With a blank TITLE keyword.
323 (let (org-export-filter-body-functions
324 org-export-filter-final-output-functions
)
325 (org-test-with-temp-text "#+TITLE:\nTest"
327 (org-export-create-backend
329 '((template .
(lambda (text info
)
330 (org-element-interpret-data
331 (plist-get info
:title
)))))))))))
332 ;; With a non-empty TITLE keyword.
336 (org-test-with-temp-text "#+TITLE: Title\nTest"
338 (org-export-create-backend
340 '((template .
(lambda (text info
)
341 (org-element-interpret-data
342 (plist-get info
:title
))))))))))
343 ;; When exporting a subtree, its heading becomes the headline of the
348 (org-test-with-temp-text "* Headline\nBody"
350 (org-export-create-backend
352 '((template .
(lambda (text info
)
353 (org-element-interpret-data
354 (plist-get info
:title
))))))
356 ;; ... unless there is an EXPORT_TITLE property at the root of the
361 (org-test-with-temp-text
362 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
364 (org-export-create-backend
366 '((template .
(lambda (text info
)
367 (org-element-interpret-data
368 (plist-get info
:title
))))))
371 (ert-deftest test-org-export
/handle-options
()
372 "Test if export options have an impact on output."
373 ;; Test exclude tags for headlines and inlinetasks.
376 (let (org-export-filter-body-functions
377 org-export-filter-final-output-functions
)
378 (org-test-with-temp-text "* Head1 :noexp:"
379 (org-export-as (org-test-default-backend)
380 nil nil nil
'(:exclude-tags
("noexp")))))))
381 ;; Test include tags for headlines and inlinetasks.
383 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
384 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
385 (let ((org-tags-column 0))
386 (org-export-as (org-test-default-backend)
387 nil nil nil
'(:select-tags
("exp")))))))
388 ;; If there is an include tag, ignore the section before the first
391 (equal "* H1 :exp:\nBody\n"
392 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
393 (let ((org-tags-column 0))
394 (org-export-as (org-test-default-backend)
395 nil nil nil
'(:select-tags
("exp")))))))
397 (equal "* H1 :exp:\n"
398 (org-test-with-temp-text "* H1 :exp:\nBody"
399 (let ((org-tags-column 0))
400 (org-export-as (org-test-default-backend)
401 nil nil nil
'(:select-tags
("exp")))))))
402 ;; Test mixing include tags and exclude tags.
405 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
406 (org-test-with-temp-text "
408 ** Sub-Head1 :noexport:
411 ** Sub-Head1 :export:"
412 (org-export-as (org-test-default-backend) nil nil nil
413 '(:select-tags
("export") :exclude-tags
("noexport"))))))
417 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
418 org-export-filter-body-functions
419 org-export-filter-final-output-functions
)
420 (org-test-with-temp-text "* TODO Head1"
421 (org-export-as (org-test-default-backend)
422 nil nil nil
'(:with-tasks nil
))))))
424 (equal "* TODO Head1\n"
425 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
426 (org-test-with-temp-text "* TODO Head1"
427 (org-export-as (org-test-default-backend)
428 nil nil nil
'(:with-tasks t
))))))
432 (let (org-export-filter-body-functions
433 org-export-filter-final-output-functions
)
434 (org-test-with-temp-text "* Head1 :archive:"
435 (let ((org-archive-tag "archive"))
436 (org-export-as (org-test-default-backend)
437 nil nil nil
'(:with-archived-trees nil
)))))))
440 "\\* Head1[ \t]+:archive:"
441 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
442 (let ((org-archive-tag "archive"))
443 (org-export-as (org-test-default-backend) nil nil nil
444 '(:with-archived-trees headline
))))))
447 "\\`\\* Head1[ \t]+:archive:\n\\'"
448 (org-test-with-temp-text "* Head1 :archive:"
449 (let ((org-archive-tag "archive"))
450 (org-export-as (org-test-default-backend)
451 nil nil nil
'(:with-archived-trees t
))))))
454 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
455 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
456 (org-export-as (org-test-default-backend)
457 nil nil nil
'(:with-clocks t
)))))
460 (let (org-export-filter-body-functions
461 org-export-filter-final-output-functions
)
462 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
463 (org-export-as (org-test-default-backend)
464 nil nil nil
'(:with-clocks nil
))))))
468 (let (org-export-filter-body-functions
469 org-export-filter-final-output-functions
)
470 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
471 (org-export-as (org-test-default-backend)
472 nil nil nil
'(:with-drawers nil
))))))
474 (equal ":TEST:\ncontents\n:END:\n"
475 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
476 (org-export-as (org-test-default-backend)
477 nil nil nil
'(:with-drawers t
)))))
479 (equal ":FOO:\nkeep\n:END:\n"
480 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
481 (org-export-as (org-test-default-backend)
482 nil nil nil
'(:with-drawers
("FOO"))))))
484 (equal ":FOO:\nkeep\n:END:\n"
485 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
486 (org-export-as (org-test-default-backend)
487 nil nil nil
'(:with-drawers
(not "BAR"))))))
491 (org-test-with-temp-text ": A"
492 (org-export-as (org-test-default-backend) nil nil nil
493 '(:with-fixed-width t
)))))
496 (let (org-export-filter-body-functions
497 org-export-filter-final-output-functions
)
498 (org-test-with-temp-text ": A"
499 (org-export-as (org-test-default-backend) nil nil nil
500 '(:with-fixed-width nil
))))))
504 (let ((org-footnote-section nil
))
505 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
506 (org-trim (org-export-as (org-test-default-backend)
507 nil nil nil
'(:with-footnotes nil
)))))))
509 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
510 (let ((org-footnote-section nil
))
511 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
512 (org-trim (org-export-as (org-test-default-backend)
513 nil nil nil
'(:with-footnotes t
)))))))
515 (when (featurep 'org-inlinetask
)
519 (let ((org-inlinetask-min-level 15)
520 org-export-filter-body-functions
521 org-export-filter-final-output-functions
)
522 (org-test-with-temp-text "*************** Task"
523 (org-export-as (org-test-default-backend)
524 nil nil nil
'(:with-inlinetasks nil
))))))
528 (let ((org-inlinetask-min-level 15)
529 org-export-filter-body-functions
530 org-export-filter-final-output-functions
)
531 (org-test-with-temp-text
532 "*************** Task\nContents\n*************** END"
533 (org-export-as (org-test-default-backend)
534 nil nil nil
'(:with-inlinetasks nil
)))))))
538 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
539 (let ((org-closed-string "CLOSED:"))
540 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
541 (org-export-as (org-test-default-backend)
542 nil nil nil
'(:with-planning t
))))))
545 (let ((org-closed-string "CLOSED:"))
546 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
547 (org-export-as (org-test-default-backend)
548 nil nil nil
'(:with-planning nil
))))))
552 (org-test-with-temp-text
553 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
554 (org-export-as (org-test-default-backend)
555 nil nil nil
'(:with-properties nil
)))))
557 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
558 (org-test-with-temp-text
559 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
560 (org-export-as (org-test-default-backend)
561 nil nil nil
'(:with-properties t
)))))
563 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
564 (org-test-with-temp-text
565 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
566 (org-export-as (org-test-default-backend)
567 nil nil nil
'(:with-properties
("B"))))))
568 ;; Statistics cookies.
571 (let (org-export-filter-body-functions
572 org-export-filter-final-output-functions
)
574 (org-test-with-temp-text "[0/0]"
575 (org-export-as (org-test-default-backend)
576 nil nil nil
'(:with-statistics-cookies nil
)))))))
580 (org-test-with-temp-text "| A |"
581 (org-export-as (org-test-default-backend) nil nil nil
582 '(:with-tables t
)))))
585 (let (org-export-filter-body-functions
586 org-export-filter-final-output-functions
)
587 (org-test-with-temp-text "| A |"
588 (org-export-as (org-test-default-backend) nil nil nil
589 '(:with-tables nil
)))))))
591 (ert-deftest test-org-export
/with-timestamps
()
592 "Test `org-export-with-timestamps' specifications."
596 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
597 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
598 (org-export-as (org-test-default-backend)
599 nil nil nil
'(:with-timestamps t
)))))
604 (let (org-export-filter-body-functions
605 org-export-filter-final-output-functions
)
607 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
608 (org-export-as (org-test-default-backend)
609 nil nil nil
'(:with-timestamps nil
)))))))
613 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
614 (org-test-with-temp-text
615 "<2012-03-29 Thu>[2012-03-29 Thu]
617 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
618 (org-export-as (org-test-default-backend)
619 nil nil nil
'(:with-timestamps active
)))))
623 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
624 (org-test-with-temp-text
625 "<2012-03-29 Thu>[2012-03-29 Thu]
627 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
628 (org-export-as (org-test-default-backend)
629 nil nil nil
'(:with-timestamps inactive
))))))
631 (ert-deftest test-org-export
/comment-tree
()
632 "Test if export process ignores commented trees."
635 (let (org-export-filter-body-functions
636 org-export-filter-final-output-functions
)
637 (org-test-with-temp-text "* COMMENT Head1"
638 (org-export-as (org-test-default-backend)))))))
640 (ert-deftest test-org-export
/uninterpreted
()
641 "Test handling of uninterpreted elements."
645 (org-test-with-temp-text "\\alpha"
647 (org-export-create-backend
648 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
649 (paragraph .
(lambda (p c i
) c
))
650 (section .
(lambda (s c i
) c
))))
651 nil nil nil
'(:with-entities t
)))))
654 (org-test-with-temp-text "\\alpha"
656 (org-export-create-backend
657 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
658 (paragraph .
(lambda (p c i
) c
))
659 (section .
(lambda (s c i
) c
))))
660 nil nil nil
'(:with-entities nil
)))))
664 (org-test-with-temp-text "*bold*"
666 (org-export-create-backend
667 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
668 (paragraph .
(lambda (p c i
) c
))
669 (section .
(lambda (s c i
) c
))))
670 nil nil nil
'(:with-emphasize t
)))))
673 (org-test-with-temp-text "*bold*"
675 (org-export-create-backend
676 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
677 (paragraph .
(lambda (p c i
) c
))
678 (section .
(lambda (s c i
) c
))))
679 nil nil nil
'(:with-emphasize nil
)))))
680 ;; LaTeX environment.
683 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
685 (org-export-create-backend
686 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
687 (section .
(lambda (s c i
) c
))))
688 nil nil nil
'(:with-latex t
)))))
690 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
691 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
693 (org-export-create-backend
694 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
695 (section .
(lambda (s c i
) c
))))
696 nil nil nil
'(:with-latex verbatim
)))))
700 (org-test-with-temp-text "$1$"
702 (org-export-create-backend
703 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
704 (paragraph .
(lambda (p c i
) c
))
705 (section .
(lambda (s c i
) c
))))
706 nil nil nil
'(:with-latex t
)))))
709 (org-test-with-temp-text "$1$"
711 (org-export-create-backend
712 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
713 (paragraph .
(lambda (p c i
) c
))
714 (section .
(lambda (s c i
) c
))))
715 nil nil nil
'(:with-latex verbatim
)))))
719 (org-test-with-temp-text "a_b"
721 (org-export-create-backend
722 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
723 (paragraph .
(lambda (p c i
) c
))
724 (section .
(lambda (s c i
) c
))))
725 nil nil nil
'(:with-sub-superscript t
)))))
728 (org-test-with-temp-text "a_b"
730 (org-export-create-backend
731 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
732 (paragraph .
(lambda (p c i
) c
))
733 (section .
(lambda (s c i
) c
))))
734 nil nil nil
'(:with-sub-superscript nil
)))))
737 (org-test-with-temp-text "a_b"
739 (org-export-create-backend
740 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
741 (paragraph .
(lambda (p c i
) c
))
742 (section .
(lambda (s c i
) c
))))
743 nil nil nil
'(:with-sub-superscript
{})))))
746 (org-test-with-temp-text "a_{b}"
748 (org-export-create-backend
749 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
750 (paragraph .
(lambda (p c i
) c
))
751 (section .
(lambda (s c i
) c
))))
752 nil nil nil
'(:with-sub-superscript
{})))))
753 ;; Also handle uninterpreted objects in title.
756 (org-test-with-temp-text "#+TITLE: a_b"
758 (org-export-create-backend
760 '((subscript .
(lambda (s c i
) "dummy"))
761 (template .
(lambda (c i
) (org-export-data
762 (plist-get i
:title
) i
)))
763 (section .
(lambda (s c i
) c
))))
764 nil nil nil
'(:with-sub-superscript nil
)))))
765 ;; Special case: multiples uninterpreted objects in a row.
768 (org-test-with-temp-text "a_b_c_d"
770 (org-export-create-backend
771 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
772 (paragraph .
(lambda (p c i
) c
))
773 (section .
(lambda (s c i
) c
))))
774 nil nil nil
'(:with-sub-superscript
{}))))))
776 (ert-deftest test-org-export
/export-scope
()
777 "Test all export scopes."
778 (org-test-with-temp-text "
785 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
786 "text\n*** Head3\n"))
788 (goto-char (point-min))
791 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
794 (goto-char (point-min))
796 (transient-mark-mode 1)
797 (push-mark (point) t t
)
798 (goto-char (point-at-eol))
799 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
800 ;; Subtree with a code block calling another block outside.
801 (let ((org-export-babel-evaluate t
))
804 (org-test-with-temp-text "
806 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
811 #+BEGIN_SRC emacs-lisp
815 (org-export-as (org-test-default-backend) 'subtree
)))))
817 (let ((backend (org-test-default-backend)))
818 (setf (org-export-backend-transcoders backend
)
819 (cons '(template .
(lambda (body i
)
820 (format "BEGIN\n%sEND" body
)))
821 (org-export-backend-transcoders backend
)))
822 (org-test-with-temp-text "Text"
823 (should (equal (org-export-as backend nil nil
'body-only
)
825 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
827 (ert-deftest test-org-export
/output-file-name
()
828 "Test `org-export-output-file-name' specifications."
829 ;; Export from a file: name is built from original file name.
831 (org-test-with-temp-text-in-file "Test"
832 (equal (concat (file-name-as-directory ".")
833 (file-name-nondirectory
834 (file-name-sans-extension (buffer-file-name))))
835 (file-name-sans-extension (org-export-output-file-name ".ext")))))
836 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
838 (org-test-with-temp-text-in-file
839 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
840 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
841 ;; From a buffer not associated to a file, too.
843 (org-test-with-temp-text
844 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
845 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
846 ;; When provided name is absolute, preserve it.
848 (org-test-with-temp-text
849 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
850 (expand-file-name "test"))
851 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
852 ;; When PUB-DIR argument is provided, use it.
854 (org-test-with-temp-text-in-file "Test"
855 (equal (file-name-directory
856 (org-export-output-file-name ".ext" nil
"dir/"))
858 ;; When returned name would overwrite original file, add EXTENSION
861 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
862 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
864 (ert-deftest test-org-export
/expand-include
()
865 "Test file inclusion in an Org buffer."
866 ;; Error when file isn't specified.
868 (org-test-with-temp-text "#+INCLUDE: dummy.org"
869 (org-export-expand-include-keyword)))
870 ;; Full insertion with recursive inclusion.
875 (expand-file-name "examples/include.org" org-test-dir
))
876 (replace-regexp-in-string
877 (regexp-quote "#+INCLUDE: \"include2.org\"")
878 "Success!" (buffer-string)))
879 (org-test-with-temp-text
880 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
881 (org-export-expand-include-keyword)
883 ;; Localized insertion.
884 (org-test-with-temp-text
885 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
887 (org-export-expand-include-keyword)
888 (should (equal (buffer-string)
889 "Small Org file with an include keyword.\n")))
890 ;; Insertion with constraints on headlines level.
893 "* Top heading\n** Heading\nbody\n"
894 (org-test-with-temp-text
896 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
898 (org-export-expand-include-keyword)
902 "* Top heading\n* Heading\nbody\n"
903 (org-test-with-temp-text
905 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
907 (org-export-expand-include-keyword)
909 ;; Inclusion within an example block.
912 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
913 (org-test-with-temp-text
914 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
916 (org-export-expand-include-keyword)
918 ;; Inclusion within a src-block.
921 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
922 (org-test-with-temp-text
924 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
926 (org-export-expand-include-keyword)
928 ;; Inclusion within an html export-block.
931 "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
932 (org-test-with-temp-text
934 "#+INCLUDE: \"%s/examples/include.html\" HTML"
936 (org-export-expand-include-keyword)
938 ;; Inclusion within an center paragraph
941 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
942 (org-test-with-temp-text
944 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
946 (org-export-expand-include-keyword)
948 ;; Footnotes labels are local to each included file.
954 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
956 \[fn:test] Footnote \"test\""))
957 (org-test-with-temp-text-in-file contents
958 (let ((file1 (buffer-file-name)))
959 (org-test-with-temp-text-in-file contents
960 (let ((file2 (buffer-file-name)))
961 (org-test-with-temp-text
962 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
964 (org-export-expand-include-keyword)
965 (org-element-map (org-element-parse-buffer)
968 (org-element-property :label ref
)))))))))))))
969 ;; Footnotes labels are not local to each include keyword.
975 Footnotes[fn:1], [fn:test], [2] and [fn:inline:anonymous footnote].
978 \[fn:test] Footnote \"test\""))
979 (org-test-with-temp-text-in-file contents
980 (let ((file (buffer-file-name)))
981 (org-test-with-temp-text
982 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
983 (org-export-expand-include-keyword)
984 (org-element-map (org-element-parse-buffer)
986 (lambda (ref) (org-element-property :label ref
)))))))))))
987 ;; Footnotes are supported by :lines-like elements and unnecessary
988 ;; footnotes are dropped.
997 Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote]
1002 \[fn:test] Footnote \"test\"
1005 (org-test-with-temp-text-in-file contents
1006 (let ((file (buffer-file-name)))
1007 (org-test-with-temp-text
1008 (format "#+INCLUDE: \"%s::*bar\"
1010 (org-export-expand-include-keyword)
1011 (org-element-map (org-element-parse-buffer)
1012 'footnote-definition
1013 (lambda (ref) (org-element-property :label ref
)))))))))))
1014 ;; If only-contents is non-nil only include contents of element.
1018 (org-test-with-temp-text
1020 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" " org-test-dir
)
1022 (org-export-expand-include-keyword)
1024 ;; Headings can be included via CUSTOM_ID.
1026 (org-test-with-temp-text
1027 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1028 (org-export-expand-include-keyword)
1029 (goto-char (point-min))
1030 (looking-at "* Another heading")))
1031 ;; Named objects can be included.
1035 (org-test-with-temp-text
1036 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t" org-test-dir
)
1037 (org-export-expand-include-keyword)
1039 ;; Including non-existing elements should result in an error.
1041 (org-test-with-temp-text
1042 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\"" org-test-dir
)
1043 (org-export-expand-include-keyword)))
1044 ;; Lines work relatively to an included element.
1048 (org-test-with-temp-text
1049 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t :lines \"2-3\"" org-test-dir
)
1050 (org-export-expand-include-keyword)
1052 ;; Properties should be dropped from headlines.
1055 (org-test-with-temp-text
1056 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t" org-test-dir
)
1057 (org-export-expand-include-keyword)
1059 (org-test-with-temp-text
1060 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1061 (org-export-expand-include-keyword)
1063 ;; Properties should be dropped, drawers should not be.
1066 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1067 (org-test-with-temp-text
1068 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir
)
1069 (org-export-expand-include-keyword)
1071 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1073 (org-every (lambda (level) (zerop (1- level
)))
1074 (org-test-with-temp-text
1076 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n" org-test-dir
)
1077 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\"" org-test-dir
))
1078 (org-export-expand-include-keyword)
1079 (org-element-map (org-element-parse-buffer) 'headline
1080 (lambda (head) (org-element-property :level head
))))))
1081 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1084 (org-test-with-temp-text
1085 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp" org-test-dir
)
1086 (org-export-expand-include-keyword)
1088 (org-test-with-temp-text
1089 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1" org-test-dir
)
1090 (org-export-expand-include-keyword)
1092 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1094 (org-test-with-temp-text-in-file
1095 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1096 (narrow-to-region (point) (point-max))
1097 (org-export-expand-include-keyword)
1098 (eq 1 (org-current-level))))
1099 ;; If :minlevel is present do not alter it.
1101 (org-test-with-temp-text
1102 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3" org-test-dir
)
1103 (narrow-to-region (point) (point-max))
1104 (org-export-expand-include-keyword)
1105 (eq 3 (org-current-level)))))
1107 (ert-deftest test-org-export
/expand-macro
()
1108 "Test macro expansion in an Org buffer."
1109 ;; Standard macro expansion.
1111 (equal "#+MACRO: macro1 value\nvalue\n"
1112 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1113 (org-export-as (org-test-default-backend)))))
1114 ;; Allow macro in parsed keywords and associated properties.
1115 ;; Standard macro expansion.
1119 (let ((backend (org-export-create-backend
1121 :options
'((:k
"K" nil nil parse
)))))
1122 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1123 (org-export-as backend
)))))
1127 (let ((backend (org-export-create-backend
1129 :options
'((:k
"K" nil nil parse
)))))
1130 (org-test-with-temp-text
1131 "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1132 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1133 ;; Expand specific macros.
1135 (equal "me 2012-03-29 me@here Title\n"
1136 (org-test-with-temp-text
1142 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1143 (let ((output (org-export-as (org-test-default-backend))))
1144 (substring output
(string-match ".*\n\\'" output
))))))
1145 ;; Expand specific macros when property contained a regular macro
1149 (org-test-with-temp-text "
1150 #+MACRO: macro1 value
1151 #+TITLE: {{{macro1}}}
1153 (let ((output (org-export-as (org-test-default-backend))))
1154 (substring output
(string-match ".*\n\\'" output
))))))
1155 ;; Expand macros with templates in included files.
1158 (org-test-with-temp-text
1159 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1160 {{{included-macro}}}" org-test-dir
)
1161 (let ((output (org-export-as (org-test-default-backend))))
1162 (substring output
(string-match ".*\n\\'" output
))))))
1163 ;; Date macro takes a optional formatting argument
1166 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1167 (org-export-as (org-test-default-backend)))))
1168 ;; Only single timestamps are formatted
1170 (equal "<2015-02x-09>\n"
1171 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1172 (org-export-as (org-test-default-backend)))))
1173 ;; Throw an error when a macro definition is missing.
1175 (org-test-with-temp-text "{{{missing}}}"
1176 (org-export-as (org-test-default-backend))))
1177 ;; Macros defined in commented subtrees are ignored.
1179 (org-test-with-temp-text
1180 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1181 (org-export-as (org-test-default-backend))))
1183 (org-test-with-temp-text
1184 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1185 (org-export-as (org-test-default-backend)))))
1187 (ert-deftest test-org-export
/before-processing-hook
()
1188 "Test `org-export-before-processing-hook'."
1191 "#+MACRO: mac val\nTest\n"
1192 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1193 (let ((org-export-before-processing-hook
1195 (while (re-search-forward "{{{" nil t
)
1196 (let ((object (org-element-context)))
1197 (when (eq (org-element-type object
) 'macro
)
1199 (org-element-property :begin object
)
1200 (org-element-property :end object
)))))))))
1201 (org-export-as (org-test-default-backend)))))))
1203 (ert-deftest test-org-export
/before-parsing-hook
()
1204 "Test `org-export-before-parsing-hook'."
1206 (equal "Body 1\nBody 2\n"
1207 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1208 (let ((org-export-before-parsing-hook
1210 (goto-char (point-min))
1211 (while (re-search-forward org-outline-regexp-bol nil t
)
1213 (point-at-bol) (progn (forward-line) (point))))))))
1214 (org-export-as (org-test-default-backend)))))))
1218 ;;; Affiliated Keywords
1220 (ert-deftest test-org-export
/read-attribute
()
1221 "Test `org-export-read-attribute' specifications."
1225 (org-export-read-attribute
1227 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1228 (org-element-at-point)))
1230 ;; Return nil on empty attribute.
1232 (org-export-read-attribute
1234 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1235 ;; Return nil on "nil" string.
1237 (equal '(:a nil
:b nil
)
1238 (org-export-read-attribute
1240 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1241 (org-element-at-point)))))
1242 ;; Return nil on empty string.
1244 (equal '(:a nil
:b nil
)
1245 (org-export-read-attribute
1247 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1248 (org-element-at-point)))))
1249 ;; Return empty string when value is "".
1252 (org-export-read-attribute
1254 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1255 (org-element-at-point)))))
1256 ;; Return \"\" when value is """".
1259 (org-export-read-attribute
1261 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1262 (org-element-at-point)))))
1263 ;; Ignore text before first property.
1266 (org-export-read-attribute
1268 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1269 (org-element-at-point))))))
1271 (ert-deftest test-org-export
/get-caption
()
1272 "Test `org-export-get-caption' specifications."
1273 ;; Without optional argument, return long caption
1277 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1278 (org-export-get-caption (org-element-at-point)))))
1279 ;; With optional argument, return short caption.
1283 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1284 (org-export-get-caption (org-element-at-point) t
))))
1285 ;; Multiple lines are separated by white spaces.
1289 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1290 (org-export-get-caption (org-element-at-point))))))
1296 (ert-deftest test-org-export
/define-backend
()
1297 "Test back-end definition and accessors."
1300 (equal '((headline . my-headline-test
))
1301 (let (org-export-registered-backends)
1302 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1303 (org-export-get-all-transcoders 'test
))))
1306 (equal '((:filter-headline . my-filter
))
1307 (let (org-export-registered-backends)
1308 (org-export-define-backend 'test
1309 '((headline . my-headline-test
))
1310 :filters-alist
'((:filter-headline . my-filter
)))
1311 (org-export-backend-filters (org-export-get-backend 'test
)))))
1314 (equal '((:prop value
))
1315 (let (org-export-registered-backends)
1316 (org-export-define-backend 'test
1317 '((headline . my-headline-test
))
1318 :options-alist
'((:prop value
)))
1319 (org-export-backend-options (org-export-get-backend 'test
)))))
1322 (equal '(?k
"Test Export" test
)
1323 (let (org-export-registered-backends)
1324 (org-export-define-backend 'test
1325 '((headline . my-headline-test
))
1326 :menu-entry
'(?k
"Test Export" test
))
1327 (org-export-backend-menu (org-export-get-backend 'test
)))))
1330 (equal '(("TEST" . org-element-export-block-parser
))
1331 (let (org-export-registered-backends org-element-block-name-alist
)
1332 (org-export-define-backend 'test
1333 '((headline . my-headline-test
))
1334 :export-block
'("test"))
1335 org-element-block-name-alist
))))
1337 (ert-deftest test-org-export
/define-derived-backend
()
1338 "Test `org-export-define-derived-backend' specifications."
1339 ;; Error when parent back-end is not defined.
1341 (let (org-export-registered-backends)
1342 (org-export-define-derived-backend 'test
'parent
)))
1343 ;; Append translation table to parent's.
1345 (equal '((:headline . test
) (:headline . parent
))
1346 (let (org-export-registered-backends)
1347 (org-export-define-backend 'parent
'((:headline . parent
)))
1348 (org-export-define-derived-backend 'test
'parent
1349 :translate-alist
'((:headline . test
)))
1350 (org-export-get-all-transcoders 'test
))))
1351 ;; Options defined in the new back have priority over those defined
1355 (let (org-export-registered-backends)
1356 (org-export-define-backend 'parent
1357 '((:headline . parent
))
1358 :options-alist
'((:a nil nil
'parent
)))
1359 (org-export-define-derived-backend 'test
'parent
1360 :options-alist
'((:a nil nil
'test
)))
1361 (plist-get (org-export--get-global-options
1362 (org-export-get-backend 'test
))
1365 (ert-deftest test-org-export
/derived-backend-p
()
1366 "Test `org-export-derived-backend-p' specifications."
1367 ;; Non-nil with direct match.
1369 (let (org-export-registered-backends)
1370 (org-export-define-backend 'test
'((headline . test
)))
1371 (org-export-derived-backend-p 'test
'test
)))
1373 (let (org-export-registered-backends)
1374 (org-export-define-backend 'test
'((headline . test
)))
1375 (org-export-define-derived-backend 'test2
'test
)
1376 (org-export-derived-backend-p 'test2
'test2
)))
1377 ;; Non-nil with a direct parent.
1379 (let (org-export-registered-backends)
1380 (org-export-define-backend 'test
'((headline . test
)))
1381 (org-export-define-derived-backend 'test2
'test
)
1382 (org-export-derived-backend-p 'test2
'test
)))
1383 ;; Non-nil with an indirect parent.
1385 (let (org-export-registered-backends)
1386 (org-export-define-backend 'test
'((headline . test
)))
1387 (org-export-define-derived-backend 'test2
'test
)
1388 (org-export-define-derived-backend 'test3
'test2
)
1389 (org-export-derived-backend-p 'test3
'test
)))
1392 (let (org-export-registered-backends)
1393 (org-export-define-backend 'test
'((headline . test
)))
1394 (org-export-define-backend 'test2
'((headline . test2
)))
1395 (org-export-derived-backend-p 'test2
'test
)))
1397 (let (org-export-registered-backends)
1398 (org-export-define-backend 'test
'((headline . test
)))
1399 (org-export-define-backend 'test2
'((headline . test2
)))
1400 (org-export-define-derived-backend 'test3
'test2
)
1401 (org-export-derived-backend-p 'test3
'test
))))
1403 (ert-deftest test-org-export
/get-all-transcoders
()
1404 "Test `org-export-get-all-transcoders' specifications."
1405 ;; Return nil when back-end cannot be found.
1406 (should-not (org-export-get-all-transcoders nil
))
1407 ;; Same as `org-export-transcoders' if no parent.
1409 (equal '((headline . ignore
))
1410 (org-export-get-all-transcoders
1411 (org-export-create-backend
1412 :transcoders
'((headline . ignore
))))))
1413 ;; But inherit from all ancestors whenever possible.
1415 (equal '((section . ignore
) (headline . ignore
))
1416 (let (org-export-registered-backends)
1417 (org-export-define-backend 'b1
'((headline . ignore
)))
1418 (org-export-get-all-transcoders
1419 (org-export-create-backend
1420 :parent
'b1
:transcoders
'((section . ignore
)))))))
1422 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1423 (let (org-export-registered-backends)
1424 (org-export-define-backend 'b1
'((headline . ignore
)))
1425 (org-export-define-derived-backend 'b2
'b1
1426 :translate-alist
'((section . ignore
)))
1427 (org-export-get-all-transcoders
1428 (org-export-create-backend
1429 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1430 ;; Back-end transcoders overrule inherited ones.
1433 (let (org-export-registered-backends)
1434 (org-export-define-backend 'b1
'((headline . a
)))
1435 (cdr (assq 'headline
1436 (org-export-get-all-transcoders
1437 (org-export-create-backend
1438 :parent
'b1
:transcoders
'((headline . b
))))))))))
1440 (ert-deftest test-org-export
/get-all-options
()
1441 "Test `org-export-get-all-options' specifications."
1442 ;; Return nil when back-end cannot be found.
1443 (should-not (org-export-get-all-options nil
))
1444 ;; Same as `org-export-options' if no parent.
1446 (equal '((headline . ignore
))
1447 (org-export-get-all-options
1448 (org-export-create-backend
1449 :options
'((headline . ignore
))))))
1450 ;; But inherit from all ancestors whenever possible.
1452 (equal '((:key2 value2
) (:key1 value1
))
1453 (let (org-export-registered-backends)
1454 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1455 (org-export-get-all-options
1456 (org-export-create-backend
1457 :parent
'b1
:options
'((:key2 value2
)))))))
1459 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1460 (let (org-export-registered-backends)
1461 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1462 (org-export-define-derived-backend 'b2
'b1
1463 :options-alist
'((:key2 value2
)))
1464 (org-export-get-all-options
1465 (org-export-create-backend
1466 :parent
'b2
:options
'((:key3 value3
)))))))
1467 ;; Back-end options overrule inherited ones.
1470 (let (org-export-registered-backends)
1471 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1473 (org-export-get-all-options
1474 (org-export-create-backend
1475 :parent
'b1
:options
'((:key1 . b
))))))))))
1477 (ert-deftest test-org-export
/get-all-filters
()
1478 "Test `org-export-get-all-filters' specifications."
1479 ;; Return nil when back-end cannot be found.
1480 (should-not (org-export-get-all-filters nil
))
1481 ;; Same as `org-export-filters' if no parent.
1483 (equal '((:filter-headline . ignore
))
1484 (org-export-get-all-filters
1485 (org-export-create-backend
1486 :filters
'((:filter-headline . ignore
))))))
1487 ;; But inherit from all ancestors whenever possible.
1489 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1490 (let (org-export-registered-backends)
1491 (org-export-define-backend 'b1
1492 nil
:filters-alist
'((:filter-headline . ignore
)))
1493 (org-export-get-all-filters
1494 (org-export-create-backend
1495 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1497 (equal '((:filter-paragraph . ignore
)
1498 (:filter-section . ignore
)
1499 (:filter-headline . ignore
))
1500 (let (org-export-registered-backends)
1501 (org-export-define-backend 'b1
1502 nil
:filters-alist
'((:filter-headline . ignore
)))
1503 (org-export-define-derived-backend 'b2
'b1
1504 :filters-alist
'((:filter-section . ignore
)))
1505 (org-export-get-all-filters
1506 (org-export-create-backend
1507 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1508 ;; Back-end filters overrule inherited ones.
1511 (let (org-export-registered-backends)
1512 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1513 (cdr (assq :filter-headline
1514 (org-export-get-all-filters
1515 (org-export-create-backend
1516 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1518 (ert-deftest test-org-export
/with-backend
()
1519 "Test `org-export-with-backend' definition."
1520 ;; Error when calling an undefined back-end
1521 (should-error (org-export-with-backend nil
"Test"))
1522 ;; Error when called back-end doesn't have an appropriate
1525 (org-export-with-backend
1526 (org-export-create-backend :transcoders
'((headline . ignore
)))
1528 ;; Otherwise, export using correct transcoder
1531 (let (org-export-registered-backends)
1532 (org-export-define-backend 'test
1533 '((plain-text .
(lambda (text contents info
) "Failure"))))
1534 (org-export-define-backend 'test2
1535 '((plain-text .
(lambda (text contents info
) "Success"))))
1536 (org-export-with-backend 'test2
"Test"))))
1537 ;; Provide correct back-end if transcoder needs to use recursive
1541 (let ((test-back-end
1542 (org-export-create-backend
1544 '((headline .
(lambda (headline contents info
)
1546 (org-element-property :title headline
)
1548 (plain-text .
(lambda (text info
) "Success"))))))
1549 (org-export-string-as
1551 (org-export-create-backend
1553 '((headline .
(lambda (headline contents info
)
1554 (org-export-with-backend
1555 test-back-end headline contents info
))))))))))
1557 (ert-deftest test-org-export
/data-with-backend
()
1558 "Test `org-export-data-with-backend' specifications."
1559 ;; Error when calling an undefined back-end.
1560 (should-error (org-export-data-with-backend nil
"nil" nil
))
1561 ;; Otherwise, export data recursively, using correct back-end.
1565 (org-export-data-with-backend
1567 (org-export-create-backend
1569 '((plain-text .
(lambda (text info
) "Success"))
1570 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1571 '(:with-emphasize t
)))))
1577 (ert-deftest test-org-export
/export-snippet
()
1578 "Test export snippets transcoding."
1580 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1581 (let ((backend (org-test-default-backend)))
1582 (setf (org-export-backend-name backend
) 'test
)
1583 (setf (org-export-backend-transcoders backend
)
1584 (cons (cons 'export-snippet
1585 (lambda (snippet contents info
)
1586 (when (eq (org-export-snippet-backend snippet
) 'test
)
1587 (org-element-property :value snippet
))))
1588 (org-export-backend-transcoders backend
)))
1589 (let ((org-export-snippet-translation-alist nil
))
1590 (should (equal (org-export-as backend
) "A\n")))
1591 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1592 (should (equal (org-export-as backend
) "AB\n")))))
1593 ;; Ignored export snippets do not remove any blank.
1595 (equal "begin end\n"
1596 (org-test-with-parsed-data "begin @@test:A@@ end"
1597 (org-export-data-with-backend
1599 (org-export-create-backend
1601 '((paragraph .
(lambda (paragraph contents info
) contents
))
1602 (section .
(lambda (section contents info
) contents
))))
1609 (ert-deftest test-org-export
/footnote-first-reference-p
()
1610 "Test `org-export-footnote-first-reference-p' specifications."
1614 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1617 (org-export-create-backend
1619 `(,(cons 'footnote-reference
1621 (push (org-export-footnote-first-reference-p f info
)
1624 (section .
(lambda (s c i
) c
))
1625 (paragraph .
(lambda (p c i
) c
))))
1626 nil nil nil
'(:with-footnotes t
))
1627 (nreverse result
)))))
1628 ;; Limit check to DATA, when non-nil.
1632 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1634 (org-element-map tree
'footnote-reference
1637 (org-export-footnote-first-reference-p
1638 ref info
(org-element-map tree
'headline
#'identity info t
))
1641 (nreverse result
)))))
1645 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1647 (org-element-map tree
'footnote-reference
1649 (push (org-export-footnote-first-reference-p ref info
) result
))
1651 (nreverse result
)))))
1652 ;; If optional argument BODY-FIRST is non-nil, first find footnote
1653 ;; in the main body of the document. Otherwise, enter footnote
1654 ;; definitions when they are encountered.
1658 (org-test-with-temp-text
1659 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1662 (org-export-create-backend
1664 `(,(cons 'footnote-reference
1666 (when (org-element-lineage f
'(drawer))
1667 (push (org-export-footnote-first-reference-p f info nil
)
1670 (drawer .
(lambda (d c i
) c
))
1671 (footnote-definition .
(lambda (d c i
) c
))
1672 (section .
(lambda (s c i
) c
))
1673 (paragraph .
(lambda (p c i
) c
))))
1674 nil nil nil
'(:with-footnotes t
))
1675 (nreverse result
)))))
1679 (org-test-with-temp-text
1680 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1683 (org-export-create-backend
1685 `(,(cons 'footnote-reference
1687 (when (org-element-lineage f
'(drawer))
1688 (push (org-export-footnote-first-reference-p f info nil t
)
1691 (drawer .
(lambda (d c i
) c
))
1692 (footnote-definition .
(lambda (d c i
) c
))
1693 (section .
(lambda (s c i
) c
))
1694 (paragraph .
(lambda (p c i
) c
))))
1695 nil nil nil
'(:with-footnotes t
))
1696 (nreverse result
))))))
1698 (ert-deftest test-org-export
/get-footnote-number
()
1699 "Test `org-export-get-footnote-number' specifications."
1702 (org-test-with-parsed-data
1703 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
1704 (org-element-map tree
'footnote-reference
1705 (lambda (ref) (org-export-get-footnote-number ref info
))
1707 ;; Anonymous footnotes all get a new number.
1710 (org-test-with-parsed-data
1711 "Text[fn::anon1][fn::anon2]"
1712 (org-element-map tree
'footnote-reference
1713 (lambda (ref) (org-export-get-footnote-number ref info
))
1715 ;; Test nested footnotes order.
1718 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (3 .
"fn:3") (4))
1719 (org-test-with-parsed-data
1720 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1721 (org-element-map tree
'footnote-reference
1723 (cons (org-export-get-footnote-number ref info
)
1724 (org-element-property :label ref
)))
1726 ;; Limit number to provided DATA, when non-nil.
1730 (org-test-with-parsed-data
1731 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1732 (org-element-map tree
'footnote-reference
1734 (org-export-get-footnote-number
1735 ref info
(org-element-map tree
'headline
#'identity info t
)))
1740 (org-test-with-parsed-data
1741 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
1742 (org-element-map tree
'footnote-reference
1743 (lambda (ref) (org-export-get-footnote-number ref info
))
1745 ;; With a non-nil BODY-FIRST optional argument, first check body,
1746 ;; then footnote definitions.
1749 '(("fn:1" .
1) ("fn:2" .
2) ("fn:3" .
3) ("fn:3" .
3))
1750 (org-test-with-parsed-data
1751 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1752 (org-element-map tree
'footnote-reference
1754 (cons (org-element-property :label ref
)
1755 (org-export-get-footnote-number ref info nil t
)))
1759 '(("fn:1" .
1) ("fn:2" .
3) ("fn:3" .
2) ("fn:3" .
2))
1760 (org-test-with-parsed-data
1761 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1762 (org-element-map tree
'footnote-reference
1764 (cons (org-element-property :label ref
)
1765 (org-export-get-footnote-number ref info nil
)))
1768 (ert-deftest test-org-export
/collect-footnote-definitions
()
1769 "Test `org-export-collect-footnote-definitions' specifications."
1772 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1774 \[fn:2] B [fn:3] [fn::D].
1777 (length (org-export-collect-footnote-definitions info
)))))
1778 ;; Limit number to provided DATA, when non-nil.
1782 (org-test-with-parsed-data
1783 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1785 (org-export-collect-footnote-definitions
1786 info
(org-element-map tree
'headline
#'identity info t
))))))
1789 '((1 "fn:1") (2 "fn:2"))
1790 (org-test-with-parsed-data
1791 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1792 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
1793 ;; With optional argument BODY-FIRST, first check body, then
1794 ;; footnote definitions.
1796 (equal '("fn:1" "fn:3" "fn:2" nil
)
1797 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1799 \[fn:2] B [fn:3] [fn::D].
1802 (mapcar (lambda (e) (nth 1 e
))
1803 (org-export-collect-footnote-definitions info nil t
)))))
1805 (equal '("fn:1" "fn:3" "fn:2" nil
)
1806 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1808 \[fn:2] B [fn:3] [fn::D].
1811 (mapcar (lambda (e) (nth 1 e
))
1812 (org-export-collect-footnote-definitions info
))))))
1814 (ert-deftest test-org-export
/footnotes
()
1815 "Miscellaneous tests on footnotes."
1816 (let ((org-footnote-section nil
)
1817 (org-export-with-footnotes t
))
1818 ;; Read every type of footnote.
1821 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1822 (org-test-with-parsed-data
1823 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1824 (org-element-map tree
'footnote-reference
1826 (let ((def (org-export-get-footnote-definition ref info
)))
1827 (cons (org-export-get-footnote-number ref info
)
1828 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1829 (car (org-element-contents
1830 (car (org-element-contents def
))))))))
1832 ;; Test nested footnote in invisible definitions.
1835 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1836 (narrow-to-region (point) (line-end-position))
1839 (org-export-create-backend
1844 (throw 'exit
(length
1845 (org-export-collect-footnote-definitions
1847 ;; Test export of footnotes defined outside parsing scope.
1850 "ParagraphOut of scope\n"
1851 (org-test-with-temp-text "[fn:1] Out of scope
1853 <point>Paragraph[fn:1]"
1854 (let ((backend (org-test-default-backend)))
1855 (setf (org-export-backend-transcoders backend
)
1857 (list (cons 'footnote-reference
1858 (lambda (fn contents info
)
1859 (org-element-interpret-data
1860 (org-export-get-footnote-definition fn info
))))
1861 (cons 'footnote-definition
#'ignore
)
1862 (cons 'headline
#'ignore
))
1863 (org-export-backend-transcoders backend
)))
1864 (org-export-as backend
'subtree
)))))
1865 ;; Footnotes without a definition should throw an error.
1867 (org-test-with-parsed-data "Text[fn:1]"
1868 (org-export-get-footnote-definition
1869 (org-element-map tree
'footnote-reference
#'identity info t
) info
)))
1870 ;; Footnote section should be ignored in TOC and in headlines
1873 (= 1 (let ((org-footnote-section "Footnotes"))
1874 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1875 (org-export-collect-headlines info
))))))
1878 (let ((org-footnote-section "Footnotes"))
1879 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1880 (org-element-map tree
'headline
1882 (when (equal (org-element-property :raw-value hl
) "H2")
1883 (org-export-get-headline-number hl info
)))
1888 ;;; Headlines and Inlinetasks
1890 (ert-deftest test-org-export
/get-relative-level
()
1891 "Test `org-export-get-relative-level' specifications."
1895 (let ((org-odd-levels-only nil
))
1896 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1897 (org-element-map tree
'headline
1898 (lambda (h) (org-export-get-relative-level h info
))
1903 (let ((org-odd-levels-only nil
))
1904 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1905 (org-element-map tree
'headline
1906 (lambda (h) (org-export-get-relative-level h info
))
1909 (ert-deftest test-org-export
/low-level-p
()
1910 "Test `org-export-low-level-p' specifications."
1914 (let ((org-odd-levels-only nil
))
1915 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1916 (org-element-map tree
'headline
1917 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1918 (plist-put info
:headline-levels
1)))))))
1920 (ert-deftest test-org-export
/get-headline-number
()
1921 "Test `org-export-get-headline-number' specifications."
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
))
1931 ;; Missing levels are replaced with 0.
1935 (let ((org-odd-levels-only nil
))
1936 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1937 (org-element-map tree
'headline
1938 (lambda (h) (org-export-get-headline-number h info
))
1941 (ert-deftest test-org-export
/numbered-headline-p
()
1942 "Test `org-export-numbered-headline-p' specifications."
1943 ;; If `:section-numbers' is nil, never number headlines.
1945 (org-test-with-parsed-data "* Headline"
1946 (org-element-map tree
'headline
1947 (lambda (h) (org-export-numbered-headline-p h info
))
1948 (plist-put info
:section-numbers nil
))))
1949 ;; If `:section-numbers' is a number, only number headlines with
1950 ;; a level greater that it.
1954 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1955 (org-element-map tree
'headline
1956 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1957 (plist-put info
:section-numbers
1)))))
1958 ;; Otherwise, headlines are always numbered.
1960 (org-test-with-parsed-data "* Headline"
1961 (org-element-map tree
'headline
1962 (lambda (h) (org-export-numbered-headline-p h info
))
1963 (plist-put info
:section-numbers t
))))
1964 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
1966 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
1967 (org-export-numbered-headline-p
1968 (org-element-map tree
'headline
'identity info t
)
1970 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
1972 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
1973 (org-export-numbered-headline-p
1974 (org-element-map tree
'headline
#'identity info t
)
1976 ;; UNNUMBERED ignores inheritance. Any non-nil value among
1977 ;; ancestors disables numbering.
1979 (org-test-with-parsed-data
1990 (lambda (h) (not (org-export-numbered-headline-p h info
)))
1991 (org-element-map tree
'headline
#'identity info
)))))
1993 (ert-deftest test-org-export
/number-to-roman
()
1994 "Test `org-export-number-to-roman' specifications."
1995 ;; If number is negative, return it as a string.
1996 (should (equal (org-export-number-to-roman -
1) "-1"))
1997 ;; Otherwise, return it as a roman number.
1998 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
2000 (ert-deftest test-org-export
/get-optional-title
()
2001 "Test `org-export-get-alt-title' specifications."
2002 ;; If ALT_TITLE property is defined, use it.
2005 (org-test-with-parsed-data
2006 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
2007 (org-export-get-alt-title
2008 (org-element-map tree
'headline
'identity info t
)
2010 ;; Otherwise, fall-back to regular title.
2012 (equal '("Headline")
2013 (org-test-with-parsed-data "* Headline"
2014 (org-export-get-alt-title
2015 (org-element-map tree
'headline
'identity info t
)
2018 (ert-deftest test-org-export
/get-tags
()
2019 "Test `org-export-get-tags' specifications."
2020 (let ((org-export-exclude-tags '("noexport"))
2021 (org-export-select-tags '("export")))
2022 ;; Standard test: tags which are not a select tag, an exclude tag,
2023 ;; or specified as optional argument shouldn't be ignored.
2025 (org-test-with-parsed-data "* Headline :tag:"
2026 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2028 ;; Exclude tags are removed.
2030 (org-test-with-parsed-data "* Headline :noexport:"
2031 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2033 ;; Select tags are removed.
2035 (org-test-with-parsed-data "* Headline :export:"
2036 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2041 (org-test-with-parsed-data "* Headline :tag:export:"
2042 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2044 ;; Tags provided in the optional argument are also ignored.
2046 (org-test-with-parsed-data "* Headline :ignore:"
2047 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2049 ;; Allow tag inheritance.
2053 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2054 (org-element-map tree
'headline
2055 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2056 ;; Tag inheritance checks FILETAGS keywords.
2060 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2061 (org-element-map tree
'headline
2062 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
2064 (ert-deftest test-org-export
/get-node-property
()
2065 "Test`org-export-get-node-property' specifications."
2069 (org-test-with-parsed-data "* Headline
2073 (org-export-get-node-property
2074 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2075 ;; Test inheritance.
2078 (org-test-with-parsed-data "* Parent
2084 (org-export-get-node-property
2085 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2086 ;; Cannot return a value before the first headline.
2088 (org-test-with-parsed-data "Paragraph
2093 (org-export-get-node-property
2094 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2096 (ert-deftest test-org-export
/get-category
()
2097 "Test `org-export-get-category' specifications."
2101 (org-test-with-parsed-data "* Headline
2105 (org-export-get-category
2106 (org-element-map tree
'headline
'identity nil t
) info
))))
2107 ;; Test inheritance from a parent headline.
2109 (equal '("value" "value")
2110 (org-test-with-parsed-data "* Headline1
2115 (org-element-map tree
'headline
2116 (lambda (hl) (org-export-get-category hl info
)) info
))))
2117 ;; Test inheritance from #+CATEGORY keyword
2120 (org-test-with-parsed-data "#+CATEGORY: value
2122 (org-export-get-category
2123 (org-element-map tree
'headline
'identity nil t
) info
))))
2124 ;; Test inheritance from file name.
2127 (org-test-with-parsed-data "* Headline"
2128 (let ((info (plist-put info
:input-file
"~/test.org")))
2129 (org-export-get-category
2130 (org-element-map tree
'headline
'identity nil t
) info
)))))
2134 (org-test-with-parsed-data "* Headline"
2135 (org-export-get-category
2136 (org-element-map tree
'headline
'identity nil t
) info
)))))
2138 (ert-deftest test-org-export
/first-sibling-p
()
2139 "Test `org-export-first-sibling-p' specifications."
2144 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2145 (org-element-map tree
'headline
2146 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2150 (org-test-with-parsed-data "- item\n\n para"
2151 (org-element-map tree
'paragraph
2152 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2154 ;; Ignore sections for headlines.
2157 (org-test-with-parsed-data "* H\nSection\n** H 2"
2158 (org-element-map tree
'headline
2159 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2161 ;; Ignore headlines not exported.
2165 (let ((org-export-exclude-tags '("ignore")))
2166 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2167 (org-element-map tree
'headline
2168 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2171 (ert-deftest test-org-export
/last-sibling-p
()
2172 "Test `org-export-last-sibling-p' specifications."
2177 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2178 (org-element-map tree
'headline
2179 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2183 (org-test-with-parsed-data "- item\n\n para"
2184 (org-element-map tree
'paragraph
2185 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2187 ;; Ignore headlines not exported.
2191 (let ((org-export-exclude-tags '("ignore")))
2192 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2193 (org-element-map tree
'headline
2194 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2197 (ert-deftest test-org-export
/handle-inlinetasks
()
2198 "Test inlinetask export."
2199 ;; Inlinetask with an exclude tag.
2200 (when (featurep 'org-inlinetask
)
2204 (let ((org-inlinetask-min-level 3)
2205 org-export-filter-body-functions
2206 org-export-filter-final-output-functions
)
2207 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2208 (org-export-as (org-test-default-backend)
2209 nil nil nil
'(:exclude-tags
("noexp")))))))
2210 ;; Inlinetask with an include tag.
2213 "* H2\n*** Inline :exp:\n"
2214 (let ((org-inlinetask-min-level 3)
2215 (org-tags-column 0))
2216 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2217 (org-export-as (org-test-default-backend)
2218 nil nil nil
'(:select-tags
("exp")))))))
2219 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2222 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2223 (org-inlinetask-min-level 3)
2224 org-export-filter-body-functions
2225 org-export-filter-final-output-functions
)
2226 (org-test-with-temp-text "*** TODO Inline"
2227 (org-export-as (org-test-default-backend)
2228 nil nil nil
'(:with-tasks nil
))))))))
2234 (ert-deftest test-org-export
/get-date
()
2235 "Test `org-export-get-date' specifications."
2236 ;; Return a properly formatted string when
2237 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2238 ;; consists in a single timestamp.
2241 (let ((org-export-date-timestamp-format "%d %m %Y"))
2242 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2243 (org-export-get-date info
)))))
2244 ;; Return a secondary string otherwise.
2247 (let ((org-export-date-timestamp-format nil
))
2248 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2249 (org-export-get-date info
)))))
2252 (org-test-with-parsed-data "#+DATE: Date"
2253 (org-export-get-date info
))))
2254 ;; Optional argument has precedence over
2255 ;; `org-export-date-timestamp-format'.
2258 (let ((org-export-date-timestamp-format "%d %m %Y"))
2259 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2260 (org-export-get-date info
"%d %m"))))))
2266 (ert-deftest test-org-export
/custom-protocol-maybe
()
2267 "Test `org-export-custom-protocol-maybe' specifications."
2271 (let ((org-link-types (copy-sequence org-link-types
)))
2272 (org-add-link-type "foo" nil
(lambda (p d f
) "success"))
2273 (org-export-string-as
2275 (org-export-create-backend
2278 '((section .
(lambda (s c i
) c
))
2279 (paragraph .
(lambda (p c i
) c
))
2280 (link .
(lambda (l c i
)
2281 (or (org-export-custom-protocol-maybe l c
'test
)
2286 (let ((org-link-types (copy-sequence org-link-types
)))
2288 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2289 (org-export-string-as
2291 (org-export-create-backend
2294 '((section .
(lambda (s c i
) c
))
2295 (paragraph .
(lambda (p c i
) c
))
2296 (link .
(lambda (l c i
)
2297 (or (org-export-custom-protocol-maybe l c
'no-test
)
2299 ;; Ignore anonymous back-ends.
2303 (let ((org-link-types (copy-sequence org-link-types
)))
2305 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2306 (org-export-string-as
2308 (org-export-create-backend
2310 '((section .
(lambda (s c i
) c
))
2311 (paragraph .
(lambda (p c i
) c
))
2312 (link .
(lambda (l c i
)
2313 (or (org-export-custom-protocol-maybe l c nil
)
2316 (ert-deftest test-org-export
/get-coderef-format
()
2317 "Test `org-export-get-coderef-format' specifications."
2318 ;; A link without description returns "%s"
2319 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2321 ;; Return "%s" when path is matched within description.
2322 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2324 ;; Otherwise return description.
2325 (should (equal (org-export-get-coderef-format "path" "desc")
2328 (ert-deftest test-org-export
/inline-image-p
()
2329 "Test `org-export-inline-image-p' specifications."
2331 (org-export-inline-image-p
2332 (org-test-with-temp-text "[[#id]]"
2333 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2334 '(("custom-id" .
"id")))))
2336 (ert-deftest test-org-export
/fuzzy-link
()
2337 "Test fuzzy links specifications."
2338 ;; Link to an headline should return headline's number.
2339 (org-test-with-parsed-data
2340 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2342 ;; Note: Headline's number is in fact a list of numbers.
2344 (org-element-map tree
'link
2346 (org-export-get-ordinal
2347 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2348 ;; Link to a target in an item should return item's number.
2349 (org-test-with-parsed-data
2350 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2352 ;; Note: Item's number is in fact a list of numbers.
2354 (org-element-map tree
'link
2356 (org-export-get-ordinal
2357 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2358 ;; Link to a target in a footnote should return footnote's number.
2359 (org-test-with-parsed-data "
2360 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
2363 (org-element-map tree
'link
2365 (org-export-get-ordinal
2366 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2367 ;; Link to a named element should return sequence number of that
2369 (org-test-with-parsed-data
2370 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2373 (org-element-map tree
'link
2375 (org-export-get-ordinal
2376 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2377 ;; Link to a target not within an item, a table, a footnote
2378 ;; reference or definition should return section number.
2379 (org-test-with-parsed-data
2380 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2383 (org-element-map tree
'link
2385 (org-export-get-ordinal
2386 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2387 ;; Space are not significant when matching a fuzzy link.
2389 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2390 (org-element-map tree
'link
2391 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2393 ;; Statistics cookies are ignored for headline match.
2395 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2396 (org-element-map tree
'link
2397 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2400 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2401 (org-element-map tree
'link
2402 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2405 (ert-deftest test-org-export
/resolve-coderef
()
2406 "Test `org-export-resolve-coderef' specifications."
2407 (let ((org-coderef-label-format "(ref:%s)"))
2408 ;; A link to a "-n -k -r" block returns line number.
2411 (org-test-with-parsed-data
2412 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2413 (org-export-resolve-coderef "coderef" info
))))
2416 (org-test-with-parsed-data
2417 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2418 (org-export-resolve-coderef "coderef" info
))))
2419 ;; A link to a "-n -r" block returns line number.
2422 (org-test-with-parsed-data
2423 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2424 (org-export-resolve-coderef "coderef" info
))))
2427 (org-test-with-parsed-data
2428 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2429 (org-export-resolve-coderef "coderef" info
))))
2430 ;; A link to a "-n" block returns coderef.
2433 (org-test-with-parsed-data
2434 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2435 (org-export-resolve-coderef "coderef" info
))))
2438 (org-test-with-parsed-data
2439 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2440 (org-export-resolve-coderef "coderef" info
))))
2441 ;; A link to a "-r" block returns line number.
2444 (org-test-with-parsed-data
2445 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2446 (org-export-resolve-coderef "coderef" info
))))
2449 (org-test-with-parsed-data
2450 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2451 (org-export-resolve-coderef "coderef" info
))))
2452 ;; A link to a block without a switch returns coderef.
2455 (org-test-with-parsed-data
2456 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2457 (org-export-resolve-coderef "coderef" info
))))
2458 (org-test-with-parsed-data
2459 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2460 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2461 ;; Correctly handle continued line numbers. A "+n" switch should
2462 ;; resume numbering from previous block with numbered lines,
2463 ;; ignoring blocks not numbering lines in the process. A "-n"
2464 ;; switch resets count.
2467 (org-test-with-parsed-data "
2472 #+BEGIN_SRC emacs-lisp
2476 #+BEGIN_SRC emacs-lisp +n -r
2477 \(+ 1 1) (ref:addition)
2480 #+BEGIN_EXAMPLE -n -r
2481 Another text. (ref:text)
2483 (list (org-export-resolve-coderef "addition" info
)
2484 (org-export-resolve-coderef "text" info
)))))
2485 ;; Recognize coderef with user-specified syntax.
2488 (org-test-with-parsed-data
2489 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2490 (org-export-resolve-coderef "text" info
))))
2491 ;; Unresolved coderefs throw an error.
2493 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2494 (org-export-resolve-coderef "unknown" info
)))))
2496 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2497 "Test `org-export-resolve-fuzzy-link' specifications."
2498 ;; Match target objects.
2500 (org-test-with-parsed-data "<<target>> [[target]]"
2501 (org-export-resolve-fuzzy-link
2502 (org-element-map tree
'link
'identity info t
) info
)))
2503 ;; Match named elements.
2505 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2506 (org-export-resolve-fuzzy-link
2507 (org-element-map tree
'link
'identity info t
) info
)))
2508 ;; Match exact headline's name.
2510 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2511 (org-export-resolve-fuzzy-link
2512 (org-element-map tree
'link
'identity info t
) info
)))
2513 ;; Targets objects have priority over named elements and headline
2517 (org-test-with-parsed-data
2518 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2520 (org-export-resolve-fuzzy-link
2521 (org-element-map tree
'link
'identity info t
) info
)))))
2522 ;; Named elements have priority over headline titles.
2525 (org-test-with-parsed-data
2526 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2528 (org-export-resolve-fuzzy-link
2529 (org-element-map tree
'link
'identity info t
) info
)))))
2530 ;; If link's path starts with a "*", only match headline titles,
2534 (org-test-with-parsed-data
2535 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2537 (org-export-resolve-fuzzy-link
2538 (org-element-map tree
'link
'identity info t
) info
)))))
2539 ;; Error if no match.
2541 (org-test-with-parsed-data "[[target]]"
2542 (org-export-resolve-fuzzy-link
2543 (org-element-map tree
'link
'identity info t
) info
)))
2544 ;; Match fuzzy link even when before first headline.
2547 (org-test-with-parsed-data "[[hl]]\n* hl"
2549 (org-export-resolve-fuzzy-link
2550 (org-element-map tree
'link
'identity info t
) info
)))))
2551 ;; Handle url-encoded fuzzy links.
2553 (org-test-with-parsed-data "* A B\n[[A%20B]]"
2554 (org-export-resolve-fuzzy-link
2555 (org-element-map tree
'link
#'identity info t
) info
))))
2557 (ert-deftest test-org-export
/resolve-id-link
()
2558 "Test `org-export-resolve-id-link' specifications."
2559 ;; Regular test for custom-id link.
2561 (equal '("Headline1")
2562 (org-test-with-parsed-data "* Headline1
2568 (org-element-property
2570 (org-export-resolve-id-link
2571 (org-element-map tree
'link
'identity info t
) info
)))))
2572 ;; Throw an error on failing searches.
2574 (org-test-with-parsed-data "* Headline1
2580 (org-export-resolve-id-link
2581 (org-element-map tree
'link
'identity info t
) info
)))
2582 ;; Test for internal id target.
2584 (equal '("Headline1")
2585 (org-test-with-parsed-data "* Headline1
2591 (org-element-property
2593 (org-export-resolve-id-link
2594 (org-element-map tree
'link
'identity info t
) info
)))))
2595 ;; Test for external id target.
2599 (org-test-with-parsed-data "[[id:aaaa]]"
2600 (org-export-resolve-id-link
2601 (org-element-map tree
'link
'identity info t
)
2602 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
2604 (ert-deftest test-org-export
/resolve-radio-link
()
2605 "Test `org-export-resolve-radio-link' specifications."
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 targets are case-insensitive.
2617 (org-test-with-temp-text "<<<RADIO>>> radio"
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.
2626 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
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 target with objects at its beginning.
2635 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
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 ;; Radio link next to an apostrophe.
2644 (org-test-with-temp-text "<<<radio>>> radio's"
2645 (org-update-radio-target-regexp)
2646 (let* ((tree (org-element-parse-buffer))
2647 (info `(:parse-tree
,tree
)))
2648 (org-export-resolve-radio-link
2649 (org-element-map tree
'link
'identity info t
)
2651 ;; Multiple radio targets.
2653 (equal '("radio1" "radio2")
2654 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2655 (org-update-radio-target-regexp)
2656 (let* ((tree (org-element-parse-buffer))
2657 (info `(:parse-tree
,tree
)))
2658 (org-element-map tree
'link
2660 (org-element-property
2661 :value
(org-export-resolve-radio-link link info
)))
2663 ;; Radio target is whitespace insensitive.
2665 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2666 (org-update-radio-target-regexp)
2667 (let* ((tree (org-element-parse-buffer))
2668 (info `(:parse-tree
,tree
)))
2669 (org-element-map tree
'link
2670 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2672 (ert-deftest test-org-export
/file-uri
()
2673 "Test `org-export-file-uri' specifications."
2674 ;; Preserve relative filenames.
2675 (should (equal "relative.org" (org-export-file-uri "relative.org")))
2676 ;; Local files start with "file:///"
2677 (should (equal "file:///local.org" (org-export-file-uri "/local.org")))
2678 ;; Remote files start with "file://"
2679 (should (equal "file://myself@some.where:papers/last.pdf"
2680 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
2681 ;; Expand filename starting with "~".
2682 (should (equal (org-export-file-uri "~/file.org")
2683 (concat "file://" (expand-file-name "~/file.org")))))
2687 ;;; Src-block and example-block
2689 (ert-deftest test-org-export
/unravel-code
()
2690 "Test `org-export-unravel-code' function."
2691 ;; Code without reference.
2693 (equal '("(+ 1 1)\n")
2694 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2695 (org-export-unravel-code (org-element-at-point)))))
2696 ;; Code with reference.
2698 (equal '("(+ 1 1)\n" (1 .
"test"))
2699 (org-test-with-temp-text
2700 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2701 (let ((org-coderef-label-format "(ref:%s)"))
2702 (org-export-unravel-code (org-element-at-point))))))
2703 ;; Code with user-defined reference.
2706 '("(+ 1 1)\n" (1 .
"test"))
2707 (org-test-with-temp-text
2708 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2709 (let ((org-coderef-label-format "(ref:%s)"))
2710 (org-export-unravel-code (org-element-at-point))))))
2711 ;; Code references keys are relative to the current block.
2713 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2714 (org-test-with-temp-text "
2723 (let ((org-coderef-label-format "(ref:%s)"))
2724 (org-export-unravel-code (org-element-at-point)))))))
2726 (ert-deftest test-org-export
/format-code-default
()
2727 "Test `org-export-format-code-default' specifications."
2728 ;; Return the empty string when code is empty.
2731 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2732 (org-export-format-code-default
2733 (org-element-map tree
'src-block
'identity info t
) info
))))
2734 ;; Number lines, two whitespace characters before the actual loc.
2737 (org-test-with-parsed-data
2738 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2739 (org-export-format-code-default
2740 (org-element-map tree
'src-block
'identity info t
) info
))))
2741 ;; Put references 6 whitespace characters after the widest line,
2742 ;; wrapped within parenthesis.
2744 (equal "123 (a)\n1 (b)\n"
2745 (let ((org-coderef-label-format "(ref:%s)"))
2746 (org-test-with-parsed-data
2747 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2748 (org-export-format-code-default
2749 (org-element-map tree
'src-block
'identity info t
) info
))))))
2755 (ert-deftest test-org-export
/activate-smart-quotes
()
2756 "Test `org-export-activate-smart-quotes' specifications."
2757 ;; Double quotes: standard test.
2760 '("some “quoted” text")
2761 (let ((org-export-default-language "en"))
2762 (org-test-with-parsed-data "some \"quoted\" text"
2763 (org-element-map tree
'plain-text
2764 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2766 ;; Opening quotes: at the beginning of a paragraph.
2770 (let ((org-export-default-language "en"))
2771 (org-test-with-parsed-data "\"begin"
2772 (org-element-map tree
'plain-text
2773 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2775 ;; Opening quotes: after an object.
2778 '("“quoted” text")
2779 (let ((org-export-default-language "en"))
2780 (org-test-with-parsed-data "=verb= \"quoted\" text"
2781 (org-element-map tree
'plain-text
2782 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2784 ;; Closing quotes: at the end of a paragraph.
2787 '("Quoted “text”")
2788 (let ((org-export-default-language "en"))
2789 (org-test-with-parsed-data "Quoted \"text\""
2790 (org-element-map tree
'plain-text
2791 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2793 ;; Inner quotes: standard test.
2795 (equal '("« outer « inner » outer »")
2796 (let ((org-export-default-language "fr"))
2797 (org-test-with-parsed-data "\"outer 'inner' outer\""
2798 (org-element-map tree
'plain-text
2799 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2801 ;; Apostrophe: standard test.
2803 (equal '("It « shouldn’t » fail")
2804 (let ((org-export-default-language "fr"))
2805 (org-test-with-parsed-data "It \"shouldn't\" fail"
2806 (org-element-map tree
'plain-text
2807 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2810 (equal '("It shouldn’t fail")
2811 (let ((org-export-default-language "fr"))
2812 (org-test-with-parsed-data "It shouldn't fail"
2813 (org-element-map tree
'plain-text
2814 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2816 ;; Apostrophe: before an object.
2819 '("« a’" " »")
2820 (let ((org-export-default-language "fr"))
2821 (org-test-with-parsed-data "\"a'=b=\""
2822 (org-element-map tree
'plain-text
2823 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2825 ;; Apostrophe: after an object.
2827 (equal '("« " "’s »")
2828 (let ((org-export-default-language "fr"))
2829 (org-test-with-parsed-data "\"=code='s\""
2830 (org-element-map tree
'plain-text
2831 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2833 ;; Special case: isolated quotes.
2835 (equal '("“" "”")
2836 (let ((org-export-default-language "en"))
2837 (org-test-with-parsed-data "\"$x$\""
2838 (org-element-map tree
'plain-text
2839 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2841 ;; Smart quotes in secondary strings.
2843 (equal '("“" "”")
2844 (let ((org-export-default-language "en"))
2845 (org-test-with-parsed-data "* \"$x$\""
2846 (org-element-map tree
'plain-text
2847 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2849 ;; Smart quotes in document keywords.
2851 (equal '("“" "”")
2852 (let ((org-export-default-language "en"))
2853 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2854 (org-element-map (plist-get info
:title
) 'plain-text
2855 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2857 ;; Smart quotes in parsed affiliated keywords.
2859 (equal '("“" "”" "Paragraph")
2860 (let ((org-export-default-language "en"))
2861 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2862 (org-element-map tree
'plain-text
2863 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2864 info nil nil t
))))))
2870 (ert-deftest test-org-export
/special-column
()
2871 "Test if the table's special column is properly recognized."
2872 ;; 1. First column is special if it contains only a special marking
2873 ;; characters or empty cells.
2874 (org-test-with-temp-text "
2878 (org-export-table-has-special-column-p
2880 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2881 ;; 2. If the column contains anything else, it isn't special.
2882 (org-test-with-temp-text "
2886 (org-export-table-has-special-column-p
2888 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2889 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2891 (org-test-with-temp-text "
2900 (org-export-table-has-special-column-p
2902 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2903 ;; 4. A first column with only empty cells isn't considered as
2905 (org-test-with-temp-text "
2909 (org-export-table-has-special-column-p
2911 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2913 (ert-deftest test-org-export
/table-row-is-special-p
()
2914 "Test `org-export-table-row-is-special-p' specifications."
2915 ;; 1. A row is special if it has a special marking character in the
2917 (org-test-with-parsed-data "| ! | 1 |"
2919 (org-export-table-row-is-special-p
2920 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2921 ;; 2. A row is special when its first field is "/"
2922 (org-test-with-parsed-data "
2926 (org-export-table-row-is-special-p
2927 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2928 ;; 3. A row only containing alignment cookies is also considered as
2930 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2932 (org-export-table-row-is-special-p
2933 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2934 ;; 4. Everything else isn't considered as special.
2935 (org-test-with-parsed-data "| \alpha | | c |"
2937 (org-export-table-row-is-special-p
2938 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2939 ;; 5. Table's rules are never considered as special rows.
2940 (org-test-with-parsed-data "|---+---|"
2942 (org-export-table-row-is-special-p
2943 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2945 (ert-deftest test-org-export
/has-header-p
()
2946 "Test `org-export-table-has-header-p' specifications."
2947 ;; 1. With an header.
2948 (org-test-with-parsed-data "
2953 (org-export-table-has-header-p
2954 (org-element-map tree
'table
'identity info
'first-match
)
2956 ;; 2. Without an header.
2957 (org-test-with-parsed-data "
2961 (org-export-table-has-header-p
2962 (org-element-map tree
'table
'identity info
'first-match
)
2964 ;; 3. Don't get fooled with starting and ending rules.
2965 (org-test-with-parsed-data "
2971 (org-export-table-has-header-p
2972 (org-element-map tree
'table
'identity info
'first-match
)
2975 (ert-deftest test-org-export
/table-row-group
()
2976 "Test `org-export-table-row-group' specifications."
2977 ;; 1. A rule creates a new group.
2980 (org-test-with-parsed-data "
2984 (org-element-map tree
'table-row
2986 (if (eq (org-element-property :type row
) 'rule
) 'rule
2987 (org-export-table-row-group row info
)))))))
2988 ;; 2. Special rows are ignored in count.
2992 (org-test-with-parsed-data "
2996 (org-element-map tree
'table-row
2998 (if (eq (org-element-property :type row
) 'rule
) 'rule
2999 (org-export-table-row-group row info
)))
3001 ;; 3. Double rules also are ignored in count.
3003 (equal '(1 rule rule
2)
3004 (org-test-with-parsed-data "
3009 (org-element-map tree
'table-row
3011 (if (eq (org-element-property :type row
) 'rule
) 'rule
3012 (org-export-table-row-group row info
))))))))
3014 (ert-deftest test-org-export
/table-row-number
()
3015 "Test `org-export-table-row-number' specifications."
3016 ;; Standard test. Number is 0-indexed.
3019 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3020 (org-element-map tree
'table-row
3021 (lambda (row) (org-export-table-row-number row info
)) info
))))
3022 ;; Number ignores separators.
3025 (org-test-with-parsed-data "
3029 (org-element-map tree
'table-row
3030 (lambda (row) (org-export-table-row-number row info
)) info
))))
3031 ;; Number ignores special rows.
3034 (org-test-with-parsed-data "
3040 (org-element-map tree
'table-row
3041 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3043 (ert-deftest test-org-export
/table-cell-width
()
3044 "Test `org-export-table-cell-width' specifications."
3045 ;; 1. Width is primarily determined by width cookies. If no cookie
3046 ;; is found, cell's width is nil.
3047 (org-test-with-parsed-data "
3048 | / | <l> | <6> | <l7> |
3053 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3054 (org-element-map tree
'table-cell
'identity info
)))))
3055 ;; 2. The last width cookie has precedence.
3056 (org-test-with-parsed-data "
3063 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3064 (org-element-map tree
'table-cell
'identity info
)))))
3065 ;; 3. Valid width cookies must have a specific row.
3066 (org-test-with-parsed-data "| <6> | cell |"
3070 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3071 (org-element-map tree
'table-cell
'identity
))))))
3073 (ert-deftest test-org-export
/table-cell-alignment
()
3074 "Test `org-export-table-cell-alignment' specifications."
3075 ;; 1. Alignment is primarily determined by alignment cookies.
3077 (equal '(left center right
)
3078 (let ((org-table-number-fraction 0.5)
3079 (org-table-number-regexp "^[0-9]+$"))
3080 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3081 (mapcar (lambda (cell)
3082 (org-export-table-cell-alignment cell info
))
3083 (org-element-map tree
'table-cell
'identity
))))))
3084 ;; 2. The last alignment cookie has precedence.
3086 (equal '(right right right
)
3087 (org-test-with-parsed-data "
3091 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3092 (org-element-map tree
'table-cell
'identity
)))))
3093 ;; 3. If there's no cookie, cell's contents determine alignment.
3094 ;; A column mostly made of cells containing numbers will align
3095 ;; its cells to the right.
3097 (equal '(right right right
)
3098 (let ((org-table-number-fraction 0.5)
3099 (org-table-number-regexp "^[0-9]+$"))
3100 (org-test-with-parsed-data "
3104 (mapcar (lambda (cell)
3105 (org-export-table-cell-alignment cell info
))
3106 (org-element-map tree
'table-cell
'identity
))))))
3107 ;; 4. Otherwise, they will be aligned to the left.
3109 (equal '(left left left
)
3110 (org-test-with-parsed-data "
3114 (mapcar (lambda (cell)
3115 (org-export-table-cell-alignment cell info
))
3116 (org-element-map tree
'table-cell
'identity info
))))))
3118 (ert-deftest test-org-export
/table-cell-borders
()
3119 "Test `org-export-table-cell-borders' specifications."
3120 ;; 1. Recognize various column groups indicators.
3121 (org-test-with-parsed-data "| / | < | > | <> |"
3124 '((right bottom top
) (left bottom top
) (right bottom top
)
3125 (right left bottom top
))
3126 (mapcar (lambda (cell)
3127 (org-export-table-cell-borders cell info
))
3128 (org-element-map tree
'table-cell
'identity
)))))
3129 ;; 2. Accept shortcuts to define column groups.
3130 (org-test-with-parsed-data "| / | < | < |"
3133 '((right bottom top
) (right left bottom top
) (left bottom top
))
3134 (mapcar (lambda (cell)
3135 (org-export-table-cell-borders cell info
))
3136 (org-element-map tree
'table-cell
'identity
)))))
3137 ;; 3. A valid column groups row must start with a "/".
3138 (org-test-with-parsed-data "
3142 (equal '((top) (top) (bottom) (bottom))
3143 (mapcar (lambda (cell)
3144 (org-export-table-cell-borders cell info
))
3145 (org-element-map tree
'table-cell
'identity
)))))
3146 ;; 4. Take table rules into consideration.
3147 (org-test-with-parsed-data "
3152 (equal '((below top
) (bottom above
))
3153 (mapcar (lambda (cell)
3154 (org-export-table-cell-borders cell info
))
3155 (org-element-map tree
'table-cell
'identity
)))))
3156 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3157 ;; (resp. `bottom' and `below') borders. Any special row is
3159 (org-test-with-parsed-data "
3165 (equal '((bottom below top above
))
3167 (mapcar (lambda (cell)
3168 (org-export-table-cell-borders cell info
))
3169 (org-element-map tree
'table-cell
'identity
)))))))
3171 (ert-deftest test-org-export
/table-dimensions
()
3172 "Test `org-export-table-dimensions' specifications."
3173 ;; 1. Standard test.
3174 (org-test-with-parsed-data "
3179 (org-export-table-dimensions
3180 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3181 ;; 2. Ignore horizontal rules and special columns.
3182 (org-test-with-parsed-data "
3189 (org-export-table-dimensions
3190 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3192 (ert-deftest test-org-export
/table-cell-address
()
3193 "Test `org-export-table-cell-address' specifications."
3194 ;; 1. Standard test: index is 0-based.
3195 (org-test-with-parsed-data "| a | b |"
3197 (equal '((0 .
0) (0 .
1))
3198 (org-element-map tree
'table-cell
3199 (lambda (cell) (org-export-table-cell-address cell info
))
3201 ;; 2. Special column isn't counted, nor are special rows.
3202 (org-test-with-parsed-data "
3207 (org-export-table-cell-address
3208 (car (last (org-element-map tree
'table-cell
'identity info
)))
3210 ;; 3. Tables rules do not count either.
3211 (org-test-with-parsed-data "
3219 (org-export-table-cell-address
3220 (car (last (org-element-map tree
'table-cell
'identity info
)))
3222 ;; 4. Return nil for special cells.
3223 (org-test-with-parsed-data "| / | a |"
3225 (org-export-table-cell-address
3226 (org-element-map tree
'table-cell
'identity nil
'first-match
)
3229 (ert-deftest test-org-export
/get-table-cell-at
()
3230 "Test `org-export-get-table-cell-at' specifications."
3231 ;; 1. Address ignores special columns, special rows and rules.
3232 (org-test-with-parsed-data "
3239 (org-element-contents
3240 (org-export-get-table-cell-at
3242 (org-element-map tree
'table
'identity info
'first-match
)
3244 ;; 2. Return value for a non-existent address is nil.
3245 (org-test-with-parsed-data "| a |"
3247 (org-export-get-table-cell-at
3249 (org-element-map tree
'table
'identity info
'first-match
)
3251 (org-test-with-parsed-data "| / |"
3253 (org-export-get-table-cell-at
3255 (org-element-map tree
'table
'identity info
'first-match
)
3258 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
3259 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3260 ;; 1. A cell at a beginning of a row always starts a column group.
3261 (org-test-with-parsed-data "| a |"
3263 (org-export-table-cell-starts-colgroup-p
3264 (org-element-map tree
'table-cell
'identity info
'first-match
)
3266 ;; 2. Special column should be ignored when determining the
3267 ;; beginning of the row.
3268 (org-test-with-parsed-data "
3272 (org-export-table-cell-starts-colgroup-p
3273 (org-element-map tree
'table-cell
'identity info
'first-match
)
3275 ;; 2. Explicit column groups.
3276 (org-test-with-parsed-data "
3282 (org-element-map tree
'table-cell
3284 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3287 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3288 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3289 ;; 1. A cell at the end of a row always ends a column group.
3290 (org-test-with-parsed-data "| a |"
3292 (org-export-table-cell-ends-colgroup-p
3293 (org-element-map tree
'table-cell
'identity info
'first-match
)
3295 ;; 2. Special column should be ignored when determining the
3296 ;; beginning of the row.
3297 (org-test-with-parsed-data "
3301 (org-export-table-cell-ends-colgroup-p
3302 (org-element-map tree
'table-cell
'identity info
'first-match
)
3304 ;; 3. Explicit column groups.
3305 (org-test-with-parsed-data "
3311 (org-element-map tree
'table-cell
3313 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
3316 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
3317 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3318 ;; 1. A row at the beginning of a table always starts a row group.
3319 ;; So does a row following a table rule.
3320 (org-test-with-parsed-data "
3327 (org-element-map tree
'table-row
3329 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3331 ;; 2. Special rows should be ignored when determining the beginning
3333 (org-test-with-parsed-data "
3342 (org-element-map tree
'table-row
3344 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3347 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
3348 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3349 ;; 1. A row at the end of a table always ends a row group. So does
3350 ;; a row preceding a table rule.
3351 (org-test-with-parsed-data "
3358 (org-element-map tree
'table-row
3360 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3362 ;; 2. Special rows should be ignored when determining the beginning
3364 (org-test-with-parsed-data "
3373 (org-element-map tree
'table-row
3375 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3378 (ert-deftest test-org-export
/table-row-in-header-p
()
3379 "Test `org-export-table-row-in-header-p' specifications."
3380 ;; Standard test. Separators are always nil.
3384 (org-test-with-parsed-data "| a |\n|---|\n| b |"
3385 (org-element-map tree
'table-row
3387 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
3388 ;; Nil when there is no header.
3392 (org-test-with-parsed-data "| a |\n| b |"
3393 (org-element-map tree
'table-row
3395 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
3397 (ert-deftest test-org-export
/table-row-starts-header-p
()
3398 "Test `org-export-table-row-starts-header-p' specifications."
3399 ;; 1. Only the row starting the first row group starts the table
3401 (org-test-with-parsed-data "
3409 (org-element-map tree
'table-row
3411 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
3413 ;; 2. A row cannot start an header if there's no header in the
3415 (org-test-with-parsed-data "
3419 (org-export-table-row-starts-header-p
3420 (org-element-map tree
'table-row
'identity info
'first-match
)
3423 (ert-deftest test-org-export
/table-row-ends-header-p
()
3424 "Test `org-export-table-row-ends-header-p' specifications."
3425 ;; 1. Only the row starting the first row group starts the table
3427 (org-test-with-parsed-data "
3435 (org-element-map tree
'table-row
3437 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
3439 ;; 2. A row cannot start an header if there's no header in the
3441 (org-test-with-parsed-data "
3445 (org-export-table-row-ends-header-p
3446 (org-element-map tree
'table-row
'identity info
'first-match
)
3451 ;;; Tables of Contents
3453 (ert-deftest test-org-export
/collect-headlines
()
3454 "Test `org-export-collect-headlines' specifications."
3459 (org-test-with-parsed-data "* H1\n** H2"
3460 (org-export-collect-headlines info
)))))
3461 ;; Do not collect headlines below optional argument.
3465 (org-test-with-parsed-data "* H1\n** H2"
3466 (org-export-collect-headlines info
1)))))
3467 ;; Never collect headlines below maximum headline level.
3471 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3472 (org-export-collect-headlines info
)))))
3476 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3477 (org-export-collect-headlines info
2)))))
3478 ;; Collect headlines locally.
3481 (org-test-with-parsed-data "* H1\n** H2\n** H3"
3482 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3483 (length (org-export-collect-headlines info nil scope
))))))
3484 ;; When collecting locally, optional level is relative.
3487 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
3488 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3489 (length (org-export-collect-headlines info
1 scope
)))))))
3495 (ert-deftest test-org-export
/inner-template
()
3496 "Test `inner-template' translator specifications."
3499 (org-test-with-temp-text "* Headline"
3501 (org-export-create-backend
3503 '((inner-template .
(lambda (contents info
) "Success!"))
3504 (headline .
(lambda (h c i
) "Headline"))))))))
3505 ;; Inner template is applied even in a "body-only" export.
3508 (org-test-with-temp-text "* Headline"
3510 (org-export-create-backend
3511 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3512 (headline .
(lambda (h c i
) "Headline"))))
3513 nil nil
'body-only
)))))
3515 (ert-deftest test-org-export
/template
()
3516 "Test `template' translator specifications."
3519 (org-test-with-temp-text "* Headline"
3521 (org-export-create-backend
3522 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3523 (headline .
(lambda (h c i
) "Headline"))))))))
3524 ;; Template is not applied in a "body-only" export.
3527 (org-test-with-temp-text "* Headline"
3529 (org-export-create-backend
3530 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3531 (headline .
(lambda (h c i
) "Headline"))))
3532 nil nil
'body-only
)))))
3538 (ert-deftest test-org-export
/get-next-element
()
3539 "Test `org-export-get-next-element' specifications."
3543 (org-test-with-parsed-data "* Headline\n*a* b"
3544 (org-export-get-next-element
3545 (org-element-map tree
'bold
'identity info t
) info
))))
3546 ;; Return nil when no previous element.
3548 (org-test-with-parsed-data "* Headline\na *b*"
3549 (org-export-get-next-element
3550 (org-element-map tree
'bold
'identity info t
) info
)))
3551 ;; Non-exportable elements are ignored.
3553 (let ((org-export-with-timestamps nil
))
3554 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3555 (org-export-get-next-element
3556 (org-element-map tree
'entity
'identity info t
) info
))))
3557 ;; Find next element in secondary strings.
3560 (org-test-with-parsed-data "* a =verb="
3562 (org-export-get-next-element
3563 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3566 (org-test-with-parsed-data "* /italic/ =verb="
3568 (org-export-get-next-element
3569 (org-element-map tree
'italic
'identity info t
) info
)))))
3570 ;; Find next element in document keywords.
3573 (org-test-with-parsed-data "#+TITLE: a =verb="
3575 (org-export-get-next-element
3577 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3578 ;; Find next element in parsed affiliated keywords.
3581 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3583 (org-export-get-next-element
3584 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3585 ;; With optional argument N, return a list containing all the
3586 ;; following elements.
3589 '(bold code underline
)
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 t
)))))
3594 ;; When N is a positive integer, return a list containing up to
3595 ;; N following elements.
3599 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3601 (org-export-get-next-element
3602 (org-element-map tree
'italic
'identity info t
) info
2))))))
3604 (ert-deftest test-org-export
/get-previous-element
()
3605 "Test `org-export-get-previous-element' specifications."
3609 (org-test-with-parsed-data "* Headline\na *b*"
3610 (org-export-get-previous-element
3611 (org-element-map tree
'bold
'identity info t
) info
))))
3612 ;; Return nil when no previous element.
3614 (org-test-with-parsed-data "* Headline\n*a* b"
3615 (org-export-get-previous-element
3616 (org-element-map tree
'bold
'identity info t
) info
)))
3617 ;; Non-exportable elements are ignored.
3619 (let ((org-export-with-timestamps nil
))
3620 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3621 (org-export-get-previous-element
3622 (org-element-map tree
'entity
'identity info t
) info
))))
3623 ;; Find previous element in secondary strings.
3626 (org-test-with-parsed-data "* =verb= a"
3628 (org-export-get-previous-element
3629 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3632 (org-test-with-parsed-data "* =verb= /italic/"
3634 (org-export-get-previous-element
3635 (org-element-map tree
'italic
'identity info t
) info
)))))
3636 ;; Find previous element in document keywords.
3639 (org-test-with-parsed-data "#+TITLE: =verb= a"
3641 (org-export-get-previous-element
3643 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3644 ;; Find previous element in parsed affiliated keywords.
3647 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3649 (org-export-get-previous-element
3650 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3651 ;; With optional argument N, return a list containing up to
3652 ;; N previous elements.
3654 (equal '(underline italic bold
)
3655 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3657 (org-export-get-previous-element
3658 (org-element-map tree
'code
'identity info t
) info t
)))))
3659 ;; When N is a positive integer, return a list containing up to
3660 ;; N previous elements.
3662 (equal '(italic bold
)
3663 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3665 (org-export-get-previous-element
3666 (org-element-map tree
'code
'identity info t
) info
2))))))
3670 ;;; test-org-export.el end here