1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012, 2013, 2014 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 (unless (featurep 'ox
)
25 (signal 'missing-test-dependency
"org-export"))
27 (defun org-test-default-backend ()
28 "Return a default export back-end.
29 This back-end simply returns parsed data as Org syntax."
30 (org-export-create-backend
31 :transcoders
(let (transcode-table)
32 (dolist (type (append org-element-all-elements
33 org-element-all-objects
)
37 (lambda (obj contents info
)
39 (intern (format "org-element-%s-interpreter"
44 (defmacro org-test-with-parsed-data
(data &rest body
)
45 "Execute body with parsed data available.
47 DATA is a string containing the data to be parsed. BODY is the
48 body to execute. Parse tree is available under the `tree'
49 variable, and communication channel under `info'.
51 This function calls `org-export-collect-tree-properties'. As
52 such, `:ignore-list' (for `org-element-map') and
53 `:parse-tree' (for `org-export-get-genealogy') properties are
54 already filled in `info'."
55 (declare (debug (form body
)) (indent 1))
56 `(org-test-with-temp-text ,data
57 (let* ((tree (org-element-parse-buffer))
58 (info (org-export-collect-tree-properties
59 tree
(org-export-get-environment))))
66 (ert-deftest test-org-export
/bind-keyword
()
67 "Test reading #+BIND: keywords."
68 ;; Test with `org-export-allow-bind-keywords' set to t.
70 (org-test-with-temp-text "#+BIND: test-ox-var value"
71 (let ((org-export-allow-bind-keywords t
))
72 (org-export-get-environment)
73 (eq test-ox-var
'value
))))
74 ;; Test with `org-export-allow-bind-keywords' set to nil.
76 (org-test-with-temp-text "#+BIND: test-ox-var value"
77 (let ((org-export-allow-bind-keywords nil
))
78 (org-export-get-environment)
79 (boundp 'test-ox-var
))))
80 ;; BIND keywords are case-insensitive.
82 (org-test-with-temp-text "#+bind: test-ox-var value"
83 (let ((org-export-allow-bind-keywords t
))
84 (org-export-get-environment)
85 (eq test-ox-var
'value
))))
86 ;; Preserve order of BIND keywords.
88 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
89 (let ((org-export-allow-bind-keywords t
))
90 (org-export-get-environment)
92 ;; Read BIND keywords in setup files.
94 (org-test-with-temp-text
95 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
96 (let ((org-export-allow-bind-keywords t
))
97 (org-export-get-environment)
98 (eq variable
'value
))))
99 ;; Verify that bound variables are seen during export.
102 (org-test-with-temp-text "#+BIND: test-ox-var value"
103 (let ((org-export-allow-bind-keywords t
))
105 (org-export-create-backend
107 '((section .
(lambda (s c i
)
108 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
110 (ert-deftest test-org-export
/parse-option-keyword
()
111 "Test reading all standard #+OPTIONS: items."
114 (org-export--parse-option-keyword
115 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
116 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
119 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
120 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
121 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
122 :with-footnotes t
:with-inlinetasks nil
:with-priority t
123 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
124 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
125 :with-todo-keywords t
)))
126 ;; Test some special values.
129 (org-export--parse-option-keyword
130 "arch:headline creator:comment d:(\"TEST\")
131 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
134 :with-archived-trees headline
:with-creator comment
135 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
136 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
138 (ert-deftest test-org-export
/get-inbuffer-options
()
139 "Test reading all standard export keywords."
140 ;; Properties should follow buffer order.
143 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
144 (org-export--get-inbuffer-options))
145 '(:language
"fr" :creator
"Me" :email
"email")))
146 ;; Parse document keywords.
149 (org-test-with-temp-text "#+AUTHOR: Me"
150 (org-export--get-inbuffer-options))
152 ;; Test `space' behaviour.
155 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
156 (org-export--get-inbuffer-options))
157 '(:title
("Some title with spaces"))))
158 ;; Test `newline' behaviour.
161 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
162 (org-export--get-inbuffer-options))
163 '(:description
"With\ntwo lines")))
164 ;; Test `split' behaviour.
167 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
168 (org-export--get-inbuffer-options))
169 '(:select-tags
("a" "b"))))
170 ;; Options set through SETUPFILE.
173 (org-test-with-temp-text
174 (format "#+DESCRIPTION: l1
178 #+SETUPFILE: \"%s/examples/setupfile.org\"
184 (org-export--get-inbuffer-options))
185 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
187 ;; More than one property can refer to the same buffer keyword.
189 (equal '(:k2
"value" :k1
"value")
190 (let ((backend (org-export-create-backend
191 :options
'((:k1
"KEYWORD")
193 (org-test-with-temp-text "#+KEYWORD: value"
194 (org-export--get-inbuffer-options backend
))))))
196 (ert-deftest test-org-export
/get-subtree-options
()
197 "Test setting options from headline's properties."
199 (org-test-with-temp-text "#+TITLE: Title
202 :EXPORT_TITLE: Subtree Title
206 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
207 '("Subtree Title"))))
211 (org-test-with-temp-text "#+OPTIONS: H:1
219 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
221 (org-test-with-temp-text "#+DATE: today
224 :EXPORT_DATE: 29-03-2012
228 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
230 ;; Properties with `split' behaviour are stored as a list of
234 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
237 :EXPORT_EXCLUDE_TAGS: a b
242 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
243 ;; Handle :PROPERTY+: syntax.
246 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
249 :EXPORT_EXCLUDE_TAGS: a
250 :EXPORT_EXCLUDE_TAGS+: b
255 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
256 ;; Export properties are case-insensitive.
257 (org-test-with-temp-text "* Headline
259 :EXPORT_Date: 29-03-2012
262 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
264 ;; Still grab correct options when section above is empty.
267 (org-test-with-temp-text "* H1\n** H11\n** H12"
268 (progn (forward-line 2)
269 (plist-get (org-export-get-environment nil t
) :title
))))))
271 (ert-deftest test-org-export
/set-title
()
272 "Test title setting."
273 ;; Without TITLE keyword.
277 (org-test-with-temp-text "Test"
279 (org-export-create-backend
281 '((template .
(lambda (text info
)
282 (org-element-interpret-data
283 (plist-get info
:title
))))))))))
284 ;; With a blank TITLE keyword.
288 (org-test-with-temp-text "#+TITLE:\nTest"
290 (org-export-create-backend
292 '((template .
(lambda (text info
)
293 (org-element-interpret-data
294 (plist-get info
:title
))))))))))
295 ;; With a non-empty TITLE keyword.
299 (org-test-with-temp-text "#+TITLE: Title\nTest"
301 (org-export-create-backend
303 '((template .
(lambda (text info
)
304 (org-element-interpret-data
305 (plist-get info
:title
))))))))))
306 ;; When exporting a subtree, its heading becomes the headline of the
311 (org-test-with-temp-text "* Headline\nBody"
313 (org-export-create-backend
315 '((template .
(lambda (text info
)
316 (org-element-interpret-data
317 (plist-get info
:title
))))))
319 ;; ... unless there is an EXPORT_TITLE property at the root of the
324 (org-test-with-temp-text
325 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
327 (org-export-create-backend
329 '((template .
(lambda (text info
)
330 (org-element-interpret-data
331 (plist-get info
:title
))))))
334 (ert-deftest test-org-export
/handle-options
()
335 "Test if export options have an impact on output."
336 ;; Test exclude tags for headlines and inlinetasks.
339 (org-test-with-temp-text "* Head1 :noexp:"
340 (org-export-as (org-test-default-backend)
341 nil nil nil
'(:exclude-tags
("noexp"))))))
342 ;; Test include tags for headlines and inlinetasks.
344 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
345 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
346 (let ((org-tags-column 0))
347 (org-export-as (org-test-default-backend)
348 nil nil nil
'(:select-tags
("exp")))))))
349 ;; If there is an include tag, ignore the section before the first
352 (equal "* H1 :exp:\nBody\n"
353 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
354 (let ((org-tags-column 0))
355 (org-export-as (org-test-default-backend)
356 nil nil nil
'(:select-tags
("exp")))))))
358 (equal "* H1 :exp:\n"
359 (org-test-with-temp-text "* H1 :exp:\nBody"
360 (let ((org-tags-column 0))
361 (org-export-as (org-test-default-backend)
362 nil nil nil
'(:select-tags
("exp")))))))
363 ;; Test mixing include tags and exclude tags.
366 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
367 (org-test-with-temp-text "
369 ** Sub-Head1 :noexport:
372 ** Sub-Head1 :export:"
373 (org-export-as (org-test-default-backend) nil nil nil
374 '(:select-tags
("export") :exclude-tags
("noexport"))))))
378 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
379 (org-test-with-temp-text "* TODO Head1"
380 (org-export-as (org-test-default-backend)
381 nil nil nil
'(:with-tasks nil
))))))
383 (equal "* TODO Head1\n"
384 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
385 (org-test-with-temp-text "* TODO Head1"
386 (org-export-as (org-test-default-backend)
387 nil nil nil
'(:with-tasks t
))))))
391 (org-test-with-temp-text "* Head1 :archive:"
392 (let ((org-archive-tag "archive"))
393 (org-export-as (org-test-default-backend)
394 nil nil nil
'(:with-archived-trees nil
))))))
397 "\\* Head1[ \t]+:archive:"
398 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
399 (let ((org-archive-tag "archive"))
400 (org-export-as (org-test-default-backend) nil nil nil
401 '(:with-archived-trees headline
))))))
404 "\\`\\* Head1[ \t]+:archive:\n\\'"
405 (org-test-with-temp-text "* Head1 :archive:"
406 (let ((org-archive-tag "archive"))
407 (org-export-as (org-test-default-backend)
408 nil nil nil
'(:with-archived-trees t
))))))
411 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
412 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
413 (org-export-as (org-test-default-backend)
414 nil nil nil
'(:with-clocks t
)))))
417 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
418 (org-export-as (org-test-default-backend)
419 nil nil nil
'(:with-clocks nil
)))))
423 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
424 (org-export-as (org-test-default-backend)
425 nil nil nil
'(:with-drawers nil
)))))
427 (equal ":TEST:\ncontents\n:END:\n"
428 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
429 (org-export-as (org-test-default-backend)
430 nil nil nil
'(:with-drawers t
)))))
432 (equal ":FOO:\nkeep\n:END:\n"
433 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
434 (org-export-as (org-test-default-backend)
435 nil nil nil
'(:with-drawers
("FOO"))))))
437 (equal ":FOO:\nkeep\n:END:\n"
438 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
439 (org-export-as (org-test-default-backend)
440 nil nil nil
'(:with-drawers
(not "BAR"))))))
444 (org-test-with-temp-text ": A"
445 (org-export-as (org-test-default-backend) nil nil nil
446 '(:with-fixed-width t
)))))
449 (org-test-with-temp-text ": A"
450 (org-export-as (org-test-default-backend) nil nil nil
451 '(:with-fixed-width nil
)))))
455 (let ((org-footnote-section nil
))
456 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
457 (org-trim (org-export-as (org-test-default-backend)
458 nil nil nil
'(:with-footnotes nil
)))))))
460 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
461 (let ((org-footnote-section nil
))
462 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
463 (org-trim (org-export-as (org-test-default-backend)
464 nil nil nil
'(:with-footnotes t
)))))))
466 (when (featurep 'org-inlinetask
)
470 (let ((org-inlinetask-min-level 15))
471 (org-test-with-temp-text "*************** Task"
472 (org-export-as (org-test-default-backend)
473 nil nil nil
'(:with-inlinetasks nil
))))))
477 (let ((org-inlinetask-min-level 15))
478 (org-test-with-temp-text
479 "*************** Task\nContents\n*************** END"
480 (org-export-as (org-test-default-backend)
481 nil nil nil
'(:with-inlinetasks nil
)))))))
485 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
486 (let ((org-closed-string "CLOSED:"))
487 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
488 (org-export-as (org-test-default-backend)
489 nil nil nil
'(:with-planning t
))))))
492 (let ((org-closed-string "CLOSED:"))
493 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
494 (org-export-as (org-test-default-backend)
495 nil nil nil
'(:with-planning nil
))))))
499 (org-test-with-temp-text
500 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
501 (org-export-as (org-test-default-backend)
502 nil nil nil
'(:with-properties nil
)))))
504 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
505 (org-test-with-temp-text
506 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
507 (org-export-as (org-test-default-backend)
508 nil nil nil
'(:with-properties t
)))))
510 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
511 (org-test-with-temp-text
512 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
513 (org-export-as (org-test-default-backend)
514 nil nil nil
'(:with-properties
("B"))))))
515 ;; Statistics cookies.
518 (org-test-with-temp-text "[0/0]"
519 (org-export-as (org-test-default-backend)
520 nil nil nil
'(:with-statistics-cookies nil
)))))
524 (org-test-with-temp-text "| A |"
525 (org-export-as (org-test-default-backend) nil nil nil
526 '(:with-tables t
)))))
529 (org-test-with-temp-text "| A |"
530 (org-export-as (org-test-default-backend) nil nil nil
531 '(:with-tables nil
))))))
533 (ert-deftest test-org-export
/with-timestamps
()
534 "Test `org-export-with-timestamps' specifications."
538 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
539 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
540 (org-export-as (org-test-default-backend)
541 nil nil nil
'(:with-timestamps t
)))))
546 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
547 (org-export-as (org-test-default-backend)
548 nil nil nil
'(:with-timestamps nil
)))))
552 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
553 (org-test-with-temp-text
554 "<2012-03-29 Thu>[2012-03-29 Thu]
556 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
557 (org-export-as (org-test-default-backend)
558 nil nil nil
'(:with-timestamps active
)))))
562 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
563 (org-test-with-temp-text
564 "<2012-03-29 Thu>[2012-03-29 Thu]
566 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
567 (org-export-as (org-test-default-backend)
568 nil nil nil
'(:with-timestamps inactive
))))))
570 (ert-deftest test-org-export
/comment-tree
()
571 "Test if export process ignores commented trees."
574 (org-test-with-temp-text "* COMMENT Head1"
575 (org-export-as (org-test-default-backend))))))
577 (ert-deftest test-org-export
/uninterpreted
()
578 "Test handling of uninterpreted elements."
582 (org-test-with-temp-text "\\alpha"
584 (org-export-create-backend
585 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
586 (paragraph .
(lambda (p c i
) c
))
587 (section .
(lambda (s c i
) c
))))
588 nil nil nil
'(:with-entities t
)))))
591 (org-test-with-temp-text "\\alpha"
593 (org-export-create-backend
594 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
595 (paragraph .
(lambda (p c i
) c
))
596 (section .
(lambda (s c i
) c
))))
597 nil nil nil
'(:with-entities nil
)))))
601 (org-test-with-temp-text "*bold*"
603 (org-export-create-backend
604 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
605 (paragraph .
(lambda (p c i
) c
))
606 (section .
(lambda (s c i
) c
))))
607 nil nil nil
'(:with-emphasize t
)))))
610 (org-test-with-temp-text "*bold*"
612 (org-export-create-backend
613 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
614 (paragraph .
(lambda (p c i
) c
))
615 (section .
(lambda (s c i
) c
))))
616 nil nil nil
'(:with-emphasize nil
)))))
617 ;; LaTeX environment.
620 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
622 (org-export-create-backend
623 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
624 (section .
(lambda (s c i
) c
))))
625 nil nil nil
'(:with-latex t
)))))
627 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
628 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
630 (org-export-create-backend
631 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
632 (section .
(lambda (s c i
) c
))))
633 nil nil nil
'(:with-latex verbatim
)))))
637 (org-test-with-temp-text "$1$"
639 (org-export-create-backend
640 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
641 (paragraph .
(lambda (p c i
) c
))
642 (section .
(lambda (s c i
) c
))))
643 nil nil nil
'(:with-latex t
)))))
646 (org-test-with-temp-text "$1$"
648 (org-export-create-backend
649 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
650 (paragraph .
(lambda (p c i
) c
))
651 (section .
(lambda (s c i
) c
))))
652 nil nil nil
'(:with-latex verbatim
)))))
656 (org-test-with-temp-text "a_b"
658 (org-export-create-backend
659 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
660 (paragraph .
(lambda (p c i
) c
))
661 (section .
(lambda (s c i
) c
))))
662 nil nil nil
'(:with-sub-superscript t
)))))
665 (org-test-with-temp-text "a_b"
667 (org-export-create-backend
668 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
669 (paragraph .
(lambda (p c i
) c
))
670 (section .
(lambda (s c i
) c
))))
671 nil nil nil
'(:with-sub-superscript nil
)))))
674 (org-test-with-temp-text "a_b"
676 (org-export-create-backend
677 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
678 (paragraph .
(lambda (p c i
) c
))
679 (section .
(lambda (s c i
) c
))))
680 nil nil nil
'(:with-sub-superscript
{})))))
683 (org-test-with-temp-text "a_{b}"
685 (org-export-create-backend
686 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
687 (paragraph .
(lambda (p c i
) c
))
688 (section .
(lambda (s c i
) c
))))
689 nil nil nil
'(:with-sub-superscript
{})))))
690 ;; Also handle uninterpreted objects in title.
693 (org-test-with-temp-text "#+TITLE: a_b"
695 (org-export-create-backend
697 '((subscript .
(lambda (s c i
) "dummy"))
698 (template .
(lambda (c i
) (org-export-data
699 (plist-get i
:title
) i
)))
700 (section .
(lambda (s c i
) c
))))
701 nil nil nil
'(:with-sub-superscript nil
)))))
702 ;; Special case: multiples uninterpreted objects in a row.
705 (org-test-with-temp-text "a_b_c_d"
707 (org-export-create-backend
708 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
709 (paragraph .
(lambda (p c i
) c
))
710 (section .
(lambda (s c i
) c
))))
711 nil nil nil
'(:with-sub-superscript
{}))))))
713 (ert-deftest test-org-export
/export-scope
()
714 "Test all export scopes."
715 (org-test-with-temp-text "
722 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
723 "text\n*** Head3\n"))
725 (goto-char (point-min))
728 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
731 (goto-char (point-min))
733 (transient-mark-mode 1)
734 (push-mark (point) t t
)
735 (goto-char (point-at-eol))
736 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
737 ;; Subtree with a code block calling another block outside.
740 (org-test-with-temp-text "
742 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
747 #+BEGIN_SRC emacs-lisp
751 (org-export-as (org-test-default-backend) 'subtree
))))
753 (let ((backend (org-test-default-backend)))
754 (setf (org-export-backend-transcoders backend
)
755 (cons '(template .
(lambda (body i
)
756 (format "BEGIN\n%sEND" body
)))
757 (org-export-backend-transcoders backend
)))
758 (org-test-with-temp-text "Text"
759 (should (equal (org-export-as backend nil nil
'body-only
)
761 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
763 (ert-deftest test-org-export
/output-file-name
()
764 "Test `org-export-output-file-name' specifications."
765 ;; Export from a file: name is built from original file name.
767 (org-test-with-temp-text-in-file "Test"
768 (equal (concat (file-name-as-directory ".")
769 (file-name-nondirectory
770 (file-name-sans-extension (buffer-file-name))))
771 (file-name-sans-extension (org-export-output-file-name ".ext")))))
772 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
774 (org-test-with-temp-text-in-file
775 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
776 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
777 ;; From a buffer not associated to a file, too.
779 (org-test-with-temp-text
780 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
781 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
782 ;; When provided name is absolute, preserve it.
784 (org-test-with-temp-text
785 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
786 (expand-file-name "test"))
787 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
788 ;; When PUB-DIR argument is provided, use it.
790 (org-test-with-temp-text-in-file "Test"
791 (equal (file-name-directory
792 (org-export-output-file-name ".ext" nil
"dir/"))
794 ;; When returned name would overwrite original file, add EXTENSION
797 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
798 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
800 (ert-deftest test-org-export
/expand-include
()
801 "Test file inclusion in an Org buffer."
802 ;; Error when file isn't specified.
804 (org-test-with-temp-text "#+INCLUDE: dummy.org"
805 (org-export-expand-include-keyword)))
806 ;; Full insertion with recursive inclusion.
811 (expand-file-name "examples/include.org" org-test-dir
))
812 (replace-regexp-in-string
813 (regexp-quote "#+INCLUDE: \"include2.org\"")
814 "Success!" (buffer-string)))
815 (org-test-with-temp-text
816 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
817 (org-export-expand-include-keyword)
819 ;; Localized insertion.
820 (org-test-with-temp-text
821 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
823 (org-export-expand-include-keyword)
824 (should (equal (buffer-string)
825 "Small Org file with an include keyword.\n")))
826 ;; Insertion with constraints on headlines level.
829 "* Top heading\n** Heading\nbody\n"
830 (org-test-with-temp-text
832 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
834 (org-export-expand-include-keyword)
838 "* Top heading\n* Heading\nbody\n"
839 (org-test-with-temp-text
841 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
843 (org-export-expand-include-keyword)
845 ;; Inclusion within an example block.
848 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
849 (org-test-with-temp-text
850 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
852 (org-export-expand-include-keyword)
854 ;; Inclusion within a src-block.
857 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
858 (org-test-with-temp-text
860 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
862 (org-export-expand-include-keyword)
864 ;; Inclusion within an html export-block.
867 "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
868 (org-test-with-temp-text
870 "#+INCLUDE: \"%s/examples/include.html\" HTML"
872 (org-export-expand-include-keyword)
874 ;; Inclusion within an center paragraph
877 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
878 (org-test-with-temp-text
880 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
882 (org-export-expand-include-keyword)
884 ;; Footnotes labels are local to each included file.
890 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
892 \[fn:test] Footnote \"test\""))
893 (org-test-with-temp-text-in-file contents
894 (let ((file1 (buffer-file-name)))
895 (org-test-with-temp-text-in-file contents
896 (let ((file2 (buffer-file-name)))
897 (org-test-with-temp-text
898 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
900 (org-export-expand-include-keyword)
901 (org-element-map (org-element-parse-buffer)
904 (org-element-property :label ref
)))))))))))))
905 ;; Footnotes labels are not local to each include keyword.
911 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
913 \[fn:test] Footnote \"test\""))
914 (org-test-with-temp-text-in-file contents
915 (let ((file (buffer-file-name)))
916 (org-test-with-temp-text
917 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
918 (org-export-expand-include-keyword)
919 (org-element-map (org-element-parse-buffer)
921 (lambda (ref) (org-element-property :label ref
)))))))))))
922 ;; If only-contents is non-nil only include contents of element.
926 (org-test-with-temp-text
928 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" " org-test-dir
)
930 (org-export-expand-include-keyword)
932 ;; Headings can be included via CUSTOM_ID.
934 (org-test-with-temp-text
935 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
936 (org-export-expand-include-keyword)
937 (goto-char (point-min))
938 (looking-at "* Another heading")))
939 ;; Named objects can be included.
943 (org-test-with-temp-text
944 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t" org-test-dir
)
945 (org-export-expand-include-keyword)
947 ;; Including non-existing elements should result in an error.
949 (org-test-with-temp-text
950 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\"" org-test-dir
)
951 (org-export-expand-include-keyword)))
952 ;; Lines work relatively to an included element.
956 (org-test-with-temp-text
957 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t :lines \"2-3\"" org-test-dir
)
958 (org-export-expand-include-keyword)
960 ;; Properties should be dropped from headlines.
963 (org-test-with-temp-text
964 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t" org-test-dir
)
965 (org-export-expand-include-keyword)
967 (org-test-with-temp-text
968 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
969 (org-export-expand-include-keyword)
971 ;; Properties should be dropped, drawers should not be.
974 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
975 (org-test-with-temp-text
976 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir
)
977 (org-export-expand-include-keyword)
980 (ert-deftest test-org-export
/expand-macro
()
981 "Test macro expansion in an Org buffer."
982 ;; Standard macro expansion.
984 (equal "#+MACRO: macro1 value\nvalue\n"
985 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
986 (org-export-as (org-test-default-backend)))))
987 ;; Expand specific macros.
989 (equal "me 2012-03-29 me@here Title\n"
990 (org-test-with-temp-text
996 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
997 (let ((output (org-export-as (org-test-default-backend))))
998 (substring output
(string-match ".*\n\\'" output
))))))
999 ;; Expand specific macros when property contained a regular macro
1003 (org-test-with-temp-text "
1004 #+MACRO: macro1 value
1005 #+TITLE: {{{macro1}}}
1007 (let ((output (org-export-as (org-test-default-backend))))
1008 (substring output
(string-match ".*\n\\'" output
))))))
1009 ;; Expand macros with templates in included files.
1012 (org-test-with-temp-text
1013 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1014 {{{included-macro}}}" org-test-dir
)
1015 (let ((output (org-export-as (org-test-default-backend))))
1016 (substring output
(string-match ".*\n\\'" output
)))))))
1018 (ert-deftest test-org-export
/user-ignore-list
()
1019 "Test if `:ignore-list' accepts user input."
1020 (let ((backend (org-test-default-backend)))
1021 (setf (org-export-backend-transcoders backend
)
1022 (cons '(template .
(lambda (body i
)
1023 (format "BEGIN\n%sEND" body
)))
1024 (org-export-backend-transcoders backend
)))
1025 (org-test-with-temp-text "Text"
1026 (should (equal (org-export-as backend nil nil
'body-only
)
1028 (should (equal (org-export-as backend
) "BEGIN\nText\nEND"))))
1032 (let ((org-export-filter-parse-tree-functions
1033 '((lambda (data backend info
)
1034 ;; Ignore headlines with the word "note" in their title.
1035 (org-element-map data
'headline
1037 (when (string-match "\\<note\\>"
1038 (org-element-property :raw-value
1040 (org-export-ignore-element headline info
)))
1043 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
1044 (org-export-as (org-test-default-backend)))))))
1046 (ert-deftest test-org-export
/before-processing-hook
()
1047 "Test `org-export-before-processing-hook'."
1050 "#+MACRO: mac val\nTest\n"
1051 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1052 (let ((org-export-before-processing-hook
1054 (while (re-search-forward "{{{" nil t
)
1055 (let ((object (org-element-context)))
1056 (when (eq (org-element-type object
) 'macro
)
1058 (org-element-property :begin object
)
1059 (org-element-property :end object
)))))))))
1060 (org-export-as (org-test-default-backend)))))))
1062 (ert-deftest test-org-export
/before-parsing-hook
()
1063 "Test `org-export-before-parsing-hook'."
1065 (equal "Body 1\nBody 2\n"
1066 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1067 (let ((org-export-before-parsing-hook
1069 (goto-char (point-min))
1070 (while (re-search-forward org-outline-regexp-bol nil t
)
1072 (point-at-bol) (progn (forward-line) (point))))))))
1073 (org-export-as (org-test-default-backend)))))))
1077 ;;; Affiliated Keywords
1079 (ert-deftest test-org-export
/read-attribute
()
1080 "Test `org-export-read-attribute' specifications."
1084 (org-export-read-attribute
1086 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1087 (org-element-at-point)))
1089 ;; Return nil on empty attribute.
1091 (org-export-read-attribute
1093 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1094 ;; Return nil on "nil" string.
1096 (equal '(:a nil
:b nil
)
1097 (org-export-read-attribute
1099 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1100 (org-element-at-point)))))
1101 ;; Return nil on empty string.
1103 (equal '(:a nil
:b nil
)
1104 (org-export-read-attribute
1106 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1107 (org-element-at-point)))))
1108 ;; Return empty string when value is "".
1111 (org-export-read-attribute
1113 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1114 (org-element-at-point)))))
1115 ;; Return \"\" when value is """".
1118 (org-export-read-attribute
1120 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1121 (org-element-at-point)))))
1122 ;; Ignore text before first property.
1125 (org-export-read-attribute
1127 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1128 (org-element-at-point))))))
1130 (ert-deftest test-org-export
/get-caption
()
1131 "Test `org-export-get-caption' specifications."
1132 ;; Without optional argument, return long caption
1136 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1137 (org-export-get-caption (org-element-at-point)))))
1138 ;; With optional argument, return short caption.
1142 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1143 (org-export-get-caption (org-element-at-point) t
))))
1144 ;; Multiple lines are separated by white spaces.
1148 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1149 (org-export-get-caption (org-element-at-point))))))
1155 (ert-deftest test-org-export
/define-backend
()
1156 "Test back-end definition and accessors."
1159 (equal '((headline . my-headline-test
))
1160 (let (org-export--registered-backends)
1161 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1162 (org-export-get-all-transcoders 'test
))))
1165 (equal '((:filter-headline . my-filter
))
1166 (let (org-export--registered-backends)
1167 (org-export-define-backend 'test
1168 '((headline . my-headline-test
))
1169 :filters-alist
'((:filter-headline . my-filter
)))
1170 (org-export-backend-filters (org-export-get-backend 'test
)))))
1173 (equal '((:prop value
))
1174 (let (org-export--registered-backends)
1175 (org-export-define-backend 'test
1176 '((headline . my-headline-test
))
1177 :options-alist
'((:prop value
)))
1178 (org-export-backend-options (org-export-get-backend 'test
)))))
1181 (equal '(?k
"Test Export" test
)
1182 (let (org-export--registered-backends)
1183 (org-export-define-backend 'test
1184 '((headline . my-headline-test
))
1185 :menu-entry
'(?k
"Test Export" test
))
1186 (org-export-backend-menu (org-export-get-backend 'test
)))))
1189 (equal '(("TEST" . org-element-export-block-parser
))
1190 (let (org-export--registered-backends org-element-block-name-alist
)
1191 (org-export-define-backend 'test
1192 '((headline . my-headline-test
))
1193 :export-block
'("test"))
1194 org-element-block-name-alist
))))
1196 (ert-deftest test-org-export
/define-derived-backend
()
1197 "Test `org-export-define-derived-backend' specifications."
1198 ;; Error when parent back-end is not defined.
1200 (let (org-export--registered-backends)
1201 (org-export-define-derived-backend 'test
'parent
)))
1202 ;; Append translation table to parent's.
1204 (equal '((:headline . test
) (:headline . parent
))
1205 (let (org-export--registered-backends)
1206 (org-export-define-backend 'parent
'((:headline . parent
)))
1207 (org-export-define-derived-backend 'test
'parent
1208 :translate-alist
'((:headline . test
)))
1209 (org-export-get-all-transcoders 'test
))))
1210 ;; Options defined in the new back have priority over those defined
1214 (let (org-export--registered-backends)
1215 (org-export-define-backend 'parent
1216 '((:headline . parent
))
1217 :options-alist
'((:a nil nil
'parent
)))
1218 (org-export-define-derived-backend 'test
'parent
1219 :options-alist
'((:a nil nil
'test
)))
1220 (plist-get (org-export--get-global-options
1221 (org-export-get-backend 'test
))
1224 (ert-deftest test-org-export
/derived-backend-p
()
1225 "Test `org-export-derived-backend-p' specifications."
1226 ;; Non-nil with direct match.
1228 (let (org-export--registered-backends)
1229 (org-export-define-backend 'test
'((headline . test
)))
1230 (org-export-derived-backend-p 'test
'test
)))
1232 (let (org-export--registered-backends)
1233 (org-export-define-backend 'test
'((headline . test
)))
1234 (org-export-define-derived-backend 'test2
'test
)
1235 (org-export-derived-backend-p 'test2
'test2
)))
1236 ;; Non-nil with a direct parent.
1238 (let (org-export--registered-backends)
1239 (org-export-define-backend 'test
'((headline . test
)))
1240 (org-export-define-derived-backend 'test2
'test
)
1241 (org-export-derived-backend-p 'test2
'test
)))
1242 ;; Non-nil with an indirect parent.
1244 (let (org-export--registered-backends)
1245 (org-export-define-backend 'test
'((headline . test
)))
1246 (org-export-define-derived-backend 'test2
'test
)
1247 (org-export-define-derived-backend 'test3
'test2
)
1248 (org-export-derived-backend-p 'test3
'test
)))
1251 (let (org-export--registered-backends)
1252 (org-export-define-backend 'test
'((headline . test
)))
1253 (org-export-define-backend 'test2
'((headline . test2
)))
1254 (org-export-derived-backend-p 'test2
'test
)))
1256 (let (org-export--registered-backends)
1257 (org-export-define-backend 'test
'((headline . test
)))
1258 (org-export-define-backend 'test2
'((headline . test2
)))
1259 (org-export-define-derived-backend 'test3
'test2
)
1260 (org-export-derived-backend-p 'test3
'test
))))
1262 (ert-deftest test-org-export
/get-all-transcoders
()
1263 "Test `org-export-get-all-transcoders' specifications."
1264 ;; Return nil when back-end cannot be found.
1265 (should-not (org-export-get-all-transcoders nil
))
1266 ;; Same as `org-export-transcoders' if no parent.
1268 (equal '((headline . ignore
))
1269 (org-export-get-all-transcoders
1270 (org-export-create-backend
1271 :transcoders
'((headline . ignore
))))))
1272 ;; But inherit from all ancestors whenever possible.
1274 (equal '((section . ignore
) (headline . ignore
))
1275 (let (org-export--registered-backends)
1276 (org-export-define-backend 'b1
'((headline . ignore
)))
1277 (org-export-get-all-transcoders
1278 (org-export-create-backend
1279 :parent
'b1
:transcoders
'((section . ignore
)))))))
1281 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1282 (let (org-export--registered-backends)
1283 (org-export-define-backend 'b1
'((headline . ignore
)))
1284 (org-export-define-derived-backend 'b2
'b1
1285 :translate-alist
'((section . ignore
)))
1286 (org-export-get-all-transcoders
1287 (org-export-create-backend
1288 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1289 ;; Back-end transcoders overrule inherited ones.
1292 (let (org-export--registered-backends)
1293 (org-export-define-backend 'b1
'((headline . a
)))
1294 (cdr (assq 'headline
1295 (org-export-get-all-transcoders
1296 (org-export-create-backend
1297 :parent
'b1
:transcoders
'((headline . b
))))))))))
1299 (ert-deftest test-org-export
/get-all-options
()
1300 "Test `org-export-get-all-options' specifications."
1301 ;; Return nil when back-end cannot be found.
1302 (should-not (org-export-get-all-options nil
))
1303 ;; Same as `org-export-options' if no parent.
1305 (equal '((headline . ignore
))
1306 (org-export-get-all-options
1307 (org-export-create-backend
1308 :options
'((headline . ignore
))))))
1309 ;; But inherit from all ancestors whenever possible.
1311 (equal '((:key2 value2
) (:key1 value1
))
1312 (let (org-export--registered-backends)
1313 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1314 (org-export-get-all-options
1315 (org-export-create-backend
1316 :parent
'b1
:options
'((:key2 value2
)))))))
1318 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1319 (let (org-export--registered-backends)
1320 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1321 (org-export-define-derived-backend 'b2
'b1
1322 :options-alist
'((:key2 value2
)))
1323 (org-export-get-all-options
1324 (org-export-create-backend
1325 :parent
'b2
:options
'((:key3 value3
)))))))
1326 ;; Back-end options overrule inherited ones.
1329 (let (org-export--registered-backends)
1330 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1332 (org-export-get-all-options
1333 (org-export-create-backend
1334 :parent
'b1
:options
'((:key1 . b
))))))))))
1336 (ert-deftest test-org-export
/get-all-filters
()
1337 "Test `org-export-get-all-filters' specifications."
1338 ;; Return nil when back-end cannot be found.
1339 (should-not (org-export-get-all-filters nil
))
1340 ;; Same as `org-export-filters' if no parent.
1342 (equal '((:filter-headline . ignore
))
1343 (org-export-get-all-filters
1344 (org-export-create-backend
1345 :filters
'((:filter-headline . ignore
))))))
1346 ;; But inherit from all ancestors whenever possible.
1348 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1349 (let (org-export--registered-backends)
1350 (org-export-define-backend 'b1
1351 nil
:filters-alist
'((:filter-headline . ignore
)))
1352 (org-export-get-all-filters
1353 (org-export-create-backend
1354 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1356 (equal '((:filter-paragraph . ignore
)
1357 (:filter-section . ignore
)
1358 (:filter-headline . ignore
))
1359 (let (org-export--registered-backends)
1360 (org-export-define-backend 'b1
1361 nil
:filters-alist
'((:filter-headline . ignore
)))
1362 (org-export-define-derived-backend 'b2
'b1
1363 :filters-alist
'((:filter-section . ignore
)))
1364 (org-export-get-all-filters
1365 (org-export-create-backend
1366 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1367 ;; Back-end filters overrule inherited ones.
1370 (let (org-export--registered-backends)
1371 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1372 (cdr (assq :filter-headline
1373 (org-export-get-all-filters
1374 (org-export-create-backend
1375 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1377 (ert-deftest test-org-export
/with-backend
()
1378 "Test `org-export-with-backend' definition."
1379 ;; Error when calling an undefined back-end
1380 (should-error (org-export-with-backend nil
"Test"))
1381 ;; Error when called back-end doesn't have an appropriate
1384 (org-export-with-backend
1385 (org-export-create-backend :transcoders
'((headline . ignore
)))
1387 ;; Otherwise, export using correct transcoder
1390 (let (org-export--registered-backends)
1391 (org-export-define-backend 'test
1392 '((plain-text .
(lambda (text contents info
) "Failure"))))
1393 (org-export-define-backend 'test2
1394 '((plain-text .
(lambda (text contents info
) "Success"))))
1395 (org-export-with-backend 'test2
"Test"))))
1396 ;; Provide correct back-end if transcoder needs to use recursive
1400 (let ((test-back-end
1401 (org-export-create-backend
1403 '((headline .
(lambda (headline contents info
)
1405 (org-element-property :title headline
)
1407 (plain-text .
(lambda (text info
) "Success"))))))
1408 (org-export-string-as
1410 (org-export-create-backend
1412 '((headline .
(lambda (headline contents info
)
1413 (org-export-with-backend
1414 test-back-end headline contents info
))))))))))
1416 (ert-deftest test-org-export
/data-with-backend
()
1417 "Test `org-export-data-with-backend' specifications."
1418 ;; Error when calling an undefined back-end.
1419 (should-error (org-export-data-with-backend nil
"nil" nil
))
1420 ;; Otherwise, export data recursively, using correct back-end.
1424 (org-export-data-with-backend
1426 (org-export-create-backend
1428 '((plain-text .
(lambda (text info
) "Success"))
1429 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1430 '(:with-emphasize t
)))))
1436 (ert-deftest test-org-export
/export-snippet
()
1437 "Test export snippets transcoding."
1439 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1440 (let ((backend (org-test-default-backend)))
1441 (setf (org-export-backend-name backend
) 'test
)
1442 (setf (org-export-backend-transcoders backend
)
1443 (cons (cons 'export-snippet
1444 (lambda (snippet contents info
)
1445 (when (eq (org-export-snippet-backend snippet
) 'test
)
1446 (org-element-property :value snippet
))))
1447 (org-export-backend-transcoders backend
)))
1448 (let ((org-export-snippet-translation-alist nil
))
1449 (should (equal (org-export-as backend
) "A\n")))
1450 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1451 (should (equal (org-export-as backend
) "AB\n")))))
1452 ;; Ignored export snippets do not remove any blank.
1454 (equal "begin end\n"
1455 (org-test-with-parsed-data "begin @@test:A@@ end"
1456 (org-export-data-with-backend
1458 (org-export-create-backend
1460 '((paragraph .
(lambda (paragraph contents info
) contents
))
1461 (section .
(lambda (section contents info
) contents
))))
1468 (ert-deftest test-org-export
/footnotes
()
1469 "Test footnotes specifications."
1470 (let ((org-footnote-section nil
)
1471 (org-export-with-footnotes t
))
1472 ;; 1. Read every type of footnote.
1475 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1476 (org-test-with-parsed-data
1477 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1478 (org-element-map tree
'footnote-reference
1480 (let ((def (org-export-get-footnote-definition ref info
)))
1481 (cons (org-export-get-footnote-number ref info
)
1482 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1483 (car (org-element-contents
1484 (car (org-element-contents def
))))))))
1486 ;; 2. Test nested footnotes order.
1489 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
1490 (org-test-with-parsed-data
1491 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1492 (org-element-map tree
'footnote-reference
1494 (when (org-export-footnote-first-reference-p ref info
)
1495 (cons (org-export-get-footnote-number ref info
)
1496 (org-element-property :label ref
))))
1498 ;; 3. Test nested footnote in invisible definitions.
1499 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1500 ;; Hide definitions.
1501 (narrow-to-region (point) (point-at-eol))
1502 (let* ((tree (org-element-parse-buffer))
1503 (info (org-combine-plists
1504 `(:parse-tree
,tree
)
1505 (org-export-collect-tree-properties
1506 tree
(org-export-get-environment)))))
1507 ;; Both footnotes should be seen.
1509 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
1510 ;; 4. Test footnotes definitions collection.
1513 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1515 \[fn:2] B [fn:3] [fn::D].
1518 (length (org-export-collect-footnote-definitions tree info
)))))
1519 ;; 5. Test export of footnotes defined outside parsing scope.
1522 "ParagraphOut of scope\n"
1523 (org-test-with-temp-text "[fn:1] Out of scope
1526 (let ((backend (org-test-default-backend)))
1527 (setf (org-export-backend-transcoders backend
)
1528 (cons (cons 'footnote-reference
1529 (lambda (fn contents info
)
1530 (org-element-interpret-data
1531 (org-export-get-footnote-definition fn info
))))
1532 (org-export-backend-transcoders backend
)))
1534 (org-export-as backend
'subtree
)))))
1535 ;; 6. Footnotes without a definition should be provided a fallback
1538 (org-test-with-parsed-data "[fn:1]"
1539 (org-export-get-footnote-definition
1540 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1541 ;; 7. Footnote section should be ignored in TOC and in headlines
1544 (= 1 (let ((org-footnote-section "Footnotes"))
1545 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1546 (org-export-collect-headlines info
))))))
1549 (let ((org-footnote-section "Footnotes"))
1550 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1551 (org-element-map tree
'headline
1553 (when (equal (org-element-property :raw-value hl
) "H2")
1554 (org-export-get-headline-number hl info
)))
1559 ;;; Headlines and Inlinetasks
1561 (ert-deftest test-org-export
/get-relative-level
()
1562 "Test `org-export-get-relative-level' specifications."
1566 (let ((org-odd-levels-only nil
))
1567 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1568 (org-element-map tree
'headline
1569 (lambda (h) (org-export-get-relative-level h info
))
1574 (let ((org-odd-levels-only nil
))
1575 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1576 (org-element-map tree
'headline
1577 (lambda (h) (org-export-get-relative-level h info
))
1580 (ert-deftest test-org-export
/low-level-p
()
1581 "Test `org-export-low-level-p' specifications."
1585 (let ((org-odd-levels-only nil
))
1586 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1587 (org-element-map tree
'headline
1588 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1589 (plist-put info
:headline-levels
1)))))))
1591 (ert-deftest test-org-export
/get-headline-number
()
1592 "Test `org-export-get-headline-number' specifications."
1597 (let ((org-odd-levels-only nil
))
1598 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1599 (org-element-map tree
'headline
1600 (lambda (h) (org-export-get-headline-number h info
))
1602 ;; Missing levels are replaced with 0.
1606 (let ((org-odd-levels-only nil
))
1607 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1608 (org-element-map tree
'headline
1609 (lambda (h) (org-export-get-headline-number h info
))
1612 (ert-deftest test-org-export
/numbered-headline-p
()
1613 "Test `org-export-numbered-headline-p' specifications."
1614 ;; If `:section-numbers' is nil, never number headlines.
1616 (org-test-with-parsed-data "* Headline"
1617 (org-element-map tree
'headline
1618 (lambda (h) (org-export-numbered-headline-p h info
))
1619 (plist-put info
:section-numbers nil
))))
1620 ;; If `:section-numbers' is a number, only number headlines with
1621 ;; a level greater that it.
1625 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1626 (org-element-map tree
'headline
1627 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1628 (plist-put info
:section-numbers
1)))))
1629 ;; Otherwise, headlines are always numbered.
1631 (org-test-with-parsed-data "* Headline"
1632 (org-element-map tree
'headline
1633 (lambda (h) (org-export-numbered-headline-p h info
))
1634 (plist-put info
:section-numbers t
)))))
1636 (ert-deftest test-org-export
/org-export-get-headline-id
()
1637 "Test `org-export-get-headline-id' specifications."
1638 ;; Numbered headlines have IDs akin to "sec-N".
1641 (org-test-with-parsed-data "* H"
1642 (org-export-get-headline-id
1643 (org-element-map tree
'headline
#'identity info t
)
1645 ;; The ID of numbered headlines reflect the hierarchy.
1648 (org-test-with-parsed-data "* H1\n** H2"
1649 (org-export-get-headline-id
1650 (org-element-map tree
'headline
1652 (and (equal "H2" (org-element-property :raw-value h
)) h
))
1655 ;; Unnumbered headlines have IDs akin to "unnumbered-N".
1657 (equal "unnumbered-1"
1658 (org-test-with-parsed-data
1659 "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
1660 (org-export-get-headline-id
1661 (org-element-map tree
'headline
#'identity info t
)
1663 ;; The ID of Unnumbered headlines do not reflect the hierarchy.
1665 (equal "unnumbered-2"
1666 (org-test-with-parsed-data
1667 "* H1\n:PROPERTIES:\n:UNNUMBERED: t\n:END:\n** H2"
1668 (org-export-get-headline-id
1669 (org-element-map tree
'headline
1671 (and (equal "H2" (org-element-property :raw-value h
)) h
))
1674 ;; When #+OPTIONS: num:nil all headlines are unnumbered.
1676 (equal "unnumbered-1"
1677 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
1678 (org-export-get-headline-id
1679 (org-element-map tree
'headline
'identity info t
)
1681 ;; UNNUMBERED ignores inheritance. Any non-nil value among
1682 ;; ancestors disables numbering.
1684 (org-test-with-parsed-data
1695 (lambda (h) (not (org-export-numbered-headline-p h info
)))
1696 (org-element-map tree
'headline
#'identity info
)))))
1698 (ert-deftest test-org-export
/number-to-roman
()
1699 "Test `org-export-number-to-roman' specifications."
1700 ;; If number is negative, return it as a string.
1701 (should (equal (org-export-number-to-roman -
1) "-1"))
1702 ;; Otherwise, return it as a roman number.
1703 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1705 (ert-deftest test-org-export
/get-optional-title
()
1706 "Test `org-export-get-alt-title' specifications."
1707 ;; If ALT_TITLE property is defined, use it.
1710 (org-test-with-parsed-data
1711 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1712 (org-export-get-alt-title
1713 (org-element-map tree
'headline
'identity info t
)
1715 ;; Otherwise, fall-back to regular title.
1717 (equal '("Headline")
1718 (org-test-with-parsed-data "* Headline"
1719 (org-export-get-alt-title
1720 (org-element-map tree
'headline
'identity info t
)
1723 (ert-deftest test-org-export
/get-tags
()
1724 "Test `org-export-get-tags' specifications."
1725 (let ((org-export-exclude-tags '("noexport"))
1726 (org-export-select-tags '("export")))
1727 ;; Standard test: tags which are not a select tag, an exclude tag,
1728 ;; or specified as optional argument shouldn't be ignored.
1730 (org-test-with-parsed-data "* Headline :tag:"
1731 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1733 ;; Exclude tags are removed.
1735 (org-test-with-parsed-data "* Headline :noexport:"
1736 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1738 ;; Select tags are removed.
1740 (org-test-with-parsed-data "* Headline :export:"
1741 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1746 (org-test-with-parsed-data "* Headline :tag:export:"
1747 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1749 ;; Tags provided in the optional argument are also ignored.
1751 (org-test-with-parsed-data "* Headline :ignore:"
1752 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1754 ;; Allow tag inheritance.
1758 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1759 (org-element-map tree
'headline
1760 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1761 ;; Tag inheritance checks FILETAGS keywords.
1765 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1766 (org-element-map tree
'headline
1767 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1769 (ert-deftest test-org-export
/get-node-property
()
1770 "Test`org-export-get-node-property' specifications."
1774 (org-test-with-parsed-data "* Headline
1778 (org-export-get-node-property
1779 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1780 ;; Test inheritance.
1783 (org-test-with-parsed-data "* Parent
1789 (org-export-get-node-property
1790 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1791 ;; Cannot return a value before the first headline.
1793 (org-test-with-parsed-data "Paragraph
1798 (org-export-get-node-property
1799 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1801 (ert-deftest test-org-export
/get-category
()
1802 "Test `org-export-get-category' specifications."
1806 (org-test-with-parsed-data "* Headline
1810 (org-export-get-category
1811 (org-element-map tree
'headline
'identity nil t
) info
))))
1812 ;; Test inheritance from a parent headline.
1814 (equal '("value" "value")
1815 (org-test-with-parsed-data "* Headline1
1820 (org-element-map tree
'headline
1821 (lambda (hl) (org-export-get-category hl info
)) info
))))
1822 ;; Test inheritance from #+CATEGORY keyword
1825 (org-test-with-parsed-data "#+CATEGORY: value
1827 (org-export-get-category
1828 (org-element-map tree
'headline
'identity nil t
) info
))))
1829 ;; Test inheritance from file name.
1832 (org-test-with-parsed-data "* Headline"
1833 (let ((info (plist-put info
:input-file
"~/test.org")))
1834 (org-export-get-category
1835 (org-element-map tree
'headline
'identity nil t
) info
)))))
1839 (org-test-with-parsed-data "* Headline"
1840 (org-export-get-category
1841 (org-element-map tree
'headline
'identity nil t
) info
)))))
1843 (ert-deftest test-org-export
/first-sibling-p
()
1844 "Test `org-export-first-sibling-p' specifications."
1849 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
1850 (org-element-map tree
'headline
1851 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1855 (org-test-with-parsed-data "- item\n\n para"
1856 (org-element-map tree
'paragraph
1857 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1859 ;; Ignore sections for headlines.
1862 (org-test-with-parsed-data "* H\nSection\n** H 2"
1863 (org-element-map tree
'headline
1864 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1866 ;; Ignore headlines not exported.
1870 (let ((org-export-exclude-tags '("ignore")))
1871 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1872 (org-element-map tree
'headline
1873 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1876 (ert-deftest test-org-export
/last-sibling-p
()
1877 "Test `org-export-last-sibling-p' specifications."
1882 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1883 (org-element-map tree
'headline
1884 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1888 (org-test-with-parsed-data "- item\n\n para"
1889 (org-element-map tree
'paragraph
1890 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1892 ;; Ignore headlines not exported.
1896 (let ((org-export-exclude-tags '("ignore")))
1897 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1898 (org-element-map tree
'headline
1899 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1902 (ert-deftest test-org-export
/handle-inlinetasks
()
1903 "Test inlinetask export."
1904 ;; Inlinetask with an exclude tag.
1905 (when (featurep 'org-inlinetask
)
1909 (let ((org-inlinetask-min-level 3))
1910 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1911 (org-export-as (org-test-default-backend)
1912 nil nil nil
'(:exclude-tags
("noexp")))))))
1913 ;; Inlinetask with an include tag.
1916 "* H2\n*** Inline :exp:\n"
1917 (let ((org-inlinetask-min-level 3)
1918 (org-tags-column 0))
1919 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1920 (org-export-as (org-test-default-backend)
1921 nil nil nil
'(:select-tags
("exp")))))))
1922 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1925 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1926 (org-inlinetask-min-level 3))
1927 (org-test-with-temp-text "*** TODO Inline"
1928 (org-export-as (org-test-default-backend)
1929 nil nil nil
'(:with-tasks nil
))))))))
1935 (ert-deftest test-org-export
/get-date
()
1936 "Test `org-export-get-date' specifications."
1937 ;; Return a properly formatted string when
1938 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1939 ;; consists in a single timestamp.
1942 (let ((org-export-date-timestamp-format "%d %m %Y"))
1943 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1944 (org-export-get-date info
)))))
1945 ;; Return a secondary string otherwise.
1948 (let ((org-export-date-timestamp-format nil
))
1949 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1950 (org-export-get-date info
)))))
1953 (org-test-with-parsed-data "#+DATE: Date"
1954 (org-export-get-date info
))))
1955 ;; Optional argument has precedence over
1956 ;; `org-export-date-timestamp-format'.
1959 (let ((org-export-date-timestamp-format "%d %m %Y"))
1960 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1961 (org-export-get-date info
"%d %m"))))))
1967 (ert-deftest test-org-export
/get-coderef-format
()
1968 "Test `org-export-get-coderef-format' specifications."
1969 ;; A link without description returns "%s"
1970 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1972 ;; Return "%s" when path is matched within description.
1973 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1975 ;; Otherwise return description.
1976 (should (equal (org-export-get-coderef-format "path" "desc")
1979 (ert-deftest test-org-export
/inline-image-p
()
1980 "Test `org-export-inline-image-p' specifications."
1982 (org-export-inline-image-p
1983 (org-test-with-temp-text "[[#id]]"
1984 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1985 '(("custom-id" .
"id")))))
1987 (ert-deftest test-org-export
/fuzzy-link
()
1988 "Test fuzzy links specifications."
1989 ;; Link to an headline should return headline's number.
1990 (org-test-with-parsed-data
1991 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1993 ;; Note: Headline's number is in fact a list of numbers.
1995 (org-element-map tree
'link
1997 (org-export-get-ordinal
1998 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1999 ;; Link to a target in an item should return item's number.
2000 (org-test-with-parsed-data
2001 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2003 ;; Note: Item's number is in fact a list of numbers.
2005 (org-element-map tree
'link
2007 (org-export-get-ordinal
2008 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2009 ;; Link to a target in a footnote should return footnote's number.
2010 (org-test-with-parsed-data "
2011 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
2014 (org-element-map tree
'link
2016 (org-export-get-ordinal
2017 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2018 ;; Link to a named element should return sequence number of that
2020 (org-test-with-parsed-data
2021 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2024 (org-element-map tree
'link
2026 (org-export-get-ordinal
2027 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2028 ;; Link to a target not within an item, a table, a footnote
2029 ;; reference or definition should return section number.
2030 (org-test-with-parsed-data
2031 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2034 (org-element-map tree
'link
2036 (org-export-get-ordinal
2037 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2038 ;; Space are not significant when matching a fuzzy link.
2040 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2041 (org-element-map tree
'link
2042 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2044 ;; Statistics cookies are ignored for headline match.
2046 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2047 (org-element-map tree
'link
2048 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2051 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2052 (org-element-map tree
'link
2053 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2055 ;; Headline match is position dependent.
2059 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
2060 (org-element-map tree
'link
2061 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
2063 (ert-deftest test-org-export
/resolve-coderef
()
2064 "Test `org-export-resolve-coderef' specifications."
2065 (let ((org-coderef-label-format "(ref:%s)"))
2066 ;; 1. A link to a "-n -k -r" block returns line number.
2067 (org-test-with-parsed-data
2068 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2069 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2070 (org-test-with-parsed-data
2071 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2072 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2073 ;; 2. A link to a "-n -r" block returns line number.
2074 (org-test-with-parsed-data
2075 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2076 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2077 (org-test-with-parsed-data
2078 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2079 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2080 ;; 3. A link to a "-n" block returns coderef.
2081 (org-test-with-parsed-data
2082 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2083 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2084 (org-test-with-parsed-data
2085 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2086 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2087 ;; 4. A link to a "-r" block returns line number.
2088 (org-test-with-parsed-data
2089 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2090 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2091 (org-test-with-parsed-data
2092 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2093 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
2094 ;; 5. A link to a block without a switch returns coderef.
2095 (org-test-with-parsed-data
2096 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2097 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2098 (org-test-with-parsed-data
2099 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2100 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2101 ;; 6. Correctly handle continued line numbers. A "+n" switch
2102 ;; should resume numbering from previous block with numbered
2103 ;; lines, ignoring blocks not numbering lines in the process.
2104 ;; A "-n" switch resets count.
2105 (org-test-with-parsed-data "
2110 #+BEGIN_SRC emacs-lisp
2114 #+BEGIN_SRC emacs-lisp +n -r
2115 \(+ 1 1) (ref:addition)
2118 #+BEGIN_EXAMPLE -n -r
2119 Another text. (ref:text)
2121 (should (= (org-export-resolve-coderef "addition" info
) 2))
2122 (should (= (org-export-resolve-coderef "text" info
) 1)))
2123 ;; 7. Recognize coderef with user-specified syntax.
2124 (org-test-with-parsed-data
2125 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2126 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
2128 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2129 "Test `org-export-resolve-fuzzy-link' specifications."
2130 ;; Match target objects.
2132 (org-test-with-parsed-data "<<target>> [[target]]"
2133 (org-export-resolve-fuzzy-link
2134 (org-element-map tree
'link
'identity info t
) info
)))
2135 ;; Match named elements.
2137 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2138 (org-export-resolve-fuzzy-link
2139 (org-element-map tree
'link
'identity info t
) info
)))
2140 ;; Match exact headline's name.
2142 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2143 (org-export-resolve-fuzzy-link
2144 (org-element-map tree
'link
'identity info t
) info
)))
2145 ;; Targets objects have priority over named elements and headline
2149 (org-test-with-parsed-data
2150 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2152 (org-export-resolve-fuzzy-link
2153 (org-element-map tree
'link
'identity info t
) info
)))))
2154 ;; Named elements have priority over headline titles.
2157 (org-test-with-parsed-data
2158 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2160 (org-export-resolve-fuzzy-link
2161 (org-element-map tree
'link
'identity info t
) info
)))))
2162 ;; If link's path starts with a "*", only match headline titles,
2166 (org-test-with-parsed-data
2167 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2169 (org-export-resolve-fuzzy-link
2170 (org-element-map tree
'link
'identity info t
) info
)))))
2171 ;; Return nil if no match.
2173 (org-test-with-parsed-data "[[target]]"
2174 (org-export-resolve-fuzzy-link
2175 (org-element-map tree
'link
'identity info t
) info
)))
2176 ;; Match fuzzy link even when before first headline.
2179 (org-test-with-parsed-data "[[hl]]\n* hl"
2181 (org-export-resolve-fuzzy-link
2182 (org-element-map tree
'link
'identity info t
) info
))))))
2184 (ert-deftest test-org-export
/resolve-id-link
()
2185 "Test `org-export-resolve-id-link' specifications."
2186 ;; 1. Regular test for custom-id link.
2187 (org-test-with-parsed-data "* Headline1
2194 (org-export-resolve-id-link
2195 (org-element-map tree
'link
'identity info t
) info
)))
2196 ;; 2. Failing test for custom-id link.
2197 (org-test-with-parsed-data "* Headline1
2204 (org-export-resolve-id-link
2205 (org-element-map tree
'link
'identity info t
) info
)))
2206 ;; 3. Test for internal id target.
2207 (org-test-with-parsed-data "* Headline1
2214 (org-export-resolve-id-link
2215 (org-element-map tree
'link
'identity info t
) info
)))
2216 ;; 4. Test for external id target.
2217 (org-test-with-parsed-data "[[id:aaaa]]"
2219 (org-export-resolve-id-link
2220 (org-element-map tree
'link
'identity info t
)
2221 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
2223 (ert-deftest test-org-export
/resolve-radio-link
()
2224 "Test `org-export-resolve-radio-link' specifications."
2227 (org-test-with-temp-text "<<<radio>>> radio"
2228 (org-update-radio-target-regexp)
2229 (let* ((tree (org-element-parse-buffer))
2230 (info `(:parse-tree
,tree
)))
2231 (org-export-resolve-radio-link
2232 (org-element-map tree
'link
'identity info t
)
2234 ;; Radio targets are case-insensitive.
2236 (org-test-with-temp-text "<<<RADIO>>> radio"
2237 (org-update-radio-target-regexp)
2238 (let* ((tree (org-element-parse-buffer))
2239 (info `(:parse-tree
,tree
)))
2240 (org-export-resolve-radio-link
2241 (org-element-map tree
'link
'identity info t
)
2243 ;; Radio target with objects.
2245 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2246 (org-update-radio-target-regexp)
2247 (let* ((tree (org-element-parse-buffer))
2248 (info `(:parse-tree
,tree
)))
2249 (org-export-resolve-radio-link
2250 (org-element-map tree
'link
'identity info t
)
2252 ;; Radio target with objects at its beginning.
2254 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2255 (org-update-radio-target-regexp)
2256 (let* ((tree (org-element-parse-buffer))
2257 (info `(:parse-tree
,tree
)))
2258 (org-export-resolve-radio-link
2259 (org-element-map tree
'link
'identity info t
)
2261 ;; Radio link next to an apostrophe.
2263 (org-test-with-temp-text "<<<radio>>> radio's"
2264 (org-update-radio-target-regexp)
2265 (let* ((tree (org-element-parse-buffer))
2266 (info `(:parse-tree
,tree
)))
2267 (org-export-resolve-radio-link
2268 (org-element-map tree
'link
'identity info t
)
2270 ;; Multiple radio targets.
2272 (equal '("radio1" "radio2")
2273 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2274 (org-update-radio-target-regexp)
2275 (let* ((tree (org-element-parse-buffer))
2276 (info `(:parse-tree
,tree
)))
2277 (org-element-map tree
'link
2279 (org-element-property
2280 :value
(org-export-resolve-radio-link link info
)))
2282 ;; Radio target is whitespace insensitive.
2284 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2285 (org-update-radio-target-regexp)
2286 (let* ((tree (org-element-parse-buffer))
2287 (info `(:parse-tree
,tree
)))
2288 (org-element-map tree
'link
2289 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2293 ;;; Src-block and example-block
2295 (ert-deftest test-org-export
/unravel-code
()
2296 "Test `org-export-unravel-code' function."
2297 ;; Code without reference.
2299 (equal '("(+ 1 1)\n")
2300 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2301 (org-export-unravel-code (org-element-at-point)))))
2302 ;; Code with reference.
2304 (equal '("(+ 1 1)\n" (1 .
"test"))
2305 (org-test-with-temp-text
2306 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2307 (let ((org-coderef-label-format "(ref:%s)"))
2308 (org-export-unravel-code (org-element-at-point))))))
2309 ;; Code with user-defined reference.
2312 '("(+ 1 1)\n" (1 .
"test"))
2313 (org-test-with-temp-text
2314 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2315 (let ((org-coderef-label-format "(ref:%s)"))
2316 (org-export-unravel-code (org-element-at-point))))))
2317 ;; Code references keys are relative to the current block.
2319 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2320 (org-test-with-temp-text "
2329 (let ((org-coderef-label-format "(ref:%s)"))
2330 (org-export-unravel-code (org-element-at-point)))))))
2332 (ert-deftest test-org-export
/format-code-default
()
2333 "Test `org-export-format-code-default' specifications."
2334 ;; Return the empty string when code is empty.
2337 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2338 (org-export-format-code-default
2339 (org-element-map tree
'src-block
'identity info t
) info
))))
2340 ;; Number lines, two whitespace characters before the actual loc.
2343 (org-test-with-parsed-data
2344 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2345 (org-export-format-code-default
2346 (org-element-map tree
'src-block
'identity info t
) info
))))
2347 ;; Put references 6 whitespace characters after the widest line,
2348 ;; wrapped within parenthesis.
2350 (equal "123 (a)\n1 (b)\n"
2351 (let ((org-coderef-label-format "(ref:%s)"))
2352 (org-test-with-parsed-data
2353 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2354 (org-export-format-code-default
2355 (org-element-map tree
'src-block
'identity info t
) info
))))))
2361 (ert-deftest test-org-export
/activate-smart-quotes
()
2362 "Test `org-export-activate-smart-quotes' specifications."
2363 ;; Opening double quotes: standard test.
2366 '("some “paragraph")
2367 (let ((org-export-default-language "en"))
2368 (org-test-with-parsed-data "some \"paragraph"
2369 (org-element-map tree
'plain-text
2370 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2372 ;; Opening quotes: at the beginning of a paragraph.
2376 (let ((org-export-default-language "en"))
2377 (org-test-with-parsed-data "\"begin"
2378 (org-element-map tree
'plain-text
2379 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2381 ;; Opening quotes: after an object.
2385 (let ((org-export-default-language "en"))
2386 (org-test-with-parsed-data "=verb= \"begin"
2387 (org-element-map tree
'plain-text
2388 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2390 ;; Closing quotes: standard test.
2393 '("some” paragraph")
2394 (let ((org-export-default-language "en"))
2395 (org-test-with-parsed-data "some\" paragraph"
2396 (org-element-map tree
'plain-text
2397 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2399 ;; Closing quotes: at the end of a paragraph.
2403 (let ((org-export-default-language "en"))
2404 (org-test-with-parsed-data "end\""
2405 (org-element-map tree
'plain-text
2406 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2408 ;; Apostrophe: standard test.
2411 '("It shouldn’t fail")
2412 (let ((org-export-default-language "en"))
2413 (org-test-with-parsed-data "It shouldn't fail"
2414 (org-element-map tree
'plain-text
2415 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2417 ;; Apostrophe: before an object.
2421 (let ((org-export-default-language "en"))
2422 (org-test-with-parsed-data "a'=b="
2423 (org-element-map tree
'plain-text
2424 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2426 ;; Apostrophe: after an object.
2430 (let ((org-export-default-language "en"))
2431 (org-test-with-parsed-data "=code='s"
2432 (org-element-map tree
'plain-text
2433 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2435 ;; Special case: isolated quotes.
2437 (equal '("“" "”")
2438 (let ((org-export-default-language "en"))
2439 (org-test-with-parsed-data "\"$x$\""
2440 (org-element-map tree
'plain-text
2441 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2443 ;; Smart quotes in secondary strings.
2445 (equal '("“" "”")
2446 (let ((org-export-default-language "en"))
2447 (org-test-with-parsed-data "* \"$x$\""
2448 (org-element-map tree
'plain-text
2449 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2451 ;; Smart quotes in document keywords.
2453 (equal '("“" "”")
2454 (let ((org-export-default-language "en"))
2455 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2456 (org-element-map (plist-get info
:title
) 'plain-text
2457 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2459 ;; Smart quotes in parsed affiliated keywords.
2461 (equal '("“" "”" "Paragraph")
2462 (let ((org-export-default-language "en"))
2463 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2464 (org-element-map tree
'plain-text
2465 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2466 info nil nil t
))))))
2472 (ert-deftest test-org-export
/special-column
()
2473 "Test if the table's special column is properly recognized."
2474 ;; 1. First column is special if it contains only a special marking
2475 ;; characters or empty cells.
2476 (org-test-with-temp-text "
2480 (org-export-table-has-special-column-p
2482 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2483 ;; 2. If the column contains anything else, it isn't special.
2484 (org-test-with-temp-text "
2488 (org-export-table-has-special-column-p
2490 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2491 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2493 (org-test-with-temp-text "
2502 (org-export-table-has-special-column-p
2504 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2505 ;; 4. A first column with only empty cells isn't considered as
2507 (org-test-with-temp-text "
2511 (org-export-table-has-special-column-p
2513 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2515 (ert-deftest test-org-export
/table-row-is-special-p
()
2516 "Test `org-export-table-row-is-special-p' specifications."
2517 ;; 1. A row is special if it has a special marking character in the
2519 (org-test-with-parsed-data "| ! | 1 |"
2521 (org-export-table-row-is-special-p
2522 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2523 ;; 2. A row is special when its first field is "/"
2524 (org-test-with-parsed-data "
2528 (org-export-table-row-is-special-p
2529 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2530 ;; 3. A row only containing alignment cookies is also considered as
2532 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2534 (org-export-table-row-is-special-p
2535 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2536 ;; 4. Everything else isn't considered as special.
2537 (org-test-with-parsed-data "| \alpha | | c |"
2539 (org-export-table-row-is-special-p
2540 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2541 ;; 5. Table's rules are never considered as special rows.
2542 (org-test-with-parsed-data "|---+---|"
2544 (org-export-table-row-is-special-p
2545 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2547 (ert-deftest test-org-export
/has-header-p
()
2548 "Test `org-export-table-has-header-p' specifications."
2549 ;; 1. With an header.
2550 (org-test-with-parsed-data "
2555 (org-export-table-has-header-p
2556 (org-element-map tree
'table
'identity info
'first-match
)
2558 ;; 2. Without an header.
2559 (org-test-with-parsed-data "
2563 (org-export-table-has-header-p
2564 (org-element-map tree
'table
'identity info
'first-match
)
2566 ;; 3. Don't get fooled with starting and ending rules.
2567 (org-test-with-parsed-data "
2573 (org-export-table-has-header-p
2574 (org-element-map tree
'table
'identity info
'first-match
)
2577 (ert-deftest test-org-export
/table-row-group
()
2578 "Test `org-export-table-row-group' specifications."
2579 ;; 1. A rule creates a new group.
2582 (org-test-with-parsed-data "
2586 (org-element-map tree
'table-row
2588 (if (eq (org-element-property :type row
) 'rule
) 'rule
2589 (org-export-table-row-group row info
)))))))
2590 ;; 2. Special rows are ignored in count.
2594 (org-test-with-parsed-data "
2598 (org-element-map tree
'table-row
2600 (if (eq (org-element-property :type row
) 'rule
) 'rule
2601 (org-export-table-row-group row info
)))
2603 ;; 3. Double rules also are ignored in count.
2605 (equal '(1 rule rule
2)
2606 (org-test-with-parsed-data "
2611 (org-element-map tree
'table-row
2613 (if (eq (org-element-property :type row
) 'rule
) 'rule
2614 (org-export-table-row-group row info
))))))))
2616 (ert-deftest test-org-export
/table-row-number
()
2617 "Test `org-export-table-row-number' specifications."
2618 ;; Standard test. Number is 0-indexed.
2621 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2622 (org-element-map tree
'table-row
2623 (lambda (row) (org-export-table-row-number row info
)) info
))))
2624 ;; Number ignores separators.
2627 (org-test-with-parsed-data "
2631 (org-element-map tree
'table-row
2632 (lambda (row) (org-export-table-row-number row info
)) info
))))
2633 ;; Number ignores special rows.
2636 (org-test-with-parsed-data "
2642 (org-element-map tree
'table-row
2643 (lambda (row) (org-export-table-row-number row info
)) info
)))))
2645 (ert-deftest test-org-export
/table-cell-width
()
2646 "Test `org-export-table-cell-width' specifications."
2647 ;; 1. Width is primarily determined by width cookies. If no cookie
2648 ;; is found, cell's width is nil.
2649 (org-test-with-parsed-data "
2650 | / | <l> | <6> | <l7> |
2655 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2656 (org-element-map tree
'table-cell
'identity info
)))))
2657 ;; 2. The last width cookie has precedence.
2658 (org-test-with-parsed-data "
2665 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2666 (org-element-map tree
'table-cell
'identity info
)))))
2667 ;; 3. Valid width cookies must have a specific row.
2668 (org-test-with-parsed-data "| <6> | cell |"
2672 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2673 (org-element-map tree
'table-cell
'identity
))))))
2675 (ert-deftest test-org-export
/table-cell-alignment
()
2676 "Test `org-export-table-cell-alignment' specifications."
2677 ;; 1. Alignment is primarily determined by alignment cookies.
2679 (equal '(left center right
)
2680 (let ((org-table-number-fraction 0.5)
2681 (org-table-number-regexp "^[0-9]+$"))
2682 (org-test-with-parsed-data "| <l> | <c> | <r> |"
2683 (mapcar (lambda (cell)
2684 (org-export-table-cell-alignment cell info
))
2685 (org-element-map tree
'table-cell
'identity
))))))
2686 ;; 2. The last alignment cookie has precedence.
2688 (equal '(right right right
)
2689 (org-test-with-parsed-data "
2693 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2694 (org-element-map tree
'table-cell
'identity
)))))
2695 ;; 3. If there's no cookie, cell's contents determine alignment.
2696 ;; A column mostly made of cells containing numbers will align
2697 ;; its cells to the right.
2699 (equal '(right right right
)
2700 (let ((org-table-number-fraction 0.5)
2701 (org-table-number-regexp "^[0-9]+$"))
2702 (org-test-with-parsed-data "
2706 (mapcar (lambda (cell)
2707 (org-export-table-cell-alignment cell info
))
2708 (org-element-map tree
'table-cell
'identity
))))))
2709 ;; 4. Otherwise, they will be aligned to the left.
2711 (equal '(left left left
)
2712 (org-test-with-parsed-data "
2716 (mapcar (lambda (cell)
2717 (org-export-table-cell-alignment cell info
))
2718 (org-element-map tree
'table-cell
'identity info
))))))
2720 (ert-deftest test-org-export
/table-cell-borders
()
2721 "Test `org-export-table-cell-borders' specifications."
2722 ;; 1. Recognize various column groups indicators.
2723 (org-test-with-parsed-data "| / | < | > | <> |"
2726 '((right bottom top
) (left bottom top
) (right bottom top
)
2727 (right left bottom top
))
2728 (mapcar (lambda (cell)
2729 (org-export-table-cell-borders cell info
))
2730 (org-element-map tree
'table-cell
'identity
)))))
2731 ;; 2. Accept shortcuts to define column groups.
2732 (org-test-with-parsed-data "| / | < | < |"
2735 '((right bottom top
) (right left bottom top
) (left bottom top
))
2736 (mapcar (lambda (cell)
2737 (org-export-table-cell-borders cell info
))
2738 (org-element-map tree
'table-cell
'identity
)))))
2739 ;; 3. A valid column groups row must start with a "/".
2740 (org-test-with-parsed-data "
2744 (equal '((top) (top) (bottom) (bottom))
2745 (mapcar (lambda (cell)
2746 (org-export-table-cell-borders cell info
))
2747 (org-element-map tree
'table-cell
'identity
)))))
2748 ;; 4. Take table rules into consideration.
2749 (org-test-with-parsed-data "
2754 (equal '((below top
) (bottom above
))
2755 (mapcar (lambda (cell)
2756 (org-export-table-cell-borders cell info
))
2757 (org-element-map tree
'table-cell
'identity
)))))
2758 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2759 ;; (resp. `bottom' and `below') borders. Any special row is
2761 (org-test-with-parsed-data "
2767 (equal '((bottom below top above
))
2769 (mapcar (lambda (cell)
2770 (org-export-table-cell-borders cell info
))
2771 (org-element-map tree
'table-cell
'identity
)))))))
2773 (ert-deftest test-org-export
/table-dimensions
()
2774 "Test `org-export-table-dimensions' specifications."
2775 ;; 1. Standard test.
2776 (org-test-with-parsed-data "
2781 (org-export-table-dimensions
2782 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2783 ;; 2. Ignore horizontal rules and special columns.
2784 (org-test-with-parsed-data "
2791 (org-export-table-dimensions
2792 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2794 (ert-deftest test-org-export
/table-cell-address
()
2795 "Test `org-export-table-cell-address' specifications."
2796 ;; 1. Standard test: index is 0-based.
2797 (org-test-with-parsed-data "| a | b |"
2799 (equal '((0 .
0) (0 .
1))
2800 (org-element-map tree
'table-cell
2801 (lambda (cell) (org-export-table-cell-address cell info
))
2803 ;; 2. Special column isn't counted, nor are special rows.
2804 (org-test-with-parsed-data "
2809 (org-export-table-cell-address
2810 (car (last (org-element-map tree
'table-cell
'identity info
)))
2812 ;; 3. Tables rules do not count either.
2813 (org-test-with-parsed-data "
2821 (org-export-table-cell-address
2822 (car (last (org-element-map tree
'table-cell
'identity info
)))
2824 ;; 4. Return nil for special cells.
2825 (org-test-with-parsed-data "| / | a |"
2827 (org-export-table-cell-address
2828 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2831 (ert-deftest test-org-export
/get-table-cell-at
()
2832 "Test `org-export-get-table-cell-at' specifications."
2833 ;; 1. Address ignores special columns, special rows and rules.
2834 (org-test-with-parsed-data "
2841 (org-element-contents
2842 (org-export-get-table-cell-at
2844 (org-element-map tree
'table
'identity info
'first-match
)
2846 ;; 2. Return value for a non-existent address is nil.
2847 (org-test-with-parsed-data "| a |"
2849 (org-export-get-table-cell-at
2851 (org-element-map tree
'table
'identity info
'first-match
)
2853 (org-test-with-parsed-data "| / |"
2855 (org-export-get-table-cell-at
2857 (org-element-map tree
'table
'identity info
'first-match
)
2860 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2861 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2862 ;; 1. A cell at a beginning of a row always starts a column group.
2863 (org-test-with-parsed-data "| a |"
2865 (org-export-table-cell-starts-colgroup-p
2866 (org-element-map tree
'table-cell
'identity info
'first-match
)
2868 ;; 2. Special column should be ignored when determining the
2869 ;; beginning of the row.
2870 (org-test-with-parsed-data "
2874 (org-export-table-cell-starts-colgroup-p
2875 (org-element-map tree
'table-cell
'identity info
'first-match
)
2877 ;; 2. Explicit column groups.
2878 (org-test-with-parsed-data "
2884 (org-element-map tree
'table-cell
2886 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2889 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2890 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2891 ;; 1. A cell at the end of a row always ends a column group.
2892 (org-test-with-parsed-data "| a |"
2894 (org-export-table-cell-ends-colgroup-p
2895 (org-element-map tree
'table-cell
'identity info
'first-match
)
2897 ;; 2. Special column should be ignored when determining the
2898 ;; beginning of the row.
2899 (org-test-with-parsed-data "
2903 (org-export-table-cell-ends-colgroup-p
2904 (org-element-map tree
'table-cell
'identity info
'first-match
)
2906 ;; 3. Explicit column groups.
2907 (org-test-with-parsed-data "
2913 (org-element-map tree
'table-cell
2915 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2918 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2919 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2920 ;; 1. A row at the beginning of a table always starts a row group.
2921 ;; So does a row following a table rule.
2922 (org-test-with-parsed-data "
2929 (org-element-map tree
'table-row
2931 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2933 ;; 2. Special rows should be ignored when determining the beginning
2935 (org-test-with-parsed-data "
2944 (org-element-map tree
'table-row
2946 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2949 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2950 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2951 ;; 1. A row at the end of a table always ends a row group. So does
2952 ;; a row preceding a table rule.
2953 (org-test-with-parsed-data "
2960 (org-element-map tree
'table-row
2962 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2964 ;; 2. Special rows should be ignored when determining the beginning
2966 (org-test-with-parsed-data "
2975 (org-element-map tree
'table-row
2977 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2980 (ert-deftest test-org-export
/table-row-in-header-p
()
2981 "Test `org-export-table-row-in-header-p' specifications."
2982 ;; Standard test. Separators are always nil.
2986 (org-test-with-parsed-data "| a |\n|---|\n| b |"
2987 (org-element-map tree
'table-row
2989 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
2990 ;; Nil when there is no header.
2994 (org-test-with-parsed-data "| a |\n| b |"
2995 (org-element-map tree
'table-row
2997 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
2999 (ert-deftest test-org-export
/table-row-starts-header-p
()
3000 "Test `org-export-table-row-starts-header-p' specifications."
3001 ;; 1. Only the row starting the first row group starts the table
3003 (org-test-with-parsed-data "
3011 (org-element-map tree
'table-row
3013 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
3015 ;; 2. A row cannot start an header if there's no header in the
3017 (org-test-with-parsed-data "
3021 (org-export-table-row-starts-header-p
3022 (org-element-map tree
'table-row
'identity info
'first-match
)
3025 (ert-deftest test-org-export
/table-row-ends-header-p
()
3026 "Test `org-export-table-row-ends-header-p' specifications."
3027 ;; 1. Only the row starting the first row group starts the table
3029 (org-test-with-parsed-data "
3037 (org-element-map tree
'table-row
3039 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
3041 ;; 2. A row cannot start an header if there's no header in the
3043 (org-test-with-parsed-data "
3047 (org-export-table-row-ends-header-p
3048 (org-element-map tree
'table-row
'identity info
'first-match
)
3053 ;;; Tables of Contents
3055 (ert-deftest test-org-export
/collect-headlines
()
3056 "Test `org-export-collect-headlines' specifications."
3061 (org-test-with-parsed-data "* H1\n** H2"
3062 (org-export-collect-headlines info
)))))
3063 ;; Do not collect headlines below optional argument.
3067 (org-test-with-parsed-data "* H1\n** H2"
3068 (org-export-collect-headlines info
1)))))
3069 ;; Never collect headlines below maximum headline level.
3073 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3074 (org-export-collect-headlines info
)))))
3078 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3079 (org-export-collect-headlines info
2))))))
3085 (ert-deftest test-org-export
/inner-template
()
3086 "Test `inner-template' translator specifications."
3089 (org-test-with-temp-text "* Headline"
3091 (org-export-create-backend
3093 '((inner-template .
(lambda (contents info
) "Success!"))
3094 (headline .
(lambda (h c i
) "Headline"))))))))
3095 ;; Inner template is applied even in a "body-only" export.
3098 (org-test-with-temp-text "* Headline"
3100 (org-export-create-backend
3101 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3102 (headline .
(lambda (h c i
) "Headline"))))
3103 nil nil
'body-only
)))))
3105 (ert-deftest test-org-export
/template
()
3106 "Test `template' translator specifications."
3109 (org-test-with-temp-text "* Headline"
3111 (org-export-create-backend
3112 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3113 (headline .
(lambda (h c i
) "Headline"))))))))
3114 ;; Template is not applied in a "body-only" export.
3117 (org-test-with-temp-text "* Headline"
3119 (org-export-create-backend
3120 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3121 (headline .
(lambda (h c i
) "Headline"))))
3122 nil nil
'body-only
)))))
3128 (ert-deftest test-org-export
/get-next-element
()
3129 "Test `org-export-get-next-element' specifications."
3133 (org-test-with-parsed-data "* Headline\n*a* b"
3134 (org-export-get-next-element
3135 (org-element-map tree
'bold
'identity info t
) info
))))
3136 ;; Return nil when no previous element.
3138 (org-test-with-parsed-data "* Headline\na *b*"
3139 (org-export-get-next-element
3140 (org-element-map tree
'bold
'identity info t
) info
)))
3141 ;; Non-exportable elements are ignored.
3143 (let ((org-export-with-timestamps nil
))
3144 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3145 (org-export-get-next-element
3146 (org-element-map tree
'entity
'identity info t
) info
))))
3147 ;; Find next element in secondary strings.
3150 (org-test-with-parsed-data "* a =verb="
3152 (org-export-get-next-element
3153 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3156 (org-test-with-parsed-data "* /italic/ =verb="
3158 (org-export-get-next-element
3159 (org-element-map tree
'italic
'identity info t
) info
)))))
3160 ;; Find next element in document keywords.
3163 (org-test-with-parsed-data "#+TITLE: a =verb="
3165 (org-export-get-next-element
3167 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3168 ;; Find next element in parsed affiliated keywords.
3171 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3173 (org-export-get-next-element
3174 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3175 ;; With optional argument N, return a list containing all the
3176 ;; following elements.
3179 '(bold code underline
)
3180 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3182 (org-export-get-next-element
3183 (org-element-map tree
'italic
'identity info t
) info t
)))))
3184 ;; When N is a positive integer, return a list containing up to
3185 ;; N following elements.
3189 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3191 (org-export-get-next-element
3192 (org-element-map tree
'italic
'identity info t
) info
2))))))
3194 (ert-deftest test-org-export
/get-previous-element
()
3195 "Test `org-export-get-previous-element' specifications."
3199 (org-test-with-parsed-data "* Headline\na *b*"
3200 (org-export-get-previous-element
3201 (org-element-map tree
'bold
'identity info t
) info
))))
3202 ;; Return nil when no previous element.
3204 (org-test-with-parsed-data "* Headline\n*a* b"
3205 (org-export-get-previous-element
3206 (org-element-map tree
'bold
'identity info t
) info
)))
3207 ;; Non-exportable elements are ignored.
3209 (let ((org-export-with-timestamps nil
))
3210 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3211 (org-export-get-previous-element
3212 (org-element-map tree
'entity
'identity info t
) info
))))
3213 ;; Find previous element in secondary strings.
3216 (org-test-with-parsed-data "* =verb= a"
3218 (org-export-get-previous-element
3219 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3222 (org-test-with-parsed-data "* =verb= /italic/"
3224 (org-export-get-previous-element
3225 (org-element-map tree
'italic
'identity info t
) info
)))))
3226 ;; Find previous element in document keywords.
3229 (org-test-with-parsed-data "#+TITLE: =verb= a"
3231 (org-export-get-previous-element
3233 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3234 ;; Find previous element in parsed affiliated keywords.
3237 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3239 (org-export-get-previous-element
3240 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3241 ;; With optional argument N, return a list containing up to
3242 ;; N previous elements.
3244 (equal '(underline italic bold
)
3245 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3247 (org-export-get-previous-element
3248 (org-element-map tree
'code
'identity info t
) info t
)))))
3249 ;; When N is a positive integer, return a list containing up to
3250 ;; N previous elements.
3252 (equal '(italic bold
)
3253 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3255 (org-export-get-previous-element
3256 (org-element-map tree
'code
'identity info t
) info
2))))))
3260 ;;; test-org-export.el end here