1 ;;; test-ox.el --- Tests for ox.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2016 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/>.
26 (unless (featurep 'ox
)
27 (signal 'missing-test-dependency
"org-export"))
29 (defun org-test-default-backend ()
30 "Return a default export back-end.
31 This back-end simply returns parsed data as Org syntax."
32 (org-export-create-backend
34 (mapcar (lambda (type)
38 (intern (format "org-element-%s-interpreter" type
))
40 (append org-element-all-elements org-element-all-objects
))))
42 (defmacro org-test-with-parsed-data
(data &rest body
)
43 "Execute body with parsed data available.
44 DATA is a string containing the data to be parsed. BODY is the
45 body to execute. Parse tree is available under the `tree'
46 variable, and communication channel under `info'."
47 (declare (debug (form body
)) (indent 1))
48 `(org-test-with-temp-text ,data
49 (org-export--delete-comment-trees)
50 (let* ((tree (org-element-parse-buffer))
51 (info (org-combine-plists
52 (org-export--get-export-attributes)
53 (org-export-get-environment))))
54 (org-export--prune-tree tree info
)
55 (org-export--remove-uninterpreted-data tree info
)
56 (let ((info (org-combine-plists
57 info
(org-export--collect-tree-properties tree info
))))
64 (ert-deftest test-org-export
/bind-keyword
()
65 "Test reading #+BIND: keywords."
66 ;; Test with `org-export-allow-bind-keywords' set to t.
68 (org-test-with-temp-text "#+BIND: test-ox-var value"
69 (let ((org-export-allow-bind-keywords t
))
70 (org-export-get-environment)
71 (eq test-ox-var
'value
))))
72 ;; Test with `org-export-allow-bind-keywords' set to nil.
74 (org-test-with-temp-text "#+BIND: test-ox-var value"
75 (let ((org-export-allow-bind-keywords nil
))
76 (org-export-get-environment)
77 (boundp 'test-ox-var
))))
78 ;; BIND keywords are case-insensitive.
80 (org-test-with-temp-text "#+bind: test-ox-var value"
81 (let ((org-export-allow-bind-keywords t
))
82 (org-export-get-environment)
83 (eq test-ox-var
'value
))))
84 ;; Preserve order of BIND keywords.
86 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
87 (let ((org-export-allow-bind-keywords t
))
88 (org-export-get-environment)
90 ;; Read BIND keywords in setup files.
92 (org-test-with-temp-text
93 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
94 (let ((org-export-allow-bind-keywords t
))
95 (org-export-get-environment)
96 (eq variable
'value
))))
97 ;; Verify that bound variables are seen during export.
100 (org-test-with-temp-text "#+BIND: test-ox-var value"
101 (let ((org-export-allow-bind-keywords t
))
103 (org-export-create-backend
105 '((section .
(lambda (s c i
)
106 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
108 (ert-deftest test-org-export
/parse-option-keyword
()
109 "Test reading all standard #+OPTIONS: items."
112 (org-export--parse-option-keyword
113 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t \
114 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil \
116 (and (eq (plist-get options
:headline-levels
) 1)
117 (eq (plist-get options
:section-numbers
) t
)
118 (eq (plist-get options
:preserve-breaks
) t
)
119 (eq (plist-get options
:time-stamp-file
) t
)
120 (eq (plist-get options
:with-archived-trees
) t
)
121 (eq (plist-get options
:with-author
) t
)
122 (eq (plist-get options
:with-drawers
) t
)
123 (eq (plist-get options
:with-email
) t
)
124 (eq (plist-get options
:with-emphasize
) t
)
125 (eq (plist-get options
:with-entities
) t
)
126 (eq (plist-get options
:with-fixed-width
) t
)
127 (eq (plist-get options
:with-footnotes
) t
)
128 (eq (plist-get options
:with-priority
) t
)
129 (eq (plist-get options
:with-special-strings
) t
)
130 (eq (plist-get options
:with-sub-superscript
) t
)
131 (eq (plist-get options
:with-toc
) t
)
132 (eq (plist-get options
:with-tables
) t
)
133 (eq (plist-get options
:with-tags
) t
)
134 (eq (plist-get options
:with-tasks
) t
)
135 (eq (plist-get options
:with-timestamps
) t
)
136 (eq (plist-get options
:with-todo-keywords
) t
)
137 (eq (plist-get options
:with-inlinetasks
) nil
)
138 (eq (plist-get options
:with-statistics-cookies
) t
)
139 (eq (plist-get options
:with-title
) t
))))
140 ;; Test some special values.
143 (org-export--parse-option-keyword
144 "arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo \
146 (and (eq (plist-get options
:with-archived-trees
) 'headline
)
147 (eq (plist-get options
:with-sub-superscript
) '{})
148 (eq (plist-get options
:with-toc
) 1)
149 (eq (plist-get options
:with-tags
) 'not-in-toc
)
150 (eq (plist-get options
:with-tasks
) 'todo
)
151 (eq (plist-get options
:section-numbers
) 2)
152 (eq (plist-get options
:with-timestamps
) 'active
)
153 (equal (plist-get options
:with-drawers
) '("TEST")))))
154 ;; Test back-end specific values.
157 (org-export--parse-option-keyword
158 "opt:t" (org-export-create-backend :options
'((:option nil
"opt"))))
160 ;; More than one property can refer to the same option item.
162 (equal '(:opt1 t
:opt2 t
)
163 (org-export--parse-option-keyword
165 (org-export-create-backend
166 :options
'((:opt1 nil
"opt") (:opt2 nil
"opt")))))))
168 (ert-deftest test-org-export
/get-inbuffer-options
()
169 "Test reading all standard export keywords."
170 ;; Properties should follow buffer order.
173 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
174 (org-export--get-inbuffer-options))
175 '(:language
"fr" :creator
"Me" :email
"email")))
176 ;; Test `space' behaviour.
179 (let ((back-end (org-export-create-backend
180 :options
'((:keyword
"KEYWORD" nil nil space
)))))
181 (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: spaces"
182 (org-export--get-inbuffer-options back-end
)))
183 '(:keyword
"With spaces")))
184 ;; Test `newline' behaviour.
187 (let ((back-end (org-export-create-backend
188 :options
'((:keyword
"KEYWORD" nil nil newline
)))))
189 (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: two lines"
190 (org-export--get-inbuffer-options back-end
)))
191 '(:keyword
"With\ntwo lines")))
192 ;; Test `split' behaviour.
195 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
196 (org-export--get-inbuffer-options))
197 '(:select-tags
("a" "b"))))
198 ;; Test `parse' behaviour. `parse' implies `space' but preserve
199 ;; line breaks. Multi-line objects are allowed.
202 (org-test-with-temp-text "#+TITLE: *bold*"
203 (plist-get (org-export--get-inbuffer-options) :title
))
204 'bold
#'identity nil t
))
207 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
208 (plist-get (org-export--get-inbuffer-options) :title
))
209 '("Some title with spaces")))
212 (org-test-with-temp-text "#+TITLE: Some title\\\\\n#+TITLE: with spaces"
213 (plist-get (org-export--get-inbuffer-options) :title
))
214 'line-break
#'identity nil t
))
217 (org-test-with-temp-text "#+TITLE: *bold\n#+TITLE: sentence*"
218 (plist-get (org-export--get-inbuffer-options) :title
))
219 'bold
#'identity nil t
))
220 ;; Options set through SETUPFILE.
223 (org-test-with-temp-text
224 (format "#+DESCRIPTION: l1
228 #+SETUPFILE: \"%s/examples/setupfile.org\"
233 (org-export--get-inbuffer-options))
234 '(:language
"fr" :select-tags
("a" "b" "c") :title
("a b c"))))
235 ;; Options set through SETUPFILE specified using a URL.
236 (let ((buffer (generate-new-buffer "url-retrieve-output")))
238 ;; Simulate successful retrieval of a setupfile from URL.
239 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
241 (with-current-buffer buffer
242 (insert "HTTP/1.1 200 OK
244 # Contents of http://link-to-my-setupfile.org
245 #+BIND: variable value
255 (org-test-with-temp-text
260 #+SETUPFILE: \"http://link-to-my-setupfile.org\"
264 (org-export--get-inbuffer-options))
265 '(:language
"fr" :select-tags
("a" "b" "c") :title
("a b c")))))
266 (kill-buffer buffer
)))
267 ;; More than one property can refer to the same buffer keyword.
269 (equal '(:k2
"value" :k1
"value")
270 (let ((backend (org-export-create-backend
271 :options
'((:k1
"KEYWORD")
273 (org-test-with-temp-text "#+KEYWORD: value"
274 (org-export--get-inbuffer-options backend
)))))
275 ;; Keywords in commented subtrees are ignored.
278 (org-test-with-parsed-data "* COMMENT H1\n#+AUTHOR: Me"
279 (plist-get info
:author
))))
282 (org-test-with-parsed-data "* COMMENT H1\n** H2\n#+EMAIL: Mine"
283 (plist-get info
:email
)))))
285 (ert-deftest test-org-export
/get-subtree-options
()
286 "Test setting options from headline's properties."
289 (equal '("Subtree Title")
290 (org-test-with-temp-text "#+TITLE: Title
293 :EXPORT_TITLE: Subtree Title
296 (plist-get (org-export-get-environment nil t
) :title
))))
300 (org-test-with-temp-text "#+OPTIONS: H:1
306 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
309 (equal '("29-03-2012")
310 (org-test-with-temp-text "#+DATE: today
313 :EXPORT_DATE: 29-03-2012
316 (plist-get (org-export-get-environment nil t
) :date
))))
317 ;; Properties with `split' behaviour are stored as a list of
321 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
324 :EXPORT_EXCLUDE_TAGS: a b
327 (plist-get (org-export-get-environment nil t
) :exclude-tags
))))
328 ;; Handle :PROPERTY+: syntax.
331 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
334 :EXPORT_EXCLUDE_TAGS: a
335 :EXPORT_EXCLUDE_TAGS+: b
338 (plist-get (org-export-get-environment nil t
) :exclude-tags
))))
339 ;; Export properties are case-insensitive.
341 (equal '("29-03-2012")
342 (org-test-with-temp-text "* Headline
344 :EXPORT_Date: 29-03-2012
347 (plist-get (org-export-get-environment nil t
) :date
))))
348 ;; Still grab correct options when section above is empty.
351 (org-test-with-temp-text "* H1\n** H11\n** H12<point>"
352 (plist-get (org-export-get-environment nil t
) :title
))))
353 ;; More than one property can refer to the same node property.
356 (org-test-with-temp-text
357 "* H\n:PROPERTIES:\n:EXPORT_A: 1\n:END:\n<point>"
358 (let* ((backend (org-export-create-backend
361 (options (org-export-get-environment backend t
)))
362 (list (plist-get options
:k1
) (plist-get options
:k2
)))))))
364 (ert-deftest test-org-export
/set-title
()
365 "Test title setting."
366 ;; Without TITLE keyword.
370 (let (org-export-filter-body-functions
371 org-export-filter-final-output-functions
)
372 (org-test-with-temp-text "Test"
374 (org-export-create-backend
376 '((template .
(lambda (text info
)
377 (org-element-interpret-data
378 (plist-get info
:title
)))))))))))
379 ;; With a blank TITLE keyword.
383 (let (org-export-filter-body-functions
384 org-export-filter-final-output-functions
)
385 (org-test-with-temp-text "#+TITLE:\nTest"
387 (org-export-create-backend
389 '((template .
(lambda (text info
)
390 (org-element-interpret-data
391 (plist-get info
:title
)))))))))))
392 ;; With a non-empty TITLE keyword.
396 (org-test-with-temp-text "#+TITLE: Title\nTest"
398 (org-export-create-backend
400 '((template .
(lambda (text info
)
401 (org-element-interpret-data
402 (plist-get info
:title
))))))))))
403 ;; When exporting a subtree, its heading becomes the headline of the
408 (org-test-with-temp-text "* Headline\nBody"
410 (org-export-create-backend
412 '((template .
(lambda (text info
)
413 (org-element-interpret-data
414 (plist-get info
:title
))))))
416 ;; ... unless there is an EXPORT_TITLE property at the root of the
421 (org-test-with-temp-text
422 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
424 (org-export-create-backend
426 '((template .
(lambda (text info
)
427 (org-element-interpret-data
428 (plist-get info
:title
))))))
431 (ert-deftest test-org-export
/handle-options
()
432 "Test if export options have an impact on output."
433 ;; Test exclude tags for headlines and inlinetasks.
436 (let (org-export-filter-body-functions
437 org-export-filter-final-output-functions
)
438 (org-test-with-temp-text "* Head1 :noexp:"
439 (org-export-as (org-test-default-backend)
440 nil nil nil
'(:exclude-tags
("noexp")))))))
442 (equal "#+FILETAGS: noexp\n"
443 (let (org-export-filter-body-functions
444 org-export-filter-final-output-functions
)
445 (org-test-with-temp-text "#+FILETAGS: noexp\n* Head1"
446 (org-export-as (org-test-default-backend)
447 nil nil nil
'(:exclude-tags
("noexp")))))))
448 ;; Test include tags for headlines and inlinetasks.
450 (equal (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
451 (let ((org-tags-column 0))
452 (org-export-as (org-test-default-backend)
453 nil nil nil
'(:select-tags
("exp")))))
454 "* H2\n** Sub :exp:\n*** Sub Sub\n"))
455 ;; If there is an include tag, ignore the section before the first
458 (equal (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
459 (let ((org-tags-column 0))
460 (org-export-as (org-test-default-backend)
461 nil nil nil
'(:select-tags
("exp")))))
462 "* H1 :exp:\nBody\n"))
464 (equal (org-test-with-temp-text "#+FILETAGS: exp\nFirst section\n* H1\nBody"
465 (org-export-as (org-test-default-backend)
466 nil nil nil
'(:select-tags
("exp"))))
469 (equal (org-test-with-temp-text "* H1 :exp:\nBody"
470 (let ((org-tags-column 0))
471 (org-export-as (org-test-default-backend)
472 nil nil nil
'(:select-tags
("exp")))))
474 ;; Test mixing include tags and exclude tags.
477 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
478 (org-test-with-temp-text "
480 ** Sub-Head1 :noexport:
483 ** Sub-Head1 :export:"
484 (org-export-as (org-test-default-backend) nil nil nil
485 '(:select-tags
("export") :exclude-tags
("noexport"))))))
489 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
490 org-export-filter-body-functions
491 org-export-filter-final-output-functions
)
492 (org-test-with-temp-text "* TODO Head1"
493 (org-export-as (org-test-default-backend)
494 nil nil nil
'(:with-tasks nil
))))))
496 (equal "* TODO Head1\n"
497 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
498 (org-test-with-temp-text "* TODO Head1"
499 (org-export-as (org-test-default-backend)
500 nil nil nil
'(:with-tasks t
))))))
504 (let (org-export-filter-body-functions
505 org-export-filter-final-output-functions
)
506 (org-test-with-temp-text "* Head1 :archive:"
507 (let ((org-archive-tag "archive"))
508 (org-export-as (org-test-default-backend)
509 nil nil nil
'(:with-archived-trees nil
)))))))
512 "\\* Head1[ \t]+:archive:"
513 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
514 (let ((org-archive-tag "archive"))
515 (org-export-as (org-test-default-backend) nil nil nil
516 '(:with-archived-trees headline
))))))
519 "\\`\\* Head1[ \t]+:archive:\n\\'"
520 (org-test-with-temp-text "* Head1 :archive:"
521 (let ((org-archive-tag "archive"))
522 (org-export-as (org-test-default-backend)
523 nil nil nil
'(:with-archived-trees t
))))))
524 ;; Broken links. Depending on `org-export-with-broken-links', raise
525 ;; an error, ignore link or mark is as broken in output.
527 (org-test-with-temp-text "[[#broken][link]]"
529 (org-export-create-backend
531 '((section .
(lambda (_e c _i
) c
))
532 (paragraph .
(lambda (_e c _i
) c
))
533 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
534 (org-export-as backend nil nil nil
'(:with-broken-links nil
)))))
536 (org-test-with-temp-text "[[#broken][link]]"
538 (org-export-create-backend
540 '((section .
(lambda (_e c _i
) c
))
541 (paragraph .
(lambda (_e c _i
) c
))
542 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
543 (org-export-as backend nil nil nil
'(:with-broken-links t
)))))
545 (org-test-with-temp-text "[[#broken][link]]"
547 (org-export-create-backend
549 '((section .
(lambda (_e c _i
) c
))
550 (paragraph .
(lambda (_e c _i
) c
))
551 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
553 (org-export-as backend nil nil nil
'(:with-broken-links mark
))))))
556 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
557 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
558 (org-export-as (org-test-default-backend)
559 nil nil nil
'(:with-clocks t
)))))
562 (let (org-export-filter-body-functions
563 org-export-filter-final-output-functions
)
564 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
565 (org-export-as (org-test-default-backend)
566 nil nil nil
'(:with-clocks nil
))))))
570 (let (org-export-filter-body-functions
571 org-export-filter-final-output-functions
)
572 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
573 (org-export-as (org-test-default-backend)
574 nil nil nil
'(:with-drawers nil
))))))
576 (equal ":TEST:\ncontents\n:END:\n"
577 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
578 (org-export-as (org-test-default-backend)
579 nil nil nil
'(:with-drawers t
)))))
581 (equal ":FOO:\nkeep\n:END:\n"
582 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
583 (org-export-as (org-test-default-backend)
584 nil nil nil
'(:with-drawers
("FOO"))))))
586 (equal ":FOO:\nkeep\n:END:\n"
587 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
588 (org-export-as (org-test-default-backend)
589 nil nil nil
'(:with-drawers
(not "BAR"))))))
593 (org-test-with-temp-text ": A"
594 (org-export-as (org-test-default-backend) nil nil nil
595 '(:with-fixed-width t
)))))
598 (let (org-export-filter-body-functions
599 org-export-filter-final-output-functions
)
600 (org-test-with-temp-text ": A"
601 (org-export-as (org-test-default-backend) nil nil nil
602 '(:with-fixed-width nil
))))))
606 (let ((org-footnote-section nil
))
607 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
608 (org-trim (org-export-as (org-test-default-backend)
609 nil nil nil
'(:with-footnotes nil
)))))))
611 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
612 (let ((org-footnote-section nil
))
613 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
614 (org-trim (org-export-as (org-test-default-backend)
615 nil nil nil
'(:with-footnotes t
)))))))
617 (when (featurep 'org-inlinetask
)
621 (let ((org-inlinetask-min-level 15)
622 org-export-filter-body-functions
623 org-export-filter-final-output-functions
)
624 (org-test-with-temp-text "*************** Task"
625 (org-export-as (org-test-default-backend)
626 nil nil nil
'(:with-inlinetasks nil
))))))
630 (let ((org-inlinetask-min-level 15)
631 org-export-filter-body-functions
632 org-export-filter-final-output-functions
)
633 (org-test-with-temp-text
634 "*************** Task\nContents\n*************** END"
635 (org-export-as (org-test-default-backend)
636 nil nil nil
'(:with-inlinetasks nil
)))))))
640 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
641 (let ((org-closed-string "CLOSED:"))
642 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
643 (org-export-as (org-test-default-backend)
644 nil nil nil
'(:with-planning t
))))))
647 (let ((org-closed-string "CLOSED:"))
648 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
649 (org-export-as (org-test-default-backend)
650 nil nil nil
'(:with-planning nil
))))))
654 (org-test-with-temp-text
655 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
656 (org-export-as (org-test-default-backend)
657 nil nil nil
'(:with-properties nil
)))))
659 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
660 (org-test-with-temp-text
661 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
662 (org-export-as (org-test-default-backend)
663 nil nil nil
'(:with-properties t
)))))
665 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
666 (org-test-with-temp-text
667 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
668 (org-export-as (org-test-default-backend)
669 nil nil nil
'(:with-properties
("B"))))))
670 ;; Statistics cookies.
673 (let (org-export-filter-body-functions
674 org-export-filter-final-output-functions
)
676 (org-test-with-temp-text "* Stats [0/0]"
677 (org-export-as (org-test-default-backend)
678 nil nil nil
'(:with-statistics-cookies nil
)))))))
682 (org-test-with-temp-text "| A |"
683 (org-export-as (org-test-default-backend) nil nil nil
684 '(:with-tables t
)))))
687 (let (org-export-filter-body-functions
688 org-export-filter-final-output-functions
)
689 (org-test-with-temp-text "| A |"
690 (org-export-as (org-test-default-backend) nil nil nil
691 '(:with-tables nil
)))))))
693 (ert-deftest test-org-export
/with-timestamps
()
694 "Test `org-export-with-timestamps' specifications."
698 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
699 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
700 (org-export-as (org-test-default-backend)
701 nil nil nil
'(:with-timestamps t
)))))
706 (let (org-export-filter-body-functions
707 org-export-filter-final-output-functions
)
709 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
710 (org-export-as (org-test-default-backend)
711 nil nil nil
'(:with-timestamps nil
)))))))
715 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
716 (org-test-with-temp-text
717 "<2012-03-29 Thu>[2012-03-29 Thu]
719 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
720 (org-export-as (org-test-default-backend)
721 nil nil nil
'(:with-timestamps active
)))))
725 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
726 (org-test-with-temp-text
727 "<2012-03-29 Thu>[2012-03-29 Thu]
729 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
730 (org-export-as (org-test-default-backend)
731 nil nil nil
'(:with-timestamps inactive
))))))
733 (ert-deftest test-org-export
/comment-tree
()
734 "Test if export process ignores commented trees."
737 (let (org-export-filter-body-functions
738 org-export-filter-final-output-functions
)
739 (org-test-with-temp-text "* COMMENT Head1"
740 (org-export-as (org-test-default-backend)))))))
742 (ert-deftest test-org-export
/uninterpreted
()
743 "Test handling of uninterpreted elements."
747 (org-test-with-temp-text "\\alpha"
749 (org-export-create-backend
750 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
751 (paragraph .
(lambda (p c i
) c
))
752 (section .
(lambda (s c i
) c
))))
753 nil nil nil
'(:with-entities t
)))))
756 (org-test-with-temp-text "\\alpha"
758 (org-export-create-backend
759 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
760 (paragraph .
(lambda (p c i
) c
))
761 (section .
(lambda (s c i
) c
))))
762 nil nil nil
'(:with-entities nil
)))))
766 (org-test-with-temp-text "*bold*"
768 (org-export-create-backend
769 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
770 (paragraph .
(lambda (p c i
) c
))
771 (section .
(lambda (s c i
) c
))))
772 nil nil nil
'(:with-emphasize t
)))))
775 (org-test-with-temp-text "*bold*"
777 (org-export-create-backend
778 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
779 (paragraph .
(lambda (p c i
) c
))
780 (section .
(lambda (s c i
) c
))))
781 nil nil nil
'(:with-emphasize nil
)))))
783 (equal "/simple/ /example/\n"
784 (org-test-with-temp-text "/simple/ /example/"
786 (org-export-create-backend
787 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
788 (paragraph .
(lambda (p c i
) c
))
789 (section .
(lambda (s c i
) c
))))
790 nil nil nil
'(:with-emphasize nil
)))))
791 ;; LaTeX environment.
794 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
796 (org-export-create-backend
797 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
798 (section .
(lambda (s c i
) c
))))
799 nil nil nil
'(:with-latex t
)))))
801 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
802 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
804 (org-export-create-backend
805 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
806 (section .
(lambda (s c i
) c
))))
807 nil nil nil
'(:with-latex verbatim
)))))
811 (org-test-with-temp-text "$1$"
813 (org-export-create-backend
814 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
815 (paragraph .
(lambda (p c i
) c
))
816 (section .
(lambda (s c i
) c
))))
817 nil nil nil
'(:with-latex t
)))))
820 (org-test-with-temp-text "$1$"
822 (org-export-create-backend
823 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
824 (paragraph .
(lambda (p c i
) c
))
825 (section .
(lambda (s c i
) c
))))
826 nil nil nil
'(:with-latex verbatim
)))))
830 (org-test-with-temp-text "a_b"
832 (org-export-create-backend
833 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
834 (paragraph .
(lambda (p c i
) c
))
835 (section .
(lambda (s c i
) c
))))
836 nil nil nil
'(:with-sub-superscript t
)))))
839 (org-test-with-temp-text "a_b"
841 (org-export-create-backend
842 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
843 (paragraph .
(lambda (p c i
) c
))
844 (section .
(lambda (s c i
) c
))))
845 nil nil nil
'(:with-sub-superscript nil
)))))
848 (org-test-with-temp-text "a_b"
850 (org-export-create-backend
851 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
852 (paragraph .
(lambda (p c i
) c
))
853 (section .
(lambda (s c i
) c
))))
854 nil nil nil
'(:with-sub-superscript
{})))))
857 (org-test-with-temp-text "a_{b}"
859 (org-export-create-backend
860 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
861 (paragraph .
(lambda (p c i
) c
))
862 (section .
(lambda (s c i
) c
))))
863 nil nil nil
'(:with-sub-superscript
{})))))
866 (org-test-with-temp-text "a_\\alpha"
868 (org-export-create-backend
869 :transcoders
'((entity .
(lambda (e c i
) "entity"))
870 (subscript .
(lambda (s c i
) "dummy"))
871 (paragraph .
(lambda (p c i
) c
))
872 (section .
(lambda (s c i
) c
))))
873 nil nil nil
'(:with-sub-superscript nil
)))))
874 ;; Handle uninterpreted objects in parsed keywords.
877 (org-test-with-temp-text "#+TITLE: a_b"
879 (org-export-create-backend
881 '((subscript .
(lambda (s c i
) "dummy"))
882 (template .
(lambda (c i
)
883 (org-export-data (plist-get i
:title
) i
)))
884 (section .
(lambda (s c i
) c
))))
885 nil nil nil
'(:with-sub-superscript nil
)))))
888 (org-test-with-temp-text "#+FOO: a_b"
890 (org-export-create-backend
892 '((:foo
"FOO" nil nil parse
))
894 '((subscript .
(lambda (s c i
) "dummy"))
895 (template .
(lambda (c i
)
896 (org-export-data (plist-get i
:foo
) i
)))
897 (section .
(lambda (s c i
) c
))))
898 nil nil nil
'(:with-sub-superscript nil
)))))
899 ;; Objects in parsed keywords are "uninterpreted" before filters are
902 (org-test-with-temp-text "#+TITLE: a_b"
904 (org-export-create-backend
908 (org-element-map (plist-get i
:title
) 'subscript
909 (lambda (_) (error "There should be no subscript here")))))))
910 nil nil nil
'(:with-sub-superscript nil
))))
911 ;; Handle uninterpreted objects in captions.
914 (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
916 (org-export-create-backend
918 '((subscript .
(lambda (s c i
) "dummy"))
919 (paragraph .
(lambda (p c i
)
920 (org-export-data (org-export-get-caption p
) i
)))
921 (section .
(lambda (s c i
) c
))))
922 nil nil nil
'(:with-sub-superscript t
)))))
925 (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
927 (org-export-create-backend
929 '((subscript .
(lambda (s c i
) "dummy"))
930 (paragraph .
(lambda (p c i
)
931 (org-export-data (org-export-get-caption p
) i
)))
932 (section .
(lambda (s c i
) c
))))
933 nil nil nil
'(:with-sub-superscript nil
)))))
934 ;; Special case: multiples uninterpreted objects in a row.
937 (org-test-with-temp-text "a_b_c_d"
939 (org-export-create-backend
940 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
941 (paragraph .
(lambda (p c i
) c
))
942 (section .
(lambda (s c i
) c
))))
943 nil nil nil
'(:with-sub-superscript
{}))))))
945 (ert-deftest test-org-export
/export-scope
()
946 "Test all export scopes."
949 (equal "text\n*** H3\n"
950 (org-test-with-temp-text "* H1\n<point>** H2\ntext\n*** H3"
951 (org-export-as (org-test-default-backend) 'subtree
))))
953 (equal "text\n*** H3\n"
954 (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
955 (org-export-as (org-test-default-backend) 'subtree
))))
956 ;; Subtree with a code block calling another block outside.
959 (org-test-with-temp-text "
961 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
966 #+BEGIN_SRC emacs-lisp
969 (let ((org-export-use-babel t
))
970 (org-export-as (org-test-default-backend) 'subtree
)))))
971 ;; Subtree export should ignore leading planning line and property
975 (org-test-with-temp-text "
977 SCHEDULED: <2012-03-29 Thu>
982 (org-export-as (org-test-default-backend)
984 '(:with-planning t
:with-properties t
)))))
988 (org-test-with-temp-text "* H1\n** H2\ntext\n*** H3"
990 (org-export-as (org-test-default-backend) nil
'visible
))))
994 (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
995 (transient-mark-mode 1)
996 (push-mark (point) t t
)
998 (org-export-as (org-test-default-backend)))))
1002 (org-test-with-temp-text "Text"
1004 (org-export-create-backend
1006 '((template .
(lambda (b _i
) (format "BEGIN\n%sEND" b
)))
1007 (section .
(lambda (_s c _i
) c
))
1008 (paragraph .
(lambda (_p c _i
) c
))))
1009 nil nil
'body-only
))))
1011 (equal "BEGIN\nText\nEND"
1012 (org-test-with-temp-text "Text"
1014 (org-export-create-backend
1016 '((template .
(lambda (b _i
) (format "BEGIN\n%sEND" b
)))
1017 (section .
(lambda (_s c _i
) c
))
1018 (paragraph .
(lambda (_p c _i
) c
))))))))
1019 ;; Pathological case: Body only on an empty buffer is expected to
1020 ;; return an empty string, not nil.
1022 (org-test-with-temp-text ""
1023 (org-export-as (org-test-default-backend) nil nil t
))))
1025 (ert-deftest test-org-export
/output-file-name
()
1026 "Test `org-export-output-file-name' specifications."
1027 ;; Export from a file: name is built from original file name.
1029 (org-test-with-temp-text-in-file "Test"
1030 (equal (file-name-base (buffer-file-name))
1031 (file-name-base (org-export-output-file-name ".ext")))))
1032 ;; When #+EXPORT_FILE_NAME is defined, use it.
1035 (org-test-with-temp-text-in-file "#+EXPORT_FILE_NAME: test"
1036 (org-export-output-file-name ".ext" t
))))
1037 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
1040 (org-test-with-temp-text-in-file
1041 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
1042 (org-export-output-file-name ".ext" t
))))
1044 (equal "property.ext"
1045 (org-test-with-temp-text
1046 "#+EXPORT_FILE_NAME: keyword
1049 :EXPORT_FILE_NAME: property
1051 (org-export-output-file-name ".ext" t
))))
1052 ;; From a buffer not associated to a file, too.
1055 (org-test-with-temp-text
1056 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
1057 (org-export-output-file-name ".ext" t
))))
1058 ;; When provided name is absolute, preserve it.
1060 (org-test-with-temp-text
1061 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
1062 (expand-file-name "test"))
1063 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
1064 ;; When PUB-DIR argument is provided, use it.
1067 (org-test-with-temp-text-in-file "Test"
1068 (file-name-directory
1069 (org-export-output-file-name ".ext" nil
"dir/")))))
1070 ;; PUB-DIR has precedence over EXPORT_FILE_NAME keyword or property.
1073 (org-test-with-temp-text-in-file
1074 "#+EXPORT_FILE_NAME: /dir/keyword\nTest"
1075 (file-name-directory
1076 (org-export-output-file-name ".ext" nil
"pub-dir/")))))
1077 ;; When returned name would overwrite original file, add EXTENSION
1080 (equal "normal.org.org"
1081 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1082 (org-export-output-file-name ".org")))))
1084 (ert-deftest test-org-export
/expand-include
()
1085 "Test file inclusion in an Org buffer."
1086 ;; Error when file isn't specified.
1088 (org-test-with-temp-text "#+INCLUDE: dummy.org"
1089 (org-export-expand-include-keyword)))
1090 ;; Refuse to expand keywords in commented headings.
1092 (org-test-with-temp-text "* COMMENT H1\n#+INCLUDE: dummy.org"
1093 (org-export-expand-include-keyword)
1095 ;; Full insertion with recursive inclusion.
1100 (expand-file-name "examples/include.org" org-test-dir
))
1101 (replace-regexp-in-string
1102 (regexp-quote "#+INCLUDE: \"include2.org\"")
1103 "Success!" (buffer-string)))
1104 (org-test-with-temp-text
1105 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
1106 (org-export-expand-include-keyword)
1108 ;; Localized insertion.
1109 (org-test-with-temp-text
1110 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
1112 (org-export-expand-include-keyword)
1113 (should (equal (buffer-string)
1114 "Small Org file with an include keyword.\n")))
1115 ;; Insertion with constraints on headlines level.
1118 "* Top heading\n** Heading\nbody\n"
1119 (org-test-with-temp-text
1121 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
1123 (org-export-expand-include-keyword)
1127 "* Top heading\n* Heading\nbody\n"
1128 (org-test-with-temp-text
1130 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
1132 (org-export-expand-include-keyword)
1134 ;; Inclusion within an example block.
1137 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
1138 (org-test-with-temp-text
1139 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
1141 (org-export-expand-include-keyword)
1143 ;; Inclusion within a src-block.
1146 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
1147 (org-test-with-temp-text
1149 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
1151 (org-export-expand-include-keyword)
1153 ;; Inclusion within an html export-block.
1156 "#+BEGIN_EXPORT html\n<p>HTML!</p>\n#+END_EXPORT\n"
1157 (org-test-with-temp-text
1159 "#+INCLUDE: \"%s/examples/include.html\" EXPORT html"
1161 (org-export-expand-include-keyword)
1163 ;; Inclusion within an center paragraph
1166 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
1167 (org-test-with-temp-text
1169 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
1171 (org-export-expand-include-keyword)
1173 ;; Footnotes labels are local to each included file.
1179 Footnotes[fn:1], [fn:test], [fn:test] and [fn:inline:inline footnote].
1181 \[fn:test] Footnote \"test\""))
1182 (org-test-with-temp-text-in-file contents
1183 (let ((file1 (buffer-file-name)))
1184 (org-test-with-temp-text-in-file contents
1185 (let ((file2 (buffer-file-name)))
1186 (org-test-with-temp-text
1187 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
1189 (org-export-expand-include-keyword)
1190 (org-element-map (org-element-parse-buffer)
1192 (lambda (r) (org-element-property :label r
)))))))))))))
1193 ;; Footnotes labels are not local to each include keyword.
1199 Footnotes[fn:1], [fn:test] and [fn:inline:inline footnote].
1201 \[fn:test] Footnote \"test\""))
1202 (org-test-with-temp-text-in-file contents
1203 (let ((file (buffer-file-name)))
1204 (org-test-with-temp-text
1205 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
1206 (org-export-expand-include-keyword)
1207 (org-element-map (org-element-parse-buffer)
1209 (lambda (ref) (org-element-property :label ref
)))))))))))
1210 ;; Footnotes are supported by :lines-like elements and unnecessary
1211 ;; footnotes are dropped.
1220 Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
1225 \[fn:test] Footnote \"test\"
1227 (org-test-with-temp-text-in-file contents
1228 (let ((file (buffer-file-name)))
1229 (org-test-with-temp-text
1230 (format "#+INCLUDE: \"%s::*bar\"\n" file
)
1231 (org-export-expand-include-keyword)
1232 (org-element-map (org-element-parse-buffer)
1233 'footnote-definition
1234 (lambda (ref) (org-element-property :label ref
)))))))))))
1235 ;; If only-contents is non-nil only include contents of element.
1239 (org-test-with-temp-text
1241 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" "
1244 (org-export-expand-include-keyword)
1246 ;; Headings can be included via CUSTOM_ID.
1248 (org-test-with-temp-text
1249 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1250 (org-export-expand-include-keyword)
1251 (goto-char (point-min))
1252 (looking-at "* Another heading")))
1253 ;; Named objects can be included.
1257 (org-test-with-temp-text
1258 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t"
1260 (org-export-expand-include-keyword)
1262 ;; Including non-existing elements should result in an error.
1264 (org-test-with-temp-text
1265 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\""
1267 (org-export-expand-include-keyword)))
1268 ;; Lines work relatively to an included element.
1272 (org-test-with-temp-text
1273 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t \
1276 (org-export-expand-include-keyword)
1278 ;; Properties should be dropped from headlines.
1281 (org-test-with-temp-text
1282 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t"
1284 (org-export-expand-include-keyword)
1286 (org-test-with-temp-text
1287 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1288 (org-export-expand-include-keyword)
1290 ;; Properties should be dropped, drawers should not be.
1293 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1294 (org-test-with-temp-text
1295 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t"
1297 (org-export-expand-include-keyword)
1299 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1301 (cl-every (lambda (level) (zerop (1- level
)))
1302 (org-test-with-temp-text
1304 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n"
1306 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\""
1308 (org-export-expand-include-keyword)
1309 (org-element-map (org-element-parse-buffer) 'headline
1310 (lambda (head) (org-element-property :level head
))))))
1311 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1314 (org-test-with-temp-text
1315 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp"
1317 (org-export-expand-include-keyword)
1319 (org-test-with-temp-text
1321 "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1"
1323 (org-export-expand-include-keyword)
1325 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1327 (org-test-with-temp-text-in-file
1328 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\""
1330 (narrow-to-region (point) (point-max))
1331 (org-export-expand-include-keyword)
1332 (eq 1 (org-current-level))))
1333 ;; If :minlevel is present do not alter it.
1335 (org-test-with-temp-text
1337 "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3"
1339 (narrow-to-region (point) (point-max))
1340 (org-export-expand-include-keyword)
1341 (eq 3 (org-current-level)))))
1343 (ert-deftest test-org-export
/expand-macro
()
1344 "Test macro expansion in an Org buffer."
1346 ;; Standard macro expansion.
1348 (equal "#+MACRO: macro1 value\nvalue\n"
1349 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1350 (org-export-as (org-test-default-backend)))))
1351 ;; Include global macros. However, local macros override them.
1354 (org-test-with-temp-text "{{{M}}}"
1355 (let ((org-export-global-macros '(("M" .
"global"))))
1356 (org-export-as (org-test-default-backend))))))
1358 (equal "global arg\n"
1359 (org-test-with-temp-text "{{{M(arg)}}}"
1360 (let ((org-export-global-macros '(("M" .
"global $1"))))
1361 (org-export-as (org-test-default-backend))))))
1364 (org-test-with-temp-text "{{{M}}}"
1365 (let ((org-export-global-macros '(("M" .
"(eval (+ 1 1))"))))
1366 (org-export-as (org-test-default-backend))))))
1368 (equal "#+MACRO: M local\nlocal\n"
1369 (org-test-with-temp-text "#+macro: M local\n{{{M}}}"
1370 (let ((org-export-global-macros '(("M" .
"global"))))
1371 (org-export-as (org-test-default-backend))))))
1372 ;; Allow macro in parsed keywords and associated properties.
1373 ;; Standard macro expansion.
1377 (let ((backend (org-export-create-backend
1379 :options
'((:k
"K" nil nil parse
)))))
1380 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1381 (org-export-as backend
)))))
1385 (let ((backend (org-export-create-backend
1387 :options
'((:k
"K" nil nil parse
)))))
1388 (org-test-with-temp-text
1389 "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1390 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1391 ;; Expand specific macros.
1393 (equal "me 2012-03-29 me@here Title\n"
1394 (org-test-with-temp-text
1400 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1401 (let ((output (org-export-as (org-test-default-backend))))
1402 (substring output
(string-match ".*\n\\'" output
))))))
1403 ;; Expand specific macros when property contained a regular macro
1407 (org-test-with-temp-text "
1408 #+MACRO: macro1 value
1409 #+TITLE: {{{macro1}}}
1411 (let ((output (org-export-as (org-test-default-backend))))
1412 (substring output
(string-match ".*\n\\'" output
))))))
1413 ;; Expand macros with templates in included files.
1416 (org-test-with-temp-text
1417 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1418 {{{included-macro}}}" org-test-dir
)
1419 (let ((output (org-export-as (org-test-default-backend))))
1420 (substring output
(string-match ".*\n\\'" output
))))))
1421 ;; Date macro takes a optional formatting argument
1424 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1425 (org-export-as (org-test-default-backend)))))
1426 ;; Only single timestamps are formatted
1428 (equal "<2015-02x-09>\n"
1429 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1430 (org-export-as (org-test-default-backend)))))
1431 ;; Throw an error when a macro definition is missing.
1433 (org-test-with-temp-text "{{{missing}}}"
1434 (org-export-as (org-test-default-backend))))
1435 ;; Inline source blocks generate {{{results}}} macros. Evaluate
1439 (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
1440 (let ((org-export-use-babel t
)
1441 (org-babel-inline-result-wrap "=%s="))
1442 (org-export-as (org-test-default-backend)))))))
1444 (ert-deftest test-org-export
/before-processing-hook
()
1445 "Test `org-export-before-processing-hook'."
1448 "#+MACRO: mac val\nTest\n"
1449 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1450 (let ((org-export-before-processing-hook
1452 (while (re-search-forward "{{{" nil t
)
1453 (let ((object (org-element-context)))
1454 (when (eq (org-element-type object
) 'macro
)
1456 (org-element-property :begin object
)
1457 (org-element-property :end object
)))))))))
1458 (org-export-as (org-test-default-backend)))))))
1460 (ert-deftest test-org-export
/before-parsing-hook
()
1461 "Test `org-export-before-parsing-hook'."
1463 (equal "Body 1\nBody 2\n"
1464 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1465 (let ((org-export-before-parsing-hook
1467 (goto-char (point-min))
1468 (while (re-search-forward org-outline-regexp-bol nil t
)
1470 (point-at-bol) (progn (forward-line) (point))))))))
1471 (org-export-as (org-test-default-backend)))))))
1475 ;;; Affiliated Keywords
1477 (ert-deftest test-org-export
/read-attribute
()
1478 "Test `org-export-read-attribute' specifications."
1482 (org-export-read-attribute
1484 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1485 (org-element-at-point)))
1487 ;; Return nil on empty attribute.
1489 (org-export-read-attribute
1491 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1492 ;; Return nil on "nil" string.
1494 (equal '(:a nil
:b nil
)
1495 (org-export-read-attribute
1497 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1498 (org-element-at-point)))))
1499 ;; Return nil on empty string.
1501 (equal '(:a nil
:b nil
)
1502 (org-export-read-attribute
1504 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1505 (org-element-at-point)))))
1506 ;; Return empty string when value is "".
1509 (org-export-read-attribute
1511 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1512 (org-element-at-point)))))
1513 ;; Return \"\" when value is """".
1516 (org-export-read-attribute
1518 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1519 (org-element-at-point)))))
1520 ;; Ignore text before first property.
1523 (org-export-read-attribute
1525 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1526 (org-element-at-point))))))
1528 (ert-deftest test-org-export
/get-caption
()
1529 "Test `org-export-get-caption' specifications."
1530 ;; Without optional argument, return long caption
1534 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1535 (org-export-get-caption (org-element-at-point)))))
1536 ;; With optional argument, return short caption.
1540 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1541 (org-export-get-caption (org-element-at-point) t
))))
1542 ;; Multiple lines are separated by white spaces.
1546 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1547 (org-export-get-caption (org-element-at-point))))))
1553 (ert-deftest test-org-export
/define-backend
()
1554 "Test back-end definition and accessors."
1557 (equal '((headline . my-headline-test
))
1558 (let (org-export-registered-backends)
1559 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1560 (org-export-get-all-transcoders 'test
))))
1563 (equal '((:filter-headline . my-filter
))
1564 (let (org-export-registered-backends)
1565 (org-export-define-backend 'test
1566 '((headline . my-headline-test
))
1567 :filters-alist
'((:filter-headline . my-filter
)))
1568 (org-export-backend-filters (org-export-get-backend 'test
)))))
1571 (equal '((:prop value
))
1572 (let (org-export-registered-backends)
1573 (org-export-define-backend 'test
1574 '((headline . my-headline-test
))
1575 :options-alist
'((:prop value
)))
1576 (org-export-backend-options (org-export-get-backend 'test
)))))
1579 (equal '(?k
"Test Export" test
)
1580 (let (org-export-registered-backends)
1581 (org-export-define-backend 'test
1582 '((headline . my-headline-test
))
1583 :menu-entry
'(?k
"Test Export" test
))
1584 (org-export-backend-menu (org-export-get-backend 'test
))))))
1586 (ert-deftest test-org-export
/define-derived-backend
()
1587 "Test `org-export-define-derived-backend' specifications."
1588 ;; Error when parent back-end is not defined.
1590 (let (org-export-registered-backends)
1591 (org-export-define-derived-backend 'test
'parent
)))
1592 ;; Append translation table to parent's.
1594 (equal '((:headline . test
) (:headline . parent
))
1595 (let (org-export-registered-backends)
1596 (org-export-define-backend 'parent
'((:headline . parent
)))
1597 (org-export-define-derived-backend 'test
'parent
1598 :translate-alist
'((:headline . test
)))
1599 (org-export-get-all-transcoders 'test
))))
1600 ;; Options defined in the new back have priority over those defined
1604 (let (org-export-registered-backends)
1605 (org-export-define-backend 'parent
1606 '((:headline . parent
))
1607 :options-alist
'((:a nil nil
'parent
)))
1608 (org-export-define-derived-backend 'test
'parent
1609 :options-alist
'((:a nil nil
'test
)))
1610 (plist-get (org-export--get-global-options
1611 (org-export-get-backend 'test
))
1614 (ert-deftest test-org-export
/derived-backend-p
()
1615 "Test `org-export-derived-backend-p' specifications."
1616 ;; Non-nil with direct match.
1618 (let (org-export-registered-backends)
1619 (org-export-define-backend 'test
'((headline . test
)))
1620 (org-export-derived-backend-p 'test
'test
)))
1622 (let (org-export-registered-backends)
1623 (org-export-define-backend 'test
'((headline . test
)))
1624 (org-export-define-derived-backend 'test2
'test
)
1625 (org-export-derived-backend-p 'test2
'test2
)))
1626 ;; Non-nil with a direct parent.
1628 (let (org-export-registered-backends)
1629 (org-export-define-backend 'test
'((headline . test
)))
1630 (org-export-define-derived-backend 'test2
'test
)
1631 (org-export-derived-backend-p 'test2
'test
)))
1632 ;; Non-nil with an indirect parent.
1634 (let (org-export-registered-backends)
1635 (org-export-define-backend 'test
'((headline . test
)))
1636 (org-export-define-derived-backend 'test2
'test
)
1637 (org-export-define-derived-backend 'test3
'test2
)
1638 (org-export-derived-backend-p 'test3
'test
)))
1641 (let (org-export-registered-backends)
1642 (org-export-define-backend 'test
'((headline . test
)))
1643 (org-export-define-backend 'test2
'((headline . test2
)))
1644 (org-export-derived-backend-p 'test2
'test
)))
1646 (let (org-export-registered-backends)
1647 (org-export-define-backend 'test
'((headline . test
)))
1648 (org-export-define-backend 'test2
'((headline . test2
)))
1649 (org-export-define-derived-backend 'test3
'test2
)
1650 (org-export-derived-backend-p 'test3
'test
))))
1652 (ert-deftest test-org-export
/get-all-transcoders
()
1653 "Test `org-export-get-all-transcoders' specifications."
1654 ;; Return nil when back-end cannot be found.
1655 (should-not (org-export-get-all-transcoders nil
))
1656 ;; Same as `org-export-transcoders' if no parent.
1658 (equal '((headline . ignore
))
1659 (org-export-get-all-transcoders
1660 (org-export-create-backend
1661 :transcoders
'((headline . ignore
))))))
1662 ;; But inherit from all ancestors whenever possible.
1664 (equal '((section . ignore
) (headline . ignore
))
1665 (let (org-export-registered-backends)
1666 (org-export-define-backend 'b1
'((headline . ignore
)))
1667 (org-export-get-all-transcoders
1668 (org-export-create-backend
1669 :parent
'b1
:transcoders
'((section . ignore
)))))))
1671 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1672 (let (org-export-registered-backends)
1673 (org-export-define-backend 'b1
'((headline . ignore
)))
1674 (org-export-define-derived-backend 'b2
'b1
1675 :translate-alist
'((section . ignore
)))
1676 (org-export-get-all-transcoders
1677 (org-export-create-backend
1678 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1679 ;; Back-end transcoders overrule inherited ones.
1682 (let (org-export-registered-backends)
1683 (org-export-define-backend 'b1
'((headline . a
)))
1684 (cdr (assq 'headline
1685 (org-export-get-all-transcoders
1686 (org-export-create-backend
1687 :parent
'b1
:transcoders
'((headline . b
))))))))))
1689 (ert-deftest test-org-export
/get-all-options
()
1690 "Test `org-export-get-all-options' specifications."
1691 ;; Return nil when back-end cannot be found.
1692 (should-not (org-export-get-all-options nil
))
1693 ;; Same as `org-export-options' if no parent.
1695 (equal '((headline . ignore
))
1696 (org-export-get-all-options
1697 (org-export-create-backend
1698 :options
'((headline . ignore
))))))
1699 ;; But inherit from all ancestors whenever possible.
1701 (equal '((:key2 value2
) (:key1 value1
))
1702 (let (org-export-registered-backends)
1703 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1704 (org-export-get-all-options
1705 (org-export-create-backend
1706 :parent
'b1
:options
'((:key2 value2
)))))))
1708 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1709 (let (org-export-registered-backends)
1710 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1711 (org-export-define-derived-backend 'b2
'b1
1712 :options-alist
'((:key2 value2
)))
1713 (org-export-get-all-options
1714 (org-export-create-backend
1715 :parent
'b2
:options
'((:key3 value3
)))))))
1716 ;; Back-end options overrule inherited ones.
1719 (let (org-export-registered-backends)
1720 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1722 (org-export-get-all-options
1723 (org-export-create-backend
1724 :parent
'b1
:options
'((:key1 . b
))))))))))
1726 (ert-deftest test-org-export
/get-all-filters
()
1727 "Test `org-export-get-all-filters' specifications."
1728 ;; Return nil when back-end cannot be found.
1729 (should-not (org-export-get-all-filters nil
))
1730 ;; Same as `org-export-filters' if no parent.
1732 (equal '((:filter-headline . ignore
))
1733 (org-export-get-all-filters
1734 (org-export-create-backend
1735 :filters
'((:filter-headline . ignore
))))))
1736 ;; But inherit from all ancestors whenever possible.
1738 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1739 (let (org-export-registered-backends)
1740 (org-export-define-backend 'b1
1741 nil
:filters-alist
'((:filter-headline . ignore
)))
1742 (org-export-get-all-filters
1743 (org-export-create-backend
1744 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1746 (equal '((:filter-paragraph . ignore
)
1747 (:filter-section . ignore
)
1748 (:filter-headline . ignore
))
1749 (let (org-export-registered-backends)
1750 (org-export-define-backend 'b1
1751 nil
:filters-alist
'((:filter-headline . ignore
)))
1752 (org-export-define-derived-backend 'b2
'b1
1753 :filters-alist
'((:filter-section . ignore
)))
1754 (org-export-get-all-filters
1755 (org-export-create-backend
1756 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1757 ;; Back-end filters overrule inherited ones.
1760 (let (org-export-registered-backends)
1761 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1762 (cdr (assq :filter-headline
1763 (org-export-get-all-filters
1764 (org-export-create-backend
1765 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1767 (ert-deftest test-org-export
/with-backend
()
1768 "Test `org-export-with-backend' definition."
1769 ;; Error when calling an undefined back-end
1770 (should-error (org-export-with-backend nil
"Test"))
1771 ;; Error when called back-end doesn't have an appropriate
1774 (org-export-with-backend
1775 (org-export-create-backend :transcoders
'((headline . ignore
)))
1777 ;; Otherwise, export using correct transcoder
1780 (let (org-export-registered-backends)
1781 (org-export-define-backend 'test
1782 '((plain-text .
(lambda (text contents info
) "Failure"))))
1783 (org-export-define-backend 'test2
1784 '((plain-text .
(lambda (text contents info
) "Success"))))
1785 (org-export-with-backend 'test2
"Test"))))
1786 ;; Provide correct back-end if transcoder needs to use recursive
1790 (let ((test-back-end
1791 (org-export-create-backend
1793 (list (cons 'headline
1794 (lambda (headline contents info
)
1796 (org-element-property :title headline
)
1798 (cons 'plain-text
(lambda (text info
) "Success"))))))
1799 (org-export-string-as
1801 (org-export-create-backend
1803 (list (cons 'headline
1804 (lambda (headline contents info
)
1805 (org-export-with-backend
1806 test-back-end headline contents info
))))))))))
1808 (ert-deftest test-org-export
/data-with-backend
()
1809 "Test `org-export-data-with-backend' specifications."
1810 ;; Error when calling an undefined back-end.
1811 (should-error (org-export-data-with-backend nil
"nil" nil
))
1812 ;; Otherwise, export data recursively, using correct back-end.
1816 (org-export-data-with-backend
1818 (org-export-create-backend
1820 '((plain-text .
(lambda (text info
) "Success"))
1821 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1822 '(:with-emphasize t
)))))
1828 (ert-deftest test-org-export
/comments
()
1829 "Test comments handling during export.
1830 In particular, structure of the document mustn't be altered after
1833 (equal "Para1\n\nPara2\n"
1834 (org-test-with-temp-text "
1840 (org-export-as (org-test-default-backend)))))
1842 (equal "Para1\n\nPara2\n"
1843 (org-test-with-temp-text "
1847 (org-export-as (org-test-default-backend)))))
1849 (equal "[fn:1] Para1\n\n\nPara2\n"
1850 (org-test-with-temp-text "
1855 # Outside definition
1857 (org-export-as (org-test-default-backend)))))
1859 (equal "[fn:1] Para1\n\nPara2\n"
1860 (org-test-with-temp-text "
1868 (org-export-as (org-test-default-backend)))))
1870 (equal "[fn:1] Para1\n\nPara2\n"
1871 (org-test-with-temp-text "
1876 (org-export-as (org-test-default-backend)))))
1878 (equal "[fn:1] Para1\n\nPara2\n"
1879 (org-test-with-temp-text "
1884 (org-export-as (org-test-default-backend)))))
1886 (equal "- item 1\n\n- item 2\n"
1887 (org-test-with-temp-text "
1893 (org-export-as (org-test-default-backend))))))
1899 (ert-deftest test-org-export
/export-block
()
1900 "Test export blocks transcoding."
1903 (org-test-with-temp-text
1904 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1906 (org-export-create-backend
1907 :transcoders
'((export-block .
(lambda (b _c _i
)
1908 (org-element-property :value b
)))
1909 (section .
(lambda (_s c _i
) c
))))))))
1912 (org-test-with-temp-text
1913 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1915 (org-export-create-backend
1920 (and (equal (org-element-property :type b
) "BACKEND")
1921 (org-element-property :value b
))))
1922 (cons 'section
(lambda (_s c _i
) c
)))))))))
1927 (ert-deftest test-org-export
/export-snippet
()
1928 "Test export snippets transcoding."
1930 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1931 (let ((backend (org-test-default-backend)))
1932 (setf (org-export-backend-name backend
) 'test
)
1933 (setf (org-export-backend-transcoders backend
)
1934 (cons (cons 'export-snippet
1935 (lambda (snippet contents info
)
1936 (when (eq (org-export-snippet-backend snippet
) 'test
)
1937 (org-element-property :value snippet
))))
1938 (org-export-backend-transcoders backend
)))
1939 (let ((org-export-snippet-translation-alist nil
))
1940 (should (equal (org-export-as backend
) "A\n")))
1941 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1942 (should (equal (org-export-as backend
) "AB\n")))))
1943 ;; Ignored export snippets do not remove any blank.
1945 (equal "begin end\n"
1946 (org-test-with-parsed-data "begin @@test:A@@ end"
1947 (org-export-data-with-backend
1949 (org-export-create-backend
1951 '((paragraph .
(lambda (paragraph contents info
) contents
))
1952 (section .
(lambda (section contents info
) contents
))))
1958 (ert-deftest test-org-export
/filter-apply-functions
()
1959 "Test `org-export-filter-apply-functions' specifications."
1960 ;; Functions are applied in order and return values are reduced.
1963 (org-export-filter-apply-functions
1964 (list (lambda (value &rest _
) (concat "1" value
))
1965 (lambda (value &rest _
) (concat "2" value
)))
1967 ;; Functions returning nil are skipped.
1970 (org-export-filter-apply-functions
1971 (list #'ignore
(lambda (value &rest _
) (concat "2" value
)))
1973 ;; If all functions are skipped, return the initial value.
1976 (org-export-filter-apply-functions (list #'ignore
) "0" nil
)))
1977 ;; If any function returns the empty string, final value is the
1981 (org-export-filter-apply-functions
1982 (list (lambda (value &rest _
) "")
1983 (lambda (value &rest _
) (concat "2" value
)))
1985 ;; Any function returning the empty string short-circuits the
1988 (org-export-filter-apply-functions
1989 (list (lambda (value &rest _
) "")
1990 (lambda (value &rest _
) (error "This shouldn't happen")))
1996 (ert-deftest test-org-export
/footnote-first-reference-p
()
1997 "Test `org-export-footnote-first-reference-p' specifications."
2001 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
2004 (org-export-create-backend
2006 `(,(cons 'footnote-reference
2008 (push (org-export-footnote-first-reference-p f i
)
2011 (section .
(lambda (s c i
) c
))
2012 (paragraph .
(lambda (p c i
) c
))))
2013 nil nil nil
'(:with-footnotes t
))
2014 (nreverse result
)))))
2015 ;; Limit check to DATA, when non-nil.
2019 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
2021 (org-element-map tree
'footnote-reference
2024 (org-export-footnote-first-reference-p
2025 ref info
(org-element-map tree
'headline
#'identity info t
))
2028 (nreverse result
)))))
2032 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
2034 (org-element-map tree
'footnote-reference
2036 (push (org-export-footnote-first-reference-p ref info
) result
))
2038 (nreverse result
)))))
2039 ;; If optional argument BODY-FIRST is non-nil, first find footnote
2040 ;; in the main body of the document. Otherwise, enter footnote
2041 ;; definitions when they are encountered.
2045 (org-test-with-temp-text
2046 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
2049 (org-export-create-backend
2051 `(,(cons 'footnote-reference
2053 (when (org-element-lineage f
'(drawer))
2054 (push (org-export-footnote-first-reference-p f i nil
)
2057 (drawer .
(lambda (d c i
) c
))
2058 (footnote-definition .
(lambda (d c i
) c
))
2059 (section .
(lambda (s c i
) c
))
2060 (paragraph .
(lambda (p c i
) c
))))
2061 nil nil nil
'(:with-footnotes t
))
2062 (nreverse result
)))))
2066 (org-test-with-temp-text
2067 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
2070 (org-export-create-backend
2072 `(,(cons 'footnote-reference
2074 (when (org-element-lineage f
'(drawer))
2075 (push (org-export-footnote-first-reference-p f i nil t
)
2078 (drawer .
(lambda (d c i
) c
))
2079 (footnote-definition .
(lambda (d c i
) c
))
2080 (section .
(lambda (s c i
) c
))
2081 (paragraph .
(lambda (p c i
) c
))))
2082 nil nil nil
'(:with-footnotes t
))
2083 (nreverse result
))))))
2085 (ert-deftest test-org-export
/get-footnote-number
()
2086 "Test `org-export-get-footnote-number' specifications."
2089 (org-test-with-parsed-data
2090 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
2091 (org-element-map tree
'footnote-reference
2092 (lambda (ref) (org-export-get-footnote-number ref info
))
2094 ;; Anonymous footnotes all get a new number.
2097 (org-test-with-parsed-data
2098 "Text[fn::anon1][fn::anon2]"
2099 (org-element-map tree
'footnote-reference
2100 (lambda (ref) (org-export-get-footnote-number ref info
))
2102 ;; Test nested footnotes order.
2105 '((1 .
"1") (2 .
"2") (3 .
"3") (3 .
"3") (4))
2106 (org-test-with-parsed-data
2107 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
2108 (org-element-map tree
'footnote-reference
2110 (cons (org-export-get-footnote-number ref info
)
2111 (org-element-property :label ref
)))
2113 ;; Limit number to provided DATA, when non-nil.
2117 (org-test-with-parsed-data
2118 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2119 (org-element-map tree
'footnote-reference
2121 (org-export-get-footnote-number
2122 ref info
(org-element-map tree
'headline
#'identity info t
)))
2127 (org-test-with-parsed-data
2128 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
2129 (org-element-map tree
'footnote-reference
2130 (lambda (ref) (org-export-get-footnote-number ref info
))
2132 ;; With a non-nil BODY-FIRST optional argument, first check body,
2133 ;; then footnote definitions.
2136 '(("1" .
1) ("2" .
2) ("3" .
3) ("3" .
3))
2137 (org-test-with-parsed-data
2138 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2139 (org-element-map tree
'footnote-reference
2141 (cons (org-element-property :label ref
)
2142 (org-export-get-footnote-number ref info nil t
)))
2146 '(("1" .
1) ("2" .
3) ("3" .
2) ("3" .
2))
2147 (org-test-with-parsed-data
2148 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2149 (org-element-map tree
'footnote-reference
2151 (cons (org-element-property :label ref
)
2152 (org-export-get-footnote-number ref info nil
)))
2155 (ert-deftest test-org-export
/get-footnote-definition
()
2156 "Test `org-export-get-footnote-definition' specifications."
2160 (org-element-interpret-data
2161 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1] A"
2162 (org-export-get-footnote-definition
2163 (org-element-map tree
'footnote-reference
#'identity nil t
)
2165 ;; Raise an error if no definition is found.
2167 (org-test-with-parsed-data "Text[fn:1]"
2168 (org-export-get-footnote-definition
2169 (org-element-map tree
'footnote-reference
#'identity nil t
)
2171 ;; Find inline definitions.
2174 (org-element-interpret-data
2175 (org-test-with-parsed-data "Text[fn:1:A]"
2176 (org-export-get-footnote-definition
2177 (org-element-map tree
'footnote-reference
#'identity nil t
)
2179 ;; Find anonymous definitions.
2182 (org-element-interpret-data
2183 (org-test-with-parsed-data "Text[fn::A]"
2184 (org-export-get-footnote-definition
2185 (org-element-map tree
'footnote-reference
#'identity nil t
)
2187 ;; Find empty definitions.
2190 (org-element-interpret-data
2191 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1]"
2192 (org-export-get-footnote-definition
2193 (org-element-map tree
'footnote-reference
#'identity nil t
)
2197 (org-element-interpret-data
2198 (org-test-with-parsed-data "Text[fn:1:]"
2199 (org-export-get-footnote-definition
2200 (org-element-map tree
'footnote-reference
#'identity nil t
)
2204 (org-element-interpret-data
2205 (org-test-with-parsed-data "Text[fn::]"
2206 (org-export-get-footnote-definition
2207 (org-element-map tree
'footnote-reference
#'identity nil t
)
2210 (ert-deftest test-org-export
/collect-footnote-definitions
()
2211 "Test `org-export-collect-footnote-definitions' specifications."
2214 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2216 \[fn:2] B [fn:3] [fn::D].
2219 (length (org-export-collect-footnote-definitions info
)))))
2220 ;; Limit number to provided DATA, when non-nil.
2224 (org-test-with-parsed-data
2225 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2227 (org-export-collect-footnote-definitions
2228 info
(org-element-map tree
'headline
#'identity info t
))))))
2232 (org-test-with-parsed-data
2233 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2234 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
2235 ;; With optional argument BODY-FIRST, first check body, then
2236 ;; footnote definitions.
2238 (equal '("1" "3" "2" nil
)
2239 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2241 \[fn:2] B [fn:3] [fn::D].
2244 (mapcar (lambda (e) (nth 1 e
))
2245 (org-export-collect-footnote-definitions info nil t
)))))
2247 (equal '("1" "3" "2" nil
)
2248 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2250 \[fn:2] B [fn:3] [fn::D].
2253 (mapcar (lambda (e) (nth 1 e
))
2254 (org-export-collect-footnote-definitions info
))))))
2256 (ert-deftest test-org-export
/footnotes
()
2257 "Miscellaneous tests on footnotes."
2258 (let ((org-footnote-section nil
)
2259 (org-export-with-footnotes t
))
2260 ;; Read every type of footnote.
2263 '((1 .
"A\n") (2 .
"C") (3 .
"D"))
2264 (org-test-with-parsed-data
2265 "Text[fn:1] [fn:label:C] [fn::D]\n\n[fn:1] A\n"
2266 (org-element-map tree
'footnote-reference
2268 (let ((def (org-export-get-footnote-definition ref info
)))
2269 (cons (org-export-get-footnote-number ref info
)
2270 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
2271 (car (org-element-contents
2272 (car (org-element-contents def
))))))))
2274 ;; Export nested footnote in invisible definitions.
2277 (org-test-with-temp-text "Text[fn:1]\n\n[fn:1] B [fn:2]\n\n[fn:2] C."
2278 (narrow-to-region (point) (line-end-position))
2281 (org-export-create-backend
2286 (throw 'exit
(length
2287 (org-export-collect-footnote-definitions
2289 ;; Export footnotes defined outside parsing scope.
2293 (org-test-with-temp-text "[fn:1] Out of scope
2295 <point>Paragraph[fn:1]"
2296 (org-export-as (org-test-default-backend) 'subtree
))))
2300 (org-test-with-temp-text "[fn:1] Out of scope
2302 <point>Paragraph[fn:1]"
2303 (narrow-to-region (point) (point-max))
2304 (org-export-as (org-test-default-backend)))))
2305 ;; Export nested footnotes defined outside parsing scope.
2309 (org-test-with-temp-text "
2310 \[fn:1] Out of scope[fn:2]
2312 \[fn:2] Very out of scope
2314 <point>Paragraph[fn:1]"
2315 (org-export-as (org-test-default-backend) 'subtree
))))
2319 (org-test-with-temp-text "
2320 \[fn:1] Out of scope[fn:2]
2322 \[fn:2] Very out of scope
2324 <point>Paragraph[fn:1]"
2325 (narrow-to-region (point) (point-max))
2326 (org-export-as (org-test-default-backend)))))
2330 (org-test-with-temp-text "
2331 \[fn:1] Out of scope[fn:2:D2]
2333 <point>Paragraph[fn:1]"
2334 (narrow-to-region (point) (point-max))
2335 (org-export-as (org-test-default-backend)))))
2336 ;; Export footnotes in pruned parts of tree.
2340 (let ((org-export-exclude-tags '("noexport")))
2341 (org-test-with-temp-text
2342 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] Definition"
2343 (org-export-as (org-test-default-backend))))))
2347 (let ((org-export-select-tags '("export")))
2348 (org-test-with-temp-text
2349 "* H :export:\nText[fn:1]\n* H2\n[fn:1] Definition"
2350 (org-export-as (org-test-default-backend))))))
2351 ;; Export nested footnotes in pruned parts of tree.
2355 (let ((org-export-exclude-tags '("noexport")))
2356 (org-test-with-temp-text
2357 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2358 (org-export-as (org-test-default-backend))))))
2362 (let ((org-export-select-tags '("export")))
2363 (org-test-with-temp-text
2364 "* H :export:\nText[fn:1]\n* H2\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2365 (org-export-as (org-test-default-backend))))))
2366 ;; Handle uninterpreted data in pruned footnote definitions.
2370 (let ((org-export-with-tables nil
))
2371 (org-test-with-temp-text
2372 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1]\n| a |"
2373 (org-export-as (org-test-default-backend))))))
2374 ;; Footnotes without a definition should throw an error.
2376 (org-test-with-parsed-data "Text[fn:1]"
2377 (org-export-get-footnote-definition
2378 (org-element-map tree
'footnote-reference
#'identity info t
) info
)))
2379 ;; Footnote section should be ignored in TOC and in headlines
2382 (= 1 (let ((org-footnote-section "Footnotes"))
2383 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
2384 (org-export-collect-headlines info
))))))
2387 (let ((org-footnote-section "Footnotes"))
2388 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
2389 (org-element-map tree
'headline
2391 (when (equal (org-element-property :raw-value hl
) "H2")
2392 (org-export-get-headline-number hl info
)))
2397 ;;; Headlines and Inlinetasks
2399 (ert-deftest test-org-export
/get-relative-level
()
2400 "Test `org-export-get-relative-level' specifications."
2404 (let ((org-odd-levels-only nil
))
2405 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2406 (org-element-map tree
'headline
2407 (lambda (h) (org-export-get-relative-level h info
))
2412 (let ((org-odd-levels-only nil
))
2413 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
2414 (org-element-map tree
'headline
2415 (lambda (h) (org-export-get-relative-level h info
))
2418 (ert-deftest test-org-export
/low-level-p
()
2419 "Test `org-export-low-level-p' specifications."
2423 (let ((org-odd-levels-only nil
))
2424 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2425 (org-element-map tree
'headline
2426 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
2427 (plist-put info
:headline-levels
1)))))))
2429 (ert-deftest test-org-export
/get-headline-number
()
2430 "Test `org-export-get-headline-number' specifications."
2435 (let ((org-odd-levels-only nil
))
2436 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2437 (org-element-map tree
'headline
2438 (lambda (h) (org-export-get-headline-number h info
))
2440 ;; Missing levels are replaced with 0.
2444 (let ((org-odd-levels-only nil
))
2445 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
2446 (org-element-map tree
'headline
2447 (lambda (h) (org-export-get-headline-number h info
))
2450 (ert-deftest test-org-export
/numbered-headline-p
()
2451 "Test `org-export-numbered-headline-p' specifications."
2452 ;; If `:section-numbers' is nil, never number headlines.
2454 (org-test-with-parsed-data "* Headline"
2455 (org-element-map tree
'headline
2456 (lambda (h) (org-export-numbered-headline-p h info
))
2457 (plist-put info
:section-numbers nil
))))
2458 ;; If `:section-numbers' is a number, only number headlines with
2459 ;; a level greater that it.
2463 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2464 (org-element-map tree
'headline
2465 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
2466 (plist-put info
:section-numbers
1)))))
2467 ;; Otherwise, headlines are always numbered.
2469 (org-test-with-parsed-data "* Headline"
2470 (org-element-map tree
'headline
2471 (lambda (h) (org-export-numbered-headline-p h info
))
2472 (plist-put info
:section-numbers t
))))
2473 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
2475 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
2476 (org-export-numbered-headline-p
2477 (org-element-map tree
'headline
'identity info t
)
2479 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
2481 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
2482 (org-export-numbered-headline-p
2483 (org-element-map tree
'headline
#'identity info t
)
2485 ;; UNNUMBERED is inherited.
2487 (equal '(unnumbered numbered unnumbered
)
2488 (org-test-with-parsed-data
2498 (org-element-map tree
'headline
2500 (if (org-export-numbered-headline-p h info
) 'numbered
2504 (ert-deftest test-org-export
/number-to-roman
()
2505 "Test `org-export-number-to-roman' specifications."
2506 ;; If number is negative, return it as a string.
2507 (should (equal (org-export-number-to-roman -
1) "-1"))
2508 ;; Otherwise, return it as a roman number.
2509 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
2511 (ert-deftest test-org-export
/get-optional-title
()
2512 "Test `org-export-get-alt-title' specifications."
2513 ;; If ALT_TITLE property is defined, use it.
2516 (org-test-with-parsed-data
2517 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
2518 (org-export-get-alt-title
2519 (org-element-map tree
'headline
'identity info t
)
2521 ;; Otherwise, fall-back to regular title.
2523 (equal '("Headline")
2524 (org-test-with-parsed-data "* Headline"
2525 (org-export-get-alt-title
2526 (org-element-map tree
'headline
'identity info t
)
2529 (ert-deftest test-org-export
/get-tags
()
2530 "Test `org-export-get-tags' specifications."
2531 ;; Standard test: tags which are not a select tag, an exclude tag,
2532 ;; or specified as optional argument shouldn't be ignored.
2534 (org-test-with-parsed-data "* Headline :tag:"
2535 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2537 ;; Tags provided in the optional argument are ignored.
2539 (org-test-with-parsed-data "* Headline :ignore:"
2540 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2542 ;; Allow tag inheritance.
2546 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2547 (org-element-map tree
'headline
2548 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2549 ;; Tag inheritance checks FILETAGS keywords.
2553 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2554 (org-element-map tree
'headline
2555 (lambda (hl) (org-export-get-tags hl info nil t
)) info
)))))
2557 (ert-deftest test-org-export
/get-node-property
()
2558 "Test`org-export-get-node-property' specifications."
2562 (org-test-with-parsed-data "* Headline
2566 (org-export-get-node-property
2567 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2568 ;; Test inheritance.
2571 (org-test-with-parsed-data "* Parent
2577 (org-export-get-node-property
2578 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2579 ;; Cannot return a value before the first headline.
2581 (org-test-with-parsed-data "Paragraph
2586 (org-export-get-node-property
2587 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2589 (ert-deftest test-org-export
/get-category
()
2590 "Test `org-export-get-category' specifications."
2594 (org-test-with-parsed-data "* Headline
2598 (org-export-get-category
2599 (org-element-map tree
'headline
'identity nil t
) info
))))
2600 ;; Test inheritance from a parent headline.
2602 (equal '("value" "value")
2603 (org-test-with-parsed-data "* Headline1
2608 (org-element-map tree
'headline
2609 (lambda (hl) (org-export-get-category hl info
)) info
))))
2610 ;; Test inheritance from #+CATEGORY keyword
2613 (org-test-with-parsed-data "#+CATEGORY: value
2615 (org-export-get-category
2616 (org-element-map tree
'headline
'identity nil t
) info
))))
2617 ;; Test inheritance from file name.
2620 (org-test-with-parsed-data "* Headline"
2621 (let ((info (plist-put info
:input-file
"~/test.org")))
2622 (org-export-get-category
2623 (org-element-map tree
'headline
'identity nil t
) info
)))))
2627 (org-test-with-parsed-data "* Headline"
2628 (org-export-get-category
2629 (org-element-map tree
'headline
'identity nil t
) info
)))))
2631 (ert-deftest test-org-export
/first-sibling-p
()
2632 "Test `org-export-first-sibling-p' specifications."
2637 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2638 (org-element-map tree
'headline
2639 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2643 (org-test-with-parsed-data "- item\n\n para"
2644 (org-element-map tree
'paragraph
2645 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2647 ;; Ignore sections for headlines.
2650 (org-test-with-parsed-data "* H\nSection\n** H 2"
2651 (org-element-map tree
'headline
2652 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2654 ;; Ignore headlines not exported.
2658 (let ((org-export-exclude-tags '("ignore")))
2659 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2660 (org-element-map tree
'headline
2661 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2664 (ert-deftest test-org-export
/last-sibling-p
()
2665 "Test `org-export-last-sibling-p' specifications."
2670 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2671 (org-element-map tree
'headline
2672 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2676 (org-test-with-parsed-data "- item\n\n para"
2677 (org-element-map tree
'paragraph
2678 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2680 ;; Ignore headlines not exported.
2684 (let ((org-export-exclude-tags '("ignore")))
2685 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2686 (org-element-map tree
'headline
2687 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2689 ;; Handle gracefully discontinuous headings.
2692 (org-test-with-parsed-data "** S\n* H"
2693 (org-element-map tree
'headline
2694 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
)))))))
2696 (ert-deftest test-org-export
/handle-inlinetasks
()
2697 "Test inlinetask export."
2698 ;; Inlinetask with an exclude tag.
2699 (when (featurep 'org-inlinetask
)
2703 (let ((org-inlinetask-min-level 3)
2704 org-export-filter-body-functions
2705 org-export-filter-final-output-functions
)
2706 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2707 (org-export-as (org-test-default-backend)
2708 nil nil nil
'(:exclude-tags
("noexp")))))))
2709 ;; Inlinetask with an include tag.
2712 "* H2\n*** Inline :exp:\n"
2713 (let ((org-inlinetask-min-level 3)
2714 (org-tags-column 0))
2715 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2716 (org-export-as (org-test-default-backend)
2717 nil nil nil
'(:select-tags
("exp")))))))
2718 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2721 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2722 (org-inlinetask-min-level 3)
2723 org-export-filter-body-functions
2724 org-export-filter-final-output-functions
)
2725 (org-test-with-temp-text "*** TODO Inline"
2726 (org-export-as (org-test-default-backend)
2727 nil nil nil
'(:with-tasks nil
))))))))
2733 (ert-deftest test-org-export
/get-date
()
2734 "Test `org-export-get-date' specifications."
2735 ;; Return a properly formatted string when
2736 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2737 ;; consists in a single timestamp.
2740 (let ((org-export-date-timestamp-format "%d %m %Y"))
2741 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2742 (org-export-get-date info
)))))
2743 ;; Return a secondary string otherwise.
2746 (let ((org-export-date-timestamp-format nil
))
2747 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2748 (org-export-get-date info
)))))
2751 (org-test-with-parsed-data "#+DATE: Date"
2752 (org-export-get-date info
))))
2753 ;; Optional argument has precedence over
2754 ;; `org-export-date-timestamp-format'.
2757 (let ((org-export-date-timestamp-format "%d %m %Y"))
2758 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2759 (org-export-get-date info
"%d %m"))))))
2765 (ert-deftest test-org-export
/custom-protocol-maybe
()
2766 "Test `org-export-custom-protocol-maybe' specifications."
2771 (org-link-set-parameters "foo" :export
(lambda (p d f
) "success"))
2772 (org-export-string-as
2774 (org-export-create-backend
2777 '((section .
(lambda (s c i
) c
))
2778 (paragraph .
(lambda (p c i
) c
))
2779 (link .
(lambda (l c i
)
2780 (or (org-export-custom-protocol-maybe l c
'test
)
2786 (org-link-set-parameters
2787 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2788 (org-export-string-as
2790 (org-export-create-backend
2793 '((section .
(lambda (s c i
) c
))
2794 (paragraph .
(lambda (p c i
) c
))
2795 (link .
(lambda (l c i
)
2796 (or (org-export-custom-protocol-maybe l c
'no-test
)
2798 ;; Ignore anonymous back-ends.
2803 (org-link-set-parameters
2804 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2805 (org-export-string-as
2807 (org-export-create-backend
2809 '((section .
(lambda (s c i
) c
))
2810 (paragraph .
(lambda (p c i
) c
))
2811 (link .
(lambda (l c i
)
2812 (or (org-export-custom-protocol-maybe l c nil
)
2815 (ert-deftest test-org-export
/get-coderef-format
()
2816 "Test `org-export-get-coderef-format' specifications."
2817 ;; A link without description returns "%s"
2818 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2820 ;; Return "%s" when path is matched within description.
2821 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2823 ;; Otherwise return description.
2824 (should (equal (org-export-get-coderef-format "path" "desc")
2827 (ert-deftest test-org-export
/inline-image-p
()
2828 "Test `org-export-inline-image-p' specifications."
2830 (org-export-inline-image-p
2831 (org-test-with-temp-text "[[#id]]"
2832 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2833 '(("custom-id" .
"id")))))
2835 (ert-deftest test-org-export
/insert-image-links
()
2836 "Test `org-export-insert-image-links' specifications."
2839 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2840 (org-element-map tree
'link
2841 (lambda (l) (org-element-property :type l
))))))
2844 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2845 (org-element-map (org-export-insert-image-links tree info
) 'link
2846 (lambda (l) (org-element-property :type l
))))))
2847 ;; Properly set `:parent' property when replace contents with image
2851 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2852 (org-element-map (org-export-insert-image-links tree info
) 'link
2854 (org-element-type (org-element-property :parent l
)))))))
2855 ;; With optional argument RULES, recognize different links as
2859 (org-test-with-parsed-data "[[http://orgmode.org][file:image.xxx]]"
2860 (org-element-map (org-export-insert-image-links tree info
) 'link
2861 (lambda (l) (org-element-property :type l
))))))
2864 (org-test-with-parsed-data "[[http://orgmode.org][file:image.xxx]]"
2866 (org-export-insert-image-links tree info
'(("file" .
"xxx")))
2868 (lambda (l) (org-element-property :type l
)))))))
2870 (ert-deftest test-org-export
/fuzzy-link
()
2871 "Test fuzzy links specifications."
2872 ;; Link to an headline should return headline's number.
2874 ;; Note: Headline's number is in fact a list of numbers.
2876 (org-test-with-parsed-data
2877 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2878 (org-element-map tree
'link
2880 (org-export-get-ordinal
2881 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2882 ;; Link to a target in an item should return item's number.
2884 ;; Note: Item's number is in fact a list of numbers.
2886 (org-test-with-parsed-data
2887 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2888 (org-element-map tree
'link
2890 (org-export-get-ordinal
2891 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2892 ;; Link to a target in a footnote should return footnote's number.
2895 (org-test-with-parsed-data "
2896 Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
2900 (org-element-map tree
'link
2902 (org-export-get-ordinal
2903 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2904 ;; Link to a named element should return sequence number of that
2908 (org-test-with-parsed-data
2909 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2910 (org-element-map tree
'link
2912 (org-export-get-ordinal
2913 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2914 ;; Link to a target not within an item, a table, a footnote
2915 ;; reference or definition should return section number.
2918 (org-test-with-parsed-data
2919 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2920 (org-element-map tree
'link
2922 (org-export-get-ordinal
2923 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2924 ;; Space are not significant when matching a fuzzy link.
2926 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2927 (org-element-map tree
'link
2928 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2930 ;; Statistics cookies are ignored for headline match.
2932 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2933 (org-element-map tree
'link
2934 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2937 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2938 (org-element-map tree
'link
2939 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2942 (defun test-org-gen-loc-list(text type
)
2943 (org-test-with-parsed-data text
2944 (org-element-map tree type
2945 (lambda (el) (or (org-export-get-loc el info
) 'no-loc
)))))
2947 (ert-deftest test-org-export
/get-loc
()
2948 "Test `org-export-get-loc' specifications."
2950 ;; "-n" resets line number.
2952 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n\n Text\n#+END_EXAMPLE"
2954 ;; The first "+n" has 0 lines before it
2957 (test-org-gen-loc-list "#+BEGIN_EXAMPLE +n\n Text\n#+END_EXAMPLE"
2959 ;; "-n 10" resets line number but has "9 lines" before it.
2962 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n Text\n#+END_EXAMPLE"
2964 ;; -n10 with two lines then +n 15
2967 (test-org-gen-loc-list "
2968 #+BEGIN_EXAMPLE -n 10
2972 #+BEGIN_EXAMPLE +n 15
2978 (test-org-gen-loc-list "
2979 #+BEGIN_EXAMPLE -n 10
2982 #+BEGIN_EXAMPLE +n 10
2990 ;; an Example Block without -n does not add to the line count.
2992 (equal '(9 no-loc
19)
2993 (test-org-gen-loc-list "
2994 #+BEGIN_EXAMPLE -n 10
3000 #+BEGIN_EXAMPLE +n 10
3004 ;; "-n" resets line number.
3008 (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n \n (- 1 1) \n#+END_SRC"
3010 ;; The first "+n" has 0 lines before it.
3013 (test-org-gen-loc-list
3014 "#+BEGIN_SRC emacs-lisp +n \n (+ 0 (- 1 1))\n#+END_SRC"
3016 ;; "-n 10" resets line number but has "9 lines" before it.
3019 (test-org-gen-loc-list
3020 "#+BEGIN_SRC emacs-lisp -n 10\n (- 10 1)\n#+END_SRC"
3024 (test-org-gen-loc-list "
3025 #+BEGIN_SRC emacs-lisp -n 10
3029 #+BEGIN_SRC emacs-lisp +n 15
3030 (+ (- 10 1) 2 (- 15 1))
3035 (test-org-gen-loc-list "
3036 #+BEGIN_SRC emacs-lisp -n 10
3039 #+BEGIN_SRC emacs-lisp +n 10
3040 (+ (- 10 1) 1 (- 10 1))
3042 #+BEGIN_SRC emacs-lisp -n
3046 ;; A SRC Block without -n does not add to the line count.
3048 (equal '(9 no-loc
19)
3049 (test-org-gen-loc-list
3050 "#+BEGIN_SRC emacs-lisp -n 10
3053 #+BEGIN_SRC emacs-lisp
3056 #+BEGIN_SRC emacs-lisp +n 10
3057 (+ (- 10 1) 1 (- 10 1))
3061 (ert-deftest test-org-export
/resolve-coderef
()
3062 "Test `org-export-resolve-coderef' specifications."
3063 (let ((org-coderef-label-format "(ref:%s)"))
3064 ;; A link to a "-n -k -r" block returns line number.
3067 (org-test-with-parsed-data
3068 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3069 (org-export-resolve-coderef "coderef" info
))))
3072 (org-test-with-parsed-data
3073 "#+BEGIN_EXAMPLE -n 10 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3074 (org-export-resolve-coderef "coderef" info
))))
3077 (org-test-with-parsed-data
3078 "#+BEGIN_EXAMPLE -n 10 -k -r\nText \n#+END_EXAMPLE\n
3079 #+BEGIN_EXAMPLE +n 125 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3080 (org-export-resolve-coderef "coderef" info
))))
3083 (org-test-with-parsed-data
3084 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3085 (org-export-resolve-coderef "coderef" info
))))
3088 (org-test-with-parsed-data
3089 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3090 (org-export-resolve-coderef "coderef" info
))))
3093 (org-test-with-parsed-data
3094 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) \n#+END_SRC\n
3095 #+BEGIN_SRC emacs-lisp +n 125 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3096 (org-export-resolve-coderef "coderef" info
))))
3097 ;; A link to a "-n -r" block returns line number.
3100 (org-test-with-parsed-data
3101 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
3102 (org-export-resolve-coderef "coderef" info
))))
3105 (org-test-with-parsed-data
3106 "#+BEGIN_EXAMPLE -n 10 -r\nText (ref:coderef)\n#+END_EXAMPLE"
3107 (org-export-resolve-coderef "coderef" info
))))
3110 (org-test-with-parsed-data
3111 "#+BEGIN_EXAMPLE +n 10 -r\nText \n#+END_EXAMPLE
3112 #+BEGIN_EXAMPLE +n 125 -r\nText (ref:coderef)\n#+END_EXAMPLE"
3113 (org-export-resolve-coderef "coderef" info
))))
3117 (org-test-with-parsed-data
3118 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3119 (org-export-resolve-coderef "coderef" info
))))
3122 (org-test-with-parsed-data
3123 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3124 (org-export-resolve-coderef "coderef" info
))))
3127 (org-test-with-parsed-data
3128 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) \n#+END_SRC
3129 #+BEGIN_SRC emacs-lisp +n125 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3130 (org-export-resolve-coderef "coderef" info
))))
3131 ;; A link to a "-n" block returns coderef.
3134 (org-test-with-parsed-data
3135 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3136 (org-export-resolve-coderef "coderef" info
))))
3139 (org-test-with-parsed-data
3140 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
3141 (org-export-resolve-coderef "coderef" info
))))
3142 ;; A link to a "-r" block returns line number.
3145 (org-test-with-parsed-data
3146 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3147 (org-export-resolve-coderef "coderef" info
))))
3150 (org-test-with-parsed-data
3151 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
3152 (org-export-resolve-coderef "coderef" info
))))
3153 ;; A link to a block without a switch returns coderef.
3156 (org-test-with-parsed-data
3157 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3158 (org-export-resolve-coderef "coderef" info
))))
3159 (org-test-with-parsed-data
3160 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
3161 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
3162 ;; Correctly handle continued line numbers. A "+n" switch should
3163 ;; resume numbering from previous block with numbered lines,
3164 ;; ignoring blocks not numbering lines in the process. A "-n"
3165 ;; switch resets count.
3168 (org-test-with-parsed-data "
3173 #+BEGIN_SRC emacs-lisp
3177 #+BEGIN_SRC emacs-lisp +n -r
3178 \(+ 1 1) (ref:addition)
3181 #+BEGIN_EXAMPLE -n -r
3182 Another text. (ref:text)
3184 (list (org-export-resolve-coderef "addition" info
)
3185 (org-export-resolve-coderef "text" info
)))))
3186 ;; Recognize coderef with user-specified syntax.
3190 (org-test-with-parsed-data
3191 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
3192 (org-export-resolve-coderef "text" info
))))
3193 ;; Unresolved coderefs raise a `org-link-broken' signal.
3196 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3197 (org-export-resolve-coderef "unknown" info
))
3198 (org-link-broken t
)))))
3200 (ert-deftest test-org-export
/resolve-fuzzy-link
()
3201 "Test `org-export-resolve-fuzzy-link' specifications."
3202 ;; Match target objects.
3204 (org-test-with-parsed-data "<<target>> [[target]]"
3205 (org-export-resolve-fuzzy-link
3206 (org-element-map tree
'link
'identity info t
) info
)))
3207 ;; Match named elements.
3209 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
3210 (org-export-resolve-fuzzy-link
3211 (org-element-map tree
'link
'identity info t
) info
)))
3212 ;; Match exact headline's name.
3214 (org-test-with-parsed-data "* My headline\n[[My headline]]"
3215 (org-export-resolve-fuzzy-link
3216 (org-element-map tree
'link
'identity info t
) info
)))
3217 ;; Targets objects have priority over headline titles.
3220 (org-test-with-parsed-data "* target\n<<target>>[[target]]"
3222 (org-export-resolve-fuzzy-link
3223 (org-element-map tree
'link
'identity info t
) info
)))))
3224 ;; Named elements have priority over headline titles.
3227 (org-test-with-parsed-data
3228 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
3230 (org-export-resolve-fuzzy-link
3231 (org-element-map tree
'link
'identity info t
) info
)))))
3232 ;; If link's path starts with a "*", only match headline titles,
3236 (org-test-with-parsed-data
3237 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
3239 (org-export-resolve-fuzzy-link
3240 (org-element-map tree
'link
'identity info t
) info
)))))
3241 ;; Raise a `org-link-broken' signal if no match.
3243 (org-test-with-parsed-data "[[target]]"
3245 (org-export-resolve-fuzzy-link
3246 (org-element-map tree
'link
#'identity info t
) info
)
3247 (org-link-broken t
))))
3248 ;; Match fuzzy link even when before first headline.
3251 (org-test-with-parsed-data "[[hl]]\n* hl"
3253 (org-export-resolve-fuzzy-link
3254 (org-element-map tree
'link
'identity info t
) info
)))))
3255 ;; Handle url-encoded fuzzy links.
3257 (org-test-with-parsed-data "* A B\n[[A%20B]]"
3258 (org-export-resolve-fuzzy-link
3259 (org-element-map tree
'link
#'identity info t
) info
))))
3261 (ert-deftest test-org-export
/resolve-id-link
()
3262 "Test `org-export-resolve-id-link' specifications."
3263 ;; Regular test for custom-id link.
3265 (equal '("Headline1")
3266 (org-test-with-parsed-data "* Headline1
3272 (org-element-property
3274 (org-export-resolve-id-link
3275 (org-element-map tree
'link
'identity info t
) info
)))))
3276 ;; Raise a `org-link-broken' signal on failing searches.
3278 (org-test-with-parsed-data "* Headline1
3285 (org-export-resolve-id-link
3286 (org-element-map tree
'link
#'identity info t
) info
)
3287 (org-link-broken t
))))
3288 ;; Test for internal id target.
3290 (equal '("Headline1")
3291 (org-test-with-parsed-data "* Headline1
3297 (org-element-property
3299 (org-export-resolve-id-link
3300 (org-element-map tree
'link
'identity info t
) info
)))))
3301 ;; Test for external id target.
3305 (org-test-with-parsed-data "[[id:aaaa]]"
3306 (org-export-resolve-id-link
3307 (org-element-map tree
'link
'identity info t
)
3308 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
3310 (ert-deftest test-org-export
/resolve-radio-link
()
3311 "Test `org-export-resolve-radio-link' specifications."
3314 (org-test-with-temp-text "<<<radio>>> radio"
3315 (org-update-radio-target-regexp)
3316 (let* ((tree (org-element-parse-buffer))
3317 (info `(:parse-tree
,tree
)))
3318 (org-export-resolve-radio-link
3319 (org-element-map tree
'link
'identity info t
)
3321 ;; Radio targets are case-insensitive.
3323 (org-test-with-temp-text "<<<RADIO>>> radio"
3324 (org-update-radio-target-regexp)
3325 (let* ((tree (org-element-parse-buffer))
3326 (info `(:parse-tree
,tree
)))
3327 (org-export-resolve-radio-link
3328 (org-element-map tree
'link
'identity info t
)
3330 ;; Radio target with objects.
3332 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
3333 (org-update-radio-target-regexp)
3334 (let* ((tree (org-element-parse-buffer))
3335 (info `(:parse-tree
,tree
)))
3336 (org-export-resolve-radio-link
3337 (org-element-map tree
'link
'identity info t
)
3339 ;; Radio target with objects at its beginning.
3341 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
3342 (org-update-radio-target-regexp)
3343 (let* ((tree (org-element-parse-buffer))
3344 (info `(:parse-tree
,tree
)))
3345 (org-export-resolve-radio-link
3346 (org-element-map tree
'link
'identity info t
)
3348 ;; Radio link next to an apostrophe.
3350 (org-test-with-temp-text "<<<radio>>> radio's"
3351 (org-update-radio-target-regexp)
3352 (let* ((tree (org-element-parse-buffer))
3353 (info `(:parse-tree
,tree
)))
3354 (org-export-resolve-radio-link
3355 (org-element-map tree
'link
'identity info t
)
3357 ;; Multiple radio targets.
3359 (equal '("radio1" "radio2")
3360 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
3361 (org-update-radio-target-regexp)
3362 (let* ((tree (org-element-parse-buffer))
3363 (info `(:parse-tree
,tree
)))
3364 (org-element-map tree
'link
3366 (org-element-property
3367 :value
(org-export-resolve-radio-link link info
)))
3369 ;; Radio target is whitespace insensitive.
3371 (org-test-with-temp-text "<<<a radio>>> a\n radio"
3372 (org-update-radio-target-regexp)
3373 (let* ((tree (org-element-parse-buffer))
3374 (info `(:parse-tree
,tree
)))
3375 (org-element-map tree
'link
3376 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
3378 (ert-deftest test-org-export
/file-uri
()
3379 "Test `org-export-file-uri' specifications."
3380 ;; Preserve relative filenames.
3381 (should (equal "relative.org" (org-export-file-uri "relative.org")))
3382 ;; Local files start with "file://"
3383 (should (equal (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "/local.org"))
3384 (org-export-file-uri "/local.org")))
3385 ;; Remote files start with "file://"
3386 (should (equal "file://ssh:myself@some.where:papers/last.pdf"
3387 (org-export-file-uri "/ssh:myself@some.where:papers/last.pdf")))
3388 (should (equal "file://localhost/etc/fstab"
3389 (org-export-file-uri "//localhost/etc/fstab")))
3390 ;; Expand filename starting with "~".
3391 (should (equal (org-export-file-uri "~/file.org")
3392 (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "~/file.org")))))
3394 (ert-deftest test-org-export
/get-reference
()
3395 "Test `org-export-get-reference' specifications."
3397 (org-test-with-parsed-data "* Headline"
3398 (org-export-get-reference (org-element-map tree
'headline
#'identity nil t
)
3400 ;; For a given element always return the same reference.
3402 (org-test-with-parsed-data "* Headline"
3403 (let ((headline (org-element-map tree
'headline
#'identity nil t
)))
3404 (equal (org-export-get-reference headline info
)
3405 (org-export-get-reference headline info
)))))
3406 ;; References get through local export back-ends.
3408 (org-test-with-parsed-data "* Headline"
3409 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3411 (org-export-create-backend
3413 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3414 (equal (org-trim (org-export-data-with-backend headline backend info
))
3415 (org-export-get-reference headline info
)))))
3417 (org-test-with-parsed-data "* Headline"
3418 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3420 (org-export-create-backend
3422 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3423 (equal (org-export-with-backend backend headline nil info
)
3424 (org-export-get-reference headline info
)))))
3425 ;; Use search cells defined in `:crossrefs'. However, handle
3426 ;; duplicate search cells.
3429 (org-test-with-parsed-data "* Headline"
3430 (let* ((headline (org-element-map tree
'headline
#'identity nil t
))
3431 (search-cell (car (org-export-search-cells headline
))))
3433 (plist-put info
:crossrefs
(list (cons search-cell
1))))
3434 (org-export-get-reference headline info
)))))
3436 (equal '("org0000001" "org0000001")
3437 (org-test-with-parsed-data "* H\n** H"
3438 (org-element-map tree
'headline
3440 (let* ((search-cell (car (org-export-search-cells h
)))
3441 (info (plist-put info
:crossrefs
3442 (list (cons search-cell
1)))))
3443 (org-export-get-reference h info
))))))))
3446 ;;; Pseudo objects and pseudo elements
3448 (ert-deftest test-org-export
/pseudo-elements
()
3449 "Test exporting pseudo-elements."
3450 ;; Handle blank lines after pseudo-elements. In particular, do not
3451 ;; replace them with white spaces.
3453 (equal "contents\n\nparagraph\n"
3454 (let ((backend (org-export-create-backend
3456 '((pseudo-element .
(lambda (_p c _i
) c
))
3457 (paragraph .
(lambda (_p c _i
) c
))
3458 (plain-text .
(lambda (c _i
) c
)))))
3459 (element '(pseudo-element (:post-blank
1) "contents"))
3460 (paragraph '(paragraph nil
"paragraph"))
3461 (data '(org-data nil
)))
3462 (org-element-adopt-elements data element paragraph
)
3463 (org-export-data-with-backend data backend nil
)))))
3465 (ert-deftest test-org-export
/pseudo-objects
()
3466 "Test exporting pseudo-objects."
3467 ;; Handle blank spaces after pseudo-objects. In particular, do not
3468 ;; replace them with newlines.
3470 (equal "begin x end\n"
3471 (let ((backend (org-export-create-backend
3473 '((pseudo-object .
(lambda (_p c _i
) c
))
3474 (paragraph .
(lambda (_p c _i
) c
))
3475 (plain-text .
(lambda (c _i
) c
)))))
3476 (object '(pseudo-object (:post-blank
1) "x"))
3477 (paragraph '(paragraph nil
)))
3478 (org-element-adopt-elements paragraph
"begin " object
"end")
3479 (org-export-data-with-backend paragraph backend nil
)))))
3482 ;;; Src-block and example-block
3484 (ert-deftest test-org-export
/unravel-code
()
3485 "Test `org-export-unravel-code' function."
3486 ;; Code without reference.
3489 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3490 (org-export-unravel-code (org-element-at-point)))))
3491 ;; Code with reference.
3493 (equal '("(+ 1 1)" (1 .
"test"))
3494 (org-test-with-temp-text
3495 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
3496 (let ((org-coderef-label-format "(ref:%s)"))
3497 (org-export-unravel-code (org-element-at-point))))))
3498 ;; Code with user-defined reference.
3501 '("(+ 1 1)" (1 .
"test"))
3502 (org-test-with-temp-text
3503 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
3504 (let ((org-coderef-label-format "(ref:%s)"))
3505 (org-export-unravel-code (org-element-at-point))))))
3506 ;; Code references keys are relative to the current block.
3508 (equal '("(+ 2 2)\n(+ 3 3)" (2 .
"one"))
3509 (org-test-with-temp-text "
3518 (let ((org-coderef-label-format "(ref:%s)"))
3519 (org-export-unravel-code (org-element-at-point)))))\x14))
3521 (ert-deftest test-org-export
/format-code-default
()
3522 "Test `org-export-format-code-default' specifications."
3523 ;; Preserve blank lines, even when code is empty.
3526 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
3527 (org-export-format-code-default
3528 (org-element-map tree
'src-block
#'identity info t
) info
))))
3529 ;; Likewise, preserve leading and trailing blank lines in the code.
3531 (equal "\n(+ 1 1)\n"
3532 (org-test-with-parsed-data
3533 "#+BEGIN_SRC emacs-lisp\n\n(+ 1 1)\n#+END_SRC"
3534 (org-export-format-code-default
3535 (org-element-map tree
'src-block
#'identity info t
) info
))))
3537 (equal "(+ 1 1)\n\n"
3538 (org-test-with-parsed-data
3539 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n\n#+END_SRC"
3540 (org-export-format-code-default
3541 (org-element-map tree
'src-block
#'identity info t
) info
))))
3542 ;; Number lines, two whitespace characters before the actual loc.
3545 (org-test-with-parsed-data
3546 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
3547 (org-export-format-code-default
3548 (org-element-map tree
'src-block
#'identity info t
) info
))))
3549 ;; Numbering includes blank lines.
3551 (equal "1 \n2 a\n3 \n4 b\n5 \n"
3552 (org-test-with-parsed-data
3553 "#+BEGIN_SRC emacs-lisp +n\n\na\n\nb\n\n#+END_SRC"
3554 (org-export-format-code-default
3555 (org-element-map tree
'src-block
#'identity info t
) info
))))
3556 ;; Put references 6 whitespace characters after the widest line,
3557 ;; wrapped within parenthesis.
3559 (equal "123 (a)\n1 (b)\n"
3560 (let ((org-coderef-label-format "(ref:%s)"))
3561 (org-test-with-parsed-data
3562 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
3563 (org-export-format-code-default
3564 (org-element-map tree
'src-block
#'identity info t
) info
))))))
3570 (ert-deftest test-org-export
/activate-smart-quotes
()
3571 "Test `org-export-activate-smart-quotes' specifications."
3572 ;; Double quotes: standard test.
3575 '("some “quoted” text")
3576 (let ((org-export-default-language "en"))
3577 (org-test-with-parsed-data "some \"quoted\" text"
3578 (org-element-map tree
'plain-text
3579 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3581 ;; Opening quotes: at the beginning of a paragraph.
3585 (let ((org-export-default-language "en"))
3586 (org-test-with-parsed-data "\"begin"
3587 (org-element-map tree
'plain-text
3588 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3590 ;; Opening quotes: after an object.
3593 '("“quoted” text")
3594 (let ((org-export-default-language "en"))
3595 (org-test-with-parsed-data "=verb= \"quoted\" text"
3596 (org-element-map tree
'plain-text
3597 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3599 ;; Closing quotes: at the end of a paragraph.
3602 '("Quoted “text”")
3603 (let ((org-export-default-language "en"))
3604 (org-test-with-parsed-data "Quoted \"text\""
3605 (org-element-map tree
'plain-text
3606 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3608 ;; Inner quotes: standard test.
3610 (equal '("« outer « inner » outer »")
3611 (let ((org-export-default-language "fr"))
3612 (org-test-with-parsed-data "\"outer 'inner' outer\""
3613 (org-element-map tree
'plain-text
3614 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3616 ;; Inner quotes: close to special symbols.
3618 (equal '("« outer (« inner ») outer »")
3619 (let ((org-export-default-language "fr"))
3620 (org-test-with-parsed-data "\"outer ('inner') outer\""
3621 (org-element-map tree
'plain-text
3622 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3625 (equal '("« « inner » »")
3626 (let ((org-export-default-language "fr"))
3627 (org-test-with-parsed-data "\"'inner'\""
3628 (org-element-map tree
'plain-text
3629 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3631 ;; Apostrophe: standard test.
3633 (equal '("It « shouldn’t » fail")
3634 (let ((org-export-default-language "fr"))
3635 (org-test-with-parsed-data "It \"shouldn't\" fail"
3636 (org-element-map tree
'plain-text
3637 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3640 (equal '("It shouldn’t fail")
3641 (let ((org-export-default-language "fr"))
3642 (org-test-with-parsed-data "It shouldn't fail"
3643 (org-element-map tree
'plain-text
3644 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3646 ;; Apostrophe: before an object.
3649 '("« a’" " »")
3650 (let ((org-export-default-language "fr"))
3651 (org-test-with-parsed-data "\"a'=b=\""
3652 (org-element-map tree
'plain-text
3653 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3655 ;; Apostrophe: after an object.
3657 (equal '("« " "’s »")
3658 (let ((org-export-default-language "fr"))
3659 (org-test-with-parsed-data "\"=code='s\""
3660 (org-element-map tree
'plain-text
3661 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3663 ;; Special case: isolated quotes.
3665 (equal '("“" "”")
3666 (let ((org-export-default-language "en"))
3667 (org-test-with-parsed-data "\"$x$\""
3668 (org-element-map tree
'plain-text
3669 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3671 ;; Smart quotes in secondary strings.
3673 (equal '("“" "”")
3674 (let ((org-export-default-language "en"))
3675 (org-test-with-parsed-data "* \"$x$\""
3676 (org-element-map tree
'plain-text
3677 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3679 ;; Smart quotes in document keywords.
3681 (equal '("“" "”")
3682 (let ((org-export-default-language "en"))
3683 (org-test-with-parsed-data "#+TITLE: \"$x$\""
3684 (org-element-map (plist-get info
:title
) 'plain-text
3685 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3687 ;; Smart quotes in parsed affiliated keywords.
3689 (equal '("“" "”" "Paragraph")
3690 (let ((org-export-default-language "en"))
3691 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
3692 (org-element-map tree
'plain-text
3693 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3695 ;; Smart quotes within objects.
3697 (equal '("“foo”")
3698 (let ((org-export-default-language "en"))
3699 (org-test-with-parsed-data "| \"foo\" |"
3700 (org-element-map tree
'plain-text
3701 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3703 ;; FIXME: Test failing non-interactively.
3706 ;; (equal '("“foo”")
3707 ;; (let ((org-export-default-language "en"))
3708 ;; (org-test-with-parsed-data "*\"foo\"*"
3709 ;; (org-element-map tree 'plain-text
3710 ;; (lambda (s) (org-export-activate-smart-quotes s :html info))
3711 ;; info nil nil t)))))
3718 (ert-deftest test-org-export
/special-column
()
3719 "Test if the table's special column is properly recognized."
3720 ;; 1. First column is special if it contains only a special marking
3721 ;; characters or empty cells.
3722 (org-test-with-temp-text "
3726 (org-export-table-has-special-column-p
3728 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3729 ;; 2. If the column contains anything else, it isn't special.
3730 (org-test-with-temp-text "
3734 (org-export-table-has-special-column-p
3736 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3737 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
3739 (org-test-with-temp-text "
3748 (org-export-table-has-special-column-p
3750 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3751 ;; 4. A first column with only empty cells isn't considered as
3753 (org-test-with-temp-text "
3757 (org-export-table-has-special-column-p
3759 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
3761 (ert-deftest test-org-export
/table-row-is-special-p
()
3762 "Test `org-export-table-row-is-special-p' specifications."
3763 ;; 1. A row is special if it has a special marking character in the
3765 (org-test-with-parsed-data "| ! | 1 |"
3767 (org-export-table-row-is-special-p
3768 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3769 ;; 2. A row is special when its first field is "/"
3770 (org-test-with-parsed-data "
3774 (org-export-table-row-is-special-p
3775 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3776 ;; 3. A row only containing alignment cookies is also considered as
3778 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
3780 (org-export-table-row-is-special-p
3781 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3782 ;; 4. Everything else isn't considered as special.
3783 (org-test-with-parsed-data "| \alpha | | c |"
3785 (org-export-table-row-is-special-p
3786 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3787 ;; 5. Table's rules are never considered as special rows.
3788 (org-test-with-parsed-data "|---+---|"
3790 (org-export-table-row-is-special-p
3791 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
3793 (ert-deftest test-org-export
/has-header-p
()
3794 "Test `org-export-table-has-header-p' specifications."
3797 (org-test-with-parsed-data "
3801 (org-export-table-has-header-p
3802 (org-element-map tree
'table
'identity info
'first-match
)
3804 ;; Without an header.
3806 (org-test-with-parsed-data "
3809 (org-export-table-has-header-p
3810 (org-element-map tree
'table
'identity info
'first-match
)
3812 ;; Don't get fooled with starting and ending rules.
3814 (org-test-with-parsed-data "
3819 (org-export-table-has-header-p
3820 (org-element-map tree
'table
'identity info
'first-match
)
3823 (ert-deftest test-org-export
/table-row-group
()
3824 "Test `org-export-table-row-group' specifications."
3825 ;; A rule creates a new group.
3828 (org-test-with-parsed-data "
3832 (org-element-map tree
'table-row
3834 (if (eq (org-element-property :type row
) 'rule
) 'rule
3835 (org-export-table-row-group row info
)))))))
3836 ;; Special rows are ignored in count.
3840 (org-test-with-parsed-data "
3844 (org-element-map tree
'table-row
3846 (if (eq (org-element-property :type row
) 'rule
) 'rule
3847 (org-export-table-row-group row info
)))
3849 ;; Double rules also are ignored in count.
3851 (equal '(1 rule rule
2)
3852 (org-test-with-parsed-data "
3857 (org-element-map tree
'table-row
3859 (if (eq (org-element-property :type row
) 'rule
) 'rule
3860 (org-export-table-row-group row info
))))))))
3862 (ert-deftest test-org-export
/table-row-number
()
3863 "Test `org-export-table-row-number' specifications."
3864 ;; Standard test. Number is 0-indexed.
3867 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3868 (org-element-map tree
'table-row
3869 (lambda (row) (org-export-table-row-number row info
)) info
))))
3870 ;; Number ignores separators.
3873 (org-test-with-parsed-data "
3877 (org-element-map tree
'table-row
3878 (lambda (row) (org-export-table-row-number row info
)) info
))))
3879 ;; Number ignores special rows.
3882 (org-test-with-parsed-data "
3888 (org-element-map tree
'table-row
3889 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3891 (ert-deftest test-org-export
/table-cell-width
()
3892 "Test `org-export-table-cell-width' specifications."
3893 ;; 1. Width is primarily determined by width cookies. If no cookie
3894 ;; is found, cell's width is nil.
3895 (org-test-with-parsed-data "
3896 | / | <l> | <6> | <l7> |
3901 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3902 (org-element-map tree
'table-cell
'identity info
)))))
3903 ;; 2. The last width cookie has precedence.
3904 (org-test-with-parsed-data "
3911 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3912 (org-element-map tree
'table-cell
'identity info
)))))
3913 ;; 3. Valid width cookies must have a specific row.
3914 (org-test-with-parsed-data "| <6> | cell |"
3918 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3919 (org-element-map tree
'table-cell
'identity
))))))
3921 (ert-deftest test-org-export
/table-cell-alignment
()
3922 "Test `org-export-table-cell-alignment' specifications."
3923 ;; 1. Alignment is primarily determined by alignment cookies.
3925 (equal '(left center right
)
3926 (let ((org-table-number-fraction 0.5)
3927 (org-table-number-regexp "^[0-9]+$"))
3928 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3929 (mapcar (lambda (cell)
3930 (org-export-table-cell-alignment cell info
))
3931 (org-element-map tree
'table-cell
'identity
))))))
3932 ;; 2. The last alignment cookie has precedence.
3934 (equal '(right right right
)
3935 (org-test-with-parsed-data "
3939 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3940 (org-element-map tree
'table-cell
'identity
)))))
3941 ;; 3. If there's no cookie, cell's contents determine alignment.
3942 ;; A column mostly made of cells containing numbers will align
3943 ;; its cells to the right.
3945 (equal '(right right right
)
3946 (let ((org-table-number-fraction 0.5)
3947 (org-table-number-regexp "^[0-9]+$"))
3948 (org-test-with-parsed-data "
3952 (mapcar (lambda (cell)
3953 (org-export-table-cell-alignment cell info
))
3954 (org-element-map tree
'table-cell
'identity
))))))
3955 ;; 4. Otherwise, they will be aligned to the left.
3957 (equal '(left left left
)
3958 (org-test-with-parsed-data "
3962 (mapcar (lambda (cell)
3963 (org-export-table-cell-alignment cell info
))
3964 (org-element-map tree
'table-cell
'identity info
))))))
3966 (ert-deftest test-org-export
/table-cell-borders
()
3967 "Test `org-export-table-cell-borders' specifications."
3968 ;; 1. Recognize various column groups indicators.
3969 (org-test-with-parsed-data "| / | < | > | <> |"
3972 '((right bottom top
) (left bottom top
) (right bottom top
)
3973 (right left bottom top
))
3974 (mapcar (lambda (cell)
3975 (org-export-table-cell-borders cell info
))
3976 (org-element-map tree
'table-cell
'identity
)))))
3977 ;; 2. Accept shortcuts to define column groups.
3978 (org-test-with-parsed-data "| / | < | < |"
3981 '((right bottom top
) (right left bottom top
) (left bottom top
))
3982 (mapcar (lambda (cell)
3983 (org-export-table-cell-borders cell info
))
3984 (org-element-map tree
'table-cell
'identity
)))))
3985 ;; 3. A valid column groups row must start with a "/".
3986 (org-test-with-parsed-data "
3990 (equal '((top) (top) (bottom) (bottom))
3991 (mapcar (lambda (cell)
3992 (org-export-table-cell-borders cell info
))
3993 (org-element-map tree
'table-cell
'identity
)))))
3994 ;; 4. Take table rules into consideration.
3995 (org-test-with-parsed-data "
4000 (equal '((below top
) (bottom above
))
4001 (mapcar (lambda (cell)
4002 (org-export-table-cell-borders cell info
))
4003 (org-element-map tree
'table-cell
'identity
)))))
4004 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
4005 ;; (resp. `bottom' and `below') borders. Any special row is
4007 (org-test-with-parsed-data "
4013 (equal '((bottom below top above
))
4015 (mapcar (lambda (cell)
4016 (org-export-table-cell-borders cell info
))
4017 (org-element-map tree
'table-cell
'identity
)))))))
4019 (ert-deftest test-org-export
/table-dimensions
()
4020 "Test `org-export-table-dimensions' specifications."
4021 ;; 1. Standard test.
4022 (org-test-with-parsed-data "
4027 (org-export-table-dimensions
4028 (org-element-map tree
'table
'identity info
'first-match
) info
))))
4029 ;; 2. Ignore horizontal rules and special columns.
4030 (org-test-with-parsed-data "
4037 (org-export-table-dimensions
4038 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
4040 (ert-deftest test-org-export
/table-cell-address
()
4041 "Test `org-export-table-cell-address' specifications."
4042 ;; 1. Standard test: index is 0-based.
4043 (org-test-with-parsed-data "| a | b |"
4045 (equal '((0 .
0) (0 .
1))
4046 (org-element-map tree
'table-cell
4047 (lambda (cell) (org-export-table-cell-address cell info
))
4049 ;; 2. Special column isn't counted, nor are special rows.
4050 (org-test-with-parsed-data "
4055 (org-export-table-cell-address
4056 (car (last (org-element-map tree
'table-cell
'identity info
)))
4058 ;; 3. Tables rules do not count either.
4059 (org-test-with-parsed-data "
4067 (org-export-table-cell-address
4068 (car (last (org-element-map tree
'table-cell
'identity info
)))
4070 ;; 4. Return nil for special cells.
4071 (org-test-with-parsed-data "| / | a |"
4073 (org-export-table-cell-address
4074 (org-element-map tree
'table-cell
'identity nil
'first-match
)
4077 (ert-deftest test-org-export
/get-table-cell-at
()
4078 "Test `org-export-get-table-cell-at' specifications."
4079 ;; 1. Address ignores special columns, special rows and rules.
4080 (org-test-with-parsed-data "
4087 (org-element-contents
4088 (org-export-get-table-cell-at
4090 (org-element-map tree
'table
'identity info
'first-match
)
4092 ;; 2. Return value for a non-existent address is nil.
4093 (org-test-with-parsed-data "| a |"
4095 (org-export-get-table-cell-at
4097 (org-element-map tree
'table
'identity info
'first-match
)
4099 (org-test-with-parsed-data "| / |"
4101 (org-export-get-table-cell-at
4103 (org-element-map tree
'table
'identity info
'first-match
)
4106 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
4107 "Test `org-export-table-cell-starts-colgroup-p' specifications."
4108 ;; 1. A cell at a beginning of a row always starts a column group.
4109 (org-test-with-parsed-data "| a |"
4111 (org-export-table-cell-starts-colgroup-p
4112 (org-element-map tree
'table-cell
'identity info
'first-match
)
4114 ;; 2. Special column should be ignored when determining the
4115 ;; beginning of the row.
4116 (org-test-with-parsed-data "
4120 (org-export-table-cell-starts-colgroup-p
4121 (org-element-map tree
'table-cell
'identity info
'first-match
)
4123 ;; 2. Explicit column groups.
4124 (org-test-with-parsed-data "
4130 (org-element-map tree
'table-cell
4132 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
4135 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
4136 "Test `org-export-table-cell-ends-colgroup-p' specifications."
4137 ;; 1. A cell at the end of a row always ends a column group.
4138 (org-test-with-parsed-data "| a |"
4140 (org-export-table-cell-ends-colgroup-p
4141 (org-element-map tree
'table-cell
'identity info
'first-match
)
4143 ;; 2. Special column should be ignored when determining the
4144 ;; beginning of the row.
4145 (org-test-with-parsed-data "
4149 (org-export-table-cell-ends-colgroup-p
4150 (org-element-map tree
'table-cell
'identity info
'first-match
)
4152 ;; 3. Explicit column groups.
4153 (org-test-with-parsed-data "
4159 (org-element-map tree
'table-cell
4161 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
4164 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
4165 "Test `org-export-table-row-starts-rowgroup-p' specifications."
4166 ;; 1. A row at the beginning of a table always starts a row group.
4167 ;; So does a row following a table rule.
4168 (org-test-with-parsed-data "
4175 (org-element-map tree
'table-row
4177 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4179 ;; 2. Special rows should be ignored when determining the beginning
4181 (org-test-with-parsed-data "
4190 (org-element-map tree
'table-row
4192 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4195 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
4196 "Test `org-export-table-row-ends-rowgroup-p' specifications."
4197 ;; 1. A row at the end of a table always ends a row group. So does
4198 ;; a row preceding a table rule.
4199 (org-test-with-parsed-data "
4206 (org-element-map tree
'table-row
4208 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4210 ;; 2. Special rows should be ignored when determining the beginning
4212 (org-test-with-parsed-data "
4221 (org-element-map tree
'table-row
4223 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4226 (ert-deftest test-org-export
/table-row-in-header-p
()
4227 "Test `org-export-table-row-in-header-p' specifications."
4228 ;; Standard test. Separators are always nil.
4232 (org-test-with-parsed-data "| a |\n|---|\n| b |"
4233 (org-element-map tree
'table-row
4235 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
4236 ;; Nil when there is no header.
4240 (org-test-with-parsed-data "| a |\n| b |"
4241 (org-element-map tree
'table-row
4243 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
4245 (ert-deftest test-org-export
/table-row-starts-header-p
()
4246 "Test `org-export-table-row-starts-header-p' specifications."
4247 ;; 1. Only the row starting the first row group starts the table
4249 (org-test-with-parsed-data "
4257 (org-element-map tree
'table-row
4259 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
4261 ;; 2. A row cannot start an header if there's no header in the
4263 (org-test-with-parsed-data "
4267 (org-export-table-row-starts-header-p
4268 (org-element-map tree
'table-row
'identity info
'first-match
)
4271 (ert-deftest test-org-export
/table-row-ends-header-p
()
4272 "Test `org-export-table-row-ends-header-p' specifications."
4273 ;; 1. Only the row starting the first row group starts the table
4275 (org-test-with-parsed-data "
4283 (org-element-map tree
'table-row
4285 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
4287 ;; 2. A row cannot start an header if there's no header in the
4289 (org-test-with-parsed-data "
4293 (org-export-table-row-ends-header-p
4294 (org-element-map tree
'table-row
'identity info
'first-match
)
4299 ;;; Tables of Contents
4301 (ert-deftest test-org-export
/collect-headlines
()
4302 "Test `org-export-collect-headlines' specifications."
4306 (org-test-with-parsed-data "* H1\n** H2"
4307 (mapcar (lambda (h) (org-element-property :raw-value h
))
4308 (org-export-collect-headlines info
)))))
4309 ;; Do not collect headlines below optional argument.
4312 (org-test-with-parsed-data "* H1\n** H2"
4313 (mapcar (lambda (h) (org-element-property :raw-value h
))
4314 (org-export-collect-headlines info
1)))))
4315 ;; Never collect headlines below maximum headline level.
4318 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4319 (mapcar (lambda (h) (org-element-property :raw-value h
))
4320 (org-export-collect-headlines info
)))))
4323 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4324 (mapcar (lambda (h) (org-element-property :raw-value h
))
4325 (org-export-collect-headlines info
2)))))
4326 ;; Do not collect footnote section.
4329 (let ((org-footnote-section "Footnotes"))
4330 (org-test-with-parsed-data "* H1\n** Footnotes"
4331 (mapcar (lambda (h) (org-element-property :raw-value h
))
4332 (org-export-collect-headlines info
))))))
4333 ;; Do not collect headlines with UNNUMBERED property set to "notoc".
4334 ;; Headlines with another value for the property are still
4335 ;; collected. UNNUMBERED property is inherited.
4338 (org-test-with-parsed-data
4339 "* H1\n* H2\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:"
4340 (mapcar (lambda (h) (org-element-property :raw-value h
))
4341 (org-export-collect-headlines info
)))))
4343 (org-test-with-parsed-data
4344 "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:\n** H2"
4345 (mapcar (lambda (h) (org-element-property :raw-value h
))
4346 (org-export-collect-headlines info
))))
4349 (org-test-with-parsed-data
4350 "* H1\n* H2\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
4351 (mapcar (lambda (h) (org-element-property :raw-value h
))
4352 (org-export-collect-headlines info
)))))
4353 ;; Collect headlines locally.
4356 (org-test-with-parsed-data "* H1\n** H2\n** H3"
4357 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4358 (mapcar (lambda (h) (org-element-property :raw-value h
))
4359 (org-export-collect-headlines info nil scope
))))))
4360 ;; When collecting locally, optional level is relative.
4363 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
4364 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4365 (mapcar (lambda (h) (org-element-property :raw-value h
))
4366 (org-export-collect-headlines info
1 scope
)))))))
4368 (ert-deftest test-org-export
/excluded-from-toc-p
()
4369 "Test `org-export-excluded-from-toc-p' specifications."
4370 ;; By default, headlines are not excluded.
4372 (org-test-with-parsed-data "* H1"
4373 (org-element-map tree
'headline
4374 (lambda (h) (org-export-excluded-from-toc-p h info
)) info t
)))
4375 ;; Exclude according to a maximum level.
4378 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4379 (org-element-map tree
'headline
4380 (lambda (h) (if (org-export-excluded-from-toc-p h info
) 'out
'in
))
4382 ;; Exclude according to UNNUMBERED property.
4384 (org-test-with-parsed-data "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:"
4385 (org-element-map tree
'headline
4386 (lambda (h) (org-export-excluded-from-toc-p h info
)) info t
)))
4387 ;; UNNUMBERED property is inherited, so is "notoc" value.
4390 (org-test-with-parsed-data
4391 "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:\n** H2"
4392 (org-element-map tree
'headline
4393 (lambda (h) (if (org-export-excluded-from-toc-p h info
) 'out
'in
))
4396 (ert-deftest test-org-export
/toc-entry-backend
()
4397 "Test `org-export-toc-entry-backend' specifications."
4401 (org-test-with-temp-text "* H <<target>>"
4402 (let (org-export-registered-backends)
4403 (org-export-define-backend 'test
4404 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4405 (org-element-property :title h
)
4406 (org-export-toc-entry-backend 'test
)
4408 (org-export-as 'test
)))))
4409 ;; Ignore footnote references.
4412 (org-test-with-temp-text "[fn:1] Definition\n* H [fn:1]"
4413 (let (org-export-registered-backends)
4414 (org-export-define-backend 'test
4415 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4416 (org-element-property :title h
)
4417 (org-export-toc-entry-backend 'test
)
4419 (org-export-as 'test
)))))
4420 ;; Replace plain links with contents, or with path.
4422 (equal "H Org mode\n"
4423 (org-test-with-temp-text "* H [[http://orgmode.org][Org mode]]"
4424 (let (org-export-registered-backends)
4425 (org-export-define-backend 'test
4426 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4427 (org-element-property :title h
)
4428 (org-export-toc-entry-backend 'test
)
4430 (org-export-as 'test
)))))
4432 (equal "H http://orgmode.org\n"
4433 (org-test-with-temp-text "* H [[http://orgmode.org]]"
4434 (let (org-export-registered-backends)
4435 (org-export-define-backend 'test
4436 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4437 (org-element-property :title h
)
4438 (org-export-toc-entry-backend 'test
)
4440 (org-export-as 'test
)))))
4441 ;; Replace radio targets with contents.
4444 (org-test-with-temp-text "* H <<<radio>>>"
4445 (let (org-export-registered-backends)
4446 (org-export-define-backend 'test
4447 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4448 (org-element-property :title h
)
4449 (org-export-toc-entry-backend 'test
)
4451 (org-export-as 'test
)))))
4452 ;; With optional argument TRANSCODERS, specify other
4456 (org-test-with-temp-text "* H *bold*"
4457 (let (org-export-registered-backends)
4458 (org-export-define-backend 'test
4459 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4460 (org-element-property :title h
)
4461 (org-export-toc-entry-backend 'test
4462 '(bold .
(lambda (_b c _i
) c
)))
4464 (org-export-as 'test
))))))
4470 (ert-deftest test-org-export
/inner-template
()
4471 "Test `inner-template' translator specifications."
4474 (org-test-with-temp-text "* Headline"
4476 (org-export-create-backend
4478 '((inner-template .
(lambda (contents info
) "Success!"))
4479 (headline .
(lambda (h c i
) "Headline"))))))))
4480 ;; Inner template is applied even in a "body-only" export.
4483 (org-test-with-temp-text "* Headline"
4485 (org-export-create-backend
4486 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
4487 (headline .
(lambda (h c i
) "Headline"))))
4488 nil nil
'body-only
)))))
4490 (ert-deftest test-org-export
/template
()
4491 "Test `template' translator specifications."
4494 (org-test-with-temp-text "* Headline"
4496 (org-export-create-backend
4497 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4498 (headline .
(lambda (h c i
) "Headline"))))))))
4499 ;; Template is not applied in a "body-only" export.
4502 (org-test-with-temp-text "* Headline"
4504 (org-export-create-backend
4505 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4506 (headline .
(lambda (h c i
) "Headline"))))
4507 nil nil
'body-only
)))))
4513 (ert-deftest test-org-export
/get-next-element
()
4514 "Test `org-export-get-next-element' specifications."
4518 (org-test-with-parsed-data "* Headline\n*a* b"
4519 (org-export-get-next-element
4520 (org-element-map tree
'bold
'identity info t
) info
))))
4521 ;; Return nil when no previous element.
4523 (org-test-with-parsed-data "* Headline\na *b*"
4524 (org-export-get-next-element
4525 (org-element-map tree
'bold
'identity info t
) info
)))
4526 ;; Non-exportable elements are ignored.
4528 (let ((org-export-with-timestamps nil
))
4529 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
4530 (org-export-get-next-element
4531 (org-element-map tree
'entity
'identity info t
) info
))))
4532 ;; Find next element in secondary strings.
4535 (org-test-with-parsed-data "* a =verb="
4537 (org-export-get-next-element
4538 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4541 (org-test-with-parsed-data "* /italic/ =verb="
4543 (org-export-get-next-element
4544 (org-element-map tree
'italic
'identity info t
) info
)))))
4545 ;; Find next element in document keywords.
4548 (org-test-with-parsed-data "#+TITLE: a =verb="
4550 (org-export-get-next-element
4552 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4553 ;; Find next element in parsed affiliated keywords.
4556 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
4558 (org-export-get-next-element
4559 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4560 ;; With optional argument N, return a list containing all the
4561 ;; following elements.
4564 '(bold code underline
)
4565 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4567 (org-export-get-next-element
4568 (org-element-map tree
'italic
'identity info t
) info t
)))))
4569 ;; When N is a positive integer, return a list containing up to
4570 ;; N following elements.
4574 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4576 (org-export-get-next-element
4577 (org-element-map tree
'italic
'identity info t
) info
2))))))
4579 (ert-deftest test-org-export
/get-previous-element
()
4580 "Test `org-export-get-previous-element' specifications."
4584 (org-test-with-parsed-data "* Headline\na *b*"
4585 (org-export-get-previous-element
4586 (org-element-map tree
'bold
'identity info t
) info
))))
4587 ;; Return nil when no previous element.
4589 (org-test-with-parsed-data "* Headline\n*a* b"
4590 (org-export-get-previous-element
4591 (org-element-map tree
'bold
'identity info t
) info
)))
4592 ;; Non-exportable elements are ignored.
4594 (let ((org-export-with-timestamps nil
))
4595 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
4596 (org-export-get-previous-element
4597 (org-element-map tree
'entity
'identity info t
) info
))))
4598 ;; Find previous element in secondary strings.
4601 (org-test-with-parsed-data "* =verb= a"
4603 (org-export-get-previous-element
4604 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4607 (org-test-with-parsed-data "* =verb= /italic/"
4609 (org-export-get-previous-element
4610 (org-element-map tree
'italic
'identity info t
) info
)))))
4611 ;; Find previous element in document keywords.
4614 (org-test-with-parsed-data "#+TITLE: =verb= a"
4616 (org-export-get-previous-element
4618 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4619 ;; Find previous element in parsed affiliated keywords.
4622 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
4624 (org-export-get-previous-element
4625 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4626 ;; With optional argument N, return a list containing up to
4627 ;; N previous elements.
4629 (equal '(underline italic bold
)
4630 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4632 (org-export-get-previous-element
4633 (org-element-map tree
'code
'identity info t
) info t
)))))
4634 ;; When N is a positive integer, return a list containing up to
4635 ;; N previous elements.
4637 (equal '(italic bold
)
4638 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4640 (org-export-get-previous-element
4641 (org-element-map tree
'code
'identity info t
) info
2))))))
4645 ;;; test-org-export.el end here