1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012, 2013, 2014 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 (unless (featurep 'ox
)
25 (signal 'missing-test-dependency
"org-export"))
27 (defun org-test-default-backend ()
28 "Return a default export back-end.
29 This back-end simply returns parsed data as Org syntax."
30 (org-export-create-backend
31 :transcoders
(let (transcode-table)
32 (dolist (type (append org-element-all-elements
33 org-element-all-objects
)
37 (lambda (obj contents info
)
39 (intern (format "org-element-%s-interpreter"
44 (defmacro org-test-with-parsed-data
(data &rest body
)
45 "Execute body with parsed data available.
47 DATA is a string containing the data to be parsed. BODY is the
48 body to execute. Parse tree is available under the `tree'
49 variable, and communication channel under `info'.
51 This function calls `org-export-collect-tree-properties'. As
52 such, `:ignore-list' (for `org-element-map') and
53 `:parse-tree' (for `org-export-get-genealogy') properties are
54 already filled in `info'."
55 (declare (debug (form body
)) (indent 1))
56 `(org-test-with-temp-text ,data
57 (let* ((tree (org-element-parse-buffer))
58 (info (org-export-collect-tree-properties
59 tree
(org-export-get-environment))))
66 (ert-deftest test-org-export
/bind-keyword
()
67 "Test reading #+BIND: keywords."
68 ;; Test with `org-export-allow-bind-keywords' set to t.
70 (org-test-with-temp-text "#+BIND: test-ox-var value"
71 (let ((org-export-allow-bind-keywords t
))
72 (org-export-get-environment)
73 (eq test-ox-var
'value
))))
74 ;; Test with `org-export-allow-bind-keywords' set to nil.
76 (org-test-with-temp-text "#+BIND: test-ox-var value"
77 (let ((org-export-allow-bind-keywords nil
))
78 (org-export-get-environment)
79 (boundp 'test-ox-var
))))
80 ;; BIND keywords are case-insensitive.
82 (org-test-with-temp-text "#+bind: test-ox-var value"
83 (let ((org-export-allow-bind-keywords t
))
84 (org-export-get-environment)
85 (eq test-ox-var
'value
))))
86 ;; Preserve order of BIND keywords.
88 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
89 (let ((org-export-allow-bind-keywords t
))
90 (org-export-get-environment)
92 ;; Read BIND keywords in setup files.
94 (org-test-with-temp-text
95 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
96 (let ((org-export-allow-bind-keywords t
))
97 (org-export-get-environment)
98 (eq variable
'value
))))
99 ;; Verify that bound variables are seen during export.
102 (org-test-with-temp-text "#+BIND: test-ox-var value"
103 (let ((org-export-allow-bind-keywords t
))
105 (org-export-create-backend
107 '((section .
(lambda (s c i
)
108 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
110 (ert-deftest test-org-export
/parse-option-keyword
()
111 "Test reading all standard #+OPTIONS: items."
114 (org-export--parse-option-keyword
115 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
116 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
119 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
120 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
121 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
122 :with-footnotes t
:with-inlinetasks nil
:with-priority t
123 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
124 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
125 :with-todo-keywords t
)))
126 ;; Test some special values.
129 (org-export--parse-option-keyword
130 "arch:headline creator:comment d:(\"TEST\")
131 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
134 :with-archived-trees headline
:with-creator comment
135 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
136 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
138 (ert-deftest test-org-export
/get-inbuffer-options
()
139 "Test reading all standard export keywords."
140 ;; Properties should follow buffer order.
143 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
144 (org-export--get-inbuffer-options))
145 '(:language
"fr" :creator
"Me" :email
"email")))
146 ;; Parse document keywords.
149 (org-test-with-temp-text "#+AUTHOR: Me"
150 (org-export--get-inbuffer-options))
152 ;; Test `space' behaviour.
155 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
156 (org-export--get-inbuffer-options))
157 '(:title
("Some title with spaces"))))
158 ;; Test `newline' behaviour.
161 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
162 (org-export--get-inbuffer-options))
163 '(:description
"With\ntwo lines")))
164 ;; Test `split' behaviour.
167 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
168 (org-export--get-inbuffer-options))
169 '(:select-tags
("a" "b"))))
170 ;; Options set through SETUPFILE.
173 (org-test-with-temp-text
174 (format "#+DESCRIPTION: l1
178 #+SETUPFILE: \"%s/examples/setupfile.org\"
184 (org-export--get-inbuffer-options))
185 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
187 ;; More than one property can refer to the same buffer keyword.
189 (equal '(:k2
"value" :k1
"value")
190 (let ((backend (org-export-create-backend
191 :options
'((:k1
"KEYWORD")
193 (org-test-with-temp-text "#+KEYWORD: value"
194 (org-export--get-inbuffer-options backend
))))))
196 (ert-deftest test-org-export
/get-subtree-options
()
197 "Test setting options from headline's properties."
199 (org-test-with-temp-text "#+TITLE: Title
202 :EXPORT_TITLE: Subtree Title
206 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
207 '("Subtree Title"))))
211 (org-test-with-temp-text "#+OPTIONS: H:1
219 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
221 (org-test-with-temp-text "#+DATE: today
224 :EXPORT_DATE: 29-03-2012
228 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
230 ;; Properties with `split' behaviour are stored as a list of
234 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
237 :EXPORT_EXCLUDE_TAGS: a b
242 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
243 ;; Handle :PROPERTY+: syntax.
246 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
249 :EXPORT_EXCLUDE_TAGS: a
250 :EXPORT_EXCLUDE_TAGS+: b
255 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
256 ;; Export properties are case-insensitive.
257 (org-test-with-temp-text "* Headline
259 :EXPORT_Date: 29-03-2012
262 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
264 ;; Still grab correct options when section above is empty.
267 (org-test-with-temp-text "* H1\n** H11\n** H12"
268 (progn (forward-line 2)
269 (plist-get (org-export-get-environment nil t
) :title
))))))
271 (ert-deftest test-org-export
/set-title
()
272 "Test title setting."
273 ;; Without TITLE keyword.
277 (org-test-with-temp-text "Test"
279 (org-export-create-backend
281 '((template .
(lambda (text info
)
282 (org-element-interpret-data
283 (plist-get info
:title
))))))))))
284 ;; With a blank TITLE keyword.
288 (org-test-with-temp-text "#+TITLE:\nTest"
290 (org-export-create-backend
292 '((template .
(lambda (text info
)
293 (org-element-interpret-data
294 (plist-get info
:title
))))))))))
295 ;; With a non-empty TITLE keyword.
299 (org-test-with-temp-text "#+TITLE: Title\nTest"
301 (org-export-create-backend
303 '((template .
(lambda (text info
)
304 (org-element-interpret-data
305 (plist-get info
:title
))))))))))
306 ;; When exporting a subtree, its heading becomes the headline of the
311 (org-test-with-temp-text "* Headline\nBody"
313 (org-export-create-backend
315 '((template .
(lambda (text info
)
316 (org-element-interpret-data
317 (plist-get info
:title
))))))
319 ;; ... unless there is an EXPORT_TITLE property at the root of the
324 (org-test-with-temp-text
325 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
327 (org-export-create-backend
329 '((template .
(lambda (text info
)
330 (org-element-interpret-data
331 (plist-get info
:title
))))))
334 (ert-deftest test-org-export
/handle-options
()
335 "Test if export options have an impact on output."
336 ;; Test exclude tags for headlines and inlinetasks.
339 (org-test-with-temp-text "* Head1 :noexp:"
340 (org-export-as (org-test-default-backend)
341 nil nil nil
'(:exclude-tags
("noexp"))))))
342 ;; Test include tags for headlines and inlinetasks.
344 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
345 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
346 (let ((org-tags-column 0))
347 (org-export-as (org-test-default-backend)
348 nil nil nil
'(:select-tags
("exp")))))))
349 ;; If there is an include tag, ignore the section before the first
352 (equal "* H1 :exp:\nBody\n"
353 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
354 (let ((org-tags-column 0))
355 (org-export-as (org-test-default-backend)
356 nil nil nil
'(:select-tags
("exp")))))))
358 (equal "* H1 :exp:\n"
359 (org-test-with-temp-text "* H1 :exp:\nBody"
360 (let ((org-tags-column 0))
361 (org-export-as (org-test-default-backend)
362 nil nil nil
'(:select-tags
("exp")))))))
363 ;; Test mixing include tags and exclude tags.
366 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
367 (org-test-with-temp-text "
369 ** Sub-Head1 :noexport:
372 ** Sub-Head1 :export:"
373 (org-export-as (org-test-default-backend) nil nil nil
374 '(:select-tags
("export") :exclude-tags
("noexport"))))))
378 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
379 (org-test-with-temp-text "* TODO Head1"
380 (org-export-as (org-test-default-backend)
381 nil nil nil
'(:with-tasks nil
))))))
383 (equal "* TODO Head1\n"
384 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
385 (org-test-with-temp-text "* TODO Head1"
386 (org-export-as (org-test-default-backend)
387 nil nil nil
'(:with-tasks t
))))))
391 (org-test-with-temp-text "* Head1 :archive:"
392 (let ((org-archive-tag "archive"))
393 (org-export-as (org-test-default-backend)
394 nil nil nil
'(:with-archived-trees nil
))))))
397 "\\* Head1[ \t]+:archive:"
398 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
399 (let ((org-archive-tag "archive"))
400 (org-export-as (org-test-default-backend) nil nil nil
401 '(:with-archived-trees headline
))))))
404 "\\`\\* Head1[ \t]+:archive:\n\\'"
405 (org-test-with-temp-text "* Head1 :archive:"
406 (let ((org-archive-tag "archive"))
407 (org-export-as (org-test-default-backend)
408 nil nil nil
'(:with-archived-trees t
))))))
411 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
412 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
413 (org-export-as (org-test-default-backend)
414 nil nil nil
'(:with-clocks t
)))))
417 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
418 (org-export-as (org-test-default-backend)
419 nil nil nil
'(:with-clocks nil
)))))
423 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
424 (org-export-as (org-test-default-backend)
425 nil nil nil
'(:with-drawers nil
)))))
427 (equal ":TEST:\ncontents\n:END:\n"
428 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
429 (org-export-as (org-test-default-backend)
430 nil nil nil
'(:with-drawers t
)))))
432 (equal ":FOO:\nkeep\n:END:\n"
433 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
434 (org-export-as (org-test-default-backend)
435 nil nil nil
'(:with-drawers
("FOO"))))))
437 (equal ":FOO:\nkeep\n:END:\n"
438 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
439 (org-export-as (org-test-default-backend)
440 nil nil nil
'(:with-drawers
(not "BAR"))))))
444 (org-test-with-temp-text ": A"
445 (org-export-as (org-test-default-backend) nil nil nil
446 '(:with-fixed-width t
)))))
449 (org-test-with-temp-text ": A"
450 (org-export-as (org-test-default-backend) nil nil nil
451 '(:with-fixed-width nil
)))))
455 (let ((org-footnote-section nil
))
456 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
457 (org-trim (org-export-as (org-test-default-backend)
458 nil nil nil
'(:with-footnotes nil
)))))))
460 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
461 (let ((org-footnote-section nil
))
462 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
463 (org-trim (org-export-as (org-test-default-backend)
464 nil nil nil
'(:with-footnotes t
)))))))
466 (when (featurep 'org-inlinetask
)
470 (let ((org-inlinetask-min-level 15))
471 (org-test-with-temp-text "*************** Task"
472 (org-export-as (org-test-default-backend)
473 nil nil nil
'(:with-inlinetasks nil
))))))
477 (let ((org-inlinetask-min-level 15))
478 (org-test-with-temp-text
479 "*************** Task\nContents\n*************** END"
480 (org-export-as (org-test-default-backend)
481 nil nil nil
'(:with-inlinetasks nil
)))))))
485 "CLOSED: \\[2012-04-29 .* 10:45\\]"
486 (let ((org-closed-string "CLOSED:"))
487 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
488 (org-export-as (org-test-default-backend)
489 nil nil nil
'(:with-planning t
))))))
492 (let ((org-closed-string "CLOSED:"))
493 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
494 (org-export-as (org-test-default-backend)
495 nil nil nil
'(:with-planning nil
))))))
499 (org-test-with-temp-text
500 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
501 (org-export-as (org-test-default-backend)
502 nil nil nil
'(:with-properties nil
)))))
504 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
505 (org-test-with-temp-text
506 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
507 (org-export-as (org-test-default-backend)
508 nil nil nil
'(:with-properties t
)))))
510 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
511 (org-test-with-temp-text
512 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
513 (org-export-as (org-test-default-backend)
514 nil nil nil
'(:with-properties
("B"))))))
515 ;; Statistics cookies.
518 (org-test-with-temp-text "[0/0]"
519 (org-export-as (org-test-default-backend)
520 nil nil nil
'(:with-statistics-cookies nil
)))))
524 (org-test-with-temp-text "| A |"
525 (org-export-as (org-test-default-backend) nil nil nil
526 '(:with-tables t
)))))
529 (org-test-with-temp-text "| A |"
530 (org-export-as (org-test-default-backend) nil nil nil
531 '(:with-tables nil
))))))
533 (ert-deftest test-org-export
/with-timestamps
()
534 "Test `org-export-with-timestamps' specifications."
538 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
539 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
540 (org-export-as (org-test-default-backend)
541 nil nil nil
'(:with-timestamps t
)))))
546 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
547 (org-export-as (org-test-default-backend)
548 nil nil nil
'(:with-timestamps nil
)))))
552 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
553 (org-test-with-temp-text
554 "<2012-03-29 Thu>[2012-03-29 Thu]
556 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
557 (org-export-as (org-test-default-backend)
558 nil nil nil
'(:with-timestamps active
)))))
562 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
563 (org-test-with-temp-text
564 "<2012-03-29 Thu>[2012-03-29 Thu]
566 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
567 (org-export-as (org-test-default-backend)
568 nil nil nil
'(:with-timestamps inactive
))))))
570 (ert-deftest test-org-export
/comment-tree
()
571 "Test if export process ignores commented trees."
574 (org-test-with-temp-text "* COMMENT Head1"
575 (org-export-as (org-test-default-backend))))))
577 (ert-deftest test-org-export
/uninterpreted
()
578 "Test handling of uninterpreted elements."
582 (org-test-with-temp-text "\\alpha"
584 (org-export-create-backend
585 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
586 (paragraph .
(lambda (p c i
) c
))
587 (section .
(lambda (s c i
) c
))))
588 nil nil nil
'(:with-entities t
)))))
591 (org-test-with-temp-text "\\alpha"
593 (org-export-create-backend
594 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
595 (paragraph .
(lambda (p c i
) c
))
596 (section .
(lambda (s c i
) c
))))
597 nil nil nil
'(:with-entities nil
)))))
601 (org-test-with-temp-text "*bold*"
603 (org-export-create-backend
604 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
605 (paragraph .
(lambda (p c i
) c
))
606 (section .
(lambda (s c i
) c
))))
607 nil nil nil
'(:with-emphasize t
)))))
610 (org-test-with-temp-text "*bold*"
612 (org-export-create-backend
613 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
614 (paragraph .
(lambda (p c i
) c
))
615 (section .
(lambda (s c i
) c
))))
616 nil nil nil
'(:with-emphasize nil
)))))
617 ;; LaTeX environment.
620 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
622 (org-export-create-backend
623 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
624 (section .
(lambda (s c i
) c
))))
625 nil nil nil
'(:with-latex t
)))))
627 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
628 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
630 (org-export-create-backend
631 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
632 (section .
(lambda (s c i
) c
))))
633 nil nil nil
'(:with-latex verbatim
)))))
637 (org-test-with-temp-text "$1$"
639 (org-export-create-backend
640 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
641 (paragraph .
(lambda (p c i
) c
))
642 (section .
(lambda (s c i
) c
))))
643 nil nil nil
'(:with-latex t
)))))
646 (org-test-with-temp-text "$1$"
648 (org-export-create-backend
649 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
650 (paragraph .
(lambda (p c i
) c
))
651 (section .
(lambda (s c i
) c
))))
652 nil nil nil
'(:with-latex verbatim
)))))
656 (org-test-with-temp-text "a_b"
658 (org-export-create-backend
659 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
660 (paragraph .
(lambda (p c i
) c
))
661 (section .
(lambda (s c i
) c
))))
662 nil nil nil
'(:with-sub-superscript t
)))))
665 (org-test-with-temp-text "a_b"
667 (org-export-create-backend
668 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
669 (paragraph .
(lambda (p c i
) c
))
670 (section .
(lambda (s c i
) c
))))
671 nil nil nil
'(:with-sub-superscript nil
)))))
674 (org-test-with-temp-text "a_b"
676 (org-export-create-backend
677 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
678 (paragraph .
(lambda (p c i
) c
))
679 (section .
(lambda (s c i
) c
))))
680 nil nil nil
'(:with-sub-superscript
{})))))
683 (org-test-with-temp-text "a_{b}"
685 (org-export-create-backend
686 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
687 (paragraph .
(lambda (p c i
) c
))
688 (section .
(lambda (s c i
) c
))))
689 nil nil nil
'(:with-sub-superscript
{})))))
690 ;; Also handle uninterpreted objects in title.
693 (org-test-with-temp-text "#+TITLE: a_b"
695 (org-export-create-backend
697 '((subscript .
(lambda (s c i
) "dummy"))
698 (template .
(lambda (c i
) (org-export-data
699 (plist-get i
:title
) i
)))
700 (section .
(lambda (s c i
) c
))))
701 nil nil nil
'(:with-sub-superscript nil
)))))
702 ;; Special case: multiples uninterpreted objects in a row.
705 (org-test-with-temp-text "a_b_c_d"
707 (org-export-create-backend
708 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
709 (paragraph .
(lambda (p c i
) c
))
710 (section .
(lambda (s c i
) c
))))
711 nil nil nil
'(:with-sub-superscript
{}))))))
713 (ert-deftest test-org-export
/export-scope
()
714 "Test all export scopes."
715 (org-test-with-temp-text "
722 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
723 "text\n*** Head3\n"))
725 (goto-char (point-min))
728 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
731 (goto-char (point-min))
733 (transient-mark-mode 1)
734 (push-mark (point) t t
)
735 (goto-char (point-at-eol))
736 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
737 ;; Subtree with a code block calling another block outside.
740 (org-test-with-temp-text "
742 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
747 #+BEGIN_SRC emacs-lisp
751 (org-export-as (org-test-default-backend) 'subtree
))))
753 (let ((backend (org-test-default-backend)))
754 (setf (org-export-backend-transcoders backend
)
755 (cons '(template .
(lambda (body i
)
756 (format "BEGIN\n%sEND" body
)))
757 (org-export-backend-transcoders backend
)))
758 (org-test-with-temp-text "Text"
759 (should (equal (org-export-as backend nil nil
'body-only
)
761 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
763 (ert-deftest test-org-export
/output-file-name
()
764 "Test `org-export-output-file-name' specifications."
765 ;; Export from a file: name is built from original file name.
767 (org-test-with-temp-text-in-file "Test"
768 (equal (concat (file-name-as-directory ".")
769 (file-name-nondirectory
770 (file-name-sans-extension (buffer-file-name))))
771 (file-name-sans-extension (org-export-output-file-name ".ext")))))
772 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
774 (org-test-with-temp-text-in-file
775 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
776 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
777 ;; From a buffer not associated to a file, too.
779 (org-test-with-temp-text
780 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
781 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
782 ;; When provided name is absolute, preserve it.
784 (org-test-with-temp-text
785 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
786 (expand-file-name "test"))
787 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
788 ;; When PUB-DIR argument is provided, use it.
790 (org-test-with-temp-text-in-file "Test"
791 (equal (file-name-directory
792 (org-export-output-file-name ".ext" nil
"dir/"))
794 ;; When returned name would overwrite original file, add EXTENSION
797 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
798 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
800 (ert-deftest test-org-export
/expand-include
()
801 "Test file inclusion in an Org buffer."
802 ;; Error when file isn't specified.
804 (org-test-with-temp-text "#+INCLUDE: dummy.org"
805 (org-export-expand-include-keyword)))
806 ;; Full insertion with recursive inclusion.
807 (org-test-with-temp-text
808 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
809 (org-export-expand-include-keyword)
810 (should (equal (buffer-string)
811 "Small Org file with an include keyword.
813 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
819 ;; Localized insertion.
820 (org-test-with-temp-text
821 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
823 (org-export-expand-include-keyword)
824 (should (equal (buffer-string)
825 "Small Org file with an include keyword.\n")))
826 ;; Insertion with constraints on headlines level.
829 "* Top heading\n** Heading\nbody\n"
830 (org-test-with-temp-text
832 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
834 (org-export-expand-include-keyword)
838 "* Top heading\n* Heading\nbody\n"
839 (org-test-with-temp-text
841 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
843 (org-export-expand-include-keyword)
845 ;; Inclusion within an example block.
848 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
849 (org-test-with-temp-text
850 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
852 (org-export-expand-include-keyword)
854 ;; Inclusion within a src-block.
857 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
858 (org-test-with-temp-text
860 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
862 (org-export-expand-include-keyword)
864 ;; Inclusion within an html export-block.
867 "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
868 (org-test-with-temp-text
870 "#+INCLUDE: \"%s/examples/include.html\" HTML"
872 (org-export-expand-include-keyword)
874 ;; Inclusion within an center paragraph
877 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
878 (org-test-with-temp-text
880 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
882 (org-export-expand-include-keyword)
884 ;; Footnotes labels are local to each included file.
890 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
892 \[fn:test] Footnote \"test\""))
893 (org-test-with-temp-text-in-file contents
894 (let ((file1 (buffer-file-name)))
895 (org-test-with-temp-text-in-file contents
896 (let ((file2 (buffer-file-name)))
897 (org-test-with-temp-text
898 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
900 (org-export-expand-include-keyword)
901 (org-element-map (org-element-parse-buffer)
904 (org-element-property :label ref
)))))))))))))
905 ;; Footnotes labels are not local to each include keyword.
911 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
913 \[fn:test] Footnote \"test\""))
914 (org-test-with-temp-text-in-file contents
915 (let ((file (buffer-file-name)))
916 (org-test-with-temp-text
917 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
918 (org-export-expand-include-keyword)
919 (org-element-map (org-element-parse-buffer)
921 (lambda (ref) (org-element-property :label ref
))))))))))))
923 (ert-deftest test-org-export
/expand-macro
()
924 "Test macro expansion in an Org buffer."
925 ;; Standard macro expansion.
927 (equal "#+MACRO: macro1 value\nvalue\n"
928 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
929 (org-export-as (org-test-default-backend)))))
930 ;; Expand specific macros.
932 (equal "me 2012-03-29 me@here Title\n"
933 (org-test-with-temp-text
939 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
940 (let ((output (org-export-as (org-test-default-backend))))
941 (substring output
(string-match ".*\n\\'" output
))))))
942 ;; Expand specific macros when property contained a regular macro
946 (org-test-with-temp-text "
947 #+MACRO: macro1 value
948 #+TITLE: {{{macro1}}}
950 (let ((output (org-export-as (org-test-default-backend))))
951 (substring output
(string-match ".*\n\\'" output
))))))
952 ;; Expand macros with templates in included files.
955 (org-test-with-temp-text
956 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
957 {{{included-macro}}}" org-test-dir
)
958 (let ((output (org-export-as (org-test-default-backend))))
959 (substring output
(string-match ".*\n\\'" output
)))))))
961 (ert-deftest test-org-export
/user-ignore-list
()
962 "Test if `:ignore-list' accepts user input."
963 (let ((backend (org-test-default-backend)))
964 (setf (org-export-backend-transcoders backend
)
965 (cons '(template .
(lambda (body i
)
966 (format "BEGIN\n%sEND" body
)))
967 (org-export-backend-transcoders backend
)))
968 (org-test-with-temp-text "Text"
969 (should (equal (org-export-as backend nil nil
'body-only
)
971 (should (equal (org-export-as backend
) "BEGIN\nText\nEND"))))
975 (let ((org-export-filter-parse-tree-functions
976 '((lambda (data backend info
)
977 ;; Ignore headlines with the word "note" in their title.
978 (org-element-map data
'headline
980 (when (string-match "\\<note\\>"
981 (org-element-property :raw-value
983 (org-export-ignore-element headline info
)))
986 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
987 (org-export-as (org-test-default-backend)))))))
989 (ert-deftest test-org-export
/before-processing-hook
()
990 "Test `org-export-before-processing-hook'."
993 "#+MACRO: mac val\nTest\n"
994 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
995 (let ((org-export-before-processing-hook
997 (while (re-search-forward "{{{" nil t
)
998 (let ((object (org-element-context)))
999 (when (eq (org-element-type object
) 'macro
)
1001 (org-element-property :begin object
)
1002 (org-element-property :end object
)))))))))
1003 (org-export-as (org-test-default-backend)))))))
1005 (ert-deftest test-org-export
/before-parsing-hook
()
1006 "Test `org-export-before-parsing-hook'."
1008 (equal "Body 1\nBody 2\n"
1009 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1010 (let ((org-export-before-parsing-hook
1012 (goto-char (point-min))
1013 (while (re-search-forward org-outline-regexp-bol nil t
)
1015 (point-at-bol) (progn (forward-line) (point))))))))
1016 (org-export-as (org-test-default-backend)))))))
1020 ;;; Affiliated Keywords
1022 (ert-deftest test-org-export
/read-attribute
()
1023 "Test `org-export-read-attribute' specifications."
1027 (org-export-read-attribute
1029 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1030 (org-element-at-point)))
1032 ;; Return nil on empty attribute.
1034 (org-export-read-attribute
1036 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1037 ;; Return nil on "nil" string.
1039 (equal '(:a nil
:b nil
)
1040 (org-export-read-attribute
1042 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1043 (org-element-at-point)))))
1044 ;; Return nil on empty string.
1046 (equal '(:a nil
:b nil
)
1047 (org-export-read-attribute
1049 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1050 (org-element-at-point)))))
1051 ;; Return empty string when value is "".
1054 (org-export-read-attribute
1056 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1057 (org-element-at-point)))))
1058 ;; Return \"\" when value is """".
1061 (org-export-read-attribute
1063 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1064 (org-element-at-point)))))
1065 ;; Ignore text before first property.
1068 (org-export-read-attribute
1070 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1071 (org-element-at-point))))))
1073 (ert-deftest test-org-export
/get-caption
()
1074 "Test `org-export-get-caption' specifications."
1075 ;; Without optional argument, return long caption
1079 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1080 (org-export-get-caption (org-element-at-point)))))
1081 ;; With optional argument, return short caption.
1085 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1086 (org-export-get-caption (org-element-at-point) t
))))
1087 ;; Multiple lines are separated by white spaces.
1091 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1092 (org-export-get-caption (org-element-at-point))))))
1098 (ert-deftest test-org-export
/define-backend
()
1099 "Test back-end definition and accessors."
1102 (equal '((headline . my-headline-test
))
1103 (let (org-export--registered-backends)
1104 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1105 (org-export-get-all-transcoders 'test
))))
1108 (equal '((:filter-headline . my-filter
))
1109 (let (org-export--registered-backends)
1110 (org-export-define-backend 'test
1111 '((headline . my-headline-test
))
1112 :filters-alist
'((:filter-headline . my-filter
)))
1113 (org-export-backend-filters (org-export-get-backend 'test
)))))
1116 (equal '((:prop value
))
1117 (let (org-export--registered-backends)
1118 (org-export-define-backend 'test
1119 '((headline . my-headline-test
))
1120 :options-alist
'((:prop value
)))
1121 (org-export-backend-options (org-export-get-backend 'test
)))))
1124 (equal '(?k
"Test Export" test
)
1125 (let (org-export--registered-backends)
1126 (org-export-define-backend 'test
1127 '((headline . my-headline-test
))
1128 :menu-entry
'(?k
"Test Export" test
))
1129 (org-export-backend-menu (org-export-get-backend 'test
))))))
1131 (ert-deftest test-org-export
/define-derived-backend
()
1132 "Test `org-export-define-derived-backend' specifications."
1133 ;; Error when parent back-end is not defined.
1135 (let (org-export--registered-backends)
1136 (org-export-define-derived-backend 'test
'parent
)))
1137 ;; Append translation table to parent's.
1139 (equal '((:headline . test
) (:headline . parent
))
1140 (let (org-export--registered-backends)
1141 (org-export-define-backend 'parent
'((:headline . parent
)))
1142 (org-export-define-derived-backend 'test
'parent
1143 :translate-alist
'((:headline . test
)))
1144 (org-export-get-all-transcoders 'test
))))
1145 ;; Options defined in the new back have priority over those defined
1149 (let (org-export--registered-backends)
1150 (org-export-define-backend 'parent
1151 '((:headline . parent
))
1152 :options-alist
'((:a nil nil
'parent
)))
1153 (org-export-define-derived-backend 'test
'parent
1154 :options-alist
'((:a nil nil
'test
)))
1155 (plist-get (org-export--get-global-options
1156 (org-export-get-backend 'test
))
1159 (ert-deftest test-org-export
/derived-backend-p
()
1160 "Test `org-export-derived-backend-p' specifications."
1161 ;; Non-nil with direct match.
1163 (let (org-export--registered-backends)
1164 (org-export-define-backend 'test
'((headline . test
)))
1165 (org-export-derived-backend-p 'test
'test
)))
1167 (let (org-export--registered-backends)
1168 (org-export-define-backend 'test
'((headline . test
)))
1169 (org-export-define-derived-backend 'test2
'test
)
1170 (org-export-derived-backend-p 'test2
'test2
)))
1171 ;; Non-nil with a direct parent.
1173 (let (org-export--registered-backends)
1174 (org-export-define-backend 'test
'((headline . test
)))
1175 (org-export-define-derived-backend 'test2
'test
)
1176 (org-export-derived-backend-p 'test2
'test
)))
1177 ;; Non-nil with an indirect parent.
1179 (let (org-export--registered-backends)
1180 (org-export-define-backend 'test
'((headline . test
)))
1181 (org-export-define-derived-backend 'test2
'test
)
1182 (org-export-define-derived-backend 'test3
'test2
)
1183 (org-export-derived-backend-p 'test3
'test
)))
1186 (let (org-export--registered-backends)
1187 (org-export-define-backend 'test
'((headline . test
)))
1188 (org-export-define-backend 'test2
'((headline . test2
)))
1189 (org-export-derived-backend-p 'test2
'test
)))
1191 (let (org-export--registered-backends)
1192 (org-export-define-backend 'test
'((headline . test
)))
1193 (org-export-define-backend 'test2
'((headline . test2
)))
1194 (org-export-define-derived-backend 'test3
'test2
)
1195 (org-export-derived-backend-p 'test3
'test
))))
1197 (ert-deftest test-org-export
/get-all-transcoders
()
1198 "Test `org-export-get-all-transcoders' specifications."
1199 ;; Return nil when back-end cannot be found.
1200 (should-not (org-export-get-all-transcoders nil
))
1201 ;; Same as `org-export-transcoders' if no parent.
1203 (equal '((headline . ignore
))
1204 (org-export-get-all-transcoders
1205 (org-export-create-backend
1206 :transcoders
'((headline . ignore
))))))
1207 ;; But inherit from all ancestors whenever possible.
1209 (equal '((section . ignore
) (headline . ignore
))
1210 (let (org-export--registered-backends)
1211 (org-export-define-backend 'b1
'((headline . ignore
)))
1212 (org-export-get-all-transcoders
1213 (org-export-create-backend
1214 :parent
'b1
:transcoders
'((section . ignore
)))))))
1216 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1217 (let (org-export--registered-backends)
1218 (org-export-define-backend 'b1
'((headline . ignore
)))
1219 (org-export-define-derived-backend 'b2
'b1
1220 :translate-alist
'((section . ignore
)))
1221 (org-export-get-all-transcoders
1222 (org-export-create-backend
1223 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1224 ;; Back-end transcoders overrule inherited ones.
1227 (let (org-export--registered-backends)
1228 (org-export-define-backend 'b1
'((headline . a
)))
1229 (cdr (assq 'headline
1230 (org-export-get-all-transcoders
1231 (org-export-create-backend
1232 :parent
'b1
:transcoders
'((headline . b
))))))))))
1234 (ert-deftest test-org-export
/get-all-options
()
1235 "Test `org-export-get-all-options' specifications."
1236 ;; Return nil when back-end cannot be found.
1237 (should-not (org-export-get-all-options nil
))
1238 ;; Same as `org-export-options' if no parent.
1240 (equal '((headline . ignore
))
1241 (org-export-get-all-options
1242 (org-export-create-backend
1243 :options
'((headline . ignore
))))))
1244 ;; But inherit from all ancestors whenever possible.
1246 (equal '((:key2 value2
) (:key1 value1
))
1247 (let (org-export--registered-backends)
1248 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1249 (org-export-get-all-options
1250 (org-export-create-backend
1251 :parent
'b1
:options
'((:key2 value2
)))))))
1253 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1254 (let (org-export--registered-backends)
1255 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1256 (org-export-define-derived-backend 'b2
'b1
1257 :options-alist
'((:key2 value2
)))
1258 (org-export-get-all-options
1259 (org-export-create-backend
1260 :parent
'b2
:options
'((:key3 value3
)))))))
1261 ;; Back-end options overrule inherited ones.
1264 (let (org-export--registered-backends)
1265 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1267 (org-export-get-all-options
1268 (org-export-create-backend
1269 :parent
'b1
:options
'((:key1 . b
))))))))))
1271 (ert-deftest test-org-export
/get-all-filters
()
1272 "Test `org-export-get-all-filters' specifications."
1273 ;; Return nil when back-end cannot be found.
1274 (should-not (org-export-get-all-filters nil
))
1275 ;; Same as `org-export-filters' if no parent.
1277 (equal '((:filter-headline . ignore
))
1278 (org-export-get-all-filters
1279 (org-export-create-backend
1280 :filters
'((:filter-headline . ignore
))))))
1281 ;; But inherit from all ancestors whenever possible.
1283 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1284 (let (org-export--registered-backends)
1285 (org-export-define-backend 'b1
1286 nil
:filters-alist
'((:filter-headline . ignore
)))
1287 (org-export-get-all-filters
1288 (org-export-create-backend
1289 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1291 (equal '((:filter-paragraph . ignore
)
1292 (:filter-section . ignore
)
1293 (:filter-headline . ignore
))
1294 (let (org-export--registered-backends)
1295 (org-export-define-backend 'b1
1296 nil
:filters-alist
'((:filter-headline . ignore
)))
1297 (org-export-define-derived-backend 'b2
'b1
1298 :filters-alist
'((:filter-section . ignore
)))
1299 (org-export-get-all-filters
1300 (org-export-create-backend
1301 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1302 ;; Back-end filters overrule inherited ones.
1305 (let (org-export--registered-backends)
1306 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1307 (cdr (assq :filter-headline
1308 (org-export-get-all-filters
1309 (org-export-create-backend
1310 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1312 (ert-deftest test-org-export
/with-backend
()
1313 "Test `org-export-with-backend' definition."
1314 ;; Error when calling an undefined back-end
1315 (should-error (org-export-with-backend nil
"Test"))
1316 ;; Error when called back-end doesn't have an appropriate
1319 (org-export-with-backend
1320 (org-export-create-backend :transcoders
'((headline . ignore
)))
1322 ;; Otherwise, export using correct transcoder
1325 (let (org-export--registered-backends)
1326 (org-export-define-backend 'test
1327 '((plain-text .
(lambda (text contents info
) "Failure"))))
1328 (org-export-define-backend 'test2
1329 '((plain-text .
(lambda (text contents info
) "Success"))))
1330 (org-export-with-backend 'test2
"Test"))))
1331 ;; Provide correct back-end if transcoder needs to use recursive
1335 (let ((test-back-end
1336 (org-export-create-backend
1338 '((headline .
(lambda (headline contents info
)
1340 (org-element-property :title headline
)
1342 (plain-text .
(lambda (text info
) "Success"))))))
1343 (org-export-string-as
1345 (org-export-create-backend
1347 '((headline .
(lambda (headline contents info
)
1348 (org-export-with-backend
1349 test-back-end headline contents info
))))))))))
1351 (ert-deftest test-org-export
/data-with-backend
()
1352 "Test `org-export-data-with-backend' specifications."
1353 ;; Error when calling an undefined back-end.
1354 (should-error (org-export-data-with-backend nil
"nil" nil
))
1355 ;; Otherwise, export data recursively, using correct back-end.
1359 (org-export-data-with-backend
1361 (org-export-create-backend
1363 '((plain-text .
(lambda (text info
) "Success"))
1364 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1365 '(:with-emphasize t
)))))
1371 (ert-deftest test-org-export
/export-snippet
()
1372 "Test export snippets transcoding."
1374 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1375 (let ((backend (org-test-default-backend)))
1376 (setf (org-export-backend-name backend
) 'test
)
1377 (setf (org-export-backend-transcoders backend
)
1378 (cons (cons 'export-snippet
1379 (lambda (snippet contents info
)
1380 (when (eq (org-export-snippet-backend snippet
) 'test
)
1381 (org-element-property :value snippet
))))
1382 (org-export-backend-transcoders backend
)))
1383 (let ((org-export-snippet-translation-alist nil
))
1384 (should (equal (org-export-as backend
) "A\n")))
1385 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1386 (should (equal (org-export-as backend
) "AB\n")))))
1387 ;; Ignored export snippets do not remove any blank.
1389 (equal "begin end\n"
1390 (org-test-with-parsed-data "begin @@test:A@@ end"
1391 (org-export-data-with-backend
1393 (org-export-create-backend
1395 '((paragraph .
(lambda (paragraph contents info
) contents
))
1396 (section .
(lambda (section contents info
) contents
))))
1403 (ert-deftest test-org-export
/footnotes
()
1404 "Test footnotes specifications."
1405 (let ((org-footnote-section nil
)
1406 (org-export-with-footnotes t
))
1407 ;; 1. Read every type of footnote.
1410 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1411 (org-test-with-parsed-data
1412 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1413 (org-element-map tree
'footnote-reference
1415 (let ((def (org-export-get-footnote-definition ref info
)))
1416 (cons (org-export-get-footnote-number ref info
)
1417 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1418 (car (org-element-contents
1419 (car (org-element-contents def
))))))))
1421 ;; 2. Test nested footnotes order.
1424 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
1425 (org-test-with-parsed-data
1426 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1427 (org-element-map tree
'footnote-reference
1429 (when (org-export-footnote-first-reference-p ref info
)
1430 (cons (org-export-get-footnote-number ref info
)
1431 (org-element-property :label ref
))))
1433 ;; 3. Test nested footnote in invisible definitions.
1434 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1435 ;; Hide definitions.
1436 (narrow-to-region (point) (point-at-eol))
1437 (let* ((tree (org-element-parse-buffer))
1438 (info (org-combine-plists
1439 `(:parse-tree
,tree
)
1440 (org-export-collect-tree-properties
1441 tree
(org-export-get-environment)))))
1442 ;; Both footnotes should be seen.
1444 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
1445 ;; 4. Test footnotes definitions collection.
1448 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1450 \[fn:2] B [fn:3] [fn::D].
1453 (length (org-export-collect-footnote-definitions tree info
)))))
1454 ;; 5. Test export of footnotes defined outside parsing scope.
1457 "ParagraphOut of scope\n"
1458 (org-test-with-temp-text "[fn:1] Out of scope
1461 (let ((backend (org-test-default-backend)))
1462 (setf (org-export-backend-transcoders backend
)
1463 (cons (cons 'footnote-reference
1464 (lambda (fn contents info
)
1465 (org-element-interpret-data
1466 (org-export-get-footnote-definition fn info
))))
1467 (org-export-backend-transcoders backend
)))
1469 (org-export-as backend
'subtree
)))))
1470 ;; 6. Footnotes without a definition should be provided a fallback
1473 (org-test-with-parsed-data "[fn:1]"
1474 (org-export-get-footnote-definition
1475 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1476 ;; 7. Footnote section should be ignored in TOC and in headlines
1479 (= 1 (let ((org-footnote-section "Footnotes"))
1480 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1481 (org-export-collect-headlines info
))))))
1484 (let ((org-footnote-section "Footnotes"))
1485 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1486 (org-element-map tree
'headline
1488 (when (equal (org-element-property :raw-value hl
) "H2")
1489 (org-export-get-headline-number hl info
)))
1494 ;;; Headlines and Inlinetasks
1496 (ert-deftest test-org-export
/get-relative-level
()
1497 "Test `org-export-get-relative-level' specifications."
1501 (let ((org-odd-levels-only nil
))
1502 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1503 (org-element-map tree
'headline
1504 (lambda (h) (org-export-get-relative-level h info
))
1509 (let ((org-odd-levels-only nil
))
1510 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1511 (org-element-map tree
'headline
1512 (lambda (h) (org-export-get-relative-level h info
))
1515 (ert-deftest test-org-export
/low-level-p
()
1516 "Test `org-export-low-level-p' specifications."
1520 (let ((org-odd-levels-only nil
))
1521 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1522 (org-element-map tree
'headline
1523 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1524 (plist-put info
:headline-levels
1)))))))
1526 (ert-deftest test-org-export
/get-headline-number
()
1527 "Test `org-export-get-headline-number' specifications."
1532 (let ((org-odd-levels-only nil
))
1533 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1534 (org-element-map tree
'headline
1535 (lambda (h) (org-export-get-headline-number h info
))
1537 ;; Missing levels are replaced with 0.
1541 (let ((org-odd-levels-only nil
))
1542 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1543 (org-element-map tree
'headline
1544 (lambda (h) (org-export-get-headline-number h info
))
1547 (ert-deftest test-org-export
/numbered-headline-p
()
1548 "Test `org-export-numbered-headline-p' specifications."
1549 ;; If `:section-numbers' is nil, never number headlines.
1551 (org-test-with-parsed-data "* Headline"
1552 (org-element-map tree
'headline
1553 (lambda (h) (org-export-numbered-headline-p h info
))
1554 (plist-put info
:section-numbers nil
))))
1555 ;; If `:section-numbers' is a number, only number headlines with
1556 ;; a level greater that it.
1560 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1561 (org-element-map tree
'headline
1562 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1563 (plist-put info
:section-numbers
1)))))
1564 ;; Otherwise, headlines are always numbered.
1566 (org-test-with-parsed-data "* Headline"
1567 (org-element-map tree
'headline
1568 (lambda (h) (org-export-numbered-headline-p h info
))
1569 (plist-put info
:section-numbers t
)))))
1571 (ert-deftest test-org-export
/number-to-roman
()
1572 "Test `org-export-number-to-roman' specifications."
1573 ;; If number is negative, return it as a string.
1574 (should (equal (org-export-number-to-roman -
1) "-1"))
1575 ;; Otherwise, return it as a roman number.
1576 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1578 (ert-deftest test-org-export
/get-optional-title
()
1579 "Test `org-export-get-alt-title' specifications."
1580 ;; If ALT_TITLE property is defined, use it.
1583 (org-test-with-parsed-data
1584 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1585 (org-export-get-alt-title
1586 (org-element-map tree
'headline
'identity info t
)
1588 ;; Otherwise, fall-back to regular title.
1590 (equal '("Headline")
1591 (org-test-with-parsed-data "* Headline"
1592 (org-export-get-alt-title
1593 (org-element-map tree
'headline
'identity info t
)
1596 (ert-deftest test-org-export
/get-tags
()
1597 "Test `org-export-get-tags' specifications."
1598 (let ((org-export-exclude-tags '("noexport"))
1599 (org-export-select-tags '("export")))
1600 ;; Standard test: tags which are not a select tag, an exclude tag,
1601 ;; or specified as optional argument shouldn't be ignored.
1603 (org-test-with-parsed-data "* Headline :tag:"
1604 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1606 ;; Exclude tags are removed.
1608 (org-test-with-parsed-data "* Headline :noexport:"
1609 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1611 ;; Select tags are removed.
1613 (org-test-with-parsed-data "* Headline :export:"
1614 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1619 (org-test-with-parsed-data "* Headline :tag:export:"
1620 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1622 ;; Tags provided in the optional argument are also ignored.
1624 (org-test-with-parsed-data "* Headline :ignore:"
1625 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1627 ;; Allow tag inheritance.
1631 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1632 (org-element-map tree
'headline
1633 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1634 ;; Tag inheritance checks FILETAGS keywords.
1638 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1639 (org-element-map tree
'headline
1640 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1642 (ert-deftest test-org-export
/get-node-property
()
1643 "Test`org-export-get-node-property' specifications."
1647 (org-test-with-parsed-data "* Headline
1651 (org-export-get-node-property
1652 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1653 ;; Test inheritance.
1656 (org-test-with-parsed-data "* Parent
1662 (org-export-get-node-property
1663 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1664 ;; Cannot return a value before the first headline.
1666 (org-test-with-parsed-data "Paragraph
1671 (org-export-get-node-property
1672 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1674 (ert-deftest test-org-export
/get-category
()
1675 "Test `org-export-get-category' specifications."
1679 (org-test-with-parsed-data "* Headline
1683 (org-export-get-category
1684 (org-element-map tree
'headline
'identity nil t
) info
))))
1685 ;; Test inheritance from a parent headline.
1687 (equal '("value" "value")
1688 (org-test-with-parsed-data "* Headline1
1693 (org-element-map tree
'headline
1694 (lambda (hl) (org-export-get-category hl info
)) info
))))
1695 ;; Test inheritance from #+CATEGORY keyword
1698 (org-test-with-parsed-data "#+CATEGORY: value
1700 (org-export-get-category
1701 (org-element-map tree
'headline
'identity nil t
) info
))))
1702 ;; Test inheritance from file name.
1705 (org-test-with-parsed-data "* Headline"
1706 (let ((info (plist-put info
:input-file
"~/test.org")))
1707 (org-export-get-category
1708 (org-element-map tree
'headline
'identity nil t
) info
)))))
1712 (org-test-with-parsed-data "* Headline"
1713 (org-export-get-category
1714 (org-element-map tree
'headline
'identity nil t
) info
)))))
1716 (ert-deftest test-org-export
/first-sibling-p
()
1717 "Test `org-export-first-sibling-p' specifications."
1722 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
1723 (org-element-map tree
'headline
1724 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1728 (org-test-with-parsed-data "- item\n\n para"
1729 (org-element-map tree
'paragraph
1730 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1732 ;; Ignore sections for headlines.
1735 (org-test-with-parsed-data "* H\nSection\n** H 2"
1736 (org-element-map tree
'headline
1737 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1739 ;; Ignore headlines not exported.
1743 (let ((org-export-exclude-tags '("ignore")))
1744 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1745 (org-element-map tree
'headline
1746 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1749 (ert-deftest test-org-export
/last-sibling-p
()
1750 "Test `org-export-last-sibling-p' specifications."
1755 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1756 (org-element-map tree
'headline
1757 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1761 (org-test-with-parsed-data "- item\n\n para"
1762 (org-element-map tree
'paragraph
1763 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1765 ;; Ignore headlines not exported.
1769 (let ((org-export-exclude-tags '("ignore")))
1770 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1771 (org-element-map tree
'headline
1772 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1775 (ert-deftest test-org-export
/handle-inlinetasks
()
1776 "Test inlinetask export."
1777 ;; Inlinetask with an exclude tag.
1778 (when (featurep 'org-inlinetask
)
1782 (let ((org-inlinetask-min-level 3))
1783 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1784 (org-export-as (org-test-default-backend)
1785 nil nil nil
'(:exclude-tags
("noexp")))))))
1786 ;; Inlinetask with an include tag.
1789 "* H2\n*** Inline :exp:\n"
1790 (let ((org-inlinetask-min-level 3)
1791 (org-tags-column 0))
1792 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1793 (org-export-as (org-test-default-backend)
1794 nil nil nil
'(:select-tags
("exp")))))))
1795 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1798 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1799 (org-inlinetask-min-level 3))
1800 (org-test-with-temp-text "*** TODO Inline"
1801 (org-export-as (org-test-default-backend)
1802 nil nil nil
'(:with-tasks nil
))))))))
1808 (ert-deftest test-org-export
/get-date
()
1809 "Test `org-export-get-date' specifications."
1810 ;; Return a properly formatted string when
1811 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1812 ;; consists in a single timestamp.
1815 (let ((org-export-date-timestamp-format "%d %m %Y"))
1816 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1817 (org-export-get-date info
)))))
1818 ;; Return a secondary string otherwise.
1821 (let ((org-export-date-timestamp-format nil
))
1822 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1823 (org-export-get-date info
)))))
1826 (org-test-with-parsed-data "#+DATE: Date"
1827 (org-export-get-date info
))))
1828 ;; Optional argument has precedence over
1829 ;; `org-export-date-timestamp-format'.
1832 (let ((org-export-date-timestamp-format "%d %m %Y"))
1833 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1834 (org-export-get-date info
"%d %m"))))))
1840 (ert-deftest test-org-export
/get-coderef-format
()
1841 "Test `org-export-get-coderef-format' specifications."
1842 ;; A link without description returns "%s"
1843 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1845 ;; Return "%s" when path is matched within description.
1846 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1848 ;; Otherwise return description.
1849 (should (equal (org-export-get-coderef-format "path" "desc")
1852 (ert-deftest test-org-export
/inline-image-p
()
1853 "Test `org-export-inline-image-p' specifications."
1855 (org-export-inline-image-p
1856 (org-test-with-temp-text "[[#id]]"
1857 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1858 '(("custom-id" .
"id")))))
1860 (ert-deftest test-org-export
/fuzzy-link
()
1861 "Test fuzzy links specifications."
1862 ;; Link to an headline should return headline's number.
1863 (org-test-with-parsed-data
1864 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1866 ;; Note: Headline's number is in fact a list of numbers.
1868 (org-element-map tree
'link
1870 (org-export-get-ordinal
1871 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1872 ;; Link to a target in an item should return item's number.
1873 (org-test-with-parsed-data
1874 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1876 ;; Note: Item's number is in fact a list of numbers.
1878 (org-element-map tree
'link
1880 (org-export-get-ordinal
1881 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1882 ;; Link to a target in a footnote should return footnote's number.
1883 (org-test-with-parsed-data "
1884 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1887 (org-element-map tree
'link
1889 (org-export-get-ordinal
1890 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1891 ;; Link to a named element should return sequence number of that
1893 (org-test-with-parsed-data
1894 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1897 (org-element-map tree
'link
1899 (org-export-get-ordinal
1900 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1901 ;; Link to a target not within an item, a table, a footnote
1902 ;; reference or definition should return section number.
1903 (org-test-with-parsed-data
1904 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1907 (org-element-map tree
'link
1909 (org-export-get-ordinal
1910 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1911 ;; Space are not significant when matching a fuzzy link.
1913 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1914 (org-element-map tree
'link
1915 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1917 ;; Statistics cookies are ignored for headline match.
1919 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1920 (org-element-map tree
'link
1921 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1924 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1925 (org-element-map tree
'link
1926 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1928 ;; Headline match is position dependent.
1932 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
1933 (org-element-map tree
'link
1934 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
1936 (ert-deftest test-org-export
/resolve-coderef
()
1937 "Test `org-export-resolve-coderef' specifications."
1938 (let ((org-coderef-label-format "(ref:%s)"))
1939 ;; 1. A link to a "-n -k -r" block returns line number.
1940 (org-test-with-parsed-data
1941 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1942 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1943 (org-test-with-parsed-data
1944 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1945 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1946 ;; 2. A link to a "-n -r" block returns line number.
1947 (org-test-with-parsed-data
1948 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1949 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1950 (org-test-with-parsed-data
1951 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1952 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1953 ;; 3. A link to a "-n" block returns coderef.
1954 (org-test-with-parsed-data
1955 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1956 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1957 (org-test-with-parsed-data
1958 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1959 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1960 ;; 4. A link to a "-r" block returns line number.
1961 (org-test-with-parsed-data
1962 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1963 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1964 (org-test-with-parsed-data
1965 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1966 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1967 ;; 5. A link to a block without a switch returns coderef.
1968 (org-test-with-parsed-data
1969 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1970 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1971 (org-test-with-parsed-data
1972 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1973 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1974 ;; 6. Correctly handle continued line numbers. A "+n" switch
1975 ;; should resume numbering from previous block with numbered
1976 ;; lines, ignoring blocks not numbering lines in the process.
1977 ;; A "-n" switch resets count.
1978 (org-test-with-parsed-data "
1983 #+BEGIN_SRC emacs-lisp
1987 #+BEGIN_SRC emacs-lisp +n -r
1988 \(+ 1 1) (ref:addition)
1991 #+BEGIN_EXAMPLE -n -r
1992 Another text. (ref:text)
1994 (should (= (org-export-resolve-coderef "addition" info
) 2))
1995 (should (= (org-export-resolve-coderef "text" info
) 1)))
1996 ;; 7. Recognize coderef with user-specified syntax.
1997 (org-test-with-parsed-data
1998 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1999 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
2001 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2002 "Test `org-export-resolve-fuzzy-link' specifications."
2003 ;; Match target objects.
2005 (org-test-with-parsed-data "<<target>> [[target]]"
2006 (org-export-resolve-fuzzy-link
2007 (org-element-map tree
'link
'identity info t
) info
)))
2008 ;; Match named elements.
2010 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2011 (org-export-resolve-fuzzy-link
2012 (org-element-map tree
'link
'identity info t
) info
)))
2013 ;; Match exact headline's name.
2015 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2016 (org-export-resolve-fuzzy-link
2017 (org-element-map tree
'link
'identity info t
) info
)))
2018 ;; Targets objects have priority over named elements and headline
2022 (org-test-with-parsed-data
2023 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2025 (org-export-resolve-fuzzy-link
2026 (org-element-map tree
'link
'identity info t
) info
)))))
2027 ;; Named elements have priority over headline titles.
2030 (org-test-with-parsed-data
2031 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2033 (org-export-resolve-fuzzy-link
2034 (org-element-map tree
'link
'identity info t
) info
)))))
2035 ;; If link's path starts with a "*", only match headline titles,
2039 (org-test-with-parsed-data
2040 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2042 (org-export-resolve-fuzzy-link
2043 (org-element-map tree
'link
'identity info t
) info
)))))
2044 ;; Return nil if no match.
2046 (org-test-with-parsed-data "[[target]]"
2047 (org-export-resolve-fuzzy-link
2048 (org-element-map tree
'link
'identity info t
) info
)))
2049 ;; Match fuzzy link even when before first headline.
2052 (org-test-with-parsed-data "[[hl]]\n* hl"
2054 (org-export-resolve-fuzzy-link
2055 (org-element-map tree
'link
'identity info t
) info
))))))
2057 (ert-deftest test-org-export
/resolve-id-link
()
2058 "Test `org-export-resolve-id-link' specifications."
2059 ;; 1. Regular test for custom-id link.
2060 (org-test-with-parsed-data "* Headline1
2067 (org-export-resolve-id-link
2068 (org-element-map tree
'link
'identity info t
) info
)))
2069 ;; 2. Failing test for custom-id link.
2070 (org-test-with-parsed-data "* Headline1
2077 (org-export-resolve-id-link
2078 (org-element-map tree
'link
'identity info t
) info
)))
2079 ;; 3. Test for internal id target.
2080 (org-test-with-parsed-data "* Headline1
2087 (org-export-resolve-id-link
2088 (org-element-map tree
'link
'identity info t
) info
)))
2089 ;; 4. Test for external id target.
2090 (org-test-with-parsed-data "[[id:aaaa]]"
2092 (org-export-resolve-id-link
2093 (org-element-map tree
'link
'identity info t
)
2094 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
2096 (ert-deftest test-org-export
/resolve-radio-link
()
2097 "Test `org-export-resolve-radio-link' specifications."
2100 (org-test-with-temp-text "<<<radio>>> radio"
2101 (org-update-radio-target-regexp)
2102 (let* ((tree (org-element-parse-buffer))
2103 (info `(:parse-tree
,tree
)))
2104 (org-export-resolve-radio-link
2105 (org-element-map tree
'link
'identity info t
)
2107 ;; Radio targets are case-insensitive.
2109 (org-test-with-temp-text "<<<RADIO>>> radio"
2110 (org-update-radio-target-regexp)
2111 (let* ((tree (org-element-parse-buffer))
2112 (info `(:parse-tree
,tree
)))
2113 (org-export-resolve-radio-link
2114 (org-element-map tree
'link
'identity info t
)
2116 ;; Radio target with objects.
2118 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2119 (org-update-radio-target-regexp)
2120 (let* ((tree (org-element-parse-buffer))
2121 (info `(:parse-tree
,tree
)))
2122 (org-export-resolve-radio-link
2123 (org-element-map tree
'link
'identity info t
)
2125 ;; Radio target with objects at its beginning.
2127 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2128 (org-update-radio-target-regexp)
2129 (let* ((tree (org-element-parse-buffer))
2130 (info `(:parse-tree
,tree
)))
2131 (org-export-resolve-radio-link
2132 (org-element-map tree
'link
'identity info t
)
2134 ;; Radio link next to an apostrophe.
2136 (org-test-with-temp-text "<<<radio>>> radio's"
2137 (org-update-radio-target-regexp)
2138 (let* ((tree (org-element-parse-buffer))
2139 (info `(:parse-tree
,tree
)))
2140 (org-export-resolve-radio-link
2141 (org-element-map tree
'link
'identity info t
)
2143 ;; Multiple radio targets.
2145 (equal '("radio1" "radio2")
2146 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2147 (org-update-radio-target-regexp)
2148 (let* ((tree (org-element-parse-buffer))
2149 (info `(:parse-tree
,tree
)))
2150 (org-element-map tree
'link
2152 (org-element-property
2153 :value
(org-export-resolve-radio-link link info
)))
2155 ;; Radio target is whitespace insensitive.
2157 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2158 (org-update-radio-target-regexp)
2159 (let* ((tree (org-element-parse-buffer))
2160 (info `(:parse-tree
,tree
)))
2161 (org-element-map tree
'link
2162 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2168 (ert-deftest test-org-export
/raw-special-block-p
()
2169 "Test `org-export-raw-special-block-p' specifications."
2172 (org-test-with-parsed-data "#+BEGIN_FOO\nContents\n#+END_FOO"
2173 (let ((info (org-combine-plists
2174 info
(list :back-end
2175 (org-export-create-backend :blocks
'("FOO"))))))
2176 (org-export-raw-special-block-p
2177 (org-element-map tree
'special-block
#'identity info t
) info
))))
2179 (org-test-with-parsed-data "#+BEGIN_BAR\nContents\n#+END_BAR"
2180 (let ((info (org-combine-plists
2181 info
(list :back-end
2182 (org-export-create-backend :blocks
'("FOO"))))))
2183 (org-export-raw-special-block-p
2184 (org-element-map tree
'special-block
#'identity info t
) info
))))
2185 ;; Check is not case-sensitive.
2187 (org-test-with-parsed-data "#+begin_foo\nContents\n#+end_foo"
2188 (let ((info (org-combine-plists
2189 info
(list :back-end
2190 (org-export-create-backend :blocks
'("FOO"))))))
2191 (org-export-raw-special-block-p
2192 (org-element-map tree
'special-block
#'identity info t
) info
))))
2193 ;; Test inheritance.
2195 (org-test-with-parsed-data "#+BEGIN_FOO\nContents\n#+END_FOO"
2196 (let* ((org-export--registered-backends
2197 (list (org-export-create-backend :name
'b1
:blocks
'("FOO"))))
2198 (info (org-combine-plists
2199 info
(list :back-end
2200 (org-export-create-backend :parent
'b1
2201 :blocks
'("BAR"))))))
2202 (org-export-raw-special-block-p
2203 (org-element-map tree
'special-block
#'identity info t
) info
))))
2205 (org-test-with-parsed-data "#+BEGIN_BAZ\nContents\n#+END_BAZ"
2206 (let* ((org-export--registered-backends
2207 (list (org-export-create-backend :name
'b1
:blocks
'("FOO"))))
2208 (info (org-combine-plists
2209 info
(list :back-end
2210 (org-export-create-backend :parent
'b1
2211 :blocks
'("BAR"))))))
2212 (org-export-raw-special-block-p
2213 (org-element-map tree
'special-block
#'identity info t
) info
))))
2214 ;; With optional argument, ignore inheritance.
2216 (org-test-with-parsed-data "#+BEGIN_FOO\nContents\n#+END_FOO"
2217 (let* ((org-export--registered-backends
2218 (list (org-export-create-backend :name
'b1
:blocks
'("FOO"))))
2219 (info (org-combine-plists
2220 info
(list :back-end
2221 (org-export-create-backend :parent
'b1
2222 :blocks
'("BAR"))))))
2223 (org-export-raw-special-block-p
2224 (org-element-map tree
'special-block
#'identity info t
) info t
)))))
2228 ;;; Src-block and example-block
2230 (ert-deftest test-org-export
/unravel-code
()
2231 "Test `org-export-unravel-code' function."
2232 ;; Code without reference.
2234 (equal '("(+ 1 1)\n")
2235 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2236 (org-export-unravel-code (org-element-at-point)))))
2237 ;; Code with reference.
2239 (equal '("(+ 1 1)\n" (1 .
"test"))
2240 (org-test-with-temp-text
2241 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2242 (let ((org-coderef-label-format "(ref:%s)"))
2243 (org-export-unravel-code (org-element-at-point))))))
2244 ;; Code with user-defined reference.
2247 '("(+ 1 1)\n" (1 .
"test"))
2248 (org-test-with-temp-text
2249 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2250 (let ((org-coderef-label-format "(ref:%s)"))
2251 (org-export-unravel-code (org-element-at-point))))))
2252 ;; Code references keys are relative to the current block.
2254 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2255 (org-test-with-temp-text "
2264 (let ((org-coderef-label-format "(ref:%s)"))
2265 (org-export-unravel-code (org-element-at-point)))))))
2267 (ert-deftest test-org-export
/format-code-default
()
2268 "Test `org-export-format-code-default' specifications."
2269 ;; Return the empty string when code is empty.
2272 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2273 (org-export-format-code-default
2274 (org-element-map tree
'src-block
'identity info t
) info
))))
2275 ;; Number lines, two whitespace characters before the actual loc.
2278 (org-test-with-parsed-data
2279 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2280 (org-export-format-code-default
2281 (org-element-map tree
'src-block
'identity info t
) info
))))
2282 ;; Put references 6 whitespace characters after the widest line,
2283 ;; wrapped within parenthesis.
2285 (equal "123 (a)\n1 (b)\n"
2286 (let ((org-coderef-label-format "(ref:%s)"))
2287 (org-test-with-parsed-data
2288 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2289 (org-export-format-code-default
2290 (org-element-map tree
'src-block
'identity info t
) info
))))))
2296 (ert-deftest test-org-export
/activate-smart-quotes
()
2297 "Test `org-export-activate-smart-quotes' specifications."
2298 ;; Opening double quotes: standard test.
2301 '("some “paragraph")
2302 (let ((org-export-default-language "en"))
2303 (org-test-with-parsed-data "some \"paragraph"
2304 (org-element-map tree
'plain-text
2305 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2307 ;; Opening quotes: at the beginning of a paragraph.
2311 (let ((org-export-default-language "en"))
2312 (org-test-with-parsed-data "\"begin"
2313 (org-element-map tree
'plain-text
2314 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2316 ;; Opening quotes: after an object.
2320 (let ((org-export-default-language "en"))
2321 (org-test-with-parsed-data "=verb= \"begin"
2322 (org-element-map tree
'plain-text
2323 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2325 ;; Closing quotes: standard test.
2328 '("some” paragraph")
2329 (let ((org-export-default-language "en"))
2330 (org-test-with-parsed-data "some\" paragraph"
2331 (org-element-map tree
'plain-text
2332 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2334 ;; Closing quotes: at the end of a paragraph.
2338 (let ((org-export-default-language "en"))
2339 (org-test-with-parsed-data "end\""
2340 (org-element-map tree
'plain-text
2341 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2343 ;; Apostrophe: standard test.
2346 '("It shouldn’t fail")
2347 (let ((org-export-default-language "en"))
2348 (org-test-with-parsed-data "It shouldn't fail"
2349 (org-element-map tree
'plain-text
2350 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2352 ;; Apostrophe: before an object.
2356 (let ((org-export-default-language "en"))
2357 (org-test-with-parsed-data "a'=b="
2358 (org-element-map tree
'plain-text
2359 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2361 ;; Apostrophe: after an object.
2365 (let ((org-export-default-language "en"))
2366 (org-test-with-parsed-data "=code='s"
2367 (org-element-map tree
'plain-text
2368 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2370 ;; Special case: isolated quotes.
2372 (equal '("“" "”")
2373 (let ((org-export-default-language "en"))
2374 (org-test-with-parsed-data "\"$x$\""
2375 (org-element-map tree
'plain-text
2376 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2378 ;; Smart quotes in secondary strings.
2380 (equal '("“" "”")
2381 (let ((org-export-default-language "en"))
2382 (org-test-with-parsed-data "* \"$x$\""
2383 (org-element-map tree
'plain-text
2384 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2386 ;; Smart quotes in document keywords.
2388 (equal '("“" "”")
2389 (let ((org-export-default-language "en"))
2390 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2391 (org-element-map (plist-get info
:title
) 'plain-text
2392 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2394 ;; Smart quotes in parsed affiliated keywords.
2396 (equal '("“" "”" "Paragraph")
2397 (let ((org-export-default-language "en"))
2398 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2399 (org-element-map tree
'plain-text
2400 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2401 info nil nil t
))))))
2407 (ert-deftest test-org-export
/special-column
()
2408 "Test if the table's special column is properly recognized."
2409 ;; 1. First column is special if it contains only a special marking
2410 ;; characters or empty cells.
2411 (org-test-with-temp-text "
2415 (org-export-table-has-special-column-p
2417 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2418 ;; 2. If the column contains anything else, it isn't special.
2419 (org-test-with-temp-text "
2423 (org-export-table-has-special-column-p
2425 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2426 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2428 (org-test-with-temp-text "
2437 (org-export-table-has-special-column-p
2439 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2440 ;; 4. A first column with only empty cells isn't considered as
2442 (org-test-with-temp-text "
2446 (org-export-table-has-special-column-p
2448 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2450 (ert-deftest test-org-export
/table-row-is-special-p
()
2451 "Test `org-export-table-row-is-special-p' specifications."
2452 ;; 1. A row is special if it has a special marking character in the
2454 (org-test-with-parsed-data "| ! | 1 |"
2456 (org-export-table-row-is-special-p
2457 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2458 ;; 2. A row is special when its first field is "/"
2459 (org-test-with-parsed-data "
2463 (org-export-table-row-is-special-p
2464 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2465 ;; 3. A row only containing alignment cookies is also considered as
2467 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2469 (org-export-table-row-is-special-p
2470 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2471 ;; 4. Everything else isn't considered as special.
2472 (org-test-with-parsed-data "| \alpha | | c |"
2474 (org-export-table-row-is-special-p
2475 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2476 ;; 5. Table's rules are never considered as special rows.
2477 (org-test-with-parsed-data "|---+---|"
2479 (org-export-table-row-is-special-p
2480 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2482 (ert-deftest test-org-export
/has-header-p
()
2483 "Test `org-export-table-has-header-p' specifications."
2484 ;; 1. With an header.
2485 (org-test-with-parsed-data "
2490 (org-export-table-has-header-p
2491 (org-element-map tree
'table
'identity info
'first-match
)
2493 ;; 2. Without an header.
2494 (org-test-with-parsed-data "
2498 (org-export-table-has-header-p
2499 (org-element-map tree
'table
'identity info
'first-match
)
2501 ;; 3. Don't get fooled with starting and ending rules.
2502 (org-test-with-parsed-data "
2508 (org-export-table-has-header-p
2509 (org-element-map tree
'table
'identity info
'first-match
)
2512 (ert-deftest test-org-export
/table-row-group
()
2513 "Test `org-export-table-row-group' specifications."
2514 ;; 1. A rule creates a new group.
2517 (org-test-with-parsed-data "
2521 (org-element-map tree
'table-row
2523 (if (eq (org-element-property :type row
) 'rule
) 'rule
2524 (org-export-table-row-group row info
)))))))
2525 ;; 2. Special rows are ignored in count.
2529 (org-test-with-parsed-data "
2533 (org-element-map tree
'table-row
2535 (if (eq (org-element-property :type row
) 'rule
) 'rule
2536 (org-export-table-row-group row info
)))
2538 ;; 3. Double rules also are ignored in count.
2540 (equal '(1 rule rule
2)
2541 (org-test-with-parsed-data "
2546 (org-element-map tree
'table-row
2548 (if (eq (org-element-property :type row
) 'rule
) 'rule
2549 (org-export-table-row-group row info
))))))))
2551 (ert-deftest test-org-export
/table-row-number
()
2552 "Test `org-export-table-row-number' specifications."
2553 ;; Standard test. Number is 0-indexed.
2556 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2557 (org-element-map tree
'table-row
2558 (lambda (row) (org-export-table-row-number row info
)) info
))))
2559 ;; Number ignores separators.
2562 (org-test-with-parsed-data "
2566 (org-element-map tree
'table-row
2567 (lambda (row) (org-export-table-row-number row info
)) info
))))
2568 ;; Number ignores special rows.
2571 (org-test-with-parsed-data "
2577 (org-element-map tree
'table-row
2578 (lambda (row) (org-export-table-row-number row info
)) info
)))))
2580 (ert-deftest test-org-export
/table-cell-width
()
2581 "Test `org-export-table-cell-width' specifications."
2582 ;; 1. Width is primarily determined by width cookies. If no cookie
2583 ;; is found, cell's width is nil.
2584 (org-test-with-parsed-data "
2585 | / | <l> | <6> | <l7> |
2590 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2591 (org-element-map tree
'table-cell
'identity info
)))))
2592 ;; 2. The last width cookie has precedence.
2593 (org-test-with-parsed-data "
2600 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2601 (org-element-map tree
'table-cell
'identity info
)))))
2602 ;; 3. Valid width cookies must have a specific row.
2603 (org-test-with-parsed-data "| <6> | cell |"
2607 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2608 (org-element-map tree
'table-cell
'identity
))))))
2610 (ert-deftest test-org-export
/table-cell-alignment
()
2611 "Test `org-export-table-cell-alignment' specifications."
2612 ;; 1. Alignment is primarily determined by alignment cookies.
2614 (equal '(left center right
)
2615 (let ((org-table-number-fraction 0.5)
2616 (org-table-number-regexp "^[0-9]+$"))
2617 (org-test-with-parsed-data "| <l> | <c> | <r> |"
2618 (mapcar (lambda (cell)
2619 (org-export-table-cell-alignment cell info
))
2620 (org-element-map tree
'table-cell
'identity
))))))
2621 ;; 2. The last alignment cookie has precedence.
2623 (equal '(right right right
)
2624 (org-test-with-parsed-data "
2628 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2629 (org-element-map tree
'table-cell
'identity
)))))
2630 ;; 3. If there's no cookie, cell's contents determine alignment.
2631 ;; A column mostly made of cells containing numbers will align
2632 ;; its cells to the right.
2634 (equal '(right right right
)
2635 (let ((org-table-number-fraction 0.5)
2636 (org-table-number-regexp "^[0-9]+$"))
2637 (org-test-with-parsed-data "
2641 (mapcar (lambda (cell)
2642 (org-export-table-cell-alignment cell info
))
2643 (org-element-map tree
'table-cell
'identity
))))))
2644 ;; 4. Otherwise, they will be aligned to the left.
2646 (equal '(left left left
)
2647 (org-test-with-parsed-data "
2651 (mapcar (lambda (cell)
2652 (org-export-table-cell-alignment cell info
))
2653 (org-element-map tree
'table-cell
'identity info
))))))
2655 (ert-deftest test-org-export
/table-cell-borders
()
2656 "Test `org-export-table-cell-borders' specifications."
2657 ;; 1. Recognize various column groups indicators.
2658 (org-test-with-parsed-data "| / | < | > | <> |"
2661 '((right bottom top
) (left bottom top
) (right bottom top
)
2662 (right left bottom top
))
2663 (mapcar (lambda (cell)
2664 (org-export-table-cell-borders cell info
))
2665 (org-element-map tree
'table-cell
'identity
)))))
2666 ;; 2. Accept shortcuts to define column groups.
2667 (org-test-with-parsed-data "| / | < | < |"
2670 '((right bottom top
) (right left bottom top
) (left bottom top
))
2671 (mapcar (lambda (cell)
2672 (org-export-table-cell-borders cell info
))
2673 (org-element-map tree
'table-cell
'identity
)))))
2674 ;; 3. A valid column groups row must start with a "/".
2675 (org-test-with-parsed-data "
2679 (equal '((top) (top) (bottom) (bottom))
2680 (mapcar (lambda (cell)
2681 (org-export-table-cell-borders cell info
))
2682 (org-element-map tree
'table-cell
'identity
)))))
2683 ;; 4. Take table rules into consideration.
2684 (org-test-with-parsed-data "
2689 (equal '((below top
) (bottom above
))
2690 (mapcar (lambda (cell)
2691 (org-export-table-cell-borders cell info
))
2692 (org-element-map tree
'table-cell
'identity
)))))
2693 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2694 ;; (resp. `bottom' and `below') borders. Any special row is
2696 (org-test-with-parsed-data "
2702 (equal '((bottom below top above
))
2704 (mapcar (lambda (cell)
2705 (org-export-table-cell-borders cell info
))
2706 (org-element-map tree
'table-cell
'identity
)))))))
2708 (ert-deftest test-org-export
/table-dimensions
()
2709 "Test `org-export-table-dimensions' specifications."
2710 ;; 1. Standard test.
2711 (org-test-with-parsed-data "
2716 (org-export-table-dimensions
2717 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2718 ;; 2. Ignore horizontal rules and special columns.
2719 (org-test-with-parsed-data "
2726 (org-export-table-dimensions
2727 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2729 (ert-deftest test-org-export
/table-cell-address
()
2730 "Test `org-export-table-cell-address' specifications."
2731 ;; 1. Standard test: index is 0-based.
2732 (org-test-with-parsed-data "| a | b |"
2734 (equal '((0 .
0) (0 .
1))
2735 (org-element-map tree
'table-cell
2736 (lambda (cell) (org-export-table-cell-address cell info
))
2738 ;; 2. Special column isn't counted, nor are special rows.
2739 (org-test-with-parsed-data "
2744 (org-export-table-cell-address
2745 (car (last (org-element-map tree
'table-cell
'identity info
)))
2747 ;; 3. Tables rules do not count either.
2748 (org-test-with-parsed-data "
2756 (org-export-table-cell-address
2757 (car (last (org-element-map tree
'table-cell
'identity info
)))
2759 ;; 4. Return nil for special cells.
2760 (org-test-with-parsed-data "| / | a |"
2762 (org-export-table-cell-address
2763 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2766 (ert-deftest test-org-export
/get-table-cell-at
()
2767 "Test `org-export-get-table-cell-at' specifications."
2768 ;; 1. Address ignores special columns, special rows and rules.
2769 (org-test-with-parsed-data "
2776 (org-element-contents
2777 (org-export-get-table-cell-at
2779 (org-element-map tree
'table
'identity info
'first-match
)
2781 ;; 2. Return value for a non-existent address is nil.
2782 (org-test-with-parsed-data "| a |"
2784 (org-export-get-table-cell-at
2786 (org-element-map tree
'table
'identity info
'first-match
)
2788 (org-test-with-parsed-data "| / |"
2790 (org-export-get-table-cell-at
2792 (org-element-map tree
'table
'identity info
'first-match
)
2795 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2796 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2797 ;; 1. A cell at a beginning of a row always starts a column group.
2798 (org-test-with-parsed-data "| a |"
2800 (org-export-table-cell-starts-colgroup-p
2801 (org-element-map tree
'table-cell
'identity info
'first-match
)
2803 ;; 2. Special column should be ignored when determining the
2804 ;; beginning of the row.
2805 (org-test-with-parsed-data "
2809 (org-export-table-cell-starts-colgroup-p
2810 (org-element-map tree
'table-cell
'identity info
'first-match
)
2812 ;; 2. Explicit column groups.
2813 (org-test-with-parsed-data "
2819 (org-element-map tree
'table-cell
2821 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2824 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2825 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2826 ;; 1. A cell at the end of a row always ends a column group.
2827 (org-test-with-parsed-data "| a |"
2829 (org-export-table-cell-ends-colgroup-p
2830 (org-element-map tree
'table-cell
'identity info
'first-match
)
2832 ;; 2. Special column should be ignored when determining the
2833 ;; beginning of the row.
2834 (org-test-with-parsed-data "
2838 (org-export-table-cell-ends-colgroup-p
2839 (org-element-map tree
'table-cell
'identity info
'first-match
)
2841 ;; 3. Explicit column groups.
2842 (org-test-with-parsed-data "
2848 (org-element-map tree
'table-cell
2850 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2853 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2854 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2855 ;; 1. A row at the beginning of a table always starts a row group.
2856 ;; So does a row following a table rule.
2857 (org-test-with-parsed-data "
2864 (org-element-map tree
'table-row
2866 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2868 ;; 2. Special rows should be ignored when determining the beginning
2870 (org-test-with-parsed-data "
2879 (org-element-map tree
'table-row
2881 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2884 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2885 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2886 ;; 1. A row at the end of a table always ends a row group. So does
2887 ;; a row preceding a table rule.
2888 (org-test-with-parsed-data "
2895 (org-element-map tree
'table-row
2897 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2899 ;; 2. Special rows should be ignored when determining the beginning
2901 (org-test-with-parsed-data "
2910 (org-element-map tree
'table-row
2912 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2915 (ert-deftest test-org-export
/table-row-in-header-p
()
2916 "Test `org-export-table-row-in-header-p' specifications."
2917 ;; Standard test. Separators are always nil.
2921 (org-test-with-parsed-data "| a |\n|---|\n| b |"
2922 (org-element-map tree
'table-row
2924 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
2925 ;; Nil when there is no header.
2929 (org-test-with-parsed-data "| a |\n| b |"
2930 (org-element-map tree
'table-row
2932 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
2934 (ert-deftest test-org-export
/table-row-starts-header-p
()
2935 "Test `org-export-table-row-starts-header-p' specifications."
2936 ;; 1. Only the row starting the first row group starts the table
2938 (org-test-with-parsed-data "
2946 (org-element-map tree
'table-row
2948 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2950 ;; 2. A row cannot start an header if there's no header in the
2952 (org-test-with-parsed-data "
2956 (org-export-table-row-starts-header-p
2957 (org-element-map tree
'table-row
'identity info
'first-match
)
2960 (ert-deftest test-org-export
/table-row-ends-header-p
()
2961 "Test `org-export-table-row-ends-header-p' specifications."
2962 ;; 1. Only the row starting the first row group starts the table
2964 (org-test-with-parsed-data "
2972 (org-element-map tree
'table-row
2974 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2976 ;; 2. A row cannot start an header if there's no header in the
2978 (org-test-with-parsed-data "
2982 (org-export-table-row-ends-header-p
2983 (org-element-map tree
'table-row
'identity info
'first-match
)
2988 ;;; Tables of Contents
2990 (ert-deftest test-org-export
/collect-headlines
()
2991 "Test `org-export-collect-headlines' specifications."
2996 (org-test-with-parsed-data "* H1\n** H2"
2997 (org-export-collect-headlines info
)))))
2998 ;; Do not collect headlines below optional argument.
3002 (org-test-with-parsed-data "* H1\n** H2"
3003 (org-export-collect-headlines info
1)))))
3004 ;; Never collect headlines below maximum headline level.
3008 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3009 (org-export-collect-headlines info
)))))
3013 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3014 (org-export-collect-headlines info
2))))))
3020 (ert-deftest test-org-export
/inner-template
()
3021 "Test `inner-template' translator specifications."
3024 (org-test-with-temp-text "* Headline"
3026 (org-export-create-backend
3028 '((inner-template .
(lambda (contents info
) "Success!"))
3029 (headline .
(lambda (h c i
) "Headline"))))))))
3030 ;; Inner template is applied even in a "body-only" export.
3033 (org-test-with-temp-text "* Headline"
3035 (org-export-create-backend
3036 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3037 (headline .
(lambda (h c i
) "Headline"))))
3038 nil nil
'body-only
)))))
3040 (ert-deftest test-org-export
/template
()
3041 "Test `template' translator specifications."
3044 (org-test-with-temp-text "* Headline"
3046 (org-export-create-backend
3047 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3048 (headline .
(lambda (h c i
) "Headline"))))))))
3049 ;; Template is not applied in a "body-only" export.
3052 (org-test-with-temp-text "* Headline"
3054 (org-export-create-backend
3055 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3056 (headline .
(lambda (h c i
) "Headline"))))
3057 nil nil
'body-only
)))))
3063 (ert-deftest test-org-export
/get-next-element
()
3064 "Test `org-export-get-next-element' specifications."
3068 (org-test-with-parsed-data "* Headline\n*a* b"
3069 (org-export-get-next-element
3070 (org-element-map tree
'bold
'identity info t
) info
))))
3071 ;; Return nil when no previous element.
3073 (org-test-with-parsed-data "* Headline\na *b*"
3074 (org-export-get-next-element
3075 (org-element-map tree
'bold
'identity info t
) info
)))
3076 ;; Non-exportable elements are ignored.
3078 (let ((org-export-with-timestamps nil
))
3079 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3080 (org-export-get-next-element
3081 (org-element-map tree
'entity
'identity info t
) info
))))
3082 ;; Find next element in secondary strings.
3085 (org-test-with-parsed-data "* a =verb="
3087 (org-export-get-next-element
3088 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3091 (org-test-with-parsed-data "* /italic/ =verb="
3093 (org-export-get-next-element
3094 (org-element-map tree
'italic
'identity info t
) info
)))))
3095 ;; Find next element in document keywords.
3098 (org-test-with-parsed-data "#+TITLE: a =verb="
3100 (org-export-get-next-element
3102 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3103 ;; Find next element in parsed affiliated keywords.
3106 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3108 (org-export-get-next-element
3109 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3110 ;; With optional argument N, return a list containing all the
3111 ;; following elements.
3114 '(bold code underline
)
3115 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3117 (org-export-get-next-element
3118 (org-element-map tree
'italic
'identity info t
) info t
)))))
3119 ;; When N is a positive integer, return a list containing up to
3120 ;; N following elements.
3124 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3126 (org-export-get-next-element
3127 (org-element-map tree
'italic
'identity info t
) info
2))))))
3129 (ert-deftest test-org-export
/get-previous-element
()
3130 "Test `org-export-get-previous-element' specifications."
3134 (org-test-with-parsed-data "* Headline\na *b*"
3135 (org-export-get-previous-element
3136 (org-element-map tree
'bold
'identity info t
) info
))))
3137 ;; Return nil when no previous element.
3139 (org-test-with-parsed-data "* Headline\n*a* b"
3140 (org-export-get-previous-element
3141 (org-element-map tree
'bold
'identity info t
) info
)))
3142 ;; Non-exportable elements are ignored.
3144 (let ((org-export-with-timestamps nil
))
3145 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3146 (org-export-get-previous-element
3147 (org-element-map tree
'entity
'identity info t
) info
))))
3148 ;; Find previous element in secondary strings.
3151 (org-test-with-parsed-data "* =verb= a"
3153 (org-export-get-previous-element
3154 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3157 (org-test-with-parsed-data "* =verb= /italic/"
3159 (org-export-get-previous-element
3160 (org-element-map tree
'italic
'identity info t
) info
)))))
3161 ;; Find previous element in document keywords.
3164 (org-test-with-parsed-data "#+TITLE: =verb= a"
3166 (org-export-get-previous-element
3168 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3169 ;; Find previous element in parsed affiliated keywords.
3172 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3174 (org-export-get-previous-element
3175 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3176 ;; With optional argument N, return a list containing up to
3177 ;; N previous elements.
3179 (equal '(underline italic bold
)
3180 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3182 (org-export-get-previous-element
3183 (org-element-map tree
'code
'identity info t
) info t
)))))
3184 ;; When N is a positive integer, return a list containing up to
3185 ;; N previous elements.
3187 (equal '(italic bold
)
3188 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3190 (org-export-get-previous-element
3191 (org-element-map tree
'code
'identity info t
) info
2))))))
3195 ;;; test-org-export.el end here