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)))))
1436 (ert-deftest test-org-export
/before-processing-hook
()
1437 "Test `org-export-before-processing-hook'."
1440 "#+MACRO: mac val\nTest\n"
1441 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1442 (let ((org-export-before-processing-hook
1444 (while (re-search-forward "{{{" nil t
)
1445 (let ((object (org-element-context)))
1446 (when (eq (org-element-type object
) 'macro
)
1448 (org-element-property :begin object
)
1449 (org-element-property :end object
)))))))))
1450 (org-export-as (org-test-default-backend)))))))
1452 (ert-deftest test-org-export
/before-parsing-hook
()
1453 "Test `org-export-before-parsing-hook'."
1455 (equal "Body 1\nBody 2\n"
1456 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1457 (let ((org-export-before-parsing-hook
1459 (goto-char (point-min))
1460 (while (re-search-forward org-outline-regexp-bol nil t
)
1462 (point-at-bol) (progn (forward-line) (point))))))))
1463 (org-export-as (org-test-default-backend)))))))
1467 ;;; Affiliated Keywords
1469 (ert-deftest test-org-export
/read-attribute
()
1470 "Test `org-export-read-attribute' specifications."
1474 (org-export-read-attribute
1476 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1477 (org-element-at-point)))
1479 ;; Return nil on empty attribute.
1481 (org-export-read-attribute
1483 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1484 ;; Return nil on "nil" string.
1486 (equal '(:a nil
:b nil
)
1487 (org-export-read-attribute
1489 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1490 (org-element-at-point)))))
1491 ;; Return nil on empty string.
1493 (equal '(:a nil
:b nil
)
1494 (org-export-read-attribute
1496 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1497 (org-element-at-point)))))
1498 ;; Return empty string when value is "".
1501 (org-export-read-attribute
1503 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1504 (org-element-at-point)))))
1505 ;; Return \"\" when value is """".
1508 (org-export-read-attribute
1510 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1511 (org-element-at-point)))))
1512 ;; Ignore text before first property.
1515 (org-export-read-attribute
1517 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1518 (org-element-at-point))))))
1520 (ert-deftest test-org-export
/get-caption
()
1521 "Test `org-export-get-caption' specifications."
1522 ;; Without optional argument, return long caption
1526 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1527 (org-export-get-caption (org-element-at-point)))))
1528 ;; With optional argument, return short caption.
1532 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1533 (org-export-get-caption (org-element-at-point) t
))))
1534 ;; Multiple lines are separated by white spaces.
1538 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1539 (org-export-get-caption (org-element-at-point))))))
1545 (ert-deftest test-org-export
/define-backend
()
1546 "Test back-end definition and accessors."
1549 (equal '((headline . my-headline-test
))
1550 (let (org-export-registered-backends)
1551 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1552 (org-export-get-all-transcoders 'test
))))
1555 (equal '((:filter-headline . my-filter
))
1556 (let (org-export-registered-backends)
1557 (org-export-define-backend 'test
1558 '((headline . my-headline-test
))
1559 :filters-alist
'((:filter-headline . my-filter
)))
1560 (org-export-backend-filters (org-export-get-backend 'test
)))))
1563 (equal '((:prop value
))
1564 (let (org-export-registered-backends)
1565 (org-export-define-backend 'test
1566 '((headline . my-headline-test
))
1567 :options-alist
'((:prop value
)))
1568 (org-export-backend-options (org-export-get-backend 'test
)))))
1571 (equal '(?k
"Test Export" test
)
1572 (let (org-export-registered-backends)
1573 (org-export-define-backend 'test
1574 '((headline . my-headline-test
))
1575 :menu-entry
'(?k
"Test Export" test
))
1576 (org-export-backend-menu (org-export-get-backend 'test
))))))
1578 (ert-deftest test-org-export
/define-derived-backend
()
1579 "Test `org-export-define-derived-backend' specifications."
1580 ;; Error when parent back-end is not defined.
1582 (let (org-export-registered-backends)
1583 (org-export-define-derived-backend 'test
'parent
)))
1584 ;; Append translation table to parent's.
1586 (equal '((:headline . test
) (:headline . parent
))
1587 (let (org-export-registered-backends)
1588 (org-export-define-backend 'parent
'((:headline . parent
)))
1589 (org-export-define-derived-backend 'test
'parent
1590 :translate-alist
'((:headline . test
)))
1591 (org-export-get-all-transcoders 'test
))))
1592 ;; Options defined in the new back have priority over those defined
1596 (let (org-export-registered-backends)
1597 (org-export-define-backend 'parent
1598 '((:headline . parent
))
1599 :options-alist
'((:a nil nil
'parent
)))
1600 (org-export-define-derived-backend 'test
'parent
1601 :options-alist
'((:a nil nil
'test
)))
1602 (plist-get (org-export--get-global-options
1603 (org-export-get-backend 'test
))
1606 (ert-deftest test-org-export
/derived-backend-p
()
1607 "Test `org-export-derived-backend-p' specifications."
1608 ;; Non-nil with direct match.
1610 (let (org-export-registered-backends)
1611 (org-export-define-backend 'test
'((headline . test
)))
1612 (org-export-derived-backend-p 'test
'test
)))
1614 (let (org-export-registered-backends)
1615 (org-export-define-backend 'test
'((headline . test
)))
1616 (org-export-define-derived-backend 'test2
'test
)
1617 (org-export-derived-backend-p 'test2
'test2
)))
1618 ;; Non-nil with a direct parent.
1620 (let (org-export-registered-backends)
1621 (org-export-define-backend 'test
'((headline . test
)))
1622 (org-export-define-derived-backend 'test2
'test
)
1623 (org-export-derived-backend-p 'test2
'test
)))
1624 ;; Non-nil with an indirect parent.
1626 (let (org-export-registered-backends)
1627 (org-export-define-backend 'test
'((headline . test
)))
1628 (org-export-define-derived-backend 'test2
'test
)
1629 (org-export-define-derived-backend 'test3
'test2
)
1630 (org-export-derived-backend-p 'test3
'test
)))
1633 (let (org-export-registered-backends)
1634 (org-export-define-backend 'test
'((headline . test
)))
1635 (org-export-define-backend 'test2
'((headline . test2
)))
1636 (org-export-derived-backend-p 'test2
'test
)))
1638 (let (org-export-registered-backends)
1639 (org-export-define-backend 'test
'((headline . test
)))
1640 (org-export-define-backend 'test2
'((headline . test2
)))
1641 (org-export-define-derived-backend 'test3
'test2
)
1642 (org-export-derived-backend-p 'test3
'test
))))
1644 (ert-deftest test-org-export
/get-all-transcoders
()
1645 "Test `org-export-get-all-transcoders' specifications."
1646 ;; Return nil when back-end cannot be found.
1647 (should-not (org-export-get-all-transcoders nil
))
1648 ;; Same as `org-export-transcoders' if no parent.
1650 (equal '((headline . ignore
))
1651 (org-export-get-all-transcoders
1652 (org-export-create-backend
1653 :transcoders
'((headline . ignore
))))))
1654 ;; But inherit from all ancestors whenever possible.
1656 (equal '((section . ignore
) (headline . ignore
))
1657 (let (org-export-registered-backends)
1658 (org-export-define-backend 'b1
'((headline . ignore
)))
1659 (org-export-get-all-transcoders
1660 (org-export-create-backend
1661 :parent
'b1
:transcoders
'((section . ignore
)))))))
1663 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1664 (let (org-export-registered-backends)
1665 (org-export-define-backend 'b1
'((headline . ignore
)))
1666 (org-export-define-derived-backend 'b2
'b1
1667 :translate-alist
'((section . ignore
)))
1668 (org-export-get-all-transcoders
1669 (org-export-create-backend
1670 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1671 ;; Back-end transcoders overrule inherited ones.
1674 (let (org-export-registered-backends)
1675 (org-export-define-backend 'b1
'((headline . a
)))
1676 (cdr (assq 'headline
1677 (org-export-get-all-transcoders
1678 (org-export-create-backend
1679 :parent
'b1
:transcoders
'((headline . b
))))))))))
1681 (ert-deftest test-org-export
/get-all-options
()
1682 "Test `org-export-get-all-options' specifications."
1683 ;; Return nil when back-end cannot be found.
1684 (should-not (org-export-get-all-options nil
))
1685 ;; Same as `org-export-options' if no parent.
1687 (equal '((headline . ignore
))
1688 (org-export-get-all-options
1689 (org-export-create-backend
1690 :options
'((headline . ignore
))))))
1691 ;; But inherit from all ancestors whenever possible.
1693 (equal '((:key2 value2
) (:key1 value1
))
1694 (let (org-export-registered-backends)
1695 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1696 (org-export-get-all-options
1697 (org-export-create-backend
1698 :parent
'b1
:options
'((:key2 value2
)))))))
1700 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1701 (let (org-export-registered-backends)
1702 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1703 (org-export-define-derived-backend 'b2
'b1
1704 :options-alist
'((:key2 value2
)))
1705 (org-export-get-all-options
1706 (org-export-create-backend
1707 :parent
'b2
:options
'((:key3 value3
)))))))
1708 ;; Back-end options overrule inherited ones.
1711 (let (org-export-registered-backends)
1712 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1714 (org-export-get-all-options
1715 (org-export-create-backend
1716 :parent
'b1
:options
'((:key1 . b
))))))))))
1718 (ert-deftest test-org-export
/get-all-filters
()
1719 "Test `org-export-get-all-filters' specifications."
1720 ;; Return nil when back-end cannot be found.
1721 (should-not (org-export-get-all-filters nil
))
1722 ;; Same as `org-export-filters' if no parent.
1724 (equal '((:filter-headline . ignore
))
1725 (org-export-get-all-filters
1726 (org-export-create-backend
1727 :filters
'((:filter-headline . ignore
))))))
1728 ;; But inherit from all ancestors whenever possible.
1730 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1731 (let (org-export-registered-backends)
1732 (org-export-define-backend 'b1
1733 nil
:filters-alist
'((:filter-headline . ignore
)))
1734 (org-export-get-all-filters
1735 (org-export-create-backend
1736 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1738 (equal '((:filter-paragraph . ignore
)
1739 (:filter-section . ignore
)
1740 (:filter-headline . ignore
))
1741 (let (org-export-registered-backends)
1742 (org-export-define-backend 'b1
1743 nil
:filters-alist
'((:filter-headline . ignore
)))
1744 (org-export-define-derived-backend 'b2
'b1
1745 :filters-alist
'((:filter-section . ignore
)))
1746 (org-export-get-all-filters
1747 (org-export-create-backend
1748 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1749 ;; Back-end filters overrule inherited ones.
1752 (let (org-export-registered-backends)
1753 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1754 (cdr (assq :filter-headline
1755 (org-export-get-all-filters
1756 (org-export-create-backend
1757 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1759 (ert-deftest test-org-export
/with-backend
()
1760 "Test `org-export-with-backend' definition."
1761 ;; Error when calling an undefined back-end
1762 (should-error (org-export-with-backend nil
"Test"))
1763 ;; Error when called back-end doesn't have an appropriate
1766 (org-export-with-backend
1767 (org-export-create-backend :transcoders
'((headline . ignore
)))
1769 ;; Otherwise, export using correct transcoder
1772 (let (org-export-registered-backends)
1773 (org-export-define-backend 'test
1774 '((plain-text .
(lambda (text contents info
) "Failure"))))
1775 (org-export-define-backend 'test2
1776 '((plain-text .
(lambda (text contents info
) "Success"))))
1777 (org-export-with-backend 'test2
"Test"))))
1778 ;; Provide correct back-end if transcoder needs to use recursive
1782 (let ((test-back-end
1783 (org-export-create-backend
1785 (list (cons 'headline
1786 (lambda (headline contents info
)
1788 (org-element-property :title headline
)
1790 (cons 'plain-text
(lambda (text info
) "Success"))))))
1791 (org-export-string-as
1793 (org-export-create-backend
1795 (list (cons 'headline
1796 (lambda (headline contents info
)
1797 (org-export-with-backend
1798 test-back-end headline contents info
))))))))))
1800 (ert-deftest test-org-export
/data-with-backend
()
1801 "Test `org-export-data-with-backend' specifications."
1802 ;; Error when calling an undefined back-end.
1803 (should-error (org-export-data-with-backend nil
"nil" nil
))
1804 ;; Otherwise, export data recursively, using correct back-end.
1808 (org-export-data-with-backend
1810 (org-export-create-backend
1812 '((plain-text .
(lambda (text info
) "Success"))
1813 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1814 '(:with-emphasize t
)))))
1820 (ert-deftest test-org-export
/comments
()
1821 "Test comments handling during export.
1822 In particular, structure of the document mustn't be altered after
1825 (equal "Para1\n\nPara2\n"
1826 (org-test-with-temp-text "
1832 (org-export-as (org-test-default-backend)))))
1834 (equal "Para1\n\nPara2\n"
1835 (org-test-with-temp-text "
1839 (org-export-as (org-test-default-backend)))))
1841 (equal "[fn:1] Para1\n\n\nPara2\n"
1842 (org-test-with-temp-text "
1847 # Outside definition
1849 (org-export-as (org-test-default-backend)))))
1851 (equal "[fn:1] Para1\n\nPara2\n"
1852 (org-test-with-temp-text "
1860 (org-export-as (org-test-default-backend)))))
1862 (equal "[fn:1] Para1\n\nPara2\n"
1863 (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 "- item 1\n\n- item 2\n"
1879 (org-test-with-temp-text "
1885 (org-export-as (org-test-default-backend))))))
1891 (ert-deftest test-org-export
/export-block
()
1892 "Test export blocks transcoding."
1895 (org-test-with-temp-text
1896 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1898 (org-export-create-backend
1899 :transcoders
'((export-block .
(lambda (b _c _i
)
1900 (org-element-property :value b
)))
1901 (section .
(lambda (_s c _i
) c
))))))))
1904 (org-test-with-temp-text
1905 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1907 (org-export-create-backend
1912 (and (equal (org-element-property :type b
) "BACKEND")
1913 (org-element-property :value b
))))
1914 (cons 'section
(lambda (_s c _i
) c
)))))))))
1919 (ert-deftest test-org-export
/export-snippet
()
1920 "Test export snippets transcoding."
1922 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1923 (let ((backend (org-test-default-backend)))
1924 (setf (org-export-backend-name backend
) 'test
)
1925 (setf (org-export-backend-transcoders backend
)
1926 (cons (cons 'export-snippet
1927 (lambda (snippet contents info
)
1928 (when (eq (org-export-snippet-backend snippet
) 'test
)
1929 (org-element-property :value snippet
))))
1930 (org-export-backend-transcoders backend
)))
1931 (let ((org-export-snippet-translation-alist nil
))
1932 (should (equal (org-export-as backend
) "A\n")))
1933 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1934 (should (equal (org-export-as backend
) "AB\n")))))
1935 ;; Ignored export snippets do not remove any blank.
1937 (equal "begin end\n"
1938 (org-test-with-parsed-data "begin @@test:A@@ end"
1939 (org-export-data-with-backend
1941 (org-export-create-backend
1943 '((paragraph .
(lambda (paragraph contents info
) contents
))
1944 (section .
(lambda (section contents info
) contents
))))
1950 (ert-deftest test-org-export
/filter-apply-functions
()
1951 "Test `org-export-filter-apply-functions' specifications."
1952 ;; Functions are applied in order and return values are reduced.
1955 (org-export-filter-apply-functions
1956 (list (lambda (value &rest _
) (concat "1" value
))
1957 (lambda (value &rest _
) (concat "2" value
)))
1959 ;; Functions returning nil are skipped.
1962 (org-export-filter-apply-functions
1963 (list #'ignore
(lambda (value &rest _
) (concat "2" value
)))
1965 ;; If all functions are skipped, return the initial value.
1968 (org-export-filter-apply-functions (list #'ignore
) "0" nil
)))
1969 ;; If any function returns the empty string, final value is the
1973 (org-export-filter-apply-functions
1974 (list (lambda (value &rest _
) "")
1975 (lambda (value &rest _
) (concat "2" value
)))
1977 ;; Any function returning the empty string short-circuits the
1980 (org-export-filter-apply-functions
1981 (list (lambda (value &rest _
) "")
1982 (lambda (value &rest _
) (error "This shouldn't happen")))
1988 (ert-deftest test-org-export
/footnote-first-reference-p
()
1989 "Test `org-export-footnote-first-reference-p' specifications."
1993 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1996 (org-export-create-backend
1998 `(,(cons 'footnote-reference
2000 (push (org-export-footnote-first-reference-p f i
)
2003 (section .
(lambda (s c i
) c
))
2004 (paragraph .
(lambda (p c i
) c
))))
2005 nil nil nil
'(:with-footnotes t
))
2006 (nreverse result
)))))
2007 ;; Limit check to DATA, when non-nil.
2011 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
2013 (org-element-map tree
'footnote-reference
2016 (org-export-footnote-first-reference-p
2017 ref info
(org-element-map tree
'headline
#'identity info t
))
2020 (nreverse result
)))))
2024 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
2026 (org-element-map tree
'footnote-reference
2028 (push (org-export-footnote-first-reference-p ref info
) result
))
2030 (nreverse result
)))))
2031 ;; If optional argument BODY-FIRST is non-nil, first find footnote
2032 ;; in the main body of the document. Otherwise, enter footnote
2033 ;; definitions when they are encountered.
2037 (org-test-with-temp-text
2038 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
2041 (org-export-create-backend
2043 `(,(cons 'footnote-reference
2045 (when (org-element-lineage f
'(drawer))
2046 (push (org-export-footnote-first-reference-p f i nil
)
2049 (drawer .
(lambda (d c i
) c
))
2050 (footnote-definition .
(lambda (d c i
) c
))
2051 (section .
(lambda (s c i
) c
))
2052 (paragraph .
(lambda (p c i
) c
))))
2053 nil nil nil
'(:with-footnotes t
))
2054 (nreverse result
)))))
2058 (org-test-with-temp-text
2059 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
2062 (org-export-create-backend
2064 `(,(cons 'footnote-reference
2066 (when (org-element-lineage f
'(drawer))
2067 (push (org-export-footnote-first-reference-p f i nil t
)
2070 (drawer .
(lambda (d c i
) c
))
2071 (footnote-definition .
(lambda (d c i
) c
))
2072 (section .
(lambda (s c i
) c
))
2073 (paragraph .
(lambda (p c i
) c
))))
2074 nil nil nil
'(:with-footnotes t
))
2075 (nreverse result
))))))
2077 (ert-deftest test-org-export
/get-footnote-number
()
2078 "Test `org-export-get-footnote-number' specifications."
2081 (org-test-with-parsed-data
2082 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
2083 (org-element-map tree
'footnote-reference
2084 (lambda (ref) (org-export-get-footnote-number ref info
))
2086 ;; Anonymous footnotes all get a new number.
2089 (org-test-with-parsed-data
2090 "Text[fn::anon1][fn::anon2]"
2091 (org-element-map tree
'footnote-reference
2092 (lambda (ref) (org-export-get-footnote-number ref info
))
2094 ;; Test nested footnotes order.
2097 '((1 .
"1") (2 .
"2") (3 .
"3") (3 .
"3") (4))
2098 (org-test-with-parsed-data
2099 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
2100 (org-element-map tree
'footnote-reference
2102 (cons (org-export-get-footnote-number ref info
)
2103 (org-element-property :label ref
)))
2105 ;; Limit number to provided DATA, when non-nil.
2109 (org-test-with-parsed-data
2110 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2111 (org-element-map tree
'footnote-reference
2113 (org-export-get-footnote-number
2114 ref info
(org-element-map tree
'headline
#'identity info t
)))
2119 (org-test-with-parsed-data
2120 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
2121 (org-element-map tree
'footnote-reference
2122 (lambda (ref) (org-export-get-footnote-number ref info
))
2124 ;; With a non-nil BODY-FIRST optional argument, first check body,
2125 ;; then footnote definitions.
2128 '(("1" .
1) ("2" .
2) ("3" .
3) ("3" .
3))
2129 (org-test-with-parsed-data
2130 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2131 (org-element-map tree
'footnote-reference
2133 (cons (org-element-property :label ref
)
2134 (org-export-get-footnote-number ref info nil t
)))
2138 '(("1" .
1) ("2" .
3) ("3" .
2) ("3" .
2))
2139 (org-test-with-parsed-data
2140 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2141 (org-element-map tree
'footnote-reference
2143 (cons (org-element-property :label ref
)
2144 (org-export-get-footnote-number ref info nil
)))
2147 (ert-deftest test-org-export
/get-footnote-definition
()
2148 "Test `org-export-get-footnote-definition' specifications."
2152 (org-element-interpret-data
2153 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1] A"
2154 (org-export-get-footnote-definition
2155 (org-element-map tree
'footnote-reference
#'identity nil t
)
2157 ;; Raise an error if no definition is found.
2159 (org-test-with-parsed-data "Text[fn:1]"
2160 (org-export-get-footnote-definition
2161 (org-element-map tree
'footnote-reference
#'identity nil t
)
2163 ;; Find inline definitions.
2166 (org-element-interpret-data
2167 (org-test-with-parsed-data "Text[fn:1:A]"
2168 (org-export-get-footnote-definition
2169 (org-element-map tree
'footnote-reference
#'identity nil t
)
2171 ;; Find anonymous definitions.
2174 (org-element-interpret-data
2175 (org-test-with-parsed-data "Text[fn::A]"
2176 (org-export-get-footnote-definition
2177 (org-element-map tree
'footnote-reference
#'identity nil t
)
2179 ;; Find empty definitions.
2182 (org-element-interpret-data
2183 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1]"
2184 (org-export-get-footnote-definition
2185 (org-element-map tree
'footnote-reference
#'identity nil t
)
2189 (org-element-interpret-data
2190 (org-test-with-parsed-data "Text[fn:1:]"
2191 (org-export-get-footnote-definition
2192 (org-element-map tree
'footnote-reference
#'identity nil t
)
2196 (org-element-interpret-data
2197 (org-test-with-parsed-data "Text[fn::]"
2198 (org-export-get-footnote-definition
2199 (org-element-map tree
'footnote-reference
#'identity nil t
)
2202 (ert-deftest test-org-export
/collect-footnote-definitions
()
2203 "Test `org-export-collect-footnote-definitions' specifications."
2206 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2208 \[fn:2] B [fn:3] [fn::D].
2211 (length (org-export-collect-footnote-definitions info
)))))
2212 ;; Limit number to provided DATA, when non-nil.
2216 (org-test-with-parsed-data
2217 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2219 (org-export-collect-footnote-definitions
2220 info
(org-element-map tree
'headline
#'identity info t
))))))
2224 (org-test-with-parsed-data
2225 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2226 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
2227 ;; With optional argument BODY-FIRST, first check body, then
2228 ;; footnote definitions.
2230 (equal '("1" "3" "2" nil
)
2231 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2233 \[fn:2] B [fn:3] [fn::D].
2236 (mapcar (lambda (e) (nth 1 e
))
2237 (org-export-collect-footnote-definitions info nil t
)))))
2239 (equal '("1" "3" "2" nil
)
2240 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2242 \[fn:2] B [fn:3] [fn::D].
2245 (mapcar (lambda (e) (nth 1 e
))
2246 (org-export-collect-footnote-definitions info
))))))
2248 (ert-deftest test-org-export
/footnotes
()
2249 "Miscellaneous tests on footnotes."
2250 (let ((org-footnote-section nil
)
2251 (org-export-with-footnotes t
))
2252 ;; Read every type of footnote.
2255 '((1 .
"A\n") (2 .
"C") (3 .
"D"))
2256 (org-test-with-parsed-data
2257 "Text[fn:1] [fn:label:C] [fn::D]\n\n[fn:1] A\n"
2258 (org-element-map tree
'footnote-reference
2260 (let ((def (org-export-get-footnote-definition ref info
)))
2261 (cons (org-export-get-footnote-number ref info
)
2262 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
2263 (car (org-element-contents
2264 (car (org-element-contents def
))))))))
2266 ;; Export nested footnote in invisible definitions.
2269 (org-test-with-temp-text "Text[fn:1]\n\n[fn:1] B [fn:2]\n\n[fn:2] C."
2270 (narrow-to-region (point) (line-end-position))
2273 (org-export-create-backend
2278 (throw 'exit
(length
2279 (org-export-collect-footnote-definitions
2281 ;; Export footnotes defined outside parsing scope.
2285 (org-test-with-temp-text "[fn:1] Out of scope
2287 <point>Paragraph[fn:1]"
2288 (org-export-as (org-test-default-backend) 'subtree
))))
2292 (org-test-with-temp-text "[fn:1] Out of scope
2294 <point>Paragraph[fn:1]"
2295 (narrow-to-region (point) (point-max))
2296 (org-export-as (org-test-default-backend)))))
2297 ;; Export nested footnotes defined outside parsing scope.
2301 (org-test-with-temp-text "
2302 \[fn:1] Out of scope[fn:2]
2304 \[fn:2] Very out of scope
2306 <point>Paragraph[fn:1]"
2307 (org-export-as (org-test-default-backend) 'subtree
))))
2311 (org-test-with-temp-text "
2312 \[fn:1] Out of scope[fn:2]
2314 \[fn:2] Very out of scope
2316 <point>Paragraph[fn:1]"
2317 (narrow-to-region (point) (point-max))
2318 (org-export-as (org-test-default-backend)))))
2322 (org-test-with-temp-text "
2323 \[fn:1] Out of scope[fn:2:D2]
2325 <point>Paragraph[fn:1]"
2326 (narrow-to-region (point) (point-max))
2327 (org-export-as (org-test-default-backend)))))
2328 ;; Export footnotes in pruned parts of tree.
2332 (let ((org-export-exclude-tags '("noexport")))
2333 (org-test-with-temp-text
2334 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] Definition"
2335 (org-export-as (org-test-default-backend))))))
2339 (let ((org-export-select-tags '("export")))
2340 (org-test-with-temp-text
2341 "* H :export:\nText[fn:1]\n* H2\n[fn:1] Definition"
2342 (org-export-as (org-test-default-backend))))))
2343 ;; Export nested footnotes in pruned parts of tree.
2347 (let ((org-export-exclude-tags '("noexport")))
2348 (org-test-with-temp-text
2349 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2350 (org-export-as (org-test-default-backend))))))
2354 (let ((org-export-select-tags '("export")))
2355 (org-test-with-temp-text
2356 "* H :export:\nText[fn:1]\n* H2\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2357 (org-export-as (org-test-default-backend))))))
2358 ;; Handle uninterpreted data in pruned footnote definitions.
2362 (let ((org-export-with-tables nil
))
2363 (org-test-with-temp-text
2364 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1]\n| a |"
2365 (org-export-as (org-test-default-backend))))))
2366 ;; Footnotes without a definition should throw an error.
2368 (org-test-with-parsed-data "Text[fn:1]"
2369 (org-export-get-footnote-definition
2370 (org-element-map tree
'footnote-reference
#'identity info t
) info
)))
2371 ;; Footnote section should be ignored in TOC and in headlines
2374 (= 1 (let ((org-footnote-section "Footnotes"))
2375 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
2376 (org-export-collect-headlines info
))))))
2379 (let ((org-footnote-section "Footnotes"))
2380 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
2381 (org-element-map tree
'headline
2383 (when (equal (org-element-property :raw-value hl
) "H2")
2384 (org-export-get-headline-number hl info
)))
2389 ;;; Headlines and Inlinetasks
2391 (ert-deftest test-org-export
/get-relative-level
()
2392 "Test `org-export-get-relative-level' specifications."
2396 (let ((org-odd-levels-only nil
))
2397 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2398 (org-element-map tree
'headline
2399 (lambda (h) (org-export-get-relative-level h info
))
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
))
2410 (ert-deftest test-org-export
/low-level-p
()
2411 "Test `org-export-low-level-p' specifications."
2415 (let ((org-odd-levels-only nil
))
2416 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2417 (org-element-map tree
'headline
2418 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
2419 (plist-put info
:headline-levels
1)))))))
2421 (ert-deftest test-org-export
/get-headline-number
()
2422 "Test `org-export-get-headline-number' specifications."
2427 (let ((org-odd-levels-only nil
))
2428 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2429 (org-element-map tree
'headline
2430 (lambda (h) (org-export-get-headline-number h info
))
2432 ;; Missing levels are replaced with 0.
2436 (let ((org-odd-levels-only nil
))
2437 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
2438 (org-element-map tree
'headline
2439 (lambda (h) (org-export-get-headline-number h info
))
2442 (ert-deftest test-org-export
/numbered-headline-p
()
2443 "Test `org-export-numbered-headline-p' specifications."
2444 ;; If `:section-numbers' is nil, never number headlines.
2446 (org-test-with-parsed-data "* Headline"
2447 (org-element-map tree
'headline
2448 (lambda (h) (org-export-numbered-headline-p h info
))
2449 (plist-put info
:section-numbers nil
))))
2450 ;; If `:section-numbers' is a number, only number headlines with
2451 ;; a level greater that it.
2455 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2456 (org-element-map tree
'headline
2457 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
2458 (plist-put info
:section-numbers
1)))))
2459 ;; Otherwise, headlines are always numbered.
2461 (org-test-with-parsed-data "* Headline"
2462 (org-element-map tree
'headline
2463 (lambda (h) (org-export-numbered-headline-p h info
))
2464 (plist-put info
:section-numbers t
))))
2465 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
2467 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
2468 (org-export-numbered-headline-p
2469 (org-element-map tree
'headline
'identity info t
)
2471 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
2473 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
2474 (org-export-numbered-headline-p
2475 (org-element-map tree
'headline
#'identity info t
)
2477 ;; UNNUMBERED ignores inheritance. Any non-nil value among
2478 ;; ancestors disables numbering.
2480 (org-test-with-parsed-data
2491 (lambda (h) (not (org-export-numbered-headline-p h info
)))
2492 (org-element-map tree
'headline
#'identity info
)))))
2494 (ert-deftest test-org-export
/number-to-roman
()
2495 "Test `org-export-number-to-roman' specifications."
2496 ;; If number is negative, return it as a string.
2497 (should (equal (org-export-number-to-roman -
1) "-1"))
2498 ;; Otherwise, return it as a roman number.
2499 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
2501 (ert-deftest test-org-export
/get-optional-title
()
2502 "Test `org-export-get-alt-title' specifications."
2503 ;; If ALT_TITLE property is defined, use it.
2506 (org-test-with-parsed-data
2507 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
2508 (org-export-get-alt-title
2509 (org-element-map tree
'headline
'identity info t
)
2511 ;; Otherwise, fall-back to regular title.
2513 (equal '("Headline")
2514 (org-test-with-parsed-data "* Headline"
2515 (org-export-get-alt-title
2516 (org-element-map tree
'headline
'identity info t
)
2519 (ert-deftest test-org-export
/get-tags
()
2520 "Test `org-export-get-tags' specifications."
2521 ;; Standard test: tags which are not a select tag, an exclude tag,
2522 ;; or specified as optional argument shouldn't be ignored.
2524 (org-test-with-parsed-data "* Headline :tag:"
2525 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2527 ;; Tags provided in the optional argument are ignored.
2529 (org-test-with-parsed-data "* Headline :ignore:"
2530 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2532 ;; Allow tag inheritance.
2536 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2537 (org-element-map tree
'headline
2538 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2539 ;; Tag inheritance checks FILETAGS keywords.
2543 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2544 (org-element-map tree
'headline
2545 (lambda (hl) (org-export-get-tags hl info nil t
)) info
)))))
2547 (ert-deftest test-org-export
/get-node-property
()
2548 "Test`org-export-get-node-property' specifications."
2552 (org-test-with-parsed-data "* Headline
2556 (org-export-get-node-property
2557 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2558 ;; Test inheritance.
2561 (org-test-with-parsed-data "* Parent
2567 (org-export-get-node-property
2568 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2569 ;; Cannot return a value before the first headline.
2571 (org-test-with-parsed-data "Paragraph
2576 (org-export-get-node-property
2577 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2579 (ert-deftest test-org-export
/get-category
()
2580 "Test `org-export-get-category' specifications."
2584 (org-test-with-parsed-data "* Headline
2588 (org-export-get-category
2589 (org-element-map tree
'headline
'identity nil t
) info
))))
2590 ;; Test inheritance from a parent headline.
2592 (equal '("value" "value")
2593 (org-test-with-parsed-data "* Headline1
2598 (org-element-map tree
'headline
2599 (lambda (hl) (org-export-get-category hl info
)) info
))))
2600 ;; Test inheritance from #+CATEGORY keyword
2603 (org-test-with-parsed-data "#+CATEGORY: value
2605 (org-export-get-category
2606 (org-element-map tree
'headline
'identity nil t
) info
))))
2607 ;; Test inheritance from file name.
2610 (org-test-with-parsed-data "* Headline"
2611 (let ((info (plist-put info
:input-file
"~/test.org")))
2612 (org-export-get-category
2613 (org-element-map tree
'headline
'identity nil t
) info
)))))
2617 (org-test-with-parsed-data "* Headline"
2618 (org-export-get-category
2619 (org-element-map tree
'headline
'identity nil t
) info
)))))
2621 (ert-deftest test-org-export
/first-sibling-p
()
2622 "Test `org-export-first-sibling-p' specifications."
2627 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2628 (org-element-map tree
'headline
2629 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2633 (org-test-with-parsed-data "- item\n\n para"
2634 (org-element-map tree
'paragraph
2635 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2637 ;; Ignore sections for headlines.
2640 (org-test-with-parsed-data "* H\nSection\n** H 2"
2641 (org-element-map tree
'headline
2642 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2644 ;; Ignore headlines not exported.
2648 (let ((org-export-exclude-tags '("ignore")))
2649 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2650 (org-element-map tree
'headline
2651 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2654 (ert-deftest test-org-export
/last-sibling-p
()
2655 "Test `org-export-last-sibling-p' specifications."
2660 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2661 (org-element-map tree
'headline
2662 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2666 (org-test-with-parsed-data "- item\n\n para"
2667 (org-element-map tree
'paragraph
2668 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2670 ;; Ignore headlines not exported.
2674 (let ((org-export-exclude-tags '("ignore")))
2675 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2676 (org-element-map tree
'headline
2677 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2680 (ert-deftest test-org-export
/handle-inlinetasks
()
2681 "Test inlinetask export."
2682 ;; Inlinetask with an exclude tag.
2683 (when (featurep 'org-inlinetask
)
2687 (let ((org-inlinetask-min-level 3)
2688 org-export-filter-body-functions
2689 org-export-filter-final-output-functions
)
2690 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2691 (org-export-as (org-test-default-backend)
2692 nil nil nil
'(:exclude-tags
("noexp")))))))
2693 ;; Inlinetask with an include tag.
2696 "* H2\n*** Inline :exp:\n"
2697 (let ((org-inlinetask-min-level 3)
2698 (org-tags-column 0))
2699 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2700 (org-export-as (org-test-default-backend)
2701 nil nil nil
'(:select-tags
("exp")))))))
2702 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2705 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2706 (org-inlinetask-min-level 3)
2707 org-export-filter-body-functions
2708 org-export-filter-final-output-functions
)
2709 (org-test-with-temp-text "*** TODO Inline"
2710 (org-export-as (org-test-default-backend)
2711 nil nil nil
'(:with-tasks nil
))))))))
2717 (ert-deftest test-org-export
/get-date
()
2718 "Test `org-export-get-date' specifications."
2719 ;; Return a properly formatted string when
2720 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2721 ;; consists in a single timestamp.
2724 (let ((org-export-date-timestamp-format "%d %m %Y"))
2725 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2726 (org-export-get-date info
)))))
2727 ;; Return a secondary string otherwise.
2730 (let ((org-export-date-timestamp-format nil
))
2731 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2732 (org-export-get-date info
)))))
2735 (org-test-with-parsed-data "#+DATE: Date"
2736 (org-export-get-date info
))))
2737 ;; Optional argument has precedence over
2738 ;; `org-export-date-timestamp-format'.
2741 (let ((org-export-date-timestamp-format "%d %m %Y"))
2742 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2743 (org-export-get-date info
"%d %m"))))))
2749 (ert-deftest test-org-export
/custom-protocol-maybe
()
2750 "Test `org-export-custom-protocol-maybe' specifications."
2755 (org-link-set-parameters "foo" :export
(lambda (p d f
) "success"))
2756 (org-export-string-as
2758 (org-export-create-backend
2761 '((section .
(lambda (s c i
) c
))
2762 (paragraph .
(lambda (p c i
) c
))
2763 (link .
(lambda (l c i
)
2764 (or (org-export-custom-protocol-maybe l c
'test
)
2770 (org-link-set-parameters
2771 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "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
'no-test
)
2782 ;; Ignore anonymous back-ends.
2787 (org-link-set-parameters
2788 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2789 (org-export-string-as
2791 (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 nil
)
2799 (ert-deftest test-org-export
/get-coderef-format
()
2800 "Test `org-export-get-coderef-format' specifications."
2801 ;; A link without description returns "%s"
2802 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2804 ;; Return "%s" when path is matched within description.
2805 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2807 ;; Otherwise return description.
2808 (should (equal (org-export-get-coderef-format "path" "desc")
2811 (ert-deftest test-org-export
/inline-image-p
()
2812 "Test `org-export-inline-image-p' specifications."
2814 (org-export-inline-image-p
2815 (org-test-with-temp-text "[[#id]]"
2816 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2817 '(("custom-id" .
"id")))))
2819 (ert-deftest test-org-export
/insert-image-links
()
2820 "Test `org-export-insert-image-links' specifications."
2823 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2824 (org-element-map tree
'link
2825 (lambda (l) (org-element-property :type l
))))))
2828 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2829 (org-element-map (org-export-insert-image-links tree info
) 'link
2830 (lambda (l) (org-element-property :type l
))))))
2831 ;; Properly set `:parent' property when replace contents with image
2835 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2836 (org-element-map (org-export-insert-image-links tree info
) 'link
2838 (org-element-type (org-element-property :parent l
)))))))
2839 ;; With optional argument RULES, recognize different links as
2843 (org-test-with-parsed-data "[[http://orgmode.org][file:image.xxx]]"
2844 (org-element-map (org-export-insert-image-links tree info
) 'link
2845 (lambda (l) (org-element-property :type l
))))))
2848 (org-test-with-parsed-data "[[http://orgmode.org][file:image.xxx]]"
2850 (org-export-insert-image-links tree info
'(("file" .
"xxx")))
2852 (lambda (l) (org-element-property :type l
)))))))
2854 (ert-deftest test-org-export
/fuzzy-link
()
2855 "Test fuzzy links specifications."
2856 ;; Link to an headline should return headline's number.
2858 ;; Note: Headline's number is in fact a list of numbers.
2860 (org-test-with-parsed-data
2861 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2862 (org-element-map tree
'link
2864 (org-export-get-ordinal
2865 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2866 ;; Link to a target in an item should return item's number.
2868 ;; Note: Item's number is in fact a list of numbers.
2870 (org-test-with-parsed-data
2871 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2872 (org-element-map tree
'link
2874 (org-export-get-ordinal
2875 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2876 ;; Link to a target in a footnote should return footnote's number.
2879 (org-test-with-parsed-data "
2880 Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
2884 (org-element-map tree
'link
2886 (org-export-get-ordinal
2887 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2888 ;; Link to a named element should return sequence number of that
2892 (org-test-with-parsed-data
2893 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2894 (org-element-map tree
'link
2896 (org-export-get-ordinal
2897 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2898 ;; Link to a target not within an item, a table, a footnote
2899 ;; reference or definition should return section number.
2902 (org-test-with-parsed-data
2903 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2904 (org-element-map tree
'link
2906 (org-export-get-ordinal
2907 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2908 ;; Space are not significant when matching a fuzzy link.
2910 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2911 (org-element-map tree
'link
2912 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2914 ;; Statistics cookies are ignored for headline match.
2916 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2917 (org-element-map tree
'link
2918 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2921 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2922 (org-element-map tree
'link
2923 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2926 (defun test-org-gen-loc-list(text type
)
2927 (org-test-with-parsed-data text
2928 (org-element-map tree type
2929 (lambda (el) (or (org-export-get-loc el info
) 'no-loc
)))))
2931 (ert-deftest test-org-export
/get-loc
()
2932 "Test `org-export-get-loc' specifications."
2934 ;; "-n" resets line number.
2936 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n\n Text\n#+END_EXAMPLE"
2938 ;; The first "+n" has 0 lines before it
2941 (test-org-gen-loc-list "#+BEGIN_EXAMPLE +n\n Text\n#+END_EXAMPLE"
2943 ;; "-n 10" resets line number but has "9 lines" before it.
2946 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n Text\n#+END_EXAMPLE"
2948 ;; -n10 with two lines then +n 15
2951 (test-org-gen-loc-list "
2952 #+BEGIN_EXAMPLE -n 10
2956 #+BEGIN_EXAMPLE +n 15
2962 (test-org-gen-loc-list "
2963 #+BEGIN_EXAMPLE -n 10
2966 #+BEGIN_EXAMPLE +n 10
2974 ;; an Example Block without -n does not add to the line count.
2976 (equal '(9 no-loc
19)
2977 (test-org-gen-loc-list "
2978 #+BEGIN_EXAMPLE -n 10
2984 #+BEGIN_EXAMPLE +n 10
2988 ;; "-n" resets line number.
2992 (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n \n (- 1 1) \n#+END_SRC"
2994 ;; The first "+n" has 0 lines before it.
2997 (test-org-gen-loc-list
2998 "#+BEGIN_SRC emacs-lisp +n \n (+ 0 (- 1 1))\n#+END_SRC"
3000 ;; "-n 10" resets line number but has "9 lines" before it.
3003 (test-org-gen-loc-list
3004 "#+BEGIN_SRC emacs-lisp -n 10\n (- 10 1)\n#+END_SRC"
3008 (test-org-gen-loc-list "
3009 #+BEGIN_SRC emacs-lisp -n 10
3013 #+BEGIN_SRC emacs-lisp +n 15
3014 (+ (- 10 1) 2 (- 15 1))
3019 (test-org-gen-loc-list "
3020 #+BEGIN_SRC emacs-lisp -n 10
3023 #+BEGIN_SRC emacs-lisp +n 10
3024 (+ (- 10 1) 1 (- 10 1))
3026 #+BEGIN_SRC emacs-lisp -n
3030 ;; A SRC Block without -n does not add to the line count.
3032 (equal '(9 no-loc
19)
3033 (test-org-gen-loc-list
3034 "#+BEGIN_SRC emacs-lisp -n 10
3037 #+BEGIN_SRC emacs-lisp
3040 #+BEGIN_SRC emacs-lisp +n 10
3041 (+ (- 10 1) 1 (- 10 1))
3045 (ert-deftest test-org-export
/resolve-coderef
()
3046 "Test `org-export-resolve-coderef' specifications."
3047 (let ((org-coderef-label-format "(ref:%s)"))
3048 ;; A link to a "-n -k -r" block returns line number.
3051 (org-test-with-parsed-data
3052 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3053 (org-export-resolve-coderef "coderef" info
))))
3056 (org-test-with-parsed-data
3057 "#+BEGIN_EXAMPLE -n 10 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3058 (org-export-resolve-coderef "coderef" info
))))
3061 (org-test-with-parsed-data
3062 "#+BEGIN_EXAMPLE -n 10 -k -r\nText \n#+END_EXAMPLE\n
3063 #+BEGIN_EXAMPLE +n 125 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3064 (org-export-resolve-coderef "coderef" info
))))
3067 (org-test-with-parsed-data
3068 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3069 (org-export-resolve-coderef "coderef" info
))))
3072 (org-test-with-parsed-data
3073 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3074 (org-export-resolve-coderef "coderef" info
))))
3077 (org-test-with-parsed-data
3078 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) \n#+END_SRC\n
3079 #+BEGIN_SRC emacs-lisp +n 125 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3080 (org-export-resolve-coderef "coderef" info
))))
3081 ;; A link to a "-n -r" block returns line number.
3084 (org-test-with-parsed-data
3085 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
3086 (org-export-resolve-coderef "coderef" info
))))
3089 (org-test-with-parsed-data
3090 "#+BEGIN_EXAMPLE -n 10 -r\nText (ref:coderef)\n#+END_EXAMPLE"
3091 (org-export-resolve-coderef "coderef" info
))))
3094 (org-test-with-parsed-data
3095 "#+BEGIN_EXAMPLE +n 10 -r\nText \n#+END_EXAMPLE
3096 #+BEGIN_EXAMPLE +n 125 -r\nText (ref:coderef)\n#+END_EXAMPLE"
3097 (org-export-resolve-coderef "coderef" info
))))
3101 (org-test-with-parsed-data
3102 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3103 (org-export-resolve-coderef "coderef" info
))))
3106 (org-test-with-parsed-data
3107 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3108 (org-export-resolve-coderef "coderef" info
))))
3111 (org-test-with-parsed-data
3112 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) \n#+END_SRC
3113 #+BEGIN_SRC emacs-lisp +n125 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3114 (org-export-resolve-coderef "coderef" info
))))
3115 ;; A link to a "-n" block returns coderef.
3118 (org-test-with-parsed-data
3119 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3120 (org-export-resolve-coderef "coderef" info
))))
3123 (org-test-with-parsed-data
3124 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
3125 (org-export-resolve-coderef "coderef" info
))))
3126 ;; A link to a "-r" block returns line number.
3129 (org-test-with-parsed-data
3130 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3131 (org-export-resolve-coderef "coderef" info
))))
3134 (org-test-with-parsed-data
3135 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
3136 (org-export-resolve-coderef "coderef" info
))))
3137 ;; A link to a block without a switch returns coderef.
3140 (org-test-with-parsed-data
3141 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3142 (org-export-resolve-coderef "coderef" info
))))
3143 (org-test-with-parsed-data
3144 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
3145 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
3146 ;; Correctly handle continued line numbers. A "+n" switch should
3147 ;; resume numbering from previous block with numbered lines,
3148 ;; ignoring blocks not numbering lines in the process. A "-n"
3149 ;; switch resets count.
3152 (org-test-with-parsed-data "
3157 #+BEGIN_SRC emacs-lisp
3161 #+BEGIN_SRC emacs-lisp +n -r
3162 \(+ 1 1) (ref:addition)
3165 #+BEGIN_EXAMPLE -n -r
3166 Another text. (ref:text)
3168 (list (org-export-resolve-coderef "addition" info
)
3169 (org-export-resolve-coderef "text" info
)))))
3170 ;; Recognize coderef with user-specified syntax.
3174 (org-test-with-parsed-data
3175 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
3176 (org-export-resolve-coderef "text" info
))))
3177 ;; Unresolved coderefs raise a `org-link-broken' signal.
3180 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3181 (org-export-resolve-coderef "unknown" info
))
3182 (org-link-broken t
)))))
3184 (ert-deftest test-org-export
/resolve-fuzzy-link
()
3185 "Test `org-export-resolve-fuzzy-link' specifications."
3186 ;; Match target objects.
3188 (org-test-with-parsed-data "<<target>> [[target]]"
3189 (org-export-resolve-fuzzy-link
3190 (org-element-map tree
'link
'identity info t
) info
)))
3191 ;; Match named elements.
3193 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
3194 (org-export-resolve-fuzzy-link
3195 (org-element-map tree
'link
'identity info t
) info
)))
3196 ;; Match exact headline's name.
3198 (org-test-with-parsed-data "* My headline\n[[My headline]]"
3199 (org-export-resolve-fuzzy-link
3200 (org-element-map tree
'link
'identity info t
) info
)))
3201 ;; Targets objects have priority over headline titles.
3204 (org-test-with-parsed-data "* target\n<<target>>[[target]]"
3206 (org-export-resolve-fuzzy-link
3207 (org-element-map tree
'link
'identity info t
) info
)))))
3208 ;; Named elements have priority over headline titles.
3211 (org-test-with-parsed-data
3212 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
3214 (org-export-resolve-fuzzy-link
3215 (org-element-map tree
'link
'identity info t
) info
)))))
3216 ;; If link's path starts with a "*", only match headline titles,
3220 (org-test-with-parsed-data
3221 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
3223 (org-export-resolve-fuzzy-link
3224 (org-element-map tree
'link
'identity info t
) info
)))))
3225 ;; Raise a `org-link-broken' signal if no match.
3227 (org-test-with-parsed-data "[[target]]"
3229 (org-export-resolve-fuzzy-link
3230 (org-element-map tree
'link
#'identity info t
) info
)
3231 (org-link-broken t
))))
3232 ;; Match fuzzy link even when before first headline.
3235 (org-test-with-parsed-data "[[hl]]\n* hl"
3237 (org-export-resolve-fuzzy-link
3238 (org-element-map tree
'link
'identity info t
) info
)))))
3239 ;; Handle url-encoded fuzzy links.
3241 (org-test-with-parsed-data "* A B\n[[A%20B]]"
3242 (org-export-resolve-fuzzy-link
3243 (org-element-map tree
'link
#'identity info t
) info
))))
3245 (ert-deftest test-org-export
/resolve-id-link
()
3246 "Test `org-export-resolve-id-link' specifications."
3247 ;; Regular test for custom-id link.
3249 (equal '("Headline1")
3250 (org-test-with-parsed-data "* Headline1
3256 (org-element-property
3258 (org-export-resolve-id-link
3259 (org-element-map tree
'link
'identity info t
) info
)))))
3260 ;; Raise a `org-link-broken' signal on failing searches.
3262 (org-test-with-parsed-data "* Headline1
3269 (org-export-resolve-id-link
3270 (org-element-map tree
'link
#'identity info t
) info
)
3271 (org-link-broken t
))))
3272 ;; Test for internal id target.
3274 (equal '("Headline1")
3275 (org-test-with-parsed-data "* Headline1
3281 (org-element-property
3283 (org-export-resolve-id-link
3284 (org-element-map tree
'link
'identity info t
) info
)))))
3285 ;; Test for external id target.
3289 (org-test-with-parsed-data "[[id:aaaa]]"
3290 (org-export-resolve-id-link
3291 (org-element-map tree
'link
'identity info t
)
3292 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
3294 (ert-deftest test-org-export
/resolve-radio-link
()
3295 "Test `org-export-resolve-radio-link' specifications."
3298 (org-test-with-temp-text "<<<radio>>> radio"
3299 (org-update-radio-target-regexp)
3300 (let* ((tree (org-element-parse-buffer))
3301 (info `(:parse-tree
,tree
)))
3302 (org-export-resolve-radio-link
3303 (org-element-map tree
'link
'identity info t
)
3305 ;; Radio targets are case-insensitive.
3307 (org-test-with-temp-text "<<<RADIO>>> radio"
3308 (org-update-radio-target-regexp)
3309 (let* ((tree (org-element-parse-buffer))
3310 (info `(:parse-tree
,tree
)))
3311 (org-export-resolve-radio-link
3312 (org-element-map tree
'link
'identity info t
)
3314 ;; Radio target with objects.
3316 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
3317 (org-update-radio-target-regexp)
3318 (let* ((tree (org-element-parse-buffer))
3319 (info `(:parse-tree
,tree
)))
3320 (org-export-resolve-radio-link
3321 (org-element-map tree
'link
'identity info t
)
3323 ;; Radio target with objects at its beginning.
3325 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
3326 (org-update-radio-target-regexp)
3327 (let* ((tree (org-element-parse-buffer))
3328 (info `(:parse-tree
,tree
)))
3329 (org-export-resolve-radio-link
3330 (org-element-map tree
'link
'identity info t
)
3332 ;; Radio link next to an apostrophe.
3334 (org-test-with-temp-text "<<<radio>>> radio's"
3335 (org-update-radio-target-regexp)
3336 (let* ((tree (org-element-parse-buffer))
3337 (info `(:parse-tree
,tree
)))
3338 (org-export-resolve-radio-link
3339 (org-element-map tree
'link
'identity info t
)
3341 ;; Multiple radio targets.
3343 (equal '("radio1" "radio2")
3344 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
3345 (org-update-radio-target-regexp)
3346 (let* ((tree (org-element-parse-buffer))
3347 (info `(:parse-tree
,tree
)))
3348 (org-element-map tree
'link
3350 (org-element-property
3351 :value
(org-export-resolve-radio-link link info
)))
3353 ;; Radio target is whitespace insensitive.
3355 (org-test-with-temp-text "<<<a radio>>> a\n radio"
3356 (org-update-radio-target-regexp)
3357 (let* ((tree (org-element-parse-buffer))
3358 (info `(:parse-tree
,tree
)))
3359 (org-element-map tree
'link
3360 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
3362 (ert-deftest test-org-export
/file-uri
()
3363 "Test `org-export-file-uri' specifications."
3364 ;; Preserve relative filenames.
3365 (should (equal "relative.org" (org-export-file-uri "relative.org")))
3366 ;; Local files start with "file://"
3367 (should (equal (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "/local.org"))
3368 (org-export-file-uri "/local.org")))
3369 ;; Remote files start with "file://"
3370 (should (equal "file://ssh:myself@some.where:papers/last.pdf"
3371 (org-export-file-uri "/ssh:myself@some.where:papers/last.pdf")))
3372 (should (equal "file://localhost/etc/fstab"
3373 (org-export-file-uri "//localhost/etc/fstab")))
3374 ;; Expand filename starting with "~".
3375 (should (equal (org-export-file-uri "~/file.org")
3376 (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "~/file.org")))))
3378 (ert-deftest test-org-export
/get-reference
()
3379 "Test `org-export-get-reference' specifications."
3381 (org-test-with-parsed-data "* Headline"
3382 (org-export-get-reference (org-element-map tree
'headline
#'identity nil t
)
3384 ;; For a given element always return the same reference.
3386 (org-test-with-parsed-data "* Headline"
3387 (let ((headline (org-element-map tree
'headline
#'identity nil t
)))
3388 (equal (org-export-get-reference headline info
)
3389 (org-export-get-reference headline info
)))))
3390 ;; References get through local export back-ends.
3392 (org-test-with-parsed-data "* Headline"
3393 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3395 (org-export-create-backend
3397 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3398 (equal (org-trim (org-export-data-with-backend headline backend info
))
3399 (org-export-get-reference headline info
)))))
3401 (org-test-with-parsed-data "* Headline"
3402 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3404 (org-export-create-backend
3406 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3407 (equal (org-export-with-backend backend headline nil info
)
3408 (org-export-get-reference headline info
)))))
3409 ;; Use search cells defined in `:crossrefs'. However, handle
3410 ;; duplicate search cells.
3413 (org-test-with-parsed-data "* Headline"
3414 (let* ((headline (org-element-map tree
'headline
#'identity nil t
))
3415 (search-cell (car (org-export-search-cells headline
))))
3417 (plist-put info
:crossrefs
(list (cons search-cell
1))))
3418 (org-export-get-reference headline info
)))))
3420 (equal '("org0000001" "org0000001")
3421 (org-test-with-parsed-data "* H\n** H"
3422 (org-element-map tree
'headline
3424 (let* ((search-cell (car (org-export-search-cells h
)))
3425 (info (plist-put info
:crossrefs
3426 (list (cons search-cell
1)))))
3427 (org-export-get-reference h info
))))))))
3430 ;;; Pseudo objects and pseudo elements
3432 (ert-deftest test-org-export
/pseudo-elements
()
3433 "Test exporting pseudo-elements."
3434 ;; Handle blank lines after pseudo-elements. In particular, do not
3435 ;; replace them with white spaces.
3437 (equal "contents\n\nparagraph\n"
3438 (let ((backend (org-export-create-backend
3440 '((pseudo-element .
(lambda (_p c _i
) c
))
3441 (paragraph .
(lambda (_p c _i
) c
))
3442 (plain-text .
(lambda (c _i
) c
)))))
3443 (element '(pseudo-element (:post-blank
1) "contents"))
3444 (paragraph '(paragraph nil
"paragraph"))
3445 (data '(org-data nil
)))
3446 (org-element-adopt-elements data element paragraph
)
3447 (org-export-data-with-backend data backend nil
)))))
3449 (ert-deftest test-org-export
/pseudo-objects
()
3450 "Test exporting pseudo-objects."
3451 ;; Handle blank spaces after pseudo-objects. In particular, do not
3452 ;; replace them with newlines.
3454 (equal "begin x end\n"
3455 (let ((backend (org-export-create-backend
3457 '((pseudo-object .
(lambda (_p c _i
) c
))
3458 (paragraph .
(lambda (_p c _i
) c
))
3459 (plain-text .
(lambda (c _i
) c
)))))
3460 (object '(pseudo-object (:post-blank
1) "x"))
3461 (paragraph '(paragraph nil
)))
3462 (org-element-adopt-elements paragraph
"begin " object
"end")
3463 (org-export-data-with-backend paragraph backend nil
)))))
3466 ;;; Src-block and example-block
3468 (ert-deftest test-org-export
/unravel-code
()
3469 "Test `org-export-unravel-code' function."
3470 ;; Code without reference.
3473 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3474 (org-export-unravel-code (org-element-at-point)))))
3475 ;; Code with reference.
3477 (equal '("(+ 1 1)" (1 .
"test"))
3478 (org-test-with-temp-text
3479 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
3480 (let ((org-coderef-label-format "(ref:%s)"))
3481 (org-export-unravel-code (org-element-at-point))))))
3482 ;; Code with user-defined reference.
3485 '("(+ 1 1)" (1 .
"test"))
3486 (org-test-with-temp-text
3487 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
3488 (let ((org-coderef-label-format "(ref:%s)"))
3489 (org-export-unravel-code (org-element-at-point))))))
3490 ;; Code references keys are relative to the current block.
3492 (equal '("(+ 2 2)\n(+ 3 3)" (2 .
"one"))
3493 (org-test-with-temp-text "
3502 (let ((org-coderef-label-format "(ref:%s)"))
3503 (org-export-unravel-code (org-element-at-point)))))\x14))
3505 (ert-deftest test-org-export
/format-code-default
()
3506 "Test `org-export-format-code-default' specifications."
3507 ;; Preserve blank lines, even when code is empty.
3510 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
3511 (org-export-format-code-default
3512 (org-element-map tree
'src-block
#'identity info t
) info
))))
3513 ;; Likewise, preserve leading and trailing blank lines in the code.
3515 (equal "\n(+ 1 1)\n"
3516 (org-test-with-parsed-data
3517 "#+BEGIN_SRC emacs-lisp\n\n(+ 1 1)\n#+END_SRC"
3518 (org-export-format-code-default
3519 (org-element-map tree
'src-block
#'identity info t
) info
))))
3521 (equal "(+ 1 1)\n\n"
3522 (org-test-with-parsed-data
3523 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n\n#+END_SRC"
3524 (org-export-format-code-default
3525 (org-element-map tree
'src-block
#'identity info t
) info
))))
3526 ;; Number lines, two whitespace characters before the actual loc.
3529 (org-test-with-parsed-data
3530 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
3531 (org-export-format-code-default
3532 (org-element-map tree
'src-block
#'identity info t
) info
))))
3533 ;; Numbering includes blank lines.
3535 (equal "1 \n2 a\n3 \n4 b\n5 \n"
3536 (org-test-with-parsed-data
3537 "#+BEGIN_SRC emacs-lisp +n\n\na\n\nb\n\n#+END_SRC"
3538 (org-export-format-code-default
3539 (org-element-map tree
'src-block
#'identity info t
) info
))))
3540 ;; Put references 6 whitespace characters after the widest line,
3541 ;; wrapped within parenthesis.
3543 (equal "123 (a)\n1 (b)\n"
3544 (let ((org-coderef-label-format "(ref:%s)"))
3545 (org-test-with-parsed-data
3546 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
3547 (org-export-format-code-default
3548 (org-element-map tree
'src-block
#'identity info t
) info
))))))
3554 (ert-deftest test-org-export
/activate-smart-quotes
()
3555 "Test `org-export-activate-smart-quotes' specifications."
3556 ;; Double quotes: standard test.
3559 '("some “quoted” text")
3560 (let ((org-export-default-language "en"))
3561 (org-test-with-parsed-data "some \"quoted\" text"
3562 (org-element-map tree
'plain-text
3563 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3565 ;; Opening quotes: at the beginning of a paragraph.
3569 (let ((org-export-default-language "en"))
3570 (org-test-with-parsed-data "\"begin"
3571 (org-element-map tree
'plain-text
3572 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3574 ;; Opening quotes: after an object.
3577 '("“quoted” text")
3578 (let ((org-export-default-language "en"))
3579 (org-test-with-parsed-data "=verb= \"quoted\" text"
3580 (org-element-map tree
'plain-text
3581 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3583 ;; Closing quotes: at the end of a paragraph.
3586 '("Quoted “text”")
3587 (let ((org-export-default-language "en"))
3588 (org-test-with-parsed-data "Quoted \"text\""
3589 (org-element-map tree
'plain-text
3590 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3592 ;; Inner quotes: standard test.
3594 (equal '("« outer « inner » outer »")
3595 (let ((org-export-default-language "fr"))
3596 (org-test-with-parsed-data "\"outer 'inner' outer\""
3597 (org-element-map tree
'plain-text
3598 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3600 ;; Inner quotes: close to special symbols.
3602 (equal '("« outer (« inner ») outer »")
3603 (let ((org-export-default-language "fr"))
3604 (org-test-with-parsed-data "\"outer ('inner') outer\""
3605 (org-element-map tree
'plain-text
3606 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3609 (equal '("« « inner » »")
3610 (let ((org-export-default-language "fr"))
3611 (org-test-with-parsed-data "\"'inner'\""
3612 (org-element-map tree
'plain-text
3613 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3615 ;; Apostrophe: standard test.
3617 (equal '("It « shouldn’t » fail")
3618 (let ((org-export-default-language "fr"))
3619 (org-test-with-parsed-data "It \"shouldn't\" fail"
3620 (org-element-map tree
'plain-text
3621 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3624 (equal '("It shouldn’t fail")
3625 (let ((org-export-default-language "fr"))
3626 (org-test-with-parsed-data "It shouldn't fail"
3627 (org-element-map tree
'plain-text
3628 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3630 ;; Apostrophe: before an object.
3633 '("« a’" " »")
3634 (let ((org-export-default-language "fr"))
3635 (org-test-with-parsed-data "\"a'=b=\""
3636 (org-element-map tree
'plain-text
3637 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3639 ;; Apostrophe: after an object.
3641 (equal '("« " "’s »")
3642 (let ((org-export-default-language "fr"))
3643 (org-test-with-parsed-data "\"=code='s\""
3644 (org-element-map tree
'plain-text
3645 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3647 ;; Special case: isolated quotes.
3649 (equal '("“" "”")
3650 (let ((org-export-default-language "en"))
3651 (org-test-with-parsed-data "\"$x$\""
3652 (org-element-map tree
'plain-text
3653 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3655 ;; Smart quotes in secondary strings.
3657 (equal '("“" "”")
3658 (let ((org-export-default-language "en"))
3659 (org-test-with-parsed-data "* \"$x$\""
3660 (org-element-map tree
'plain-text
3661 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3663 ;; Smart quotes in document keywords.
3665 (equal '("“" "”")
3666 (let ((org-export-default-language "en"))
3667 (org-test-with-parsed-data "#+TITLE: \"$x$\""
3668 (org-element-map (plist-get info
:title
) 'plain-text
3669 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3671 ;; Smart quotes in parsed affiliated keywords.
3673 (equal '("“" "”" "Paragraph")
3674 (let ((org-export-default-language "en"))
3675 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
3676 (org-element-map tree
'plain-text
3677 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3679 ;; Smart quotes within objects.
3681 (equal '("“foo”")
3682 (let ((org-export-default-language "en"))
3683 (org-test-with-parsed-data "| \"foo\" |"
3684 (org-element-map tree
'plain-text
3685 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3687 ;; FIXME: Test failing non-interactively.
3690 ;; (equal '("“foo”")
3691 ;; (let ((org-export-default-language "en"))
3692 ;; (org-test-with-parsed-data "*\"foo\"*"
3693 ;; (org-element-map tree 'plain-text
3694 ;; (lambda (s) (org-export-activate-smart-quotes s :html info))
3695 ;; info nil nil t)))))
3702 (ert-deftest test-org-export
/special-column
()
3703 "Test if the table's special column is properly recognized."
3704 ;; 1. First column is special if it contains only a special marking
3705 ;; characters or empty cells.
3706 (org-test-with-temp-text "
3710 (org-export-table-has-special-column-p
3712 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3713 ;; 2. If the column contains anything else, it isn't special.
3714 (org-test-with-temp-text "
3718 (org-export-table-has-special-column-p
3720 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3721 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
3723 (org-test-with-temp-text "
3732 (org-export-table-has-special-column-p
3734 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3735 ;; 4. A first column with only empty cells isn't considered as
3737 (org-test-with-temp-text "
3741 (org-export-table-has-special-column-p
3743 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
3745 (ert-deftest test-org-export
/table-row-is-special-p
()
3746 "Test `org-export-table-row-is-special-p' specifications."
3747 ;; 1. A row is special if it has a special marking character in the
3749 (org-test-with-parsed-data "| ! | 1 |"
3751 (org-export-table-row-is-special-p
3752 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3753 ;; 2. A row is special when its first field is "/"
3754 (org-test-with-parsed-data "
3758 (org-export-table-row-is-special-p
3759 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3760 ;; 3. A row only containing alignment cookies is also considered as
3762 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
3764 (org-export-table-row-is-special-p
3765 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3766 ;; 4. Everything else isn't considered as special.
3767 (org-test-with-parsed-data "| \alpha | | c |"
3769 (org-export-table-row-is-special-p
3770 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3771 ;; 5. Table's rules are never considered as special rows.
3772 (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
))))
3777 (ert-deftest test-org-export
/has-header-p
()
3778 "Test `org-export-table-has-header-p' specifications."
3781 (org-test-with-parsed-data "
3785 (org-export-table-has-header-p
3786 (org-element-map tree
'table
'identity info
'first-match
)
3788 ;; Without an header.
3790 (org-test-with-parsed-data "
3793 (org-export-table-has-header-p
3794 (org-element-map tree
'table
'identity info
'first-match
)
3796 ;; Don't get fooled with starting and ending rules.
3798 (org-test-with-parsed-data "
3803 (org-export-table-has-header-p
3804 (org-element-map tree
'table
'identity info
'first-match
)
3807 (ert-deftest test-org-export
/table-row-group
()
3808 "Test `org-export-table-row-group' specifications."
3809 ;; A rule creates a new group.
3812 (org-test-with-parsed-data "
3816 (org-element-map tree
'table-row
3818 (if (eq (org-element-property :type row
) 'rule
) 'rule
3819 (org-export-table-row-group row info
)))))))
3820 ;; Special rows are ignored in count.
3824 (org-test-with-parsed-data "
3828 (org-element-map tree
'table-row
3830 (if (eq (org-element-property :type row
) 'rule
) 'rule
3831 (org-export-table-row-group row info
)))
3833 ;; Double rules also are ignored in count.
3835 (equal '(1 rule rule
2)
3836 (org-test-with-parsed-data "
3841 (org-element-map tree
'table-row
3843 (if (eq (org-element-property :type row
) 'rule
) 'rule
3844 (org-export-table-row-group row info
))))))))
3846 (ert-deftest test-org-export
/table-row-number
()
3847 "Test `org-export-table-row-number' specifications."
3848 ;; Standard test. Number is 0-indexed.
3851 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3852 (org-element-map tree
'table-row
3853 (lambda (row) (org-export-table-row-number row info
)) info
))))
3854 ;; Number ignores separators.
3857 (org-test-with-parsed-data "
3861 (org-element-map tree
'table-row
3862 (lambda (row) (org-export-table-row-number row info
)) info
))))
3863 ;; Number ignores special rows.
3866 (org-test-with-parsed-data "
3872 (org-element-map tree
'table-row
3873 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3875 (ert-deftest test-org-export
/table-cell-width
()
3876 "Test `org-export-table-cell-width' specifications."
3877 ;; 1. Width is primarily determined by width cookies. If no cookie
3878 ;; is found, cell's width is nil.
3879 (org-test-with-parsed-data "
3880 | / | <l> | <6> | <l7> |
3885 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3886 (org-element-map tree
'table-cell
'identity info
)))))
3887 ;; 2. The last width cookie has precedence.
3888 (org-test-with-parsed-data "
3895 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3896 (org-element-map tree
'table-cell
'identity info
)))))
3897 ;; 3. Valid width cookies must have a specific row.
3898 (org-test-with-parsed-data "| <6> | cell |"
3902 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3903 (org-element-map tree
'table-cell
'identity
))))))
3905 (ert-deftest test-org-export
/table-cell-alignment
()
3906 "Test `org-export-table-cell-alignment' specifications."
3907 ;; 1. Alignment is primarily determined by alignment cookies.
3909 (equal '(left center right
)
3910 (let ((org-table-number-fraction 0.5)
3911 (org-table-number-regexp "^[0-9]+$"))
3912 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3913 (mapcar (lambda (cell)
3914 (org-export-table-cell-alignment cell info
))
3915 (org-element-map tree
'table-cell
'identity
))))))
3916 ;; 2. The last alignment cookie has precedence.
3918 (equal '(right right right
)
3919 (org-test-with-parsed-data "
3923 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3924 (org-element-map tree
'table-cell
'identity
)))))
3925 ;; 3. If there's no cookie, cell's contents determine alignment.
3926 ;; A column mostly made of cells containing numbers will align
3927 ;; its cells to the right.
3929 (equal '(right right right
)
3930 (let ((org-table-number-fraction 0.5)
3931 (org-table-number-regexp "^[0-9]+$"))
3932 (org-test-with-parsed-data "
3936 (mapcar (lambda (cell)
3937 (org-export-table-cell-alignment cell info
))
3938 (org-element-map tree
'table-cell
'identity
))))))
3939 ;; 4. Otherwise, they will be aligned to the left.
3941 (equal '(left left left
)
3942 (org-test-with-parsed-data "
3946 (mapcar (lambda (cell)
3947 (org-export-table-cell-alignment cell info
))
3948 (org-element-map tree
'table-cell
'identity info
))))))
3950 (ert-deftest test-org-export
/table-cell-borders
()
3951 "Test `org-export-table-cell-borders' specifications."
3952 ;; 1. Recognize various column groups indicators.
3953 (org-test-with-parsed-data "| / | < | > | <> |"
3956 '((right bottom top
) (left bottom top
) (right bottom top
)
3957 (right left bottom top
))
3958 (mapcar (lambda (cell)
3959 (org-export-table-cell-borders cell info
))
3960 (org-element-map tree
'table-cell
'identity
)))))
3961 ;; 2. Accept shortcuts to define column groups.
3962 (org-test-with-parsed-data "| / | < | < |"
3965 '((right bottom top
) (right left bottom top
) (left bottom top
))
3966 (mapcar (lambda (cell)
3967 (org-export-table-cell-borders cell info
))
3968 (org-element-map tree
'table-cell
'identity
)))))
3969 ;; 3. A valid column groups row must start with a "/".
3970 (org-test-with-parsed-data "
3974 (equal '((top) (top) (bottom) (bottom))
3975 (mapcar (lambda (cell)
3976 (org-export-table-cell-borders cell info
))
3977 (org-element-map tree
'table-cell
'identity
)))))
3978 ;; 4. Take table rules into consideration.
3979 (org-test-with-parsed-data "
3984 (equal '((below top
) (bottom above
))
3985 (mapcar (lambda (cell)
3986 (org-export-table-cell-borders cell info
))
3987 (org-element-map tree
'table-cell
'identity
)))))
3988 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3989 ;; (resp. `bottom' and `below') borders. Any special row is
3991 (org-test-with-parsed-data "
3997 (equal '((bottom below top above
))
3999 (mapcar (lambda (cell)
4000 (org-export-table-cell-borders cell info
))
4001 (org-element-map tree
'table-cell
'identity
)))))))
4003 (ert-deftest test-org-export
/table-dimensions
()
4004 "Test `org-export-table-dimensions' specifications."
4005 ;; 1. Standard test.
4006 (org-test-with-parsed-data "
4011 (org-export-table-dimensions
4012 (org-element-map tree
'table
'identity info
'first-match
) info
))))
4013 ;; 2. Ignore horizontal rules and special columns.
4014 (org-test-with-parsed-data "
4021 (org-export-table-dimensions
4022 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
4024 (ert-deftest test-org-export
/table-cell-address
()
4025 "Test `org-export-table-cell-address' specifications."
4026 ;; 1. Standard test: index is 0-based.
4027 (org-test-with-parsed-data "| a | b |"
4029 (equal '((0 .
0) (0 .
1))
4030 (org-element-map tree
'table-cell
4031 (lambda (cell) (org-export-table-cell-address cell info
))
4033 ;; 2. Special column isn't counted, nor are special rows.
4034 (org-test-with-parsed-data "
4039 (org-export-table-cell-address
4040 (car (last (org-element-map tree
'table-cell
'identity info
)))
4042 ;; 3. Tables rules do not count either.
4043 (org-test-with-parsed-data "
4051 (org-export-table-cell-address
4052 (car (last (org-element-map tree
'table-cell
'identity info
)))
4054 ;; 4. Return nil for special cells.
4055 (org-test-with-parsed-data "| / | a |"
4057 (org-export-table-cell-address
4058 (org-element-map tree
'table-cell
'identity nil
'first-match
)
4061 (ert-deftest test-org-export
/get-table-cell-at
()
4062 "Test `org-export-get-table-cell-at' specifications."
4063 ;; 1. Address ignores special columns, special rows and rules.
4064 (org-test-with-parsed-data "
4071 (org-element-contents
4072 (org-export-get-table-cell-at
4074 (org-element-map tree
'table
'identity info
'first-match
)
4076 ;; 2. Return value for a non-existent address is nil.
4077 (org-test-with-parsed-data "| a |"
4079 (org-export-get-table-cell-at
4081 (org-element-map tree
'table
'identity info
'first-match
)
4083 (org-test-with-parsed-data "| / |"
4085 (org-export-get-table-cell-at
4087 (org-element-map tree
'table
'identity info
'first-match
)
4090 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
4091 "Test `org-export-table-cell-starts-colgroup-p' specifications."
4092 ;; 1. A cell at a beginning of a row always starts a column group.
4093 (org-test-with-parsed-data "| a |"
4095 (org-export-table-cell-starts-colgroup-p
4096 (org-element-map tree
'table-cell
'identity info
'first-match
)
4098 ;; 2. Special column should be ignored when determining the
4099 ;; beginning of the row.
4100 (org-test-with-parsed-data "
4104 (org-export-table-cell-starts-colgroup-p
4105 (org-element-map tree
'table-cell
'identity info
'first-match
)
4107 ;; 2. Explicit column groups.
4108 (org-test-with-parsed-data "
4114 (org-element-map tree
'table-cell
4116 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
4119 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
4120 "Test `org-export-table-cell-ends-colgroup-p' specifications."
4121 ;; 1. A cell at the end of a row always ends a column group.
4122 (org-test-with-parsed-data "| a |"
4124 (org-export-table-cell-ends-colgroup-p
4125 (org-element-map tree
'table-cell
'identity info
'first-match
)
4127 ;; 2. Special column should be ignored when determining the
4128 ;; beginning of the row.
4129 (org-test-with-parsed-data "
4133 (org-export-table-cell-ends-colgroup-p
4134 (org-element-map tree
'table-cell
'identity info
'first-match
)
4136 ;; 3. Explicit column groups.
4137 (org-test-with-parsed-data "
4143 (org-element-map tree
'table-cell
4145 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
4148 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
4149 "Test `org-export-table-row-starts-rowgroup-p' specifications."
4150 ;; 1. A row at the beginning of a table always starts a row group.
4151 ;; So does a row following a table rule.
4152 (org-test-with-parsed-data "
4159 (org-element-map tree
'table-row
4161 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4163 ;; 2. Special rows should be ignored when determining the beginning
4165 (org-test-with-parsed-data "
4174 (org-element-map tree
'table-row
4176 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4179 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
4180 "Test `org-export-table-row-ends-rowgroup-p' specifications."
4181 ;; 1. A row at the end of a table always ends a row group. So does
4182 ;; a row preceding a table rule.
4183 (org-test-with-parsed-data "
4190 (org-element-map tree
'table-row
4192 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4194 ;; 2. Special rows should be ignored when determining the beginning
4196 (org-test-with-parsed-data "
4205 (org-element-map tree
'table-row
4207 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4210 (ert-deftest test-org-export
/table-row-in-header-p
()
4211 "Test `org-export-table-row-in-header-p' specifications."
4212 ;; Standard test. Separators are always nil.
4216 (org-test-with-parsed-data "| a |\n|---|\n| b |"
4217 (org-element-map tree
'table-row
4219 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
4220 ;; Nil when there is no header.
4224 (org-test-with-parsed-data "| a |\n| b |"
4225 (org-element-map tree
'table-row
4227 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
4229 (ert-deftest test-org-export
/table-row-starts-header-p
()
4230 "Test `org-export-table-row-starts-header-p' specifications."
4231 ;; 1. Only the row starting the first row group starts the table
4233 (org-test-with-parsed-data "
4241 (org-element-map tree
'table-row
4243 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
4245 ;; 2. A row cannot start an header if there's no header in the
4247 (org-test-with-parsed-data "
4251 (org-export-table-row-starts-header-p
4252 (org-element-map tree
'table-row
'identity info
'first-match
)
4255 (ert-deftest test-org-export
/table-row-ends-header-p
()
4256 "Test `org-export-table-row-ends-header-p' specifications."
4257 ;; 1. Only the row starting the first row group starts the table
4259 (org-test-with-parsed-data "
4267 (org-element-map tree
'table-row
4269 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
4271 ;; 2. A row cannot start an header if there's no header in the
4273 (org-test-with-parsed-data "
4277 (org-export-table-row-ends-header-p
4278 (org-element-map tree
'table-row
'identity info
'first-match
)
4283 ;;; Tables of Contents
4285 (ert-deftest test-org-export
/collect-headlines
()
4286 "Test `org-export-collect-headlines' specifications."
4291 (org-test-with-parsed-data "* H1\n** H2"
4292 (org-export-collect-headlines info
)))))
4293 ;; Do not collect headlines below optional argument.
4297 (org-test-with-parsed-data "* H1\n** H2"
4298 (org-export-collect-headlines info
1)))))
4299 ;; Never collect headlines below maximum headline level.
4303 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4304 (org-export-collect-headlines info
)))))
4308 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4309 (org-export-collect-headlines info
2)))))
4310 ;; Collect headlines locally.
4313 (org-test-with-parsed-data "* H1\n** H2\n** H3"
4314 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4315 (length (org-export-collect-headlines info nil scope
))))))
4316 ;; When collecting locally, optional level is relative.
4319 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
4320 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4321 (length (org-export-collect-headlines info
1 scope
)))))))
4327 (ert-deftest test-org-export
/inner-template
()
4328 "Test `inner-template' translator specifications."
4331 (org-test-with-temp-text "* Headline"
4333 (org-export-create-backend
4335 '((inner-template .
(lambda (contents info
) "Success!"))
4336 (headline .
(lambda (h c i
) "Headline"))))))))
4337 ;; Inner template is applied even in a "body-only" export.
4340 (org-test-with-temp-text "* Headline"
4342 (org-export-create-backend
4343 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
4344 (headline .
(lambda (h c i
) "Headline"))))
4345 nil nil
'body-only
)))))
4347 (ert-deftest test-org-export
/template
()
4348 "Test `template' translator specifications."
4351 (org-test-with-temp-text "* Headline"
4353 (org-export-create-backend
4354 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4355 (headline .
(lambda (h c i
) "Headline"))))))))
4356 ;; Template is not applied in a "body-only" export.
4359 (org-test-with-temp-text "* Headline"
4361 (org-export-create-backend
4362 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4363 (headline .
(lambda (h c i
) "Headline"))))
4364 nil nil
'body-only
)))))
4370 (ert-deftest test-org-export
/get-next-element
()
4371 "Test `org-export-get-next-element' specifications."
4375 (org-test-with-parsed-data "* Headline\n*a* b"
4376 (org-export-get-next-element
4377 (org-element-map tree
'bold
'identity info t
) info
))))
4378 ;; Return nil when no previous element.
4380 (org-test-with-parsed-data "* Headline\na *b*"
4381 (org-export-get-next-element
4382 (org-element-map tree
'bold
'identity info t
) info
)))
4383 ;; Non-exportable elements are ignored.
4385 (let ((org-export-with-timestamps nil
))
4386 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
4387 (org-export-get-next-element
4388 (org-element-map tree
'entity
'identity info t
) info
))))
4389 ;; Find next element in secondary strings.
4392 (org-test-with-parsed-data "* a =verb="
4394 (org-export-get-next-element
4395 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4398 (org-test-with-parsed-data "* /italic/ =verb="
4400 (org-export-get-next-element
4401 (org-element-map tree
'italic
'identity info t
) info
)))))
4402 ;; Find next element in document keywords.
4405 (org-test-with-parsed-data "#+TITLE: a =verb="
4407 (org-export-get-next-element
4409 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4410 ;; Find next element in parsed affiliated keywords.
4413 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
4415 (org-export-get-next-element
4416 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4417 ;; With optional argument N, return a list containing all the
4418 ;; following elements.
4421 '(bold code underline
)
4422 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4424 (org-export-get-next-element
4425 (org-element-map tree
'italic
'identity info t
) info t
)))))
4426 ;; When N is a positive integer, return a list containing up to
4427 ;; N following elements.
4431 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4433 (org-export-get-next-element
4434 (org-element-map tree
'italic
'identity info t
) info
2))))))
4436 (ert-deftest test-org-export
/get-previous-element
()
4437 "Test `org-export-get-previous-element' specifications."
4441 (org-test-with-parsed-data "* Headline\na *b*"
4442 (org-export-get-previous-element
4443 (org-element-map tree
'bold
'identity info t
) info
))))
4444 ;; Return nil when no previous element.
4446 (org-test-with-parsed-data "* Headline\n*a* b"
4447 (org-export-get-previous-element
4448 (org-element-map tree
'bold
'identity info t
) info
)))
4449 ;; Non-exportable elements are ignored.
4451 (let ((org-export-with-timestamps nil
))
4452 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
4453 (org-export-get-previous-element
4454 (org-element-map tree
'entity
'identity info t
) info
))))
4455 ;; Find previous element in secondary strings.
4458 (org-test-with-parsed-data "* =verb= a"
4460 (org-export-get-previous-element
4461 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4464 (org-test-with-parsed-data "* =verb= /italic/"
4466 (org-export-get-previous-element
4467 (org-element-map tree
'italic
'identity info t
) info
)))))
4468 ;; Find previous element in document keywords.
4471 (org-test-with-parsed-data "#+TITLE: =verb= a"
4473 (org-export-get-previous-element
4475 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4476 ;; Find previous element in parsed affiliated keywords.
4479 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
4481 (org-export-get-previous-element
4482 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4483 ;; With optional argument N, return a list containing up to
4484 ;; N previous elements.
4486 (equal '(underline italic bold
)
4487 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4489 (org-export-get-previous-element
4490 (org-element-map tree
'code
'identity info t
) info t
)))))
4491 ;; When N is a positive integer, return a list containing up to
4492 ;; N previous elements.
4494 (equal '(italic bold
)
4495 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4497 (org-export-get-previous-element
4498 (org-element-map tree
'code
'identity info t
) info
2))))))
4502 ;;; test-org-export.el end here