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.
46 DATA is a string containing the data to be parsed. BODY is the
47 body to execute. Parse tree is available under the `tree'
48 variable, and communication channel under `info'."
49 (declare (debug (form body
)) (indent 1))
50 `(org-test-with-temp-text ,data
51 (let* ((tree (org-element-parse-buffer))
52 (info (org-export-get-environment)))
53 (org-export-prune-tree tree info
)
54 (org-export-remove-uninterpreted-data tree info
)
55 (let ((info (org-combine-plists
56 info
(org-export-collect-tree-properties tree info
))))
63 (ert-deftest test-org-export
/bind-keyword
()
64 "Test reading #+BIND: keywords."
65 ;; Test with `org-export-allow-bind-keywords' set to t.
67 (org-test-with-temp-text "#+BIND: test-ox-var value"
68 (let ((org-export-allow-bind-keywords t
))
69 (org-export-get-environment)
70 (eq test-ox-var
'value
))))
71 ;; Test with `org-export-allow-bind-keywords' set to nil.
73 (org-test-with-temp-text "#+BIND: test-ox-var value"
74 (let ((org-export-allow-bind-keywords nil
))
75 (org-export-get-environment)
76 (boundp 'test-ox-var
))))
77 ;; BIND keywords are case-insensitive.
79 (org-test-with-temp-text "#+bind: test-ox-var value"
80 (let ((org-export-allow-bind-keywords t
))
81 (org-export-get-environment)
82 (eq test-ox-var
'value
))))
83 ;; Preserve order of BIND keywords.
85 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
86 (let ((org-export-allow-bind-keywords t
))
87 (org-export-get-environment)
89 ;; Read BIND keywords in setup files.
91 (org-test-with-temp-text
92 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
93 (let ((org-export-allow-bind-keywords t
))
94 (org-export-get-environment)
95 (eq variable
'value
))))
96 ;; Verify that bound variables are seen during export.
99 (org-test-with-temp-text "#+BIND: test-ox-var value"
100 (let ((org-export-allow-bind-keywords t
))
102 (org-export-create-backend
104 '((section .
(lambda (s c i
)
105 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
107 (ert-deftest test-org-export
/parse-option-keyword
()
108 "Test reading all standard #+OPTIONS: items."
111 (org-export--parse-option-keyword
112 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
113 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
116 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
117 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
118 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
119 :with-footnotes t
:with-inlinetasks nil
:with-priority t
120 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
121 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
122 :with-todo-keywords t
)))
123 ;; Test some special values.
126 (org-export--parse-option-keyword
127 "arch:headline creator:comment d:(\"TEST\")
128 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
131 :with-archived-trees headline
:with-creator comment
132 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
133 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
135 (ert-deftest test-org-export
/get-inbuffer-options
()
136 "Test reading all standard export keywords."
137 ;; Properties should follow buffer order.
140 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
141 (org-export--get-inbuffer-options))
142 '(:language
"fr" :creator
"Me" :email
"email")))
143 ;; Parse document keywords.
146 (org-test-with-temp-text "#+AUTHOR: Me"
147 (org-export--get-inbuffer-options))
149 ;; Test `space' behaviour.
152 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
153 (org-export--get-inbuffer-options))
154 '(:title
("Some title with spaces"))))
155 ;; Test `newline' behaviour.
158 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
159 (org-export--get-inbuffer-options))
160 '(:description
"With\ntwo lines")))
161 ;; Test `split' behaviour.
164 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
165 (org-export--get-inbuffer-options))
166 '(:select-tags
("a" "b"))))
167 ;; Options set through SETUPFILE.
170 (org-test-with-temp-text
171 (format "#+DESCRIPTION: l1
175 #+SETUPFILE: \"%s/examples/setupfile.org\"
181 (org-export--get-inbuffer-options))
182 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
184 ;; More than one property can refer to the same buffer keyword.
186 (equal '(:k2
"value" :k1
"value")
187 (let ((backend (org-export-create-backend
188 :options
'((:k1
"KEYWORD")
190 (org-test-with-temp-text "#+KEYWORD: value"
191 (org-export--get-inbuffer-options backend
))))))
193 (ert-deftest test-org-export
/get-subtree-options
()
194 "Test setting options from headline's properties."
196 (org-test-with-temp-text "#+TITLE: Title
199 :EXPORT_TITLE: Subtree Title
203 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
204 '("Subtree Title"))))
208 (org-test-with-temp-text "#+OPTIONS: H:1
216 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
218 (org-test-with-temp-text "#+DATE: today
221 :EXPORT_DATE: 29-03-2012
225 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
227 ;; Properties with `split' behaviour are stored as a list of
231 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
234 :EXPORT_EXCLUDE_TAGS: a b
239 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
240 ;; Handle :PROPERTY+: syntax.
243 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
246 :EXPORT_EXCLUDE_TAGS: a
247 :EXPORT_EXCLUDE_TAGS+: b
252 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
253 ;; Export properties are case-insensitive.
254 (org-test-with-temp-text "* Headline
256 :EXPORT_Date: 29-03-2012
259 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
261 ;; Still grab correct options when section above is empty.
264 (org-test-with-temp-text "* H1\n** H11\n** H12"
265 (progn (forward-line 2)
266 (plist-get (org-export-get-environment nil t
) :title
))))))
268 (ert-deftest test-org-export
/set-title
()
269 "Test title setting."
270 ;; Without TITLE keyword.
274 (let (org-export-filter-body-functions
275 org-export-filter-final-output-functions
)
276 (org-test-with-temp-text "Test"
278 (org-export-create-backend
280 '((template .
(lambda (text info
)
281 (org-element-interpret-data
282 (plist-get info
:title
)))))))))))
283 ;; With a blank TITLE keyword.
287 (let (org-export-filter-body-functions
288 org-export-filter-final-output-functions
)
289 (org-test-with-temp-text "#+TITLE:\nTest"
291 (org-export-create-backend
293 '((template .
(lambda (text info
)
294 (org-element-interpret-data
295 (plist-get info
:title
)))))))))))
296 ;; With a non-empty TITLE keyword.
300 (org-test-with-temp-text "#+TITLE: Title\nTest"
302 (org-export-create-backend
304 '((template .
(lambda (text info
)
305 (org-element-interpret-data
306 (plist-get info
:title
))))))))))
307 ;; When exporting a subtree, its heading becomes the headline of the
312 (org-test-with-temp-text "* Headline\nBody"
314 (org-export-create-backend
316 '((template .
(lambda (text info
)
317 (org-element-interpret-data
318 (plist-get info
:title
))))))
320 ;; ... unless there is an EXPORT_TITLE property at the root of the
325 (org-test-with-temp-text
326 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
328 (org-export-create-backend
330 '((template .
(lambda (text info
)
331 (org-element-interpret-data
332 (plist-get info
:title
))))))
335 (ert-deftest test-org-export
/handle-options
()
336 "Test if export options have an impact on output."
337 ;; Test exclude tags for headlines and inlinetasks.
340 (let (org-export-filter-body-functions
341 org-export-filter-final-output-functions
)
342 (org-test-with-temp-text "* Head1 :noexp:"
343 (org-export-as (org-test-default-backend)
344 nil nil nil
'(:exclude-tags
("noexp")))))))
345 ;; Test include tags for headlines and inlinetasks.
347 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
348 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
349 (let ((org-tags-column 0))
350 (org-export-as (org-test-default-backend)
351 nil nil nil
'(:select-tags
("exp")))))))
352 ;; If there is an include tag, ignore the section before the first
355 (equal "* H1 :exp:\nBody\n"
356 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
357 (let ((org-tags-column 0))
358 (org-export-as (org-test-default-backend)
359 nil nil nil
'(:select-tags
("exp")))))))
361 (equal "* H1 :exp:\n"
362 (org-test-with-temp-text "* H1 :exp:\nBody"
363 (let ((org-tags-column 0))
364 (org-export-as (org-test-default-backend)
365 nil nil nil
'(:select-tags
("exp")))))))
366 ;; Test mixing include tags and exclude tags.
369 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
370 (org-test-with-temp-text "
372 ** Sub-Head1 :noexport:
375 ** Sub-Head1 :export:"
376 (org-export-as (org-test-default-backend) nil nil nil
377 '(:select-tags
("export") :exclude-tags
("noexport"))))))
381 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
382 org-export-filter-body-functions
383 org-export-filter-final-output-functions
)
384 (org-test-with-temp-text "* TODO Head1"
385 (org-export-as (org-test-default-backend)
386 nil nil nil
'(:with-tasks nil
))))))
388 (equal "* TODO Head1\n"
389 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
390 (org-test-with-temp-text "* TODO Head1"
391 (org-export-as (org-test-default-backend)
392 nil nil nil
'(:with-tasks t
))))))
396 (let (org-export-filter-body-functions
397 org-export-filter-final-output-functions
)
398 (org-test-with-temp-text "* Head1 :archive:"
399 (let ((org-archive-tag "archive"))
400 (org-export-as (org-test-default-backend)
401 nil nil nil
'(:with-archived-trees nil
)))))))
404 "\\* Head1[ \t]+:archive:"
405 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
406 (let ((org-archive-tag "archive"))
407 (org-export-as (org-test-default-backend) nil nil nil
408 '(:with-archived-trees headline
))))))
411 "\\`\\* Head1[ \t]+:archive:\n\\'"
412 (org-test-with-temp-text "* Head1 :archive:"
413 (let ((org-archive-tag "archive"))
414 (org-export-as (org-test-default-backend)
415 nil nil nil
'(:with-archived-trees t
))))))
418 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
419 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
420 (org-export-as (org-test-default-backend)
421 nil nil nil
'(:with-clocks t
)))))
424 (let (org-export-filter-body-functions
425 org-export-filter-final-output-functions
)
426 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
427 (org-export-as (org-test-default-backend)
428 nil nil nil
'(:with-clocks nil
))))))
432 (let (org-export-filter-body-functions
433 org-export-filter-final-output-functions
)
434 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
435 (org-export-as (org-test-default-backend)
436 nil nil nil
'(:with-drawers nil
))))))
438 (equal ":TEST:\ncontents\n:END:\n"
439 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
440 (org-export-as (org-test-default-backend)
441 nil nil nil
'(:with-drawers t
)))))
443 (equal ":FOO:\nkeep\n:END:\n"
444 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
445 (org-export-as (org-test-default-backend)
446 nil nil nil
'(:with-drawers
("FOO"))))))
448 (equal ":FOO:\nkeep\n:END:\n"
449 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
450 (org-export-as (org-test-default-backend)
451 nil nil nil
'(:with-drawers
(not "BAR"))))))
455 (org-test-with-temp-text ": A"
456 (org-export-as (org-test-default-backend) nil nil nil
457 '(:with-fixed-width t
)))))
460 (let (org-export-filter-body-functions
461 org-export-filter-final-output-functions
)
462 (org-test-with-temp-text ": A"
463 (org-export-as (org-test-default-backend) nil nil nil
464 '(:with-fixed-width nil
))))))
468 (let ((org-footnote-section nil
))
469 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
470 (org-trim (org-export-as (org-test-default-backend)
471 nil nil nil
'(:with-footnotes nil
)))))))
473 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
474 (let ((org-footnote-section nil
))
475 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
476 (org-trim (org-export-as (org-test-default-backend)
477 nil nil nil
'(:with-footnotes t
)))))))
479 (when (featurep 'org-inlinetask
)
483 (let ((org-inlinetask-min-level 15)
484 org-export-filter-body-functions
485 org-export-filter-final-output-functions
)
486 (org-test-with-temp-text "*************** Task"
487 (org-export-as (org-test-default-backend)
488 nil nil nil
'(:with-inlinetasks nil
))))))
492 (let ((org-inlinetask-min-level 15)
493 org-export-filter-body-functions
494 org-export-filter-final-output-functions
)
495 (org-test-with-temp-text
496 "*************** Task\nContents\n*************** END"
497 (org-export-as (org-test-default-backend)
498 nil nil nil
'(:with-inlinetasks nil
)))))))
502 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
503 (let ((org-closed-string "CLOSED:"))
504 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
505 (org-export-as (org-test-default-backend)
506 nil nil nil
'(:with-planning t
))))))
509 (let ((org-closed-string "CLOSED:"))
510 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
511 (org-export-as (org-test-default-backend)
512 nil nil nil
'(:with-planning nil
))))))
516 (org-test-with-temp-text
517 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
518 (org-export-as (org-test-default-backend)
519 nil nil nil
'(:with-properties nil
)))))
521 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
522 (org-test-with-temp-text
523 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
524 (org-export-as (org-test-default-backend)
525 nil nil nil
'(:with-properties t
)))))
527 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
528 (org-test-with-temp-text
529 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
530 (org-export-as (org-test-default-backend)
531 nil nil nil
'(:with-properties
("B"))))))
532 ;; Statistics cookies.
535 (let (org-export-filter-body-functions
536 org-export-filter-final-output-functions
)
538 (org-test-with-temp-text "[0/0]"
539 (org-export-as (org-test-default-backend)
540 nil nil nil
'(:with-statistics-cookies nil
)))))))
544 (org-test-with-temp-text "| A |"
545 (org-export-as (org-test-default-backend) nil nil nil
546 '(:with-tables t
)))))
549 (let (org-export-filter-body-functions
550 org-export-filter-final-output-functions
)
551 (org-test-with-temp-text "| A |"
552 (org-export-as (org-test-default-backend) nil nil nil
553 '(:with-tables nil
)))))))
555 (ert-deftest test-org-export
/with-timestamps
()
556 "Test `org-export-with-timestamps' specifications."
560 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
561 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
562 (org-export-as (org-test-default-backend)
563 nil nil nil
'(:with-timestamps t
)))))
568 (let (org-export-filter-body-functions
569 org-export-filter-final-output-functions
)
571 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
572 (org-export-as (org-test-default-backend)
573 nil nil nil
'(:with-timestamps nil
)))))))
577 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
578 (org-test-with-temp-text
579 "<2012-03-29 Thu>[2012-03-29 Thu]
581 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
582 (org-export-as (org-test-default-backend)
583 nil nil nil
'(:with-timestamps active
)))))
587 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
588 (org-test-with-temp-text
589 "<2012-03-29 Thu>[2012-03-29 Thu]
591 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
592 (org-export-as (org-test-default-backend)
593 nil nil nil
'(:with-timestamps inactive
))))))
595 (ert-deftest test-org-export
/comment-tree
()
596 "Test if export process ignores commented trees."
599 (let (org-export-filter-body-functions
600 org-export-filter-final-output-functions
)
601 (org-test-with-temp-text "* COMMENT Head1"
602 (org-export-as (org-test-default-backend)))))))
604 (ert-deftest test-org-export
/uninterpreted
()
605 "Test handling of uninterpreted elements."
609 (org-test-with-temp-text "\\alpha"
611 (org-export-create-backend
612 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
613 (paragraph .
(lambda (p c i
) c
))
614 (section .
(lambda (s c i
) c
))))
615 nil nil nil
'(:with-entities t
)))))
618 (org-test-with-temp-text "\\alpha"
620 (org-export-create-backend
621 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
622 (paragraph .
(lambda (p c i
) c
))
623 (section .
(lambda (s c i
) c
))))
624 nil nil nil
'(:with-entities nil
)))))
628 (org-test-with-temp-text "*bold*"
630 (org-export-create-backend
631 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
632 (paragraph .
(lambda (p c i
) c
))
633 (section .
(lambda (s c i
) c
))))
634 nil nil nil
'(:with-emphasize t
)))))
637 (org-test-with-temp-text "*bold*"
639 (org-export-create-backend
640 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
641 (paragraph .
(lambda (p c i
) c
))
642 (section .
(lambda (s c i
) c
))))
643 nil nil nil
'(:with-emphasize nil
)))))
644 ;; LaTeX environment.
647 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
649 (org-export-create-backend
650 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
651 (section .
(lambda (s c i
) c
))))
652 nil nil nil
'(:with-latex t
)))))
654 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
655 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
657 (org-export-create-backend
658 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
659 (section .
(lambda (s c i
) c
))))
660 nil nil nil
'(:with-latex verbatim
)))))
664 (org-test-with-temp-text "$1$"
666 (org-export-create-backend
667 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
668 (paragraph .
(lambda (p c i
) c
))
669 (section .
(lambda (s c i
) c
))))
670 nil nil nil
'(:with-latex t
)))))
673 (org-test-with-temp-text "$1$"
675 (org-export-create-backend
676 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
677 (paragraph .
(lambda (p c i
) c
))
678 (section .
(lambda (s c i
) c
))))
679 nil nil nil
'(:with-latex verbatim
)))))
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 t
)))))
692 (org-test-with-temp-text "a_b"
694 (org-export-create-backend
695 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
696 (paragraph .
(lambda (p c i
) c
))
697 (section .
(lambda (s c i
) c
))))
698 nil nil nil
'(:with-sub-superscript nil
)))))
701 (org-test-with-temp-text "a_b"
703 (org-export-create-backend
704 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
705 (paragraph .
(lambda (p c i
) c
))
706 (section .
(lambda (s c i
) c
))))
707 nil nil nil
'(:with-sub-superscript
{})))))
710 (org-test-with-temp-text "a_{b}"
712 (org-export-create-backend
713 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
714 (paragraph .
(lambda (p c i
) c
))
715 (section .
(lambda (s c i
) c
))))
716 nil nil nil
'(:with-sub-superscript
{})))))
717 ;; Also handle uninterpreted objects in title.
720 (org-test-with-temp-text "#+TITLE: a_b"
722 (org-export-create-backend
724 '((subscript .
(lambda (s c i
) "dummy"))
725 (template .
(lambda (c i
) (org-export-data
726 (plist-get i
:title
) i
)))
727 (section .
(lambda (s c i
) c
))))
728 nil nil nil
'(:with-sub-superscript nil
)))))
729 ;; Special case: multiples uninterpreted objects in a row.
732 (org-test-with-temp-text "a_b_c_d"
734 (org-export-create-backend
735 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
736 (paragraph .
(lambda (p c i
) c
))
737 (section .
(lambda (s c i
) c
))))
738 nil nil nil
'(:with-sub-superscript
{}))))))
740 (ert-deftest test-org-export
/export-scope
()
741 "Test all export scopes."
742 (org-test-with-temp-text "
749 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
750 "text\n*** Head3\n"))
752 (goto-char (point-min))
755 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
758 (goto-char (point-min))
760 (transient-mark-mode 1)
761 (push-mark (point) t t
)
762 (goto-char (point-at-eol))
763 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
764 ;; Subtree with a code block calling another block outside.
765 (let ((org-export-babel-evaluate t
))
768 (org-test-with-temp-text "
770 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
775 #+BEGIN_SRC emacs-lisp
779 (org-export-as (org-test-default-backend) 'subtree
)))))
781 (let ((backend (org-test-default-backend)))
782 (setf (org-export-backend-transcoders backend
)
783 (cons '(template .
(lambda (body i
)
784 (format "BEGIN\n%sEND" body
)))
785 (org-export-backend-transcoders backend
)))
786 (org-test-with-temp-text "Text"
787 (should (equal (org-export-as backend nil nil
'body-only
)
789 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
791 (ert-deftest test-org-export
/output-file-name
()
792 "Test `org-export-output-file-name' specifications."
793 ;; Export from a file: name is built from original file name.
795 (org-test-with-temp-text-in-file "Test"
796 (equal (concat (file-name-as-directory ".")
797 (file-name-nondirectory
798 (file-name-sans-extension (buffer-file-name))))
799 (file-name-sans-extension (org-export-output-file-name ".ext")))))
800 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
802 (org-test-with-temp-text-in-file
803 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
804 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
805 ;; From a buffer not associated to a file, too.
807 (org-test-with-temp-text
808 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
809 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
810 ;; When provided name is absolute, preserve it.
812 (org-test-with-temp-text
813 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
814 (expand-file-name "test"))
815 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
816 ;; When PUB-DIR argument is provided, use it.
818 (org-test-with-temp-text-in-file "Test"
819 (equal (file-name-directory
820 (org-export-output-file-name ".ext" nil
"dir/"))
822 ;; When returned name would overwrite original file, add EXTENSION
825 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
826 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
828 (ert-deftest test-org-export
/expand-include
()
829 "Test file inclusion in an Org buffer."
830 ;; Error when file isn't specified.
832 (org-test-with-temp-text "#+INCLUDE: dummy.org"
833 (org-export-expand-include-keyword)))
834 ;; Full insertion with recursive inclusion.
839 (expand-file-name "examples/include.org" org-test-dir
))
840 (replace-regexp-in-string
841 (regexp-quote "#+INCLUDE: \"include2.org\"")
842 "Success!" (buffer-string)))
843 (org-test-with-temp-text
844 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
845 (org-export-expand-include-keyword)
847 ;; Localized insertion.
848 (org-test-with-temp-text
849 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
851 (org-export-expand-include-keyword)
852 (should (equal (buffer-string)
853 "Small Org file with an include keyword.\n")))
854 ;; Insertion with constraints on headlines level.
857 "* Top heading\n** Heading\nbody\n"
858 (org-test-with-temp-text
860 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
862 (org-export-expand-include-keyword)
866 "* Top heading\n* Heading\nbody\n"
867 (org-test-with-temp-text
869 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
871 (org-export-expand-include-keyword)
873 ;; Inclusion within an example block.
876 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
877 (org-test-with-temp-text
878 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
880 (org-export-expand-include-keyword)
882 ;; Inclusion within a src-block.
885 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
886 (org-test-with-temp-text
888 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
890 (org-export-expand-include-keyword)
892 ;; Inclusion within an html export-block.
895 "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
896 (org-test-with-temp-text
898 "#+INCLUDE: \"%s/examples/include.html\" HTML"
900 (org-export-expand-include-keyword)
902 ;; Inclusion within an center paragraph
905 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
906 (org-test-with-temp-text
908 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
910 (org-export-expand-include-keyword)
912 ;; Footnotes labels are local to each included file.
918 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
920 \[fn:test] Footnote \"test\""))
921 (org-test-with-temp-text-in-file contents
922 (let ((file1 (buffer-file-name)))
923 (org-test-with-temp-text-in-file contents
924 (let ((file2 (buffer-file-name)))
925 (org-test-with-temp-text
926 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
928 (org-export-expand-include-keyword)
929 (org-element-map (org-element-parse-buffer)
932 (org-element-property :label ref
)))))))))))))
933 ;; Footnotes labels are not local to each include keyword.
939 Footnotes[fn:1], [fn:test], [2] and [fn:inline:anonymous footnote].
942 \[fn:test] Footnote \"test\""))
943 (org-test-with-temp-text-in-file contents
944 (let ((file (buffer-file-name)))
945 (org-test-with-temp-text
946 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
947 (org-export-expand-include-keyword)
948 (org-element-map (org-element-parse-buffer)
950 (lambda (ref) (org-element-property :label ref
)))))))))))
951 ;; Footnotes are supported by :lines-like elements and unnecessary
952 ;; footnotes are dropped.
961 Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote]
966 \[fn:test] Footnote \"test\"
969 (org-test-with-temp-text-in-file contents
970 (let ((file (buffer-file-name)))
971 (org-test-with-temp-text
972 (format "#+INCLUDE: \"%s::*bar\"
974 (org-export-expand-include-keyword)
975 (org-element-map (org-element-parse-buffer)
977 (lambda (ref) (org-element-property :label ref
)))))))))))
978 ;; If only-contents is non-nil only include contents of element.
982 (org-test-with-temp-text
984 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" " org-test-dir
)
986 (org-export-expand-include-keyword)
988 ;; Headings can be included via CUSTOM_ID.
990 (org-test-with-temp-text
991 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
992 (org-export-expand-include-keyword)
993 (goto-char (point-min))
994 (looking-at "* Another heading")))
995 ;; Named objects can be included.
999 (org-test-with-temp-text
1000 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t" org-test-dir
)
1001 (org-export-expand-include-keyword)
1003 ;; Including non-existing elements should result in an error.
1005 (org-test-with-temp-text
1006 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\"" org-test-dir
)
1007 (org-export-expand-include-keyword)))
1008 ;; Lines work relatively to an included element.
1012 (org-test-with-temp-text
1013 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t :lines \"2-3\"" org-test-dir
)
1014 (org-export-expand-include-keyword)
1016 ;; Properties should be dropped from headlines.
1019 (org-test-with-temp-text
1020 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t" org-test-dir
)
1021 (org-export-expand-include-keyword)
1023 (org-test-with-temp-text
1024 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1025 (org-export-expand-include-keyword)
1027 ;; Properties should be dropped, drawers should not be.
1030 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1031 (org-test-with-temp-text
1032 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir
)
1033 (org-export-expand-include-keyword)
1035 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1037 (org-every (lambda (level) (zerop (1- level
)))
1038 (org-test-with-temp-text
1040 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n" org-test-dir
)
1041 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\"" org-test-dir
))
1042 (org-export-expand-include-keyword)
1043 (org-element-map (org-element-parse-buffer) 'headline
1044 (lambda (head) (org-element-property :level head
))))))
1045 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1048 (org-test-with-temp-text
1049 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp" org-test-dir
)
1050 (org-export-expand-include-keyword)
1052 (org-test-with-temp-text
1053 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1" org-test-dir
)
1054 (org-export-expand-include-keyword)
1056 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1058 (org-test-with-temp-text-in-file
1059 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1060 (narrow-to-region (point) (point-max))
1061 (org-export-expand-include-keyword)
1062 (eq 1 (org-current-level))))
1063 ;; If :minlevel is present do not alter it.
1065 (org-test-with-temp-text
1066 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3" org-test-dir
)
1067 (narrow-to-region (point) (point-max))
1068 (org-export-expand-include-keyword)
1069 (eq 3 (org-current-level)))))
1071 (ert-deftest test-org-export
/expand-macro
()
1072 "Test macro expansion in an Org buffer."
1073 ;; Standard macro expansion.
1075 (equal "#+MACRO: macro1 value\nvalue\n"
1076 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1077 (org-export-as (org-test-default-backend)))))
1078 ;; Expand specific macros.
1080 (equal "me 2012-03-29 me@here Title\n"
1081 (org-test-with-temp-text
1087 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1088 (let ((output (org-export-as (org-test-default-backend))))
1089 (substring output
(string-match ".*\n\\'" output
))))))
1090 ;; Expand specific macros when property contained a regular macro
1094 (org-test-with-temp-text "
1095 #+MACRO: macro1 value
1096 #+TITLE: {{{macro1}}}
1098 (let ((output (org-export-as (org-test-default-backend))))
1099 (substring output
(string-match ".*\n\\'" output
))))))
1100 ;; Expand macros with templates in included files.
1103 (org-test-with-temp-text
1104 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1105 {{{included-macro}}}" org-test-dir
)
1106 (let ((output (org-export-as (org-test-default-backend))))
1107 (substring output
(string-match ".*\n\\'" output
)))))))
1109 (ert-deftest test-org-export
/before-processing-hook
()
1110 "Test `org-export-before-processing-hook'."
1113 "#+MACRO: mac val\nTest\n"
1114 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1115 (let ((org-export-before-processing-hook
1117 (while (re-search-forward "{{{" nil t
)
1118 (let ((object (org-element-context)))
1119 (when (eq (org-element-type object
) 'macro
)
1121 (org-element-property :begin object
)
1122 (org-element-property :end object
)))))))))
1123 (org-export-as (org-test-default-backend)))))))
1125 (ert-deftest test-org-export
/before-parsing-hook
()
1126 "Test `org-export-before-parsing-hook'."
1128 (equal "Body 1\nBody 2\n"
1129 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1130 (let ((org-export-before-parsing-hook
1132 (goto-char (point-min))
1133 (while (re-search-forward org-outline-regexp-bol nil t
)
1135 (point-at-bol) (progn (forward-line) (point))))))))
1136 (org-export-as (org-test-default-backend)))))))
1140 ;;; Affiliated Keywords
1142 (ert-deftest test-org-export
/read-attribute
()
1143 "Test `org-export-read-attribute' specifications."
1147 (org-export-read-attribute
1149 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1150 (org-element-at-point)))
1152 ;; Return nil on empty attribute.
1154 (org-export-read-attribute
1156 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1157 ;; Return nil on "nil" string.
1159 (equal '(:a nil
:b nil
)
1160 (org-export-read-attribute
1162 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1163 (org-element-at-point)))))
1164 ;; Return nil on empty string.
1166 (equal '(:a nil
:b nil
)
1167 (org-export-read-attribute
1169 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1170 (org-element-at-point)))))
1171 ;; Return empty string when value is "".
1174 (org-export-read-attribute
1176 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1177 (org-element-at-point)))))
1178 ;; Return \"\" when value is """".
1181 (org-export-read-attribute
1183 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1184 (org-element-at-point)))))
1185 ;; Ignore text before first property.
1188 (org-export-read-attribute
1190 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1191 (org-element-at-point))))))
1193 (ert-deftest test-org-export
/get-caption
()
1194 "Test `org-export-get-caption' specifications."
1195 ;; Without optional argument, return long caption
1199 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1200 (org-export-get-caption (org-element-at-point)))))
1201 ;; With optional argument, return short caption.
1205 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1206 (org-export-get-caption (org-element-at-point) t
))))
1207 ;; Multiple lines are separated by white spaces.
1211 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1212 (org-export-get-caption (org-element-at-point))))))
1218 (ert-deftest test-org-export
/define-backend
()
1219 "Test back-end definition and accessors."
1222 (equal '((headline . my-headline-test
))
1223 (let (org-export--registered-backends)
1224 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1225 (org-export-get-all-transcoders 'test
))))
1228 (equal '((:filter-headline . my-filter
))
1229 (let (org-export--registered-backends)
1230 (org-export-define-backend 'test
1231 '((headline . my-headline-test
))
1232 :filters-alist
'((:filter-headline . my-filter
)))
1233 (org-export-backend-filters (org-export-get-backend 'test
)))))
1236 (equal '((:prop value
))
1237 (let (org-export--registered-backends)
1238 (org-export-define-backend 'test
1239 '((headline . my-headline-test
))
1240 :options-alist
'((:prop value
)))
1241 (org-export-backend-options (org-export-get-backend 'test
)))))
1244 (equal '(?k
"Test Export" test
)
1245 (let (org-export--registered-backends)
1246 (org-export-define-backend 'test
1247 '((headline . my-headline-test
))
1248 :menu-entry
'(?k
"Test Export" test
))
1249 (org-export-backend-menu (org-export-get-backend 'test
)))))
1252 (equal '(("TEST" . org-element-export-block-parser
))
1253 (let (org-export--registered-backends org-element-block-name-alist
)
1254 (org-export-define-backend 'test
1255 '((headline . my-headline-test
))
1256 :export-block
'("test"))
1257 org-element-block-name-alist
))))
1259 (ert-deftest test-org-export
/define-derived-backend
()
1260 "Test `org-export-define-derived-backend' specifications."
1261 ;; Error when parent back-end is not defined.
1263 (let (org-export--registered-backends)
1264 (org-export-define-derived-backend 'test
'parent
)))
1265 ;; Append translation table to parent's.
1267 (equal '((:headline . test
) (:headline . parent
))
1268 (let (org-export--registered-backends)
1269 (org-export-define-backend 'parent
'((:headline . parent
)))
1270 (org-export-define-derived-backend 'test
'parent
1271 :translate-alist
'((:headline . test
)))
1272 (org-export-get-all-transcoders 'test
))))
1273 ;; Options defined in the new back have priority over those defined
1277 (let (org-export--registered-backends)
1278 (org-export-define-backend 'parent
1279 '((:headline . parent
))
1280 :options-alist
'((:a nil nil
'parent
)))
1281 (org-export-define-derived-backend 'test
'parent
1282 :options-alist
'((:a nil nil
'test
)))
1283 (plist-get (org-export--get-global-options
1284 (org-export-get-backend 'test
))
1287 (ert-deftest test-org-export
/derived-backend-p
()
1288 "Test `org-export-derived-backend-p' specifications."
1289 ;; Non-nil with direct match.
1291 (let (org-export--registered-backends)
1292 (org-export-define-backend 'test
'((headline . test
)))
1293 (org-export-derived-backend-p 'test
'test
)))
1295 (let (org-export--registered-backends)
1296 (org-export-define-backend 'test
'((headline . test
)))
1297 (org-export-define-derived-backend 'test2
'test
)
1298 (org-export-derived-backend-p 'test2
'test2
)))
1299 ;; Non-nil with a direct parent.
1301 (let (org-export--registered-backends)
1302 (org-export-define-backend 'test
'((headline . test
)))
1303 (org-export-define-derived-backend 'test2
'test
)
1304 (org-export-derived-backend-p 'test2
'test
)))
1305 ;; Non-nil with an indirect parent.
1307 (let (org-export--registered-backends)
1308 (org-export-define-backend 'test
'((headline . test
)))
1309 (org-export-define-derived-backend 'test2
'test
)
1310 (org-export-define-derived-backend 'test3
'test2
)
1311 (org-export-derived-backend-p 'test3
'test
)))
1314 (let (org-export--registered-backends)
1315 (org-export-define-backend 'test
'((headline . test
)))
1316 (org-export-define-backend 'test2
'((headline . test2
)))
1317 (org-export-derived-backend-p 'test2
'test
)))
1319 (let (org-export--registered-backends)
1320 (org-export-define-backend 'test
'((headline . test
)))
1321 (org-export-define-backend 'test2
'((headline . test2
)))
1322 (org-export-define-derived-backend 'test3
'test2
)
1323 (org-export-derived-backend-p 'test3
'test
))))
1325 (ert-deftest test-org-export
/get-all-transcoders
()
1326 "Test `org-export-get-all-transcoders' specifications."
1327 ;; Return nil when back-end cannot be found.
1328 (should-not (org-export-get-all-transcoders nil
))
1329 ;; Same as `org-export-transcoders' if no parent.
1331 (equal '((headline . ignore
))
1332 (org-export-get-all-transcoders
1333 (org-export-create-backend
1334 :transcoders
'((headline . ignore
))))))
1335 ;; But inherit from all ancestors whenever possible.
1337 (equal '((section . ignore
) (headline . ignore
))
1338 (let (org-export--registered-backends)
1339 (org-export-define-backend 'b1
'((headline . ignore
)))
1340 (org-export-get-all-transcoders
1341 (org-export-create-backend
1342 :parent
'b1
:transcoders
'((section . ignore
)))))))
1344 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1345 (let (org-export--registered-backends)
1346 (org-export-define-backend 'b1
'((headline . ignore
)))
1347 (org-export-define-derived-backend 'b2
'b1
1348 :translate-alist
'((section . ignore
)))
1349 (org-export-get-all-transcoders
1350 (org-export-create-backend
1351 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1352 ;; Back-end transcoders overrule inherited ones.
1355 (let (org-export--registered-backends)
1356 (org-export-define-backend 'b1
'((headline . a
)))
1357 (cdr (assq 'headline
1358 (org-export-get-all-transcoders
1359 (org-export-create-backend
1360 :parent
'b1
:transcoders
'((headline . b
))))))))))
1362 (ert-deftest test-org-export
/get-all-options
()
1363 "Test `org-export-get-all-options' specifications."
1364 ;; Return nil when back-end cannot be found.
1365 (should-not (org-export-get-all-options nil
))
1366 ;; Same as `org-export-options' if no parent.
1368 (equal '((headline . ignore
))
1369 (org-export-get-all-options
1370 (org-export-create-backend
1371 :options
'((headline . ignore
))))))
1372 ;; But inherit from all ancestors whenever possible.
1374 (equal '((:key2 value2
) (:key1 value1
))
1375 (let (org-export--registered-backends)
1376 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1377 (org-export-get-all-options
1378 (org-export-create-backend
1379 :parent
'b1
:options
'((:key2 value2
)))))))
1381 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1382 (let (org-export--registered-backends)
1383 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1384 (org-export-define-derived-backend 'b2
'b1
1385 :options-alist
'((:key2 value2
)))
1386 (org-export-get-all-options
1387 (org-export-create-backend
1388 :parent
'b2
:options
'((:key3 value3
)))))))
1389 ;; Back-end options overrule inherited ones.
1392 (let (org-export--registered-backends)
1393 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1395 (org-export-get-all-options
1396 (org-export-create-backend
1397 :parent
'b1
:options
'((:key1 . b
))))))))))
1399 (ert-deftest test-org-export
/get-all-filters
()
1400 "Test `org-export-get-all-filters' specifications."
1401 ;; Return nil when back-end cannot be found.
1402 (should-not (org-export-get-all-filters nil
))
1403 ;; Same as `org-export-filters' if no parent.
1405 (equal '((:filter-headline . ignore
))
1406 (org-export-get-all-filters
1407 (org-export-create-backend
1408 :filters
'((:filter-headline . ignore
))))))
1409 ;; But inherit from all ancestors whenever possible.
1411 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1412 (let (org-export--registered-backends)
1413 (org-export-define-backend 'b1
1414 nil
:filters-alist
'((:filter-headline . ignore
)))
1415 (org-export-get-all-filters
1416 (org-export-create-backend
1417 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1419 (equal '((:filter-paragraph . ignore
)
1420 (:filter-section . ignore
)
1421 (:filter-headline . ignore
))
1422 (let (org-export--registered-backends)
1423 (org-export-define-backend 'b1
1424 nil
:filters-alist
'((:filter-headline . ignore
)))
1425 (org-export-define-derived-backend 'b2
'b1
1426 :filters-alist
'((:filter-section . ignore
)))
1427 (org-export-get-all-filters
1428 (org-export-create-backend
1429 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1430 ;; Back-end filters overrule inherited ones.
1433 (let (org-export--registered-backends)
1434 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1435 (cdr (assq :filter-headline
1436 (org-export-get-all-filters
1437 (org-export-create-backend
1438 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1440 (ert-deftest test-org-export
/with-backend
()
1441 "Test `org-export-with-backend' definition."
1442 ;; Error when calling an undefined back-end
1443 (should-error (org-export-with-backend nil
"Test"))
1444 ;; Error when called back-end doesn't have an appropriate
1447 (org-export-with-backend
1448 (org-export-create-backend :transcoders
'((headline . ignore
)))
1450 ;; Otherwise, export using correct transcoder
1453 (let (org-export--registered-backends)
1454 (org-export-define-backend 'test
1455 '((plain-text .
(lambda (text contents info
) "Failure"))))
1456 (org-export-define-backend 'test2
1457 '((plain-text .
(lambda (text contents info
) "Success"))))
1458 (org-export-with-backend 'test2
"Test"))))
1459 ;; Provide correct back-end if transcoder needs to use recursive
1463 (let ((test-back-end
1464 (org-export-create-backend
1466 '((headline .
(lambda (headline contents info
)
1468 (org-element-property :title headline
)
1470 (plain-text .
(lambda (text info
) "Success"))))))
1471 (org-export-string-as
1473 (org-export-create-backend
1475 '((headline .
(lambda (headline contents info
)
1476 (org-export-with-backend
1477 test-back-end headline contents info
))))))))))
1479 (ert-deftest test-org-export
/data-with-backend
()
1480 "Test `org-export-data-with-backend' specifications."
1481 ;; Error when calling an undefined back-end.
1482 (should-error (org-export-data-with-backend nil
"nil" nil
))
1483 ;; Otherwise, export data recursively, using correct back-end.
1487 (org-export-data-with-backend
1489 (org-export-create-backend
1491 '((plain-text .
(lambda (text info
) "Success"))
1492 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1493 '(:with-emphasize t
)))))
1499 (ert-deftest test-org-export
/export-snippet
()
1500 "Test export snippets transcoding."
1502 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1503 (let ((backend (org-test-default-backend)))
1504 (setf (org-export-backend-name backend
) 'test
)
1505 (setf (org-export-backend-transcoders backend
)
1506 (cons (cons 'export-snippet
1507 (lambda (snippet contents info
)
1508 (when (eq (org-export-snippet-backend snippet
) 'test
)
1509 (org-element-property :value snippet
))))
1510 (org-export-backend-transcoders backend
)))
1511 (let ((org-export-snippet-translation-alist nil
))
1512 (should (equal (org-export-as backend
) "A\n")))
1513 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1514 (should (equal (org-export-as backend
) "AB\n")))))
1515 ;; Ignored export snippets do not remove any blank.
1517 (equal "begin end\n"
1518 (org-test-with-parsed-data "begin @@test:A@@ end"
1519 (org-export-data-with-backend
1521 (org-export-create-backend
1523 '((paragraph .
(lambda (paragraph contents info
) contents
))
1524 (section .
(lambda (section contents info
) contents
))))
1531 (ert-deftest test-org-export
/footnotes
()
1532 "Test footnotes specifications."
1533 (let ((org-footnote-section nil
)
1534 (org-export-with-footnotes t
))
1535 ;; 1. Read every type of footnote.
1538 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1539 (org-test-with-parsed-data
1540 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1541 (org-element-map tree
'footnote-reference
1543 (let ((def (org-export-get-footnote-definition ref info
)))
1544 (cons (org-export-get-footnote-number ref info
)
1545 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1546 (car (org-element-contents
1547 (car (org-element-contents def
))))))))
1549 ;; 2. Test nested footnotes order.
1552 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
1553 (org-test-with-parsed-data
1554 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1555 (org-element-map tree
'footnote-reference
1557 (when (org-export-footnote-first-reference-p ref info
)
1558 (cons (org-export-get-footnote-number ref info
)
1559 (org-element-property :label ref
))))
1561 ;; 3. Test nested footnote in invisible definitions.
1562 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1563 ;; Hide definitions.
1564 (narrow-to-region (point) (point-at-eol))
1565 (let* ((tree (org-element-parse-buffer))
1566 (info (org-combine-plists
1567 `(:parse-tree
,tree
)
1568 (org-export-collect-tree-properties
1569 tree
(org-export-get-environment)))))
1570 ;; Both footnotes should be seen.
1572 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
1573 ;; 4. Test footnotes definitions collection.
1576 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1578 \[fn:2] B [fn:3] [fn::D].
1581 (length (org-export-collect-footnote-definitions tree info
)))))
1582 ;; 5. Test export of footnotes defined outside parsing scope.
1585 "ParagraphOut of scope\n"
1586 (org-test-with-temp-text "[fn:1] Out of scope
1589 (let ((backend (org-test-default-backend)))
1590 (setf (org-export-backend-transcoders backend
)
1591 (cons (cons 'footnote-reference
1592 (lambda (fn contents info
)
1593 (org-element-interpret-data
1594 (org-export-get-footnote-definition fn info
))))
1595 (org-export-backend-transcoders backend
)))
1597 (org-export-as backend
'subtree
)))))
1598 ;; 6. Footnotes without a definition should throw an error.
1600 (org-test-with-parsed-data "Text[fn:1]"
1601 (org-export-get-footnote-definition
1602 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1603 ;; 7. Footnote section should be ignored in TOC and in headlines
1606 (= 1 (let ((org-footnote-section "Footnotes"))
1607 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1608 (org-export-collect-headlines info
))))))
1611 (let ((org-footnote-section "Footnotes"))
1612 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1613 (org-element-map tree
'headline
1615 (when (equal (org-element-property :raw-value hl
) "H2")
1616 (org-export-get-headline-number hl info
)))
1621 ;;; Headlines and Inlinetasks
1623 (ert-deftest test-org-export
/get-relative-level
()
1624 "Test `org-export-get-relative-level' specifications."
1628 (let ((org-odd-levels-only nil
))
1629 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1630 (org-element-map tree
'headline
1631 (lambda (h) (org-export-get-relative-level h info
))
1636 (let ((org-odd-levels-only nil
))
1637 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1638 (org-element-map tree
'headline
1639 (lambda (h) (org-export-get-relative-level h info
))
1642 (ert-deftest test-org-export
/low-level-p
()
1643 "Test `org-export-low-level-p' specifications."
1647 (let ((org-odd-levels-only nil
))
1648 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1649 (org-element-map tree
'headline
1650 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1651 (plist-put info
:headline-levels
1)))))))
1653 (ert-deftest test-org-export
/get-headline-number
()
1654 "Test `org-export-get-headline-number' specifications."
1659 (let ((org-odd-levels-only nil
))
1660 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1661 (org-element-map tree
'headline
1662 (lambda (h) (org-export-get-headline-number h info
))
1664 ;; Missing levels are replaced with 0.
1668 (let ((org-odd-levels-only nil
))
1669 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1670 (org-element-map tree
'headline
1671 (lambda (h) (org-export-get-headline-number h info
))
1674 (ert-deftest test-org-export
/numbered-headline-p
()
1675 "Test `org-export-numbered-headline-p' specifications."
1676 ;; If `:section-numbers' is nil, never number headlines.
1678 (org-test-with-parsed-data "* Headline"
1679 (org-element-map tree
'headline
1680 (lambda (h) (org-export-numbered-headline-p h info
))
1681 (plist-put info
:section-numbers nil
))))
1682 ;; If `:section-numbers' is a number, only number headlines with
1683 ;; a level greater that it.
1687 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1688 (org-element-map tree
'headline
1689 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1690 (plist-put info
:section-numbers
1)))))
1691 ;; Otherwise, headlines are always numbered.
1693 (org-test-with-parsed-data "* Headline"
1694 (org-element-map tree
'headline
1695 (lambda (h) (org-export-numbered-headline-p h info
))
1696 (plist-put info
:section-numbers t
)))))
1698 (ert-deftest test-org-export
/org-export-get-headline-id
()
1699 "Test `org-export-get-headline-id' specifications."
1700 ;; Numbered headlines have IDs akin to "sec-N".
1703 (org-test-with-parsed-data "* H"
1704 (org-export-get-headline-id
1705 (org-element-map tree
'headline
#'identity info t
)
1707 ;; The ID of numbered headlines reflect the hierarchy.
1710 (org-test-with-parsed-data "* H1\n** H2"
1711 (org-export-get-headline-id
1712 (org-element-map tree
'headline
1714 (and (equal "H2" (org-element-property :raw-value h
)) h
))
1717 ;; Unnumbered headlines have IDs akin to "unnumbered-N".
1719 (equal "unnumbered-1"
1720 (org-test-with-parsed-data
1721 "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
1722 (org-export-get-headline-id
1723 (org-element-map tree
'headline
#'identity info t
)
1725 ;; The ID of Unnumbered headlines do not reflect the hierarchy.
1727 (equal "unnumbered-2"
1728 (org-test-with-parsed-data
1729 "* H1\n:PROPERTIES:\n:UNNUMBERED: t\n:END:\n** H2"
1730 (org-export-get-headline-id
1731 (org-element-map tree
'headline
1733 (and (equal "H2" (org-element-property :raw-value h
)) h
))
1736 ;; When #+OPTIONS: num:nil all headlines are unnumbered.
1738 (equal "unnumbered-1"
1739 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
1740 (org-export-get-headline-id
1741 (org-element-map tree
'headline
'identity info t
)
1743 ;; UNNUMBERED ignores inheritance. Any non-nil value among
1744 ;; ancestors disables numbering.
1746 (org-test-with-parsed-data
1757 (lambda (h) (not (org-export-numbered-headline-p h info
)))
1758 (org-element-map tree
'headline
#'identity info
)))))
1760 (ert-deftest test-org-export
/number-to-roman
()
1761 "Test `org-export-number-to-roman' specifications."
1762 ;; If number is negative, return it as a string.
1763 (should (equal (org-export-number-to-roman -
1) "-1"))
1764 ;; Otherwise, return it as a roman number.
1765 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1767 (ert-deftest test-org-export
/get-optional-title
()
1768 "Test `org-export-get-alt-title' specifications."
1769 ;; If ALT_TITLE property is defined, use it.
1772 (org-test-with-parsed-data
1773 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1774 (org-export-get-alt-title
1775 (org-element-map tree
'headline
'identity info t
)
1777 ;; Otherwise, fall-back to regular title.
1779 (equal '("Headline")
1780 (org-test-with-parsed-data "* Headline"
1781 (org-export-get-alt-title
1782 (org-element-map tree
'headline
'identity info t
)
1785 (ert-deftest test-org-export
/get-tags
()
1786 "Test `org-export-get-tags' specifications."
1787 (let ((org-export-exclude-tags '("noexport"))
1788 (org-export-select-tags '("export")))
1789 ;; Standard test: tags which are not a select tag, an exclude tag,
1790 ;; or specified as optional argument shouldn't be ignored.
1792 (org-test-with-parsed-data "* Headline :tag:"
1793 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1795 ;; Exclude tags are removed.
1797 (org-test-with-parsed-data "* Headline :noexport:"
1798 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1800 ;; Select tags are removed.
1802 (org-test-with-parsed-data "* Headline :export:"
1803 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1808 (org-test-with-parsed-data "* Headline :tag:export:"
1809 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1811 ;; Tags provided in the optional argument are also ignored.
1813 (org-test-with-parsed-data "* Headline :ignore:"
1814 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1816 ;; Allow tag inheritance.
1820 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1821 (org-element-map tree
'headline
1822 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1823 ;; Tag inheritance checks FILETAGS keywords.
1827 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1828 (org-element-map tree
'headline
1829 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1831 (ert-deftest test-org-export
/get-node-property
()
1832 "Test`org-export-get-node-property' specifications."
1836 (org-test-with-parsed-data "* Headline
1840 (org-export-get-node-property
1841 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1842 ;; Test inheritance.
1845 (org-test-with-parsed-data "* Parent
1851 (org-export-get-node-property
1852 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1853 ;; Cannot return a value before the first headline.
1855 (org-test-with-parsed-data "Paragraph
1860 (org-export-get-node-property
1861 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1863 (ert-deftest test-org-export
/get-category
()
1864 "Test `org-export-get-category' specifications."
1868 (org-test-with-parsed-data "* Headline
1872 (org-export-get-category
1873 (org-element-map tree
'headline
'identity nil t
) info
))))
1874 ;; Test inheritance from a parent headline.
1876 (equal '("value" "value")
1877 (org-test-with-parsed-data "* Headline1
1882 (org-element-map tree
'headline
1883 (lambda (hl) (org-export-get-category hl info
)) info
))))
1884 ;; Test inheritance from #+CATEGORY keyword
1887 (org-test-with-parsed-data "#+CATEGORY: value
1889 (org-export-get-category
1890 (org-element-map tree
'headline
'identity nil t
) info
))))
1891 ;; Test inheritance from file name.
1894 (org-test-with-parsed-data "* Headline"
1895 (let ((info (plist-put info
:input-file
"~/test.org")))
1896 (org-export-get-category
1897 (org-element-map tree
'headline
'identity nil t
) info
)))))
1901 (org-test-with-parsed-data "* Headline"
1902 (org-export-get-category
1903 (org-element-map tree
'headline
'identity nil t
) info
)))))
1905 (ert-deftest test-org-export
/first-sibling-p
()
1906 "Test `org-export-first-sibling-p' specifications."
1911 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
1912 (org-element-map tree
'headline
1913 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1917 (org-test-with-parsed-data "- item\n\n para"
1918 (org-element-map tree
'paragraph
1919 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1921 ;; Ignore sections for headlines.
1924 (org-test-with-parsed-data "* H\nSection\n** H 2"
1925 (org-element-map tree
'headline
1926 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1928 ;; Ignore headlines not exported.
1932 (let ((org-export-exclude-tags '("ignore")))
1933 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1934 (org-element-map tree
'headline
1935 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1938 (ert-deftest test-org-export
/last-sibling-p
()
1939 "Test `org-export-last-sibling-p' specifications."
1944 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1945 (org-element-map tree
'headline
1946 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1950 (org-test-with-parsed-data "- item\n\n para"
1951 (org-element-map tree
'paragraph
1952 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1954 ;; Ignore headlines not exported.
1958 (let ((org-export-exclude-tags '("ignore")))
1959 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1960 (org-element-map tree
'headline
1961 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1964 (ert-deftest test-org-export
/handle-inlinetasks
()
1965 "Test inlinetask export."
1966 ;; Inlinetask with an exclude tag.
1967 (when (featurep 'org-inlinetask
)
1971 (let ((org-inlinetask-min-level 3)
1972 org-export-filter-body-functions
1973 org-export-filter-final-output-functions
)
1974 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1975 (org-export-as (org-test-default-backend)
1976 nil nil nil
'(:exclude-tags
("noexp")))))))
1977 ;; Inlinetask with an include tag.
1980 "* H2\n*** Inline :exp:\n"
1981 (let ((org-inlinetask-min-level 3)
1982 (org-tags-column 0))
1983 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1984 (org-export-as (org-test-default-backend)
1985 nil nil nil
'(:select-tags
("exp")))))))
1986 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1989 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1990 (org-inlinetask-min-level 3)
1991 org-export-filter-body-functions
1992 org-export-filter-final-output-functions
)
1993 (org-test-with-temp-text "*** TODO Inline"
1994 (org-export-as (org-test-default-backend)
1995 nil nil nil
'(:with-tasks nil
))))))))
2001 (ert-deftest test-org-export
/get-date
()
2002 "Test `org-export-get-date' specifications."
2003 ;; Return a properly formatted string when
2004 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2005 ;; consists in a single timestamp.
2008 (let ((org-export-date-timestamp-format "%d %m %Y"))
2009 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2010 (org-export-get-date info
)))))
2011 ;; Return a secondary string otherwise.
2014 (let ((org-export-date-timestamp-format nil
))
2015 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2016 (org-export-get-date info
)))))
2019 (org-test-with-parsed-data "#+DATE: Date"
2020 (org-export-get-date info
))))
2021 ;; Optional argument has precedence over
2022 ;; `org-export-date-timestamp-format'.
2025 (let ((org-export-date-timestamp-format "%d %m %Y"))
2026 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2027 (org-export-get-date info
"%d %m"))))))
2033 (ert-deftest test-org-export
/custom-protocol-maybe
()
2034 "Test `org-export-custom-protocol-maybe' specifications."
2038 (let ((org-link-types (copy-sequence org-link-types
)))
2039 (org-add-link-type "foo" nil
(lambda (p d f
) "success"))
2040 (org-export-string-as
2042 (org-export-create-backend
2044 :transcoders
'((section .
(lambda (s c i
) c
))
2045 (paragraph .
(lambda (p c i
) c
))
2046 (link .
(lambda (l c i
)
2047 (or (org-export-custom-protocol-maybe l c i
)
2052 (let ((org-link-types (copy-sequence org-link-types
)))
2054 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2055 (org-export-string-as
2057 (org-export-create-backend
2059 :transcoders
'((section .
(lambda (s c i
) c
))
2060 (paragraph .
(lambda (p c i
) c
))
2061 (link .
(lambda (l c i
)
2062 (or (org-export-custom-protocol-maybe l c i
)
2064 ;; Ignore anonymous back-ends.
2068 (let ((org-link-types (copy-sequence org-link-types
)))
2070 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2071 (org-export-string-as
2073 (org-export-create-backend
2074 :transcoders
'((section .
(lambda (s c i
) c
))
2075 (paragraph .
(lambda (p c i
) c
))
2076 (link .
(lambda (l c i
)
2077 (or (org-export-custom-protocol-maybe l c i
)
2080 (ert-deftest test-org-export
/get-coderef-format
()
2081 "Test `org-export-get-coderef-format' specifications."
2082 ;; A link without description returns "%s"
2083 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2085 ;; Return "%s" when path is matched within description.
2086 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2088 ;; Otherwise return description.
2089 (should (equal (org-export-get-coderef-format "path" "desc")
2092 (ert-deftest test-org-export
/inline-image-p
()
2093 "Test `org-export-inline-image-p' specifications."
2095 (org-export-inline-image-p
2096 (org-test-with-temp-text "[[#id]]"
2097 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2098 '(("custom-id" .
"id")))))
2100 (ert-deftest test-org-export
/fuzzy-link
()
2101 "Test fuzzy links specifications."
2102 ;; Link to an headline should return headline's number.
2103 (org-test-with-parsed-data
2104 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2106 ;; Note: Headline's number is in fact a list of numbers.
2108 (org-element-map tree
'link
2110 (org-export-get-ordinal
2111 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2112 ;; Link to a target in an item should return item's number.
2113 (org-test-with-parsed-data
2114 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2116 ;; Note: Item's number is in fact a list of numbers.
2118 (org-element-map tree
'link
2120 (org-export-get-ordinal
2121 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2122 ;; Link to a target in a footnote should return footnote's number.
2123 (org-test-with-parsed-data "
2124 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
2127 (org-element-map tree
'link
2129 (org-export-get-ordinal
2130 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2131 ;; Link to a named element should return sequence number of that
2133 (org-test-with-parsed-data
2134 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2137 (org-element-map tree
'link
2139 (org-export-get-ordinal
2140 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2141 ;; Link to a target not within an item, a table, a footnote
2142 ;; reference or definition should return section number.
2143 (org-test-with-parsed-data
2144 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2147 (org-element-map tree
'link
2149 (org-export-get-ordinal
2150 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2151 ;; Space are not significant when matching a fuzzy link.
2153 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2154 (org-element-map tree
'link
2155 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2157 ;; Statistics cookies are ignored for headline match.
2159 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2160 (org-element-map tree
'link
2161 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2164 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2165 (org-element-map tree
'link
2166 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2168 ;; Headline match is position dependent.
2172 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
2173 (org-element-map tree
'link
2174 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
2176 (ert-deftest test-org-export
/resolve-coderef
()
2177 "Test `org-export-resolve-coderef' specifications."
2178 (let ((org-coderef-label-format "(ref:%s)"))
2179 ;; 1. A link to a "-n -k -r" block returns line number.
2180 (org-test-with-parsed-data
2181 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2182 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2183 (org-test-with-parsed-data
2184 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2185 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2186 ;; 2. A link to a "-n -r" block returns line number.
2187 (org-test-with-parsed-data
2188 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2189 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2190 (org-test-with-parsed-data
2191 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2192 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2193 ;; 3. A link to a "-n" block returns coderef.
2194 (org-test-with-parsed-data
2195 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2196 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2197 (org-test-with-parsed-data
2198 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2199 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2200 ;; 4. A link to a "-r" block returns line number.
2201 (org-test-with-parsed-data
2202 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2203 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2204 (org-test-with-parsed-data
2205 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2206 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2207 ;; 5. A link to a block without a switch returns coderef.
2208 (org-test-with-parsed-data
2209 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2210 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2211 (org-test-with-parsed-data
2212 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2213 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2214 ;; 6. Correctly handle continued line numbers. A "+n" switch
2215 ;; should resume numbering from previous block with numbered
2216 ;; lines, ignoring blocks not numbering lines in the process.
2217 ;; A "-n" switch resets count.
2218 (org-test-with-parsed-data "
2223 #+BEGIN_SRC emacs-lisp
2227 #+BEGIN_SRC emacs-lisp +n -r
2228 \(+ 1 1) (ref:addition)
2231 #+BEGIN_EXAMPLE -n -r
2232 Another text. (ref:text)
2234 (should (= (org-export-resolve-coderef "addition" info
) 2))
2235 (should (= (org-export-resolve-coderef "text" info
) 1)))
2236 ;; 7. Recognize coderef with user-specified syntax.
2237 (org-test-with-parsed-data
2238 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2239 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
2241 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2242 "Test `org-export-resolve-fuzzy-link' specifications."
2243 ;; Match target objects.
2245 (org-test-with-parsed-data "<<target>> [[target]]"
2246 (org-export-resolve-fuzzy-link
2247 (org-element-map tree
'link
'identity info t
) info
)))
2248 ;; Match named elements.
2250 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2251 (org-export-resolve-fuzzy-link
2252 (org-element-map tree
'link
'identity info t
) info
)))
2253 ;; Match exact headline's name.
2255 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2256 (org-export-resolve-fuzzy-link
2257 (org-element-map tree
'link
'identity info t
) info
)))
2258 ;; Targets objects have priority over named elements and headline
2262 (org-test-with-parsed-data
2263 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2265 (org-export-resolve-fuzzy-link
2266 (org-element-map tree
'link
'identity info t
) info
)))))
2267 ;; Named elements have priority over headline titles.
2270 (org-test-with-parsed-data
2271 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2273 (org-export-resolve-fuzzy-link
2274 (org-element-map tree
'link
'identity info t
) info
)))))
2275 ;; If link's path starts with a "*", only match headline titles,
2279 (org-test-with-parsed-data
2280 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2282 (org-export-resolve-fuzzy-link
2283 (org-element-map tree
'link
'identity info t
) info
)))))
2284 ;; Return nil if no match.
2286 (org-test-with-parsed-data "[[target]]"
2287 (org-export-resolve-fuzzy-link
2288 (org-element-map tree
'link
'identity info t
) info
)))
2289 ;; Match fuzzy link even when before first headline.
2292 (org-test-with-parsed-data "[[hl]]\n* hl"
2294 (org-export-resolve-fuzzy-link
2295 (org-element-map tree
'link
'identity info t
) info
))))))
2297 (ert-deftest test-org-export
/resolve-id-link
()
2298 "Test `org-export-resolve-id-link' specifications."
2299 ;; 1. Regular test for custom-id link.
2300 (org-test-with-parsed-data "* Headline1
2307 (org-export-resolve-id-link
2308 (org-element-map tree
'link
'identity info t
) info
)))
2309 ;; 2. Failing test for custom-id link.
2310 (org-test-with-parsed-data "* Headline1
2317 (org-export-resolve-id-link
2318 (org-element-map tree
'link
'identity info t
) info
)))
2319 ;; 3. Test for internal id target.
2320 (org-test-with-parsed-data "* Headline1
2327 (org-export-resolve-id-link
2328 (org-element-map tree
'link
'identity info t
) info
)))
2329 ;; 4. Test for external id target.
2330 (org-test-with-parsed-data "[[id:aaaa]]"
2332 (org-export-resolve-id-link
2333 (org-element-map tree
'link
'identity info t
)
2334 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
2336 (ert-deftest test-org-export
/resolve-radio-link
()
2337 "Test `org-export-resolve-radio-link' specifications."
2340 (org-test-with-temp-text "<<<radio>>> radio"
2341 (org-update-radio-target-regexp)
2342 (let* ((tree (org-element-parse-buffer))
2343 (info `(:parse-tree
,tree
)))
2344 (org-export-resolve-radio-link
2345 (org-element-map tree
'link
'identity info t
)
2347 ;; Radio targets are case-insensitive.
2349 (org-test-with-temp-text "<<<RADIO>>> radio"
2350 (org-update-radio-target-regexp)
2351 (let* ((tree (org-element-parse-buffer))
2352 (info `(:parse-tree
,tree
)))
2353 (org-export-resolve-radio-link
2354 (org-element-map tree
'link
'identity info t
)
2356 ;; Radio target with objects.
2358 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2359 (org-update-radio-target-regexp)
2360 (let* ((tree (org-element-parse-buffer))
2361 (info `(:parse-tree
,tree
)))
2362 (org-export-resolve-radio-link
2363 (org-element-map tree
'link
'identity info t
)
2365 ;; Radio target with objects at its beginning.
2367 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2368 (org-update-radio-target-regexp)
2369 (let* ((tree (org-element-parse-buffer))
2370 (info `(:parse-tree
,tree
)))
2371 (org-export-resolve-radio-link
2372 (org-element-map tree
'link
'identity info t
)
2374 ;; Radio link next to an apostrophe.
2376 (org-test-with-temp-text "<<<radio>>> radio's"
2377 (org-update-radio-target-regexp)
2378 (let* ((tree (org-element-parse-buffer))
2379 (info `(:parse-tree
,tree
)))
2380 (org-export-resolve-radio-link
2381 (org-element-map tree
'link
'identity info t
)
2383 ;; Multiple radio targets.
2385 (equal '("radio1" "radio2")
2386 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2387 (org-update-radio-target-regexp)
2388 (let* ((tree (org-element-parse-buffer))
2389 (info `(:parse-tree
,tree
)))
2390 (org-element-map tree
'link
2392 (org-element-property
2393 :value
(org-export-resolve-radio-link link info
)))
2395 ;; Radio target is whitespace insensitive.
2397 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2398 (org-update-radio-target-regexp)
2399 (let* ((tree (org-element-parse-buffer))
2400 (info `(:parse-tree
,tree
)))
2401 (org-element-map tree
'link
2402 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2406 ;;; Src-block and example-block
2408 (ert-deftest test-org-export
/unravel-code
()
2409 "Test `org-export-unravel-code' function."
2410 ;; Code without reference.
2412 (equal '("(+ 1 1)\n")
2413 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2414 (org-export-unravel-code (org-element-at-point)))))
2415 ;; Code with reference.
2417 (equal '("(+ 1 1)\n" (1 .
"test"))
2418 (org-test-with-temp-text
2419 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2420 (let ((org-coderef-label-format "(ref:%s)"))
2421 (org-export-unravel-code (org-element-at-point))))))
2422 ;; Code with user-defined reference.
2425 '("(+ 1 1)\n" (1 .
"test"))
2426 (org-test-with-temp-text
2427 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2428 (let ((org-coderef-label-format "(ref:%s)"))
2429 (org-export-unravel-code (org-element-at-point))))))
2430 ;; Code references keys are relative to the current block.
2432 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2433 (org-test-with-temp-text "
2442 (let ((org-coderef-label-format "(ref:%s)"))
2443 (org-export-unravel-code (org-element-at-point)))))))
2445 (ert-deftest test-org-export
/format-code-default
()
2446 "Test `org-export-format-code-default' specifications."
2447 ;; Return the empty string when code is empty.
2450 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2451 (org-export-format-code-default
2452 (org-element-map tree
'src-block
'identity info t
) info
))))
2453 ;; Number lines, two whitespace characters before the actual loc.
2456 (org-test-with-parsed-data
2457 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2458 (org-export-format-code-default
2459 (org-element-map tree
'src-block
'identity info t
) info
))))
2460 ;; Put references 6 whitespace characters after the widest line,
2461 ;; wrapped within parenthesis.
2463 (equal "123 (a)\n1 (b)\n"
2464 (let ((org-coderef-label-format "(ref:%s)"))
2465 (org-test-with-parsed-data
2466 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2467 (org-export-format-code-default
2468 (org-element-map tree
'src-block
'identity info t
) info
))))))
2474 (ert-deftest test-org-export
/activate-smart-quotes
()
2475 "Test `org-export-activate-smart-quotes' specifications."
2476 ;; Opening double quotes: standard test.
2479 '("some “paragraph")
2480 (let ((org-export-default-language "en"))
2481 (org-test-with-parsed-data "some \"paragraph"
2482 (org-element-map tree
'plain-text
2483 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2485 ;; Opening quotes: at the beginning of a paragraph.
2489 (let ((org-export-default-language "en"))
2490 (org-test-with-parsed-data "\"begin"
2491 (org-element-map tree
'plain-text
2492 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2494 ;; Opening quotes: after an object.
2498 (let ((org-export-default-language "en"))
2499 (org-test-with-parsed-data "=verb= \"begin"
2500 (org-element-map tree
'plain-text
2501 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2503 ;; Closing quotes: standard test.
2506 '("some” paragraph")
2507 (let ((org-export-default-language "en"))
2508 (org-test-with-parsed-data "some\" paragraph"
2509 (org-element-map tree
'plain-text
2510 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2512 ;; Closing quotes: at the end of a paragraph.
2516 (let ((org-export-default-language "en"))
2517 (org-test-with-parsed-data "end\""
2518 (org-element-map tree
'plain-text
2519 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2521 ;; Apostrophe: standard test.
2524 '("It shouldn’t fail")
2525 (let ((org-export-default-language "en"))
2526 (org-test-with-parsed-data "It shouldn't fail"
2527 (org-element-map tree
'plain-text
2528 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2530 ;; Apostrophe: before an object.
2534 (let ((org-export-default-language "en"))
2535 (org-test-with-parsed-data "a'=b="
2536 (org-element-map tree
'plain-text
2537 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2539 ;; Apostrophe: after an object.
2543 (let ((org-export-default-language "en"))
2544 (org-test-with-parsed-data "=code='s"
2545 (org-element-map tree
'plain-text
2546 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2548 ;; Special case: isolated quotes.
2550 (equal '("“" "”")
2551 (let ((org-export-default-language "en"))
2552 (org-test-with-parsed-data "\"$x$\""
2553 (org-element-map tree
'plain-text
2554 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2556 ;; Smart quotes in secondary strings.
2558 (equal '("“" "”")
2559 (let ((org-export-default-language "en"))
2560 (org-test-with-parsed-data "* \"$x$\""
2561 (org-element-map tree
'plain-text
2562 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2564 ;; Smart quotes in document keywords.
2566 (equal '("“" "”")
2567 (let ((org-export-default-language "en"))
2568 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2569 (org-element-map (plist-get info
:title
) 'plain-text
2570 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2572 ;; Smart quotes in parsed affiliated keywords.
2574 (equal '("“" "”" "Paragraph")
2575 (let ((org-export-default-language "en"))
2576 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2577 (org-element-map tree
'plain-text
2578 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2579 info nil nil t
))))))
2585 (ert-deftest test-org-export
/special-column
()
2586 "Test if the table's special column is properly recognized."
2587 ;; 1. First column is special if it contains only a special marking
2588 ;; characters or empty cells.
2589 (org-test-with-temp-text "
2593 (org-export-table-has-special-column-p
2595 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2596 ;; 2. If the column contains anything else, it isn't special.
2597 (org-test-with-temp-text "
2601 (org-export-table-has-special-column-p
2603 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2604 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2606 (org-test-with-temp-text "
2615 (org-export-table-has-special-column-p
2617 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2618 ;; 4. A first column with only empty cells isn't considered as
2620 (org-test-with-temp-text "
2624 (org-export-table-has-special-column-p
2626 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2628 (ert-deftest test-org-export
/table-row-is-special-p
()
2629 "Test `org-export-table-row-is-special-p' specifications."
2630 ;; 1. A row is special if it has a special marking character in the
2632 (org-test-with-parsed-data "| ! | 1 |"
2634 (org-export-table-row-is-special-p
2635 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2636 ;; 2. A row is special when its first field is "/"
2637 (org-test-with-parsed-data "
2641 (org-export-table-row-is-special-p
2642 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2643 ;; 3. A row only containing alignment cookies is also considered as
2645 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2647 (org-export-table-row-is-special-p
2648 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2649 ;; 4. Everything else isn't considered as special.
2650 (org-test-with-parsed-data "| \alpha | | c |"
2652 (org-export-table-row-is-special-p
2653 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2654 ;; 5. Table's rules are never considered as special rows.
2655 (org-test-with-parsed-data "|---+---|"
2657 (org-export-table-row-is-special-p
2658 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2660 (ert-deftest test-org-export
/has-header-p
()
2661 "Test `org-export-table-has-header-p' specifications."
2662 ;; 1. With an header.
2663 (org-test-with-parsed-data "
2668 (org-export-table-has-header-p
2669 (org-element-map tree
'table
'identity info
'first-match
)
2671 ;; 2. Without an header.
2672 (org-test-with-parsed-data "
2676 (org-export-table-has-header-p
2677 (org-element-map tree
'table
'identity info
'first-match
)
2679 ;; 3. Don't get fooled with starting and ending rules.
2680 (org-test-with-parsed-data "
2686 (org-export-table-has-header-p
2687 (org-element-map tree
'table
'identity info
'first-match
)
2690 (ert-deftest test-org-export
/table-row-group
()
2691 "Test `org-export-table-row-group' specifications."
2692 ;; 1. A rule creates a new group.
2695 (org-test-with-parsed-data "
2699 (org-element-map tree
'table-row
2701 (if (eq (org-element-property :type row
) 'rule
) 'rule
2702 (org-export-table-row-group row info
)))))))
2703 ;; 2. Special rows are ignored in count.
2707 (org-test-with-parsed-data "
2711 (org-element-map tree
'table-row
2713 (if (eq (org-element-property :type row
) 'rule
) 'rule
2714 (org-export-table-row-group row info
)))
2716 ;; 3. Double rules also are ignored in count.
2718 (equal '(1 rule rule
2)
2719 (org-test-with-parsed-data "
2724 (org-element-map tree
'table-row
2726 (if (eq (org-element-property :type row
) 'rule
) 'rule
2727 (org-export-table-row-group row info
))))))))
2729 (ert-deftest test-org-export
/table-row-number
()
2730 "Test `org-export-table-row-number' specifications."
2731 ;; Standard test. Number is 0-indexed.
2734 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2735 (org-element-map tree
'table-row
2736 (lambda (row) (org-export-table-row-number row info
)) info
))))
2737 ;; Number ignores separators.
2740 (org-test-with-parsed-data "
2744 (org-element-map tree
'table-row
2745 (lambda (row) (org-export-table-row-number row info
)) info
))))
2746 ;; Number ignores special rows.
2749 (org-test-with-parsed-data "
2755 (org-element-map tree
'table-row
2756 (lambda (row) (org-export-table-row-number row info
)) info
)))))
2758 (ert-deftest test-org-export
/table-cell-width
()
2759 "Test `org-export-table-cell-width' specifications."
2760 ;; 1. Width is primarily determined by width cookies. If no cookie
2761 ;; is found, cell's width is nil.
2762 (org-test-with-parsed-data "
2763 | / | <l> | <6> | <l7> |
2768 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2769 (org-element-map tree
'table-cell
'identity info
)))))
2770 ;; 2. The last width cookie has precedence.
2771 (org-test-with-parsed-data "
2778 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2779 (org-element-map tree
'table-cell
'identity info
)))))
2780 ;; 3. Valid width cookies must have a specific row.
2781 (org-test-with-parsed-data "| <6> | cell |"
2785 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2786 (org-element-map tree
'table-cell
'identity
))))))
2788 (ert-deftest test-org-export
/table-cell-alignment
()
2789 "Test `org-export-table-cell-alignment' specifications."
2790 ;; 1. Alignment is primarily determined by alignment cookies.
2792 (equal '(left center right
)
2793 (let ((org-table-number-fraction 0.5)
2794 (org-table-number-regexp "^[0-9]+$"))
2795 (org-test-with-parsed-data "| <l> | <c> | <r> |"
2796 (mapcar (lambda (cell)
2797 (org-export-table-cell-alignment cell info
))
2798 (org-element-map tree
'table-cell
'identity
))))))
2799 ;; 2. The last alignment cookie has precedence.
2801 (equal '(right right right
)
2802 (org-test-with-parsed-data "
2806 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2807 (org-element-map tree
'table-cell
'identity
)))))
2808 ;; 3. If there's no cookie, cell's contents determine alignment.
2809 ;; A column mostly made of cells containing numbers will align
2810 ;; its cells to the right.
2812 (equal '(right right right
)
2813 (let ((org-table-number-fraction 0.5)
2814 (org-table-number-regexp "^[0-9]+$"))
2815 (org-test-with-parsed-data "
2819 (mapcar (lambda (cell)
2820 (org-export-table-cell-alignment cell info
))
2821 (org-element-map tree
'table-cell
'identity
))))))
2822 ;; 4. Otherwise, they will be aligned to the left.
2824 (equal '(left left left
)
2825 (org-test-with-parsed-data "
2829 (mapcar (lambda (cell)
2830 (org-export-table-cell-alignment cell info
))
2831 (org-element-map tree
'table-cell
'identity info
))))))
2833 (ert-deftest test-org-export
/table-cell-borders
()
2834 "Test `org-export-table-cell-borders' specifications."
2835 ;; 1. Recognize various column groups indicators.
2836 (org-test-with-parsed-data "| / | < | > | <> |"
2839 '((right bottom top
) (left bottom top
) (right bottom top
)
2840 (right left bottom top
))
2841 (mapcar (lambda (cell)
2842 (org-export-table-cell-borders cell info
))
2843 (org-element-map tree
'table-cell
'identity
)))))
2844 ;; 2. Accept shortcuts to define column groups.
2845 (org-test-with-parsed-data "| / | < | < |"
2848 '((right bottom top
) (right left bottom top
) (left bottom top
))
2849 (mapcar (lambda (cell)
2850 (org-export-table-cell-borders cell info
))
2851 (org-element-map tree
'table-cell
'identity
)))))
2852 ;; 3. A valid column groups row must start with a "/".
2853 (org-test-with-parsed-data "
2857 (equal '((top) (top) (bottom) (bottom))
2858 (mapcar (lambda (cell)
2859 (org-export-table-cell-borders cell info
))
2860 (org-element-map tree
'table-cell
'identity
)))))
2861 ;; 4. Take table rules into consideration.
2862 (org-test-with-parsed-data "
2867 (equal '((below top
) (bottom above
))
2868 (mapcar (lambda (cell)
2869 (org-export-table-cell-borders cell info
))
2870 (org-element-map tree
'table-cell
'identity
)))))
2871 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2872 ;; (resp. `bottom' and `below') borders. Any special row is
2874 (org-test-with-parsed-data "
2880 (equal '((bottom below top above
))
2882 (mapcar (lambda (cell)
2883 (org-export-table-cell-borders cell info
))
2884 (org-element-map tree
'table-cell
'identity
)))))))
2886 (ert-deftest test-org-export
/table-dimensions
()
2887 "Test `org-export-table-dimensions' specifications."
2888 ;; 1. Standard test.
2889 (org-test-with-parsed-data "
2894 (org-export-table-dimensions
2895 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2896 ;; 2. Ignore horizontal rules and special columns.
2897 (org-test-with-parsed-data "
2904 (org-export-table-dimensions
2905 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2907 (ert-deftest test-org-export
/table-cell-address
()
2908 "Test `org-export-table-cell-address' specifications."
2909 ;; 1. Standard test: index is 0-based.
2910 (org-test-with-parsed-data "| a | b |"
2912 (equal '((0 .
0) (0 .
1))
2913 (org-element-map tree
'table-cell
2914 (lambda (cell) (org-export-table-cell-address cell info
))
2916 ;; 2. Special column isn't counted, nor are special rows.
2917 (org-test-with-parsed-data "
2922 (org-export-table-cell-address
2923 (car (last (org-element-map tree
'table-cell
'identity info
)))
2925 ;; 3. Tables rules do not count either.
2926 (org-test-with-parsed-data "
2934 (org-export-table-cell-address
2935 (car (last (org-element-map tree
'table-cell
'identity info
)))
2937 ;; 4. Return nil for special cells.
2938 (org-test-with-parsed-data "| / | a |"
2940 (org-export-table-cell-address
2941 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2944 (ert-deftest test-org-export
/get-table-cell-at
()
2945 "Test `org-export-get-table-cell-at' specifications."
2946 ;; 1. Address ignores special columns, special rows and rules.
2947 (org-test-with-parsed-data "
2954 (org-element-contents
2955 (org-export-get-table-cell-at
2957 (org-element-map tree
'table
'identity info
'first-match
)
2959 ;; 2. Return value for a non-existent address is nil.
2960 (org-test-with-parsed-data "| a |"
2962 (org-export-get-table-cell-at
2964 (org-element-map tree
'table
'identity info
'first-match
)
2966 (org-test-with-parsed-data "| / |"
2968 (org-export-get-table-cell-at
2970 (org-element-map tree
'table
'identity info
'first-match
)
2973 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2974 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2975 ;; 1. A cell at a beginning of a row always starts a column group.
2976 (org-test-with-parsed-data "| a |"
2978 (org-export-table-cell-starts-colgroup-p
2979 (org-element-map tree
'table-cell
'identity info
'first-match
)
2981 ;; 2. Special column should be ignored when determining the
2982 ;; beginning of the row.
2983 (org-test-with-parsed-data "
2987 (org-export-table-cell-starts-colgroup-p
2988 (org-element-map tree
'table-cell
'identity info
'first-match
)
2990 ;; 2. Explicit column groups.
2991 (org-test-with-parsed-data "
2997 (org-element-map tree
'table-cell
2999 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3002 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3003 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3004 ;; 1. A cell at the end of a row always ends a column group.
3005 (org-test-with-parsed-data "| a |"
3007 (org-export-table-cell-ends-colgroup-p
3008 (org-element-map tree
'table-cell
'identity info
'first-match
)
3010 ;; 2. Special column should be ignored when determining the
3011 ;; beginning of the row.
3012 (org-test-with-parsed-data "
3016 (org-export-table-cell-ends-colgroup-p
3017 (org-element-map tree
'table-cell
'identity info
'first-match
)
3019 ;; 3. Explicit column groups.
3020 (org-test-with-parsed-data "
3026 (org-element-map tree
'table-cell
3028 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
3031 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
3032 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3033 ;; 1. A row at the beginning of a table always starts a row group.
3034 ;; So does a row following a table rule.
3035 (org-test-with-parsed-data "
3042 (org-element-map tree
'table-row
3044 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3046 ;; 2. Special rows should be ignored when determining the beginning
3048 (org-test-with-parsed-data "
3057 (org-element-map tree
'table-row
3059 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3062 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
3063 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3064 ;; 1. A row at the end of a table always ends a row group. So does
3065 ;; a row preceding a table rule.
3066 (org-test-with-parsed-data "
3073 (org-element-map tree
'table-row
3075 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3077 ;; 2. Special rows should be ignored when determining the beginning
3079 (org-test-with-parsed-data "
3088 (org-element-map tree
'table-row
3090 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3093 (ert-deftest test-org-export
/table-row-in-header-p
()
3094 "Test `org-export-table-row-in-header-p' specifications."
3095 ;; Standard test. Separators are always nil.
3099 (org-test-with-parsed-data "| a |\n|---|\n| b |"
3100 (org-element-map tree
'table-row
3102 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
3103 ;; Nil when there is no header.
3107 (org-test-with-parsed-data "| a |\n| b |"
3108 (org-element-map tree
'table-row
3110 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
3112 (ert-deftest test-org-export
/table-row-starts-header-p
()
3113 "Test `org-export-table-row-starts-header-p' specifications."
3114 ;; 1. Only the row starting the first row group starts the table
3116 (org-test-with-parsed-data "
3124 (org-element-map tree
'table-row
3126 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
3128 ;; 2. A row cannot start an header if there's no header in the
3130 (org-test-with-parsed-data "
3134 (org-export-table-row-starts-header-p
3135 (org-element-map tree
'table-row
'identity info
'first-match
)
3138 (ert-deftest test-org-export
/table-row-ends-header-p
()
3139 "Test `org-export-table-row-ends-header-p' specifications."
3140 ;; 1. Only the row starting the first row group starts the table
3142 (org-test-with-parsed-data "
3150 (org-element-map tree
'table-row
3152 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
3154 ;; 2. A row cannot start an header if there's no header in the
3156 (org-test-with-parsed-data "
3160 (org-export-table-row-ends-header-p
3161 (org-element-map tree
'table-row
'identity info
'first-match
)
3166 ;;; Tables of Contents
3168 (ert-deftest test-org-export
/collect-headlines
()
3169 "Test `org-export-collect-headlines' specifications."
3174 (org-test-with-parsed-data "* H1\n** H2"
3175 (org-export-collect-headlines info
)))))
3176 ;; Do not collect headlines below optional argument.
3180 (org-test-with-parsed-data "* H1\n** H2"
3181 (org-export-collect-headlines info
1)))))
3182 ;; Never collect headlines below maximum headline level.
3186 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3187 (org-export-collect-headlines info
)))))
3191 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3192 (org-export-collect-headlines info
2)))))
3193 ;; Collect headlines locally.
3196 (org-test-with-parsed-data "* H1\n** H2\n** H3"
3197 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3198 (length (org-export-collect-headlines info nil scope
))))))
3199 ;; When collecting locally, optional level is relative.
3202 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
3203 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3204 (length (org-export-collect-headlines info
1 scope
)))))))
3210 (ert-deftest test-org-export
/inner-template
()
3211 "Test `inner-template' translator specifications."
3214 (org-test-with-temp-text "* Headline"
3216 (org-export-create-backend
3218 '((inner-template .
(lambda (contents info
) "Success!"))
3219 (headline .
(lambda (h c i
) "Headline"))))))))
3220 ;; Inner template is applied even in a "body-only" export.
3223 (org-test-with-temp-text "* Headline"
3225 (org-export-create-backend
3226 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3227 (headline .
(lambda (h c i
) "Headline"))))
3228 nil nil
'body-only
)))))
3230 (ert-deftest test-org-export
/template
()
3231 "Test `template' translator specifications."
3234 (org-test-with-temp-text "* Headline"
3236 (org-export-create-backend
3237 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3238 (headline .
(lambda (h c i
) "Headline"))))))))
3239 ;; Template is not applied in a "body-only" export.
3242 (org-test-with-temp-text "* Headline"
3244 (org-export-create-backend
3245 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3246 (headline .
(lambda (h c i
) "Headline"))))
3247 nil nil
'body-only
)))))
3253 (ert-deftest test-org-export
/get-next-element
()
3254 "Test `org-export-get-next-element' specifications."
3258 (org-test-with-parsed-data "* Headline\n*a* b"
3259 (org-export-get-next-element
3260 (org-element-map tree
'bold
'identity info t
) info
))))
3261 ;; Return nil when no previous element.
3263 (org-test-with-parsed-data "* Headline\na *b*"
3264 (org-export-get-next-element
3265 (org-element-map tree
'bold
'identity info t
) info
)))
3266 ;; Non-exportable elements are ignored.
3268 (let ((org-export-with-timestamps nil
))
3269 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3270 (org-export-get-next-element
3271 (org-element-map tree
'entity
'identity info t
) info
))))
3272 ;; Find next element in secondary strings.
3275 (org-test-with-parsed-data "* a =verb="
3277 (org-export-get-next-element
3278 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3281 (org-test-with-parsed-data "* /italic/ =verb="
3283 (org-export-get-next-element
3284 (org-element-map tree
'italic
'identity info t
) info
)))))
3285 ;; Find next element in document keywords.
3288 (org-test-with-parsed-data "#+TITLE: a =verb="
3290 (org-export-get-next-element
3292 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3293 ;; Find next element in parsed affiliated keywords.
3296 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3298 (org-export-get-next-element
3299 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3300 ;; With optional argument N, return a list containing all the
3301 ;; following elements.
3304 '(bold code underline
)
3305 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3307 (org-export-get-next-element
3308 (org-element-map tree
'italic
'identity info t
) info t
)))))
3309 ;; When N is a positive integer, return a list containing up to
3310 ;; N following elements.
3314 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3316 (org-export-get-next-element
3317 (org-element-map tree
'italic
'identity info t
) info
2))))))
3319 (ert-deftest test-org-export
/get-previous-element
()
3320 "Test `org-export-get-previous-element' specifications."
3324 (org-test-with-parsed-data "* Headline\na *b*"
3325 (org-export-get-previous-element
3326 (org-element-map tree
'bold
'identity info t
) info
))))
3327 ;; Return nil when no previous element.
3329 (org-test-with-parsed-data "* Headline\n*a* b"
3330 (org-export-get-previous-element
3331 (org-element-map tree
'bold
'identity info t
) info
)))
3332 ;; Non-exportable elements are ignored.
3334 (let ((org-export-with-timestamps nil
))
3335 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3336 (org-export-get-previous-element
3337 (org-element-map tree
'entity
'identity info t
) info
))))
3338 ;; Find previous element in secondary strings.
3341 (org-test-with-parsed-data "* =verb= a"
3343 (org-export-get-previous-element
3344 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3347 (org-test-with-parsed-data "* =verb= /italic/"
3349 (org-export-get-previous-element
3350 (org-element-map tree
'italic
'identity info t
) info
)))))
3351 ;; Find previous element in document keywords.
3354 (org-test-with-parsed-data "#+TITLE: =verb= a"
3356 (org-export-get-previous-element
3358 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3359 ;; Find previous element in parsed affiliated keywords.
3362 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3364 (org-export-get-previous-element
3365 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3366 ;; With optional argument N, return a list containing up to
3367 ;; N previous elements.
3369 (equal '(underline italic bold
)
3370 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3372 (org-export-get-previous-element
3373 (org-element-map tree
'code
'identity info t
) info t
)))))
3374 ;; When N is a positive integer, return a list containing up to
3375 ;; N previous elements.
3377 (equal '(italic bold
)
3378 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3380 (org-export-get-previous-element
3381 (org-element-map tree
'code
'identity info t
) info
2))))))
3385 ;;; test-org-export.el end here