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 ;; Excluding a tag excludes its whole group.
451 (let (org-export-filter-body-functions
452 org-export-filter-final-output-functions
)
453 (org-test-with-temp-text "* Head1 :baz:"
454 (let ((org-tag-alist '((:startgrouptag
)
455 ("foo") (:grouptags
) ("bar") ("baz")
457 (org-export-as (org-test-default-backend)
458 nil nil nil
'(:exclude-tags
("foo"))))))))
459 ;; Test include tags for headlines and inlinetasks.
461 (equal (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
462 (let ((org-tags-column 0))
463 (org-export-as (org-test-default-backend)
464 nil nil nil
'(:select-tags
("exp")))))
465 "* H2\n** Sub :exp:\n*** Sub Sub\n"))
466 ;; Including a tag includes its whole group.
470 (let (org-export-filter-body-functions
471 org-export-filter-final-output-functions
)
472 (org-test-with-temp-text "* H1\n* H2 :bar:"
473 (let ((org-tag-alist '((:startgrouptag
)
474 ("foo") (:grouptags
) ("bar") ("baz")
476 (org-export-as (org-test-default-backend)
477 nil nil nil
'(:select-tags
("foo"))))))))
478 ;; If there is an include tag, ignore the section before the first
481 (equal (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
482 (let ((org-tags-column 0))
483 (org-export-as (org-test-default-backend)
484 nil nil nil
'(:select-tags
("exp")))))
485 "* H1 :exp:\nBody\n"))
487 (equal (org-test-with-temp-text "#+FILETAGS: exp\nFirst section\n* H1\nBody"
488 (org-export-as (org-test-default-backend)
489 nil nil nil
'(:select-tags
("exp"))))
492 (equal (org-test-with-temp-text "* H1 :exp:\nBody"
493 (let ((org-tags-column 0))
494 (org-export-as (org-test-default-backend)
495 nil nil nil
'(:select-tags
("exp")))))
497 ;; Test mixing include tags and exclude tags.
500 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
501 (org-test-with-temp-text "
503 ** Sub-Head1 :noexport:
506 ** Sub-Head1 :export:"
507 (org-export-as (org-test-default-backend) nil nil nil
508 '(:select-tags
("export") :exclude-tags
("noexport"))))))
512 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
513 org-export-filter-body-functions
514 org-export-filter-final-output-functions
)
515 (org-test-with-temp-text "* TODO Head1"
516 (org-export-as (org-test-default-backend)
517 nil nil nil
'(:with-tasks nil
))))))
519 (equal "* TODO Head1\n"
520 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
521 (org-test-with-temp-text "* TODO Head1"
522 (org-export-as (org-test-default-backend)
523 nil nil nil
'(:with-tasks t
))))))
527 (let (org-export-filter-body-functions
528 org-export-filter-final-output-functions
)
529 (org-test-with-temp-text "* Head1 :archive:"
530 (let ((org-archive-tag "archive"))
531 (org-export-as (org-test-default-backend)
532 nil nil nil
'(:with-archived-trees nil
)))))))
535 "\\* Head1[ \t]+:archive:"
536 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
537 (let ((org-archive-tag "archive"))
538 (org-export-as (org-test-default-backend) nil nil nil
539 '(:with-archived-trees headline
))))))
542 "\\`\\* Head1[ \t]+:archive:\n\\'"
543 (org-test-with-temp-text "* Head1 :archive:"
544 (let ((org-archive-tag "archive"))
545 (org-export-as (org-test-default-backend)
546 nil nil nil
'(:with-archived-trees t
))))))
547 ;; Broken links. Depending on `org-export-with-broken-links', raise
548 ;; an error, ignore link or mark is as broken in output.
550 (org-test-with-temp-text "[[#broken][link]]"
552 (org-export-create-backend
554 '((section .
(lambda (_e c _i
) c
))
555 (paragraph .
(lambda (_e c _i
) c
))
556 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
557 (org-export-as backend nil nil nil
'(:with-broken-links nil
)))))
559 (org-test-with-temp-text "[[#broken][link]]"
561 (org-export-create-backend
563 '((section .
(lambda (_e c _i
) c
))
564 (paragraph .
(lambda (_e c _i
) c
))
565 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
566 (org-export-as backend nil nil nil
'(:with-broken-links t
)))))
568 (org-test-with-temp-text "[[#broken][link]]"
570 (org-export-create-backend
572 '((section .
(lambda (_e c _i
) c
))
573 (paragraph .
(lambda (_e c _i
) c
))
574 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
576 (org-export-as backend nil nil nil
'(:with-broken-links mark
))))))
579 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
580 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
581 (org-export-as (org-test-default-backend)
582 nil nil nil
'(:with-clocks t
)))))
585 (let (org-export-filter-body-functions
586 org-export-filter-final-output-functions
)
587 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
588 (org-export-as (org-test-default-backend)
589 nil nil nil
'(:with-clocks nil
))))))
593 (let (org-export-filter-body-functions
594 org-export-filter-final-output-functions
)
595 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
596 (org-export-as (org-test-default-backend)
597 nil nil nil
'(:with-drawers nil
))))))
599 (equal ":TEST:\ncontents\n:END:\n"
600 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
601 (org-export-as (org-test-default-backend)
602 nil nil nil
'(:with-drawers t
)))))
604 (equal ":FOO:\nkeep\n:END:\n"
605 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
606 (org-export-as (org-test-default-backend)
607 nil nil nil
'(:with-drawers
("FOO"))))))
609 (equal ":FOO:\nkeep\n:END:\n"
610 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
611 (org-export-as (org-test-default-backend)
612 nil nil nil
'(:with-drawers
(not "BAR"))))))
616 (org-test-with-temp-text ": A"
617 (org-export-as (org-test-default-backend) nil nil nil
618 '(:with-fixed-width t
)))))
621 (let (org-export-filter-body-functions
622 org-export-filter-final-output-functions
)
623 (org-test-with-temp-text ": A"
624 (org-export-as (org-test-default-backend) nil nil nil
625 '(:with-fixed-width nil
))))))
629 (let ((org-footnote-section nil
))
630 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
631 (org-trim (org-export-as (org-test-default-backend)
632 nil nil nil
'(:with-footnotes nil
)))))))
634 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
635 (let ((org-footnote-section nil
))
636 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
637 (org-trim (org-export-as (org-test-default-backend)
638 nil nil nil
'(:with-footnotes t
)))))))
640 (when (featurep 'org-inlinetask
)
644 (let ((org-inlinetask-min-level 15)
645 org-export-filter-body-functions
646 org-export-filter-final-output-functions
)
647 (org-test-with-temp-text "*************** Task"
648 (org-export-as (org-test-default-backend)
649 nil nil nil
'(:with-inlinetasks nil
))))))
653 (let ((org-inlinetask-min-level 15)
654 org-export-filter-body-functions
655 org-export-filter-final-output-functions
)
656 (org-test-with-temp-text
657 "*************** Task\nContents\n*************** END"
658 (org-export-as (org-test-default-backend)
659 nil nil nil
'(:with-inlinetasks nil
)))))))
663 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
664 (let ((org-closed-string "CLOSED:"))
665 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
666 (org-export-as (org-test-default-backend)
667 nil nil nil
'(:with-planning t
))))))
670 (let ((org-closed-string "CLOSED:"))
671 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
672 (org-export-as (org-test-default-backend)
673 nil nil nil
'(:with-planning nil
))))))
677 (org-test-with-temp-text
678 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
679 (org-export-as (org-test-default-backend)
680 nil nil nil
'(:with-properties nil
)))))
682 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
683 (org-test-with-temp-text
684 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
685 (org-export-as (org-test-default-backend)
686 nil nil nil
'(:with-properties t
)))))
688 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
689 (org-test-with-temp-text
690 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
691 (org-export-as (org-test-default-backend)
692 nil nil nil
'(:with-properties
("B"))))))
693 ;; Statistics cookies.
696 (let (org-export-filter-body-functions
697 org-export-filter-final-output-functions
)
699 (org-test-with-temp-text "* Stats [0/0]"
700 (org-export-as (org-test-default-backend)
701 nil nil nil
'(:with-statistics-cookies nil
)))))))
705 (org-test-with-temp-text "| A |"
706 (org-export-as (org-test-default-backend) nil nil nil
707 '(:with-tables t
)))))
710 (let (org-export-filter-body-functions
711 org-export-filter-final-output-functions
)
712 (org-test-with-temp-text "| A |"
713 (org-export-as (org-test-default-backend) nil nil nil
714 '(:with-tables nil
)))))))
716 (ert-deftest test-org-export
/with-timestamps
()
717 "Test `org-export-with-timestamps' specifications."
721 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
722 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
723 (org-export-as (org-test-default-backend)
724 nil nil nil
'(:with-timestamps t
)))))
729 (let (org-export-filter-body-functions
730 org-export-filter-final-output-functions
)
732 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
733 (org-export-as (org-test-default-backend)
734 nil nil nil
'(:with-timestamps nil
)))))))
738 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
739 (org-test-with-temp-text
740 "<2012-03-29 Thu>[2012-03-29 Thu]
742 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
743 (org-export-as (org-test-default-backend)
744 nil nil nil
'(:with-timestamps active
)))))
748 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
749 (org-test-with-temp-text
750 "<2012-03-29 Thu>[2012-03-29 Thu]
752 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
753 (org-export-as (org-test-default-backend)
754 nil nil nil
'(:with-timestamps inactive
))))))
756 (ert-deftest test-org-export
/comment-tree
()
757 "Test if export process ignores commented trees."
760 (let (org-export-filter-body-functions
761 org-export-filter-final-output-functions
)
762 (org-test-with-temp-text "* COMMENT Head1"
763 (org-export-as (org-test-default-backend)))))))
765 (ert-deftest test-org-export
/uninterpreted
()
766 "Test handling of uninterpreted elements."
770 (org-test-with-temp-text "\\alpha"
772 (org-export-create-backend
773 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
774 (paragraph .
(lambda (p c i
) c
))
775 (section .
(lambda (s c i
) c
))))
776 nil nil nil
'(:with-entities t
)))))
779 (org-test-with-temp-text "\\alpha"
781 (org-export-create-backend
782 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
783 (paragraph .
(lambda (p c i
) c
))
784 (section .
(lambda (s c i
) c
))))
785 nil nil nil
'(:with-entities nil
)))))
789 (org-test-with-temp-text "*bold*"
791 (org-export-create-backend
792 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
793 (paragraph .
(lambda (p c i
) c
))
794 (section .
(lambda (s c i
) c
))))
795 nil nil nil
'(:with-emphasize t
)))))
798 (org-test-with-temp-text "*bold*"
800 (org-export-create-backend
801 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
802 (paragraph .
(lambda (p c i
) c
))
803 (section .
(lambda (s c i
) c
))))
804 nil nil nil
'(:with-emphasize nil
)))))
806 (equal "/simple/ /example/\n"
807 (org-test-with-temp-text "/simple/ /example/"
809 (org-export-create-backend
810 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
811 (paragraph .
(lambda (p c i
) c
))
812 (section .
(lambda (s c i
) c
))))
813 nil nil nil
'(:with-emphasize nil
)))))
814 ;; LaTeX environment.
817 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
819 (org-export-create-backend
820 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
821 (section .
(lambda (s c i
) c
))))
822 nil nil nil
'(:with-latex t
)))))
824 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
825 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
827 (org-export-create-backend
828 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
829 (section .
(lambda (s c i
) c
))))
830 nil nil nil
'(:with-latex verbatim
)))))
834 (org-test-with-temp-text "$1$"
836 (org-export-create-backend
837 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
838 (paragraph .
(lambda (p c i
) c
))
839 (section .
(lambda (s c i
) c
))))
840 nil nil nil
'(:with-latex t
)))))
843 (org-test-with-temp-text "$1$"
845 (org-export-create-backend
846 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
847 (paragraph .
(lambda (p c i
) c
))
848 (section .
(lambda (s c i
) c
))))
849 nil nil nil
'(:with-latex verbatim
)))))
853 (org-test-with-temp-text "a_b"
855 (org-export-create-backend
856 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
857 (paragraph .
(lambda (p c i
) c
))
858 (section .
(lambda (s c i
) c
))))
859 nil nil nil
'(:with-sub-superscript t
)))))
862 (org-test-with-temp-text "a_b"
864 (org-export-create-backend
865 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
866 (paragraph .
(lambda (p c i
) c
))
867 (section .
(lambda (s c i
) c
))))
868 nil nil nil
'(:with-sub-superscript nil
)))))
871 (org-test-with-temp-text "a_b"
873 (org-export-create-backend
874 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
875 (paragraph .
(lambda (p c i
) c
))
876 (section .
(lambda (s c i
) c
))))
877 nil nil nil
'(:with-sub-superscript
{})))))
880 (org-test-with-temp-text "a_{b}"
882 (org-export-create-backend
883 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
884 (paragraph .
(lambda (p c i
) c
))
885 (section .
(lambda (s c i
) c
))))
886 nil nil nil
'(:with-sub-superscript
{})))))
889 (org-test-with-temp-text "a_\\alpha"
891 (org-export-create-backend
892 :transcoders
'((entity .
(lambda (e c i
) "entity"))
893 (subscript .
(lambda (s c i
) "dummy"))
894 (paragraph .
(lambda (p c i
) c
))
895 (section .
(lambda (s c i
) c
))))
896 nil nil nil
'(:with-sub-superscript nil
)))))
897 ;; Handle uninterpreted objects in parsed keywords.
900 (org-test-with-temp-text "#+TITLE: a_b"
902 (org-export-create-backend
904 '((subscript .
(lambda (s c i
) "dummy"))
905 (template .
(lambda (c i
)
906 (org-export-data (plist-get i
:title
) i
)))
907 (section .
(lambda (s c i
) c
))))
908 nil nil nil
'(:with-sub-superscript nil
)))))
911 (org-test-with-temp-text "#+FOO: a_b"
913 (org-export-create-backend
915 '((:foo
"FOO" nil nil parse
))
917 '((subscript .
(lambda (s c i
) "dummy"))
918 (template .
(lambda (c i
)
919 (org-export-data (plist-get i
:foo
) i
)))
920 (section .
(lambda (s c i
) c
))))
921 nil nil nil
'(:with-sub-superscript nil
)))))
922 ;; Objects in parsed keywords are "uninterpreted" before filters are
925 (org-test-with-temp-text "#+TITLE: a_b"
927 (org-export-create-backend
931 (org-element-map (plist-get i
:title
) 'subscript
932 (lambda (_) (error "There should be no subscript here")))))))
933 nil nil nil
'(:with-sub-superscript nil
))))
934 ;; Handle uninterpreted objects in captions.
937 (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
939 (org-export-create-backend
941 '((subscript .
(lambda (s c i
) "dummy"))
942 (paragraph .
(lambda (p c i
)
943 (org-export-data (org-export-get-caption p
) i
)))
944 (section .
(lambda (s c i
) c
))))
945 nil nil nil
'(:with-sub-superscript t
)))))
948 (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
950 (org-export-create-backend
952 '((subscript .
(lambda (s c i
) "dummy"))
953 (paragraph .
(lambda (p c i
)
954 (org-export-data (org-export-get-caption p
) i
)))
955 (section .
(lambda (s c i
) c
))))
956 nil nil nil
'(:with-sub-superscript nil
)))))
957 ;; Special case: multiples uninterpreted objects in a row.
960 (org-test-with-temp-text "a_b_c_d"
962 (org-export-create-backend
963 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
964 (paragraph .
(lambda (p c i
) c
))
965 (section .
(lambda (s c i
) c
))))
966 nil nil nil
'(:with-sub-superscript
{}))))))
968 (ert-deftest test-org-export
/export-scope
()
969 "Test all export scopes."
972 (equal "text\n*** H3\n"
973 (org-test-with-temp-text "* H1\n<point>** H2\ntext\n*** H3"
974 (org-export-as (org-test-default-backend) 'subtree
))))
976 (equal "text\n*** H3\n"
977 (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
978 (org-export-as (org-test-default-backend) 'subtree
))))
979 ;; Subtree with a code block calling another block outside.
982 (org-test-with-temp-text "
984 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
989 #+BEGIN_SRC emacs-lisp
992 (let ((org-export-use-babel t
))
993 (org-export-as (org-test-default-backend) 'subtree
)))))
994 ;; Subtree export should ignore leading planning line and property
998 (org-test-with-temp-text "
1000 SCHEDULED: <2012-03-29 Thu>
1005 (org-export-as (org-test-default-backend)
1007 '(:with-planning t
:with-properties t
)))))
1011 (org-test-with-temp-text "* H1\n** H2\ntext\n*** H3"
1013 (org-export-as (org-test-default-backend) nil
'visible
))))
1017 (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
1018 (transient-mark-mode 1)
1019 (push-mark (point) t t
)
1021 (org-export-as (org-test-default-backend)))))
1025 (org-test-with-temp-text "Text"
1027 (org-export-create-backend
1029 '((template .
(lambda (b _i
) (format "BEGIN\n%sEND" b
)))
1030 (section .
(lambda (_s c _i
) c
))
1031 (paragraph .
(lambda (_p c _i
) c
))))
1032 nil nil
'body-only
))))
1034 (equal "BEGIN\nText\nEND"
1035 (org-test-with-temp-text "Text"
1037 (org-export-create-backend
1039 '((template .
(lambda (b _i
) (format "BEGIN\n%sEND" b
)))
1040 (section .
(lambda (_s c _i
) c
))
1041 (paragraph .
(lambda (_p c _i
) c
))))))))
1042 ;; Pathological case: Body only on an empty buffer is expected to
1043 ;; return an empty string, not nil.
1045 (org-test-with-temp-text ""
1046 (org-export-as (org-test-default-backend) nil nil t
))))
1048 (ert-deftest test-org-export
/output-file-name
()
1049 "Test `org-export-output-file-name' specifications."
1050 ;; Export from a file: name is built from original file name.
1052 (org-test-with-temp-text-in-file "Test"
1053 (equal (file-name-base (buffer-file-name))
1054 (file-name-base (org-export-output-file-name ".ext")))))
1055 ;; When #+EXPORT_FILE_NAME is defined, use it.
1058 (org-test-with-temp-text-in-file "#+EXPORT_FILE_NAME: test"
1059 (org-export-output-file-name ".ext" t
))))
1060 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
1063 (org-test-with-temp-text-in-file
1064 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
1065 (org-export-output-file-name ".ext" t
))))
1067 (equal "property.ext"
1068 (org-test-with-temp-text
1069 "#+EXPORT_FILE_NAME: keyword
1072 :EXPORT_FILE_NAME: property
1074 (org-export-output-file-name ".ext" t
))))
1075 ;; From a buffer not associated to a file, too.
1078 (org-test-with-temp-text
1079 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
1080 (org-export-output-file-name ".ext" t
))))
1081 ;; When provided name is absolute, preserve it.
1083 (org-test-with-temp-text
1084 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
1085 (expand-file-name "test"))
1086 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
1087 ;; When PUB-DIR argument is provided, use it.
1090 (org-test-with-temp-text-in-file "Test"
1091 (file-name-directory
1092 (org-export-output-file-name ".ext" nil
"dir/")))))
1093 ;; PUB-DIR has precedence over EXPORT_FILE_NAME keyword or property.
1096 (org-test-with-temp-text-in-file
1097 "#+EXPORT_FILE_NAME: /dir/keyword\nTest"
1098 (file-name-directory
1099 (org-export-output-file-name ".ext" nil
"pub-dir/")))))
1100 ;; When returned name would overwrite original file, add EXTENSION
1103 (equal "normal.org.org"
1104 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1105 (org-export-output-file-name ".org")))))
1107 (ert-deftest test-org-export
/expand-include
()
1108 "Test file inclusion in an Org buffer."
1109 ;; Error when file isn't specified.
1111 (org-test-with-temp-text "#+INCLUDE: dummy.org"
1112 (org-export-expand-include-keyword)))
1113 ;; Refuse to expand keywords in commented headings.
1115 (org-test-with-temp-text "* COMMENT H1\n#+INCLUDE: dummy.org"
1116 (org-export-expand-include-keyword)
1118 ;; Full insertion with recursive inclusion.
1123 (expand-file-name "examples/include.org" org-test-dir
))
1124 (replace-regexp-in-string
1125 (regexp-quote "#+INCLUDE: \"include2.org\"")
1126 "Success!" (buffer-string)))
1127 (org-test-with-temp-text
1128 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
1129 (org-export-expand-include-keyword)
1131 ;; Localized insertion.
1132 (org-test-with-temp-text
1133 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
1135 (org-export-expand-include-keyword)
1136 (should (equal (buffer-string)
1137 "Small Org file with an include keyword.\n")))
1138 ;; Insertion with constraints on headlines level.
1141 "* Top heading\n** Heading\nbody\n"
1142 (org-test-with-temp-text
1144 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
1146 (org-export-expand-include-keyword)
1150 "* Top heading\n* Heading\nbody\n"
1151 (org-test-with-temp-text
1153 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
1155 (org-export-expand-include-keyword)
1157 ;; Inclusion within an example block.
1160 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
1161 (org-test-with-temp-text
1162 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
1164 (org-export-expand-include-keyword)
1166 ;; Inclusion within a src-block.
1169 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
1170 (org-test-with-temp-text
1172 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
1174 (org-export-expand-include-keyword)
1176 ;; Inclusion within an html export-block.
1179 "#+BEGIN_EXPORT html\n<p>HTML!</p>\n#+END_EXPORT\n"
1180 (org-test-with-temp-text
1182 "#+INCLUDE: \"%s/examples/include.html\" EXPORT html"
1184 (org-export-expand-include-keyword)
1186 ;; Inclusion within an center paragraph
1189 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
1190 (org-test-with-temp-text
1192 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
1194 (org-export-expand-include-keyword)
1196 ;; Footnotes labels are local to each included file.
1202 Footnotes[fn:1], [fn:test], [fn:test] and [fn:inline:inline footnote].
1204 \[fn:test] Footnote \"test\""))
1205 (org-test-with-temp-text-in-file contents
1206 (let ((file1 (buffer-file-name)))
1207 (org-test-with-temp-text-in-file contents
1208 (let ((file2 (buffer-file-name)))
1209 (org-test-with-temp-text
1210 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
1212 (org-export-expand-include-keyword)
1213 (org-element-map (org-element-parse-buffer)
1215 (lambda (r) (org-element-property :label r
)))))))))))))
1216 ;; Footnotes labels are not local to each include keyword.
1222 Footnotes[fn:1], [fn:test] and [fn:inline:inline footnote].
1224 \[fn:test] Footnote \"test\""))
1225 (org-test-with-temp-text-in-file contents
1226 (let ((file (buffer-file-name)))
1227 (org-test-with-temp-text
1228 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
1229 (org-export-expand-include-keyword)
1230 (org-element-map (org-element-parse-buffer)
1232 (lambda (ref) (org-element-property :label ref
)))))))))))
1233 ;; Footnotes are supported by :lines-like elements and unnecessary
1234 ;; footnotes are dropped.
1243 Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
1248 \[fn:test] Footnote \"test\"
1250 (org-test-with-temp-text-in-file contents
1251 (let ((file (buffer-file-name)))
1252 (org-test-with-temp-text
1253 (format "#+INCLUDE: \"%s::*bar\"\n" file
)
1254 (org-export-expand-include-keyword)
1255 (org-element-map (org-element-parse-buffer)
1256 'footnote-definition
1257 (lambda (ref) (org-element-property :label ref
)))))))))))
1258 ;; If only-contents is non-nil only include contents of element.
1262 (org-test-with-temp-text
1264 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" "
1267 (org-export-expand-include-keyword)
1269 ;; Headings can be included via CUSTOM_ID.
1271 (org-test-with-temp-text
1272 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1273 (org-export-expand-include-keyword)
1274 (goto-char (point-min))
1275 (looking-at "* Another heading")))
1276 ;; Named objects can be included.
1280 (org-test-with-temp-text
1281 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t"
1283 (org-export-expand-include-keyword)
1285 ;; Including non-existing elements should result in an error.
1287 (org-test-with-temp-text
1288 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\""
1290 (org-export-expand-include-keyword)))
1291 ;; Lines work relatively to an included element.
1295 (org-test-with-temp-text
1296 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t \
1299 (org-export-expand-include-keyword)
1301 ;; Properties should be dropped from headlines.
1304 (org-test-with-temp-text
1305 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t"
1307 (org-export-expand-include-keyword)
1309 (org-test-with-temp-text
1310 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1311 (org-export-expand-include-keyword)
1313 ;; Properties should be dropped, drawers should not be.
1316 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1317 (org-test-with-temp-text
1318 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t"
1320 (org-export-expand-include-keyword)
1322 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1324 (cl-every (lambda (level) (zerop (1- level
)))
1325 (org-test-with-temp-text
1327 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n"
1329 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\""
1331 (org-export-expand-include-keyword)
1332 (org-element-map (org-element-parse-buffer) 'headline
1333 (lambda (head) (org-element-property :level head
))))))
1334 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1337 (org-test-with-temp-text
1338 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp"
1340 (org-export-expand-include-keyword)
1342 (org-test-with-temp-text
1344 "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1"
1346 (org-export-expand-include-keyword)
1348 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1350 (org-test-with-temp-text-in-file
1351 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\""
1353 (narrow-to-region (point) (point-max))
1354 (org-export-expand-include-keyword)
1355 (eq 1 (org-current-level))))
1356 ;; If :minlevel is present do not alter it.
1358 (org-test-with-temp-text
1360 "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3"
1362 (narrow-to-region (point) (point-max))
1363 (org-export-expand-include-keyword)
1364 (eq 3 (org-current-level)))))
1366 (ert-deftest test-org
/expand-include
/links
()
1367 "Test links modifications when including files."
1368 ;; Preserve relative plain links.
1371 "file:org-includee-"
1372 (let* ((subdir (make-temp-file "org-includee-" t
))
1373 (includee (expand-file-name "includee.org" subdir
))
1374 (includer (make-temp-file "org-includer-")))
1375 (write-region "file:foo.org" nil includee
)
1376 (write-region (format "#+INCLUDE: %S"
1377 (file-relative-name includee
1378 temporary-file-directory
))
1380 (let ((buffer (find-file-noselect includer t
)))
1382 (with-current-buffer buffer
1383 (org-export-expand-include-keyword)
1384 (org-trim (buffer-string)))
1385 (when (buffer-live-p buffer
)
1386 (with-current-buffer buffer
(set-buffer-modified-p nil
))
1387 (kill-buffer buffer
))
1388 (when (file-exists-p subdir
) (delete-directory subdir t
))
1389 (when (file-exists-p includer
) (delete-file includer
)))))))
1390 ;; Preserve relative angular links.
1393 "<file:org-includee-"
1394 (let* ((subdir (make-temp-file "org-includee-" t
))
1395 (includee (expand-file-name "includee.org" subdir
))
1396 (includer (make-temp-file "org-includer-")))
1397 (write-region "<file:foo.org>" nil includee
)
1398 (write-region (format "#+INCLUDE: %S"
1399 (file-relative-name includee
1400 temporary-file-directory
))
1402 (let ((buffer (find-file-noselect includer t
)))
1404 (with-current-buffer buffer
1405 (org-export-expand-include-keyword)
1406 (org-trim (buffer-string)))
1407 (when (buffer-live-p buffer
)
1408 (with-current-buffer buffer
(set-buffer-modified-p nil
))
1409 (kill-buffer buffer
))
1410 (when (file-exists-p subdir
) (delete-directory subdir t
))
1411 (when (file-exists-p includer
) (delete-file includer
)))))))
1412 ;; Preserve relative bracket links without description.
1415 "[[file:org-includee-"
1416 (let* ((subdir (make-temp-file "org-includee-" t
))
1417 (includee (expand-file-name "includee.org" subdir
))
1418 (includer (make-temp-file "org-includer-")))
1419 (write-region "[[file:foo.org]]" nil includee
)
1420 (write-region (format "#+INCLUDE: %S"
1421 (file-relative-name includee
1422 temporary-file-directory
))
1424 (let ((buffer (find-file-noselect includer t
)))
1426 (with-current-buffer buffer
1427 (org-export-expand-include-keyword)
1428 (org-trim (buffer-string)))
1429 (when (buffer-live-p buffer
)
1430 (with-current-buffer buffer
(set-buffer-modified-p nil
))
1431 (kill-buffer buffer
))
1432 (when (file-exists-p subdir
) (delete-directory subdir t
))
1433 (when (file-exists-p includer
) (delete-file includer
)))))))
1434 ;; Preserve relative bracket links with description.
1437 "[[file:org-includee-"
1438 (let* ((subdir (make-temp-file "org-includee-" t
))
1439 (includee (expand-file-name "includee.org" subdir
))
1440 (includer (make-temp-file "org-includer-")))
1441 (write-region "[[file:foo.org][description]]" nil includee
)
1442 (write-region (format "#+INCLUDE: %S"
1443 (file-relative-name includee
1444 temporary-file-directory
))
1446 (let ((buffer (find-file-noselect includer t
)))
1448 (with-current-buffer buffer
1449 (org-export-expand-include-keyword)
1450 (org-trim (buffer-string)))
1451 (when (buffer-live-p buffer
)
1452 (with-current-buffer buffer
(set-buffer-modified-p nil
))
1453 (kill-buffer buffer
))
1454 (when (file-exists-p subdir
) (delete-directory subdir t
))
1455 (when (file-exists-p includer
) (delete-file includer
)))))))
1456 ;; Preserve absolute links.
1459 "[[file:/foo/bar.org]]"
1460 (let* ((subdir (make-temp-file "org-includee-" t
))
1461 (includee (expand-file-name "includee.org" subdir
))
1462 (includer (make-temp-file "org-includer-")))
1463 (write-region "[[file:/foo/bar.org]]" nil includee
)
1464 (write-region (format "#+INCLUDE: %S"
1465 (file-relative-name includee
1466 temporary-file-directory
))
1468 (let ((buffer (find-file-noselect includer t
)))
1470 (with-current-buffer buffer
1471 (org-export-expand-include-keyword)
1472 (org-trim (buffer-string)))
1473 (when (buffer-live-p buffer
)
1474 (with-current-buffer buffer
(set-buffer-modified-p nil
))
1475 (kill-buffer buffer
))
1476 (when (file-exists-p subdir
) (delete-directory subdir t
))
1477 (when (file-exists-p includer
) (delete-file includer
)))))))
1478 ;; Pathological case: Do not error when fixing a path in a headline.
1480 (let* ((subdir (make-temp-file "org-includee-" t
))
1481 (includee (expand-file-name "includee.org" subdir
))
1482 (includer (make-temp-file "org-includer-")))
1483 (write-region "* [[file:foo.org]]" nil includee
)
1484 (write-region (format "#+INCLUDE: %S"
1485 (file-relative-name includee
1486 temporary-file-directory
))
1488 (let ((buffer (find-file-noselect includer t
)))
1490 (with-current-buffer buffer
1491 (org-export-expand-include-keyword)
1492 (org-trim (buffer-string)))
1493 (when (buffer-live-p buffer
)
1494 (with-current-buffer buffer
(set-buffer-modified-p nil
))
1495 (kill-buffer buffer
))
1496 (when (file-exists-p subdir
) (delete-directory subdir t
))
1497 (when (file-exists-p includer
) (delete-file includer
)))))))
1499 (ert-deftest test-org-export
/expand-macro
()
1500 "Test macro expansion in an Org buffer."
1502 ;; Standard macro expansion.
1504 (equal "#+macro: macro1 value\nvalue\n"
1505 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1506 (org-export-as (org-test-default-backend)))))
1507 ;; Include global macros. However, local macros override them.
1510 (org-test-with-temp-text "{{{M}}}"
1511 (let ((org-export-global-macros '(("M" .
"global"))))
1512 (org-export-as (org-test-default-backend))))))
1514 (equal "global arg\n"
1515 (org-test-with-temp-text "{{{M(arg)}}}"
1516 (let ((org-export-global-macros '(("M" .
"global $1"))))
1517 (org-export-as (org-test-default-backend))))))
1520 (org-test-with-temp-text "{{{M}}}"
1521 (let ((org-export-global-macros '(("M" .
"(eval (+ 1 1))"))))
1522 (org-export-as (org-test-default-backend))))))
1524 (equal "#+macro: M local\nlocal\n"
1525 (org-test-with-temp-text "#+macro: M local\n{{{M}}}"
1526 (let ((org-export-global-macros '(("M" .
"global"))))
1527 (org-export-as (org-test-default-backend))))))
1528 ;; Allow macro in parsed keywords and associated properties.
1529 ;; Standard macro expansion.
1533 (let ((backend (org-export-create-backend
1535 :options
'((:k
"K" nil nil parse
)))))
1536 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1537 (org-export-as backend
)))))
1541 (let ((backend (org-export-create-backend
1543 :options
'((:k
"K" nil nil parse
)))))
1544 (org-test-with-temp-text
1545 "#+macro: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1546 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1547 ;; Expand specific macros.
1549 (equal "me 2012-03-29 me@here Title\n"
1550 (org-test-with-temp-text
1556 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1557 (let ((output (org-export-as (org-test-default-backend))))
1558 (substring output
(string-match ".*\n\\'" output
))))))
1559 ;; Expand specific macros when property contained a regular macro
1563 (org-test-with-temp-text "
1564 #+MACRO: macro1 value
1565 #+TITLE: {{{macro1}}}
1567 (let ((output (org-export-as (org-test-default-backend))))
1568 (substring output
(string-match ".*\n\\'" output
))))))
1569 ;; Expand macros with templates in included files.
1572 (org-test-with-temp-text
1573 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1574 {{{included-macro}}}" org-test-dir
)
1575 (let ((output (org-export-as (org-test-default-backend))))
1576 (substring output
(string-match ".*\n\\'" output
))))))
1577 ;; Date macro takes a optional formatting argument
1580 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1581 (org-export-as (org-test-default-backend)))))
1582 ;; Only single timestamps are formatted
1584 (equal "<2015-02x-09>\n"
1585 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1586 (org-export-as (org-test-default-backend)))))
1587 ;; Throw an error when a macro definition is missing.
1589 (org-test-with-temp-text "{{{missing}}}"
1590 (org-export-as (org-test-default-backend))))
1591 ;; Inline source blocks generate {{{results}}} macros. Evaluate
1595 (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
1596 (let ((org-export-use-babel t
)
1597 (org-babel-inline-result-wrap "=%s="))
1598 (org-export-as (org-test-default-backend)))))))
1600 (ert-deftest test-org-export
/before-processing-hook
()
1601 "Test `org-export-before-processing-hook'."
1604 "#+macro: mac val\nTest\n"
1605 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1606 (let ((org-export-before-processing-hook
1608 (while (re-search-forward "{{{" nil t
)
1609 (let ((object (org-element-context)))
1610 (when (eq (org-element-type object
) 'macro
)
1612 (org-element-property :begin object
)
1613 (org-element-property :end object
)))))))))
1614 (org-export-as (org-test-default-backend)))))))
1616 (ert-deftest test-org-export
/before-parsing-hook
()
1617 "Test `org-export-before-parsing-hook'."
1619 (equal "Body 1\nBody 2\n"
1620 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1621 (let ((org-export-before-parsing-hook
1623 (goto-char (point-min))
1624 (while (re-search-forward org-outline-regexp-bol nil t
)
1626 (point-at-bol) (progn (forward-line) (point))))))))
1627 (org-export-as (org-test-default-backend)))))))
1631 ;;; Affiliated Keywords
1633 (ert-deftest test-org-export
/read-attribute
()
1634 "Test `org-export-read-attribute' specifications."
1638 (org-export-read-attribute
1640 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1641 (org-element-at-point)))
1643 ;; Return nil on empty attribute.
1645 (org-export-read-attribute
1647 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1648 ;; Return nil on "nil" string.
1650 (equal '(:a nil
:b nil
)
1651 (org-export-read-attribute
1653 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1654 (org-element-at-point)))))
1655 ;; Return nil on empty string.
1657 (equal '(:a nil
:b nil
)
1658 (org-export-read-attribute
1660 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1661 (org-element-at-point)))))
1662 ;; Return empty string when value is "".
1665 (org-export-read-attribute
1667 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1668 (org-element-at-point)))))
1669 ;; Return \"\" when value is """".
1672 (org-export-read-attribute
1674 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1675 (org-element-at-point)))))
1676 ;; Ignore text before first property.
1679 (org-export-read-attribute
1681 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1682 (org-element-at-point))))))
1684 (ert-deftest test-org-export
/get-caption
()
1685 "Test `org-export-get-caption' specifications."
1686 ;; Without optional argument, return long caption
1690 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1691 (org-export-get-caption (org-element-at-point)))))
1692 ;; With optional argument, return short caption.
1696 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1697 (org-export-get-caption (org-element-at-point) t
))))
1698 ;; Multiple lines are separated by white spaces.
1702 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1703 (org-export-get-caption (org-element-at-point))))))
1709 (ert-deftest test-org-export
/define-backend
()
1710 "Test back-end definition and accessors."
1713 (equal '((headline . my-headline-test
))
1714 (let (org-export-registered-backends)
1715 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1716 (org-export-get-all-transcoders 'test
))))
1719 (equal '((:filter-headline . my-filter
))
1720 (let (org-export-registered-backends)
1721 (org-export-define-backend 'test
1722 '((headline . my-headline-test
))
1723 :filters-alist
'((:filter-headline . my-filter
)))
1724 (org-export-backend-filters (org-export-get-backend 'test
)))))
1727 (equal '((:prop value
))
1728 (let (org-export-registered-backends)
1729 (org-export-define-backend 'test
1730 '((headline . my-headline-test
))
1731 :options-alist
'((:prop value
)))
1732 (org-export-backend-options (org-export-get-backend 'test
)))))
1735 (equal '(?k
"Test Export" test
)
1736 (let (org-export-registered-backends)
1737 (org-export-define-backend 'test
1738 '((headline . my-headline-test
))
1739 :menu-entry
'(?k
"Test Export" test
))
1740 (org-export-backend-menu (org-export-get-backend 'test
))))))
1742 (ert-deftest test-org-export
/define-derived-backend
()
1743 "Test `org-export-define-derived-backend' specifications."
1744 ;; Error when parent back-end is not defined.
1746 (let (org-export-registered-backends)
1747 (org-export-define-derived-backend 'test
'parent
)))
1748 ;; Append translation table to parent's.
1750 (equal '((:headline . test
) (:headline . parent
))
1751 (let (org-export-registered-backends)
1752 (org-export-define-backend 'parent
'((:headline . parent
)))
1753 (org-export-define-derived-backend 'test
'parent
1754 :translate-alist
'((:headline . test
)))
1755 (org-export-get-all-transcoders 'test
))))
1756 ;; Options defined in the new back have priority over those defined
1760 (let (org-export-registered-backends)
1761 (org-export-define-backend 'parent
1762 '((:headline . parent
))
1763 :options-alist
'((:a nil nil
'parent
)))
1764 (org-export-define-derived-backend 'test
'parent
1765 :options-alist
'((:a nil nil
'test
)))
1766 (plist-get (org-export--get-global-options
1767 (org-export-get-backend 'test
))
1770 (ert-deftest test-org-export
/derived-backend-p
()
1771 "Test `org-export-derived-backend-p' specifications."
1772 ;; Non-nil with direct match.
1774 (let (org-export-registered-backends)
1775 (org-export-define-backend 'test
'((headline . test
)))
1776 (org-export-derived-backend-p 'test
'test
)))
1778 (let (org-export-registered-backends)
1779 (org-export-define-backend 'test
'((headline . test
)))
1780 (org-export-define-derived-backend 'test2
'test
)
1781 (org-export-derived-backend-p 'test2
'test2
)))
1782 ;; Non-nil with a direct parent.
1784 (let (org-export-registered-backends)
1785 (org-export-define-backend 'test
'((headline . test
)))
1786 (org-export-define-derived-backend 'test2
'test
)
1787 (org-export-derived-backend-p 'test2
'test
)))
1788 ;; Non-nil with an indirect parent.
1790 (let (org-export-registered-backends)
1791 (org-export-define-backend 'test
'((headline . test
)))
1792 (org-export-define-derived-backend 'test2
'test
)
1793 (org-export-define-derived-backend 'test3
'test2
)
1794 (org-export-derived-backend-p 'test3
'test
)))
1797 (let (org-export-registered-backends)
1798 (org-export-define-backend 'test
'((headline . test
)))
1799 (org-export-define-backend 'test2
'((headline . test2
)))
1800 (org-export-derived-backend-p 'test2
'test
)))
1802 (let (org-export-registered-backends)
1803 (org-export-define-backend 'test
'((headline . test
)))
1804 (org-export-define-backend 'test2
'((headline . test2
)))
1805 (org-export-define-derived-backend 'test3
'test2
)
1806 (org-export-derived-backend-p 'test3
'test
))))
1808 (ert-deftest test-org-export
/get-all-transcoders
()
1809 "Test `org-export-get-all-transcoders' specifications."
1810 ;; Return nil when back-end cannot be found.
1811 (should-not (org-export-get-all-transcoders nil
))
1812 ;; Same as `org-export-transcoders' if no parent.
1814 (equal '((headline . ignore
))
1815 (org-export-get-all-transcoders
1816 (org-export-create-backend
1817 :transcoders
'((headline . ignore
))))))
1818 ;; But inherit from all ancestors whenever possible.
1820 (equal '((section . ignore
) (headline . ignore
))
1821 (let (org-export-registered-backends)
1822 (org-export-define-backend 'b1
'((headline . ignore
)))
1823 (org-export-get-all-transcoders
1824 (org-export-create-backend
1825 :parent
'b1
:transcoders
'((section . ignore
)))))))
1827 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1828 (let (org-export-registered-backends)
1829 (org-export-define-backend 'b1
'((headline . ignore
)))
1830 (org-export-define-derived-backend 'b2
'b1
1831 :translate-alist
'((section . ignore
)))
1832 (org-export-get-all-transcoders
1833 (org-export-create-backend
1834 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1835 ;; Back-end transcoders overrule inherited ones.
1838 (let (org-export-registered-backends)
1839 (org-export-define-backend 'b1
'((headline . a
)))
1840 (cdr (assq 'headline
1841 (org-export-get-all-transcoders
1842 (org-export-create-backend
1843 :parent
'b1
:transcoders
'((headline . b
))))))))))
1845 (ert-deftest test-org-export
/get-all-options
()
1846 "Test `org-export-get-all-options' specifications."
1847 ;; Return nil when back-end cannot be found.
1848 (should-not (org-export-get-all-options nil
))
1849 ;; Same as `org-export-options' if no parent.
1851 (equal '((headline . ignore
))
1852 (org-export-get-all-options
1853 (org-export-create-backend
1854 :options
'((headline . ignore
))))))
1855 ;; But inherit from all ancestors whenever possible.
1857 (equal '((:key2 value2
) (:key1 value1
))
1858 (let (org-export-registered-backends)
1859 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1860 (org-export-get-all-options
1861 (org-export-create-backend
1862 :parent
'b1
:options
'((:key2 value2
)))))))
1864 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1865 (let (org-export-registered-backends)
1866 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1867 (org-export-define-derived-backend 'b2
'b1
1868 :options-alist
'((:key2 value2
)))
1869 (org-export-get-all-options
1870 (org-export-create-backend
1871 :parent
'b2
:options
'((:key3 value3
)))))))
1872 ;; Back-end options overrule inherited ones.
1875 (let (org-export-registered-backends)
1876 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1878 (org-export-get-all-options
1879 (org-export-create-backend
1880 :parent
'b1
:options
'((:key1 . b
))))))))))
1882 (ert-deftest test-org-export
/get-all-filters
()
1883 "Test `org-export-get-all-filters' specifications."
1884 ;; Return nil when back-end cannot be found.
1885 (should-not (org-export-get-all-filters nil
))
1886 ;; Same as `org-export-filters' if no parent.
1888 (equal '((:filter-headline . ignore
))
1889 (org-export-get-all-filters
1890 (org-export-create-backend
1891 :filters
'((:filter-headline . ignore
))))))
1892 ;; But inherit from all ancestors whenever possible.
1894 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1895 (let (org-export-registered-backends)
1896 (org-export-define-backend 'b1
1897 nil
:filters-alist
'((:filter-headline . ignore
)))
1898 (org-export-get-all-filters
1899 (org-export-create-backend
1900 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1902 (equal '((:filter-paragraph . ignore
)
1903 (:filter-section . ignore
)
1904 (:filter-headline . ignore
))
1905 (let (org-export-registered-backends)
1906 (org-export-define-backend 'b1
1907 nil
:filters-alist
'((:filter-headline . ignore
)))
1908 (org-export-define-derived-backend 'b2
'b1
1909 :filters-alist
'((:filter-section . ignore
)))
1910 (org-export-get-all-filters
1911 (org-export-create-backend
1912 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1913 ;; Back-end filters overrule inherited ones.
1916 (let (org-export-registered-backends)
1917 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1918 (cdr (assq :filter-headline
1919 (org-export-get-all-filters
1920 (org-export-create-backend
1921 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1923 (ert-deftest test-org-export
/with-backend
()
1924 "Test `org-export-with-backend' definition."
1925 ;; Error when calling an undefined back-end
1926 (should-error (org-export-with-backend nil
"Test"))
1927 ;; Error when called back-end doesn't have an appropriate
1930 (org-export-with-backend
1931 (org-export-create-backend :transcoders
'((headline . ignore
)))
1933 ;; Otherwise, export using correct transcoder
1936 (let (org-export-registered-backends)
1937 (org-export-define-backend 'test
1938 '((verbatim .
(lambda (text contents info
) "Failure"))))
1939 (org-export-define-backend 'test2
1940 '((verbatim .
(lambda (text contents info
) "Success"))))
1941 (org-export-with-backend 'test2
'(verbatim (:value
"=Test="))))))
1942 ;; Corner case: plain-text transcoders have a different arity.
1945 (org-export-with-backend
1946 (org-export-create-backend
1947 :transcoders
'((plain-text .
(lambda (text info
) "Success"))))
1949 ;; Provide correct back-end if transcoder needs to use recursive
1953 (let ((test-back-end
1954 (org-export-create-backend
1956 (list (cons 'headline
1957 (lambda (headline contents info
)
1959 (org-element-property :title headline
)
1961 (cons 'plain-text
(lambda (text info
) "Success"))))))
1962 (org-export-string-as
1964 (org-export-create-backend
1966 (list (cons 'headline
1967 (lambda (headline contents info
)
1968 (org-export-with-backend
1969 test-back-end headline contents info
))))))))))
1971 (ert-deftest test-org-export
/data-with-backend
()
1972 "Test `org-export-data-with-backend' specifications."
1973 ;; Error when calling an undefined back-end.
1974 (should-error (org-export-data-with-backend nil
"nil" nil
))
1975 ;; Otherwise, export data recursively, using correct back-end.
1979 (org-export-data-with-backend
1981 (org-export-create-backend
1983 '((plain-text .
(lambda (text info
) "Success"))
1984 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1985 '(:with-emphasize t
)))))
1991 (ert-deftest test-org-export
/comments
()
1992 "Test comments handling during export.
1993 In particular, structure of the document mustn't be altered after
1996 (equal "Para1\n\nPara2\n"
1997 (org-test-with-temp-text "
2003 (org-export-as (org-test-default-backend)))))
2005 (equal "Para1\n\nPara2\n"
2006 (org-test-with-temp-text "
2010 (org-export-as (org-test-default-backend)))))
2012 (equal "[fn:1] Para1\n\n\nPara2\n"
2013 (org-test-with-temp-text "
2018 # Outside definition
2020 (org-export-as (org-test-default-backend)))))
2022 (equal "[fn:1] Para1\n\nPara2\n"
2023 (org-test-with-temp-text "
2031 (org-export-as (org-test-default-backend)))))
2033 (equal "[fn:1] Para1\n\nPara2\n"
2034 (org-test-with-temp-text "
2039 (org-export-as (org-test-default-backend)))))
2041 (equal "[fn:1] Para1\n\nPara2\n"
2042 (org-test-with-temp-text "
2047 (org-export-as (org-test-default-backend)))))
2049 (equal "- item 1\n\n- item 2\n"
2050 (org-test-with-temp-text "
2056 (org-export-as (org-test-default-backend))))))
2062 (ert-deftest test-org-export
/export-block
()
2063 "Test export blocks transcoding."
2066 (org-test-with-temp-text
2067 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
2069 (org-export-create-backend
2070 :transcoders
'((export-block .
(lambda (b _c _i
)
2071 (org-element-property :value b
)))
2072 (section .
(lambda (_s c _i
) c
))))))))
2075 (org-test-with-temp-text
2076 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
2078 (org-export-create-backend
2083 (and (equal (org-element-property :type b
) "BACKEND")
2084 (org-element-property :value b
))))
2085 (cons 'section
(lambda (_s c _i
) c
)))))))))
2090 (ert-deftest test-org-export
/export-snippet
()
2091 "Test export snippets transcoding."
2093 (org-test-with-temp-text "@@test:A@@@@t:B@@"
2094 (let ((backend (org-test-default-backend)))
2095 (setf (org-export-backend-name backend
) 'test
)
2096 (setf (org-export-backend-transcoders backend
)
2097 (cons (cons 'export-snippet
2098 (lambda (snippet contents info
)
2099 (when (eq (org-export-snippet-backend snippet
) 'test
)
2100 (org-element-property :value snippet
))))
2101 (org-export-backend-transcoders backend
)))
2102 (let ((org-export-snippet-translation-alist nil
))
2103 (should (equal (org-export-as backend
) "A\n")))
2104 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
2105 (should (equal (org-export-as backend
) "AB\n")))))
2106 ;; Ignored export snippets do not remove any blank.
2108 (equal "begin end\n"
2109 (org-test-with-parsed-data "begin @@test:A@@ end"
2110 (org-export-data-with-backend
2112 (org-export-create-backend
2114 '((paragraph .
(lambda (paragraph contents info
) contents
))
2115 (section .
(lambda (section contents info
) contents
))))
2121 (ert-deftest test-org-export
/filter-apply-functions
()
2122 "Test `org-export-filter-apply-functions' specifications."
2123 ;; Functions are applied in order and return values are reduced.
2126 (org-export-filter-apply-functions
2127 (list (lambda (value &rest _
) (concat "1" value
))
2128 (lambda (value &rest _
) (concat "2" value
)))
2130 ;; Functions returning nil are skipped.
2133 (org-export-filter-apply-functions
2134 (list #'ignore
(lambda (value &rest _
) (concat "2" value
)))
2136 ;; If all functions are skipped, return the initial value.
2139 (org-export-filter-apply-functions (list #'ignore
) "0" nil
)))
2140 ;; If any function returns the empty string, final value is the
2144 (org-export-filter-apply-functions
2145 (list (lambda (value &rest _
) "")
2146 (lambda (value &rest _
) (concat "2" value
)))
2148 ;; Any function returning the empty string short-circuits the
2151 (org-export-filter-apply-functions
2152 (list (lambda (value &rest _
) "")
2153 (lambda (value &rest _
) (error "This shouldn't happen")))
2159 (ert-deftest test-org-export
/footnote-first-reference-p
()
2160 "Test `org-export-footnote-first-reference-p' specifications."
2164 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
2167 (org-export-create-backend
2169 `(,(cons 'footnote-reference
2171 (push (org-export-footnote-first-reference-p f i
)
2174 (section .
(lambda (s c i
) c
))
2175 (paragraph .
(lambda (p c i
) c
))))
2176 nil nil nil
'(:with-footnotes t
))
2177 (nreverse result
)))))
2178 ;; Limit check to DATA, when non-nil.
2182 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
2184 (org-element-map tree
'footnote-reference
2187 (org-export-footnote-first-reference-p
2188 ref info
(org-element-map tree
'headline
#'identity info t
))
2191 (nreverse result
)))))
2195 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
2197 (org-element-map tree
'footnote-reference
2199 (push (org-export-footnote-first-reference-p ref info
) result
))
2201 (nreverse result
)))))
2202 ;; If optional argument BODY-FIRST is non-nil, first find footnote
2203 ;; in the main body of the document. Otherwise, enter footnote
2204 ;; definitions when they are encountered.
2208 (org-test-with-temp-text
2209 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
2212 (org-export-create-backend
2214 `(,(cons 'footnote-reference
2216 (when (org-element-lineage f
'(drawer))
2217 (push (org-export-footnote-first-reference-p f i nil
)
2220 (drawer .
(lambda (d c i
) c
))
2221 (footnote-definition .
(lambda (d c i
) c
))
2222 (section .
(lambda (s c i
) c
))
2223 (paragraph .
(lambda (p c i
) c
))))
2224 nil nil nil
'(:with-footnotes t
))
2225 (nreverse result
)))))
2229 (org-test-with-temp-text
2230 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
2233 (org-export-create-backend
2235 `(,(cons 'footnote-reference
2237 (when (org-element-lineage f
'(drawer))
2238 (push (org-export-footnote-first-reference-p f i nil t
)
2241 (drawer .
(lambda (d c i
) c
))
2242 (footnote-definition .
(lambda (d c i
) c
))
2243 (section .
(lambda (s c i
) c
))
2244 (paragraph .
(lambda (p c i
) c
))))
2245 nil nil nil
'(:with-footnotes t
))
2246 (nreverse result
))))))
2248 (ert-deftest test-org-export
/get-footnote-number
()
2249 "Test `org-export-get-footnote-number' specifications."
2252 (org-test-with-parsed-data
2253 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
2254 (org-element-map tree
'footnote-reference
2255 (lambda (ref) (org-export-get-footnote-number ref info
))
2257 ;; Anonymous footnotes all get a new number.
2260 (org-test-with-parsed-data
2261 "Text[fn::anon1][fn::anon2]"
2262 (org-element-map tree
'footnote-reference
2263 (lambda (ref) (org-export-get-footnote-number ref info
))
2265 ;; Test nested footnotes order.
2268 '((1 .
"1") (2 .
"2") (3 .
"3") (3 .
"3") (4))
2269 (org-test-with-parsed-data
2270 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
2271 (org-element-map tree
'footnote-reference
2273 (cons (org-export-get-footnote-number ref info
)
2274 (org-element-property :label ref
)))
2276 ;; Limit number to provided DATA, when non-nil.
2280 (org-test-with-parsed-data
2281 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2282 (org-element-map tree
'footnote-reference
2284 (org-export-get-footnote-number
2285 ref info
(org-element-map tree
'headline
#'identity info t
)))
2290 (org-test-with-parsed-data
2291 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
2292 (org-element-map tree
'footnote-reference
2293 (lambda (ref) (org-export-get-footnote-number ref info
))
2295 ;; With a non-nil BODY-FIRST optional argument, first check body,
2296 ;; then footnote definitions.
2299 '(("1" .
1) ("2" .
2) ("3" .
3) ("3" .
3))
2300 (org-test-with-parsed-data
2301 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2302 (org-element-map tree
'footnote-reference
2304 (cons (org-element-property :label ref
)
2305 (org-export-get-footnote-number ref info nil t
)))
2309 '(("1" .
1) ("2" .
3) ("3" .
2) ("3" .
2))
2310 (org-test-with-parsed-data
2311 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2312 (org-element-map tree
'footnote-reference
2314 (cons (org-element-property :label ref
)
2315 (org-export-get-footnote-number ref info nil
)))
2318 (ert-deftest test-org-export
/get-footnote-definition
()
2319 "Test `org-export-get-footnote-definition' specifications."
2323 (org-element-interpret-data
2324 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1] A"
2325 (org-export-get-footnote-definition
2326 (org-element-map tree
'footnote-reference
#'identity nil t
)
2328 ;; Raise an error if no definition is found.
2330 (org-test-with-parsed-data "Text[fn:1]"
2331 (org-export-get-footnote-definition
2332 (org-element-map tree
'footnote-reference
#'identity nil t
)
2334 ;; Find inline definitions.
2337 (org-element-interpret-data
2338 (org-test-with-parsed-data "Text[fn:1:A]"
2339 (org-export-get-footnote-definition
2340 (org-element-map tree
'footnote-reference
#'identity nil t
)
2342 ;; Find anonymous definitions.
2345 (org-element-interpret-data
2346 (org-test-with-parsed-data "Text[fn::A]"
2347 (org-export-get-footnote-definition
2348 (org-element-map tree
'footnote-reference
#'identity nil t
)
2350 ;; Find empty definitions.
2353 (org-element-interpret-data
2354 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1]"
2355 (org-export-get-footnote-definition
2356 (org-element-map tree
'footnote-reference
#'identity nil t
)
2360 (org-element-interpret-data
2361 (org-test-with-parsed-data "Text[fn:1:]"
2362 (org-export-get-footnote-definition
2363 (org-element-map tree
'footnote-reference
#'identity nil t
)
2367 (org-element-interpret-data
2368 (org-test-with-parsed-data "Text[fn::]"
2369 (org-export-get-footnote-definition
2370 (org-element-map tree
'footnote-reference
#'identity nil t
)
2373 (ert-deftest test-org-export
/collect-footnote-definitions
()
2374 "Test `org-export-collect-footnote-definitions' specifications."
2377 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2379 \[fn:2] B [fn:3] [fn::D].
2382 (length (org-export-collect-footnote-definitions info
)))))
2383 ;; Limit number to provided DATA, when non-nil.
2387 (org-test-with-parsed-data
2388 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2390 (org-export-collect-footnote-definitions
2391 info
(org-element-map tree
'headline
#'identity info t
))))))
2395 (org-test-with-parsed-data
2396 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2397 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
2398 ;; With optional argument BODY-FIRST, first check body, then
2399 ;; footnote definitions.
2401 (equal '("1" "3" "2" nil
)
2402 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2404 \[fn:2] B [fn:3] [fn::D].
2407 (mapcar (lambda (e) (nth 1 e
))
2408 (org-export-collect-footnote-definitions info nil t
)))))
2410 (equal '("1" "3" "2" nil
)
2411 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2413 \[fn:2] B [fn:3] [fn::D].
2416 (mapcar (lambda (e) (nth 1 e
))
2417 (org-export-collect-footnote-definitions info
))))))
2419 (ert-deftest test-org-export
/footnotes
()
2420 "Miscellaneous tests on footnotes."
2421 (let ((org-footnote-section nil
)
2422 (org-export-with-footnotes t
))
2423 ;; Read every type of footnote.
2426 '((1 .
"A\n") (2 .
"C") (3 .
"D"))
2427 (org-test-with-parsed-data
2428 "Text[fn:1] [fn:label:C] [fn::D]\n\n[fn:1] A\n"
2429 (org-element-map tree
'footnote-reference
2431 (let ((def (org-export-get-footnote-definition ref info
)))
2432 (cons (org-export-get-footnote-number ref info
)
2433 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
2434 (car (org-element-contents
2435 (car (org-element-contents def
))))))))
2437 ;; Export nested footnote in invisible definitions.
2440 (org-test-with-temp-text "Text[fn:1]\n\n[fn:1] B [fn:2]\n\n[fn:2] C."
2441 (narrow-to-region (point) (line-end-position))
2444 (org-export-create-backend
2449 (throw 'exit
(length
2450 (org-export-collect-footnote-definitions
2452 ;; Export footnotes defined outside parsing scope.
2456 (org-test-with-temp-text "[fn:1] Out of scope
2458 <point>Paragraph[fn:1]"
2459 (org-export-as (org-test-default-backend) 'subtree
))))
2463 (org-test-with-temp-text "[fn:1] Out of scope
2465 <point>Paragraph[fn:1]"
2466 (narrow-to-region (point) (point-max))
2467 (org-export-as (org-test-default-backend)))))
2468 ;; Export nested footnotes defined outside parsing scope.
2472 (org-test-with-temp-text "
2473 \[fn:1] Out of scope[fn:2]
2475 \[fn:2] Very out of scope
2477 <point>Paragraph[fn:1]"
2478 (org-export-as (org-test-default-backend) 'subtree
))))
2482 (org-test-with-temp-text "
2483 \[fn:1] Out of scope[fn:2]
2485 \[fn:2] Very out of scope
2487 <point>Paragraph[fn:1]"
2488 (narrow-to-region (point) (point-max))
2489 (org-export-as (org-test-default-backend)))))
2493 (org-test-with-temp-text "
2494 \[fn:1] Out of scope[fn:2:D2]
2496 <point>Paragraph[fn:1]"
2497 (narrow-to-region (point) (point-max))
2498 (org-export-as (org-test-default-backend)))))
2499 ;; Export footnotes in pruned parts of tree.
2503 (let ((org-export-exclude-tags '("noexport")))
2504 (org-test-with-temp-text
2505 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] Definition"
2506 (org-export-as (org-test-default-backend))))))
2510 (let ((org-export-select-tags '("export")))
2511 (org-test-with-temp-text
2512 "* H :export:\nText[fn:1]\n* H2\n[fn:1] Definition"
2513 (org-export-as (org-test-default-backend))))))
2514 ;; Export nested footnotes in pruned parts of tree.
2518 (let ((org-export-exclude-tags '("noexport")))
2519 (org-test-with-temp-text
2520 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2521 (org-export-as (org-test-default-backend))))))
2525 (let ((org-export-select-tags '("export")))
2526 (org-test-with-temp-text
2527 "* H :export:\nText[fn:1]\n* H2\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2528 (org-export-as (org-test-default-backend))))))
2529 ;; Handle uninterpreted data in pruned footnote definitions.
2533 (let ((org-export-with-tables nil
))
2534 (org-test-with-temp-text
2535 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1]\n| a |"
2536 (org-export-as (org-test-default-backend))))))
2537 ;; Footnotes without a definition should throw an error.
2539 (org-test-with-parsed-data "Text[fn:1]"
2540 (org-export-get-footnote-definition
2541 (org-element-map tree
'footnote-reference
#'identity info t
) info
)))
2542 ;; Footnote section should be ignored in TOC and in headlines
2545 (= 1 (let ((org-footnote-section "Footnotes"))
2546 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
2547 (org-export-collect-headlines info
))))))
2550 (let ((org-footnote-section "Footnotes"))
2551 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
2552 (org-element-map tree
'headline
2554 (when (equal (org-element-property :raw-value hl
) "H2")
2555 (org-export-get-headline-number hl info
)))
2560 ;;; Headlines and Inlinetasks
2562 (ert-deftest test-org-export
/get-relative-level
()
2563 "Test `org-export-get-relative-level' specifications."
2567 (let ((org-odd-levels-only nil
))
2568 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2569 (org-element-map tree
'headline
2570 (lambda (h) (org-export-get-relative-level h info
))
2575 (let ((org-odd-levels-only nil
))
2576 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
2577 (org-element-map tree
'headline
2578 (lambda (h) (org-export-get-relative-level h info
))
2581 (ert-deftest test-org-export
/low-level-p
()
2582 "Test `org-export-low-level-p' specifications."
2586 (let ((org-odd-levels-only nil
))
2587 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2588 (org-element-map tree
'headline
2589 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
2590 (plist-put info
:headline-levels
1)))))))
2592 (ert-deftest test-org-export
/get-headline-number
()
2593 "Test `org-export-get-headline-number' specifications."
2598 (let ((org-odd-levels-only nil
))
2599 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2600 (org-element-map tree
'headline
2601 (lambda (h) (org-export-get-headline-number h info
))
2603 ;; Missing levels are replaced with 0.
2607 (let ((org-odd-levels-only nil
))
2608 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
2609 (org-element-map tree
'headline
2610 (lambda (h) (org-export-get-headline-number h info
))
2613 (ert-deftest test-org-export
/numbered-headline-p
()
2614 "Test `org-export-numbered-headline-p' specifications."
2615 ;; If `:section-numbers' is nil, never number headlines.
2617 (org-test-with-parsed-data "* Headline"
2618 (org-element-map tree
'headline
2619 (lambda (h) (org-export-numbered-headline-p h info
))
2620 (plist-put info
:section-numbers nil
))))
2621 ;; If `:section-numbers' is a number, only number headlines with
2622 ;; a level greater that it.
2626 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2627 (org-element-map tree
'headline
2628 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
2629 (plist-put info
:section-numbers
1)))))
2630 ;; Otherwise, headlines are always numbered.
2632 (org-test-with-parsed-data "* Headline"
2633 (org-element-map tree
'headline
2634 (lambda (h) (org-export-numbered-headline-p h info
))
2635 (plist-put info
:section-numbers t
))))
2636 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
2638 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
2639 (org-export-numbered-headline-p
2640 (org-element-map tree
'headline
'identity info t
)
2642 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
2644 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
2645 (org-export-numbered-headline-p
2646 (org-element-map tree
'headline
#'identity info t
)
2648 ;; UNNUMBERED is inherited.
2650 (equal '(unnumbered numbered unnumbered
)
2651 (org-test-with-parsed-data
2661 (org-element-map tree
'headline
2663 (if (org-export-numbered-headline-p h info
) 'numbered
2667 (ert-deftest test-org-export
/number-to-roman
()
2668 "Test `org-export-number-to-roman' specifications."
2669 ;; If number is negative, return it as a string.
2670 (should (equal (org-export-number-to-roman -
1) "-1"))
2671 ;; Otherwise, return it as a roman number.
2672 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
2674 (ert-deftest test-org-export
/get-optional-title
()
2675 "Test `org-export-get-alt-title' specifications."
2676 ;; If ALT_TITLE property is defined, use it.
2679 (org-test-with-parsed-data
2680 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
2681 (org-export-get-alt-title
2682 (org-element-map tree
'headline
'identity info t
)
2684 ;; Otherwise, fall-back to regular title.
2686 (equal '("Headline")
2687 (org-test-with-parsed-data "* Headline"
2688 (org-export-get-alt-title
2689 (org-element-map tree
'headline
'identity info t
)
2692 (ert-deftest test-org-export
/get-tags
()
2693 "Test `org-export-get-tags' specifications."
2694 ;; Standard test: tags which are not a select tag, an exclude tag,
2695 ;; or specified as optional argument shouldn't be ignored.
2697 (org-test-with-parsed-data "* Headline :tag:"
2698 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2700 ;; Tags provided in the optional argument are ignored.
2702 (org-test-with-parsed-data "* Headline :ignore:"
2703 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2705 ;; Allow tag inheritance.
2709 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2710 (org-element-map tree
'headline
2711 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2712 ;; Tag inheritance checks FILETAGS keywords.
2716 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2717 (org-element-map tree
'headline
2718 (lambda (hl) (org-export-get-tags hl info nil t
)) info
)))))
2720 (ert-deftest test-org-export
/get-node-property
()
2721 "Test`org-export-get-node-property' specifications."
2725 (org-test-with-parsed-data "* Headline
2729 (org-export-get-node-property
2730 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2731 ;; Test inheritance.
2734 (org-test-with-parsed-data "* Parent
2740 (org-export-get-node-property
2741 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2742 ;; Cannot return a value before the first headline.
2744 (org-test-with-parsed-data "Paragraph
2749 (org-export-get-node-property
2750 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2752 (ert-deftest test-org-export
/get-category
()
2753 "Test `org-export-get-category' specifications."
2757 (org-test-with-parsed-data "* Headline
2761 (org-export-get-category
2762 (org-element-map tree
'headline
'identity nil t
) info
))))
2763 ;; Test inheritance from a parent headline.
2765 (equal '("value" "value")
2766 (org-test-with-parsed-data "* Headline1
2771 (org-element-map tree
'headline
2772 (lambda (hl) (org-export-get-category hl info
)) info
))))
2773 ;; Test inheritance from #+CATEGORY keyword
2776 (org-test-with-parsed-data "#+CATEGORY: value
2778 (org-export-get-category
2779 (org-element-map tree
'headline
'identity nil t
) info
))))
2780 ;; Test inheritance from file name.
2783 (org-test-with-parsed-data "* Headline"
2784 (let ((info (plist-put info
:input-file
"~/test.org")))
2785 (org-export-get-category
2786 (org-element-map tree
'headline
'identity nil t
) info
)))))
2790 (org-test-with-parsed-data "* Headline"
2791 (org-export-get-category
2792 (org-element-map tree
'headline
'identity nil t
) info
)))))
2794 (ert-deftest test-org-export
/first-sibling-p
()
2795 "Test `org-export-first-sibling-p' specifications."
2800 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2801 (org-element-map tree
'headline
2802 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2806 (org-test-with-parsed-data "- item\n\n para"
2807 (org-element-map tree
'paragraph
2808 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2810 ;; Ignore sections for headlines.
2813 (org-test-with-parsed-data "* H\nSection\n** H 2"
2814 (org-element-map tree
'headline
2815 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2817 ;; Ignore headlines not exported.
2821 (let ((org-export-exclude-tags '("ignore")))
2822 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2823 (org-element-map tree
'headline
2824 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2827 (ert-deftest test-org-export
/last-sibling-p
()
2828 "Test `org-export-last-sibling-p' specifications."
2833 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2834 (org-element-map tree
'headline
2835 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2839 (org-test-with-parsed-data "- item\n\n para"
2840 (org-element-map tree
'paragraph
2841 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2843 ;; Ignore headlines not exported.
2847 (let ((org-export-exclude-tags '("ignore")))
2848 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2849 (org-element-map tree
'headline
2850 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2852 ;; Handle gracefully discontinuous headings.
2855 (org-test-with-parsed-data "** S\n* H"
2856 (org-element-map tree
'headline
2857 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
)))))))
2859 (ert-deftest test-org-export
/handle-inlinetasks
()
2860 "Test inlinetask export."
2861 ;; Inlinetask with an exclude tag.
2862 (when (featurep 'org-inlinetask
)
2866 (let ((org-inlinetask-min-level 3)
2867 org-export-filter-body-functions
2868 org-export-filter-final-output-functions
)
2869 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2870 (org-export-as (org-test-default-backend)
2871 nil nil nil
'(:exclude-tags
("noexp")))))))
2872 ;; Inlinetask with an include tag.
2875 "* H2\n*** Inline :exp:\n"
2876 (let ((org-inlinetask-min-level 3)
2877 (org-tags-column 0))
2878 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2879 (org-export-as (org-test-default-backend)
2880 nil nil nil
'(:select-tags
("exp")))))))
2881 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2884 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2885 (org-inlinetask-min-level 3)
2886 org-export-filter-body-functions
2887 org-export-filter-final-output-functions
)
2888 (org-test-with-temp-text "*** TODO Inline"
2889 (org-export-as (org-test-default-backend)
2890 nil nil nil
'(:with-tasks nil
))))))))
2896 (ert-deftest test-org-export
/get-date
()
2897 "Test `org-export-get-date' specifications."
2898 ;; Return a properly formatted string when
2899 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2900 ;; consists in a single timestamp.
2903 (let ((org-export-date-timestamp-format "%d %m %Y"))
2904 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2905 (org-export-get-date info
)))))
2906 ;; Return a secondary string otherwise.
2909 (let ((org-export-date-timestamp-format nil
))
2910 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2911 (org-export-get-date info
)))))
2914 (org-test-with-parsed-data "#+DATE: Date"
2915 (org-export-get-date info
))))
2916 ;; Optional argument has precedence over
2917 ;; `org-export-date-timestamp-format'.
2920 (let ((org-export-date-timestamp-format "%d %m %Y"))
2921 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2922 (org-export-get-date info
"%d %m"))))))
2928 (ert-deftest test-org-export
/custom-protocol-maybe
()
2929 "Test `org-export-custom-protocol-maybe' specifications."
2934 (org-link-set-parameters "foo" :export
(lambda (p d f
) "success"))
2935 (org-export-string-as
2937 (org-export-create-backend
2940 '((section .
(lambda (s c i
) c
))
2941 (paragraph .
(lambda (p c i
) c
))
2942 (link .
(lambda (l c i
)
2943 (or (org-export-custom-protocol-maybe l c
'test
)
2949 (org-link-set-parameters
2950 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2951 (org-export-string-as
2953 (org-export-create-backend
2956 '((section .
(lambda (s c i
) c
))
2957 (paragraph .
(lambda (p c i
) c
))
2958 (link .
(lambda (l c i
)
2959 (or (org-export-custom-protocol-maybe l c
'no-test
)
2961 ;; Ignore anonymous back-ends.
2966 (org-link-set-parameters
2967 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2968 (org-export-string-as
2970 (org-export-create-backend
2972 '((section .
(lambda (s c i
) c
))
2973 (paragraph .
(lambda (p c i
) c
))
2974 (link .
(lambda (l c i
)
2975 (or (org-export-custom-protocol-maybe l c nil
)
2978 (ert-deftest test-org-export
/get-coderef-format
()
2979 "Test `org-export-get-coderef-format' specifications."
2980 ;; A link without description returns "%s"
2981 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2983 ;; Return "%s" when path is matched within description.
2984 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2986 ;; Otherwise return description.
2987 (should (equal (org-export-get-coderef-format "path" "desc")
2990 (ert-deftest test-org-export
/inline-image-p
()
2991 "Test `org-export-inline-image-p' specifications."
2993 (org-export-inline-image-p
2994 (org-test-with-temp-text "[[#id]]"
2995 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2996 '(("custom-id" .
"id")))))
2998 (ert-deftest test-org-export
/insert-image-links
()
2999 "Test `org-export-insert-image-links' specifications."
3002 (org-test-with-parsed-data "[[https://orgmode.org][file:image.png]]"
3003 (org-element-map tree
'link
3004 (lambda (l) (org-element-property :type l
))))))
3007 (org-test-with-parsed-data "[[https://orgmode.org][file:image.png]]"
3008 (org-element-map (org-export-insert-image-links tree info
) 'link
3009 (lambda (l) (org-element-property :type l
))))))
3010 ;; Properly set `:parent' property when replace contents with image
3014 (org-test-with-parsed-data "[[https://orgmode.org][file:image.png]]"
3015 (org-element-map (org-export-insert-image-links tree info
) 'link
3017 (org-element-type (org-element-property :parent l
)))))))
3018 ;; With optional argument RULES, recognize different links as
3022 (org-test-with-parsed-data "[[https://orgmode.org][file:image.xxx]]"
3023 (org-element-map (org-export-insert-image-links tree info
) 'link
3024 (lambda (l) (org-element-property :type l
))))))
3027 (org-test-with-parsed-data "[[https://orgmode.org][file:image.xxx]]"
3029 (org-export-insert-image-links tree info
'(("file" .
"xxx")))
3031 (lambda (l) (org-element-property :type l
)))))))
3033 (ert-deftest test-org-export
/fuzzy-link
()
3034 "Test fuzzy links specifications."
3035 ;; Link to an headline should return headline's number.
3037 ;; Note: Headline's number is in fact a list of numbers.
3039 (org-test-with-parsed-data
3040 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
3041 (org-element-map tree
'link
3043 (org-export-get-ordinal
3044 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
3045 ;; Link to a target in an item should return item's number.
3047 ;; Note: Item's number is in fact a list of numbers.
3049 (org-test-with-parsed-data
3050 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
3051 (org-element-map tree
'link
3053 (org-export-get-ordinal
3054 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
3055 ;; Link to a target in a footnote should return footnote's number.
3058 (org-test-with-parsed-data "
3059 Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
3063 (org-element-map tree
'link
3065 (org-export-get-ordinal
3066 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
3067 ;; Link to a named element should return sequence number of that
3071 (org-test-with-parsed-data
3072 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
3073 (org-element-map tree
'link
3075 (org-export-get-ordinal
3076 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
3077 ;; Link to a target not within an item, a table, a footnote
3078 ;; reference or definition should return section number.
3081 (org-test-with-parsed-data
3082 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
3083 (org-element-map tree
'link
3085 (org-export-get-ordinal
3086 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
3087 ;; Space are not significant when matching a fuzzy link.
3089 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
3090 (org-element-map tree
'link
3091 (lambda (link) (org-export-resolve-fuzzy-link link info
))
3093 ;; Statistics cookies are ignored for headline match.
3095 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
3096 (org-element-map tree
'link
3097 (lambda (link) (org-export-resolve-fuzzy-link link info
))
3100 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
3101 (org-element-map tree
'link
3102 (lambda (link) (org-export-resolve-fuzzy-link link info
))
3105 (defun test-org-gen-loc-list(text type
)
3106 (org-test-with-parsed-data text
3107 (org-element-map tree type
3108 (lambda (el) (or (org-export-get-loc el info
) 'no-loc
)))))
3110 (ert-deftest test-org-export
/get-loc
()
3111 "Test `org-export-get-loc' specifications."
3113 ;; "-n" resets line number.
3115 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n\n Text\n#+END_EXAMPLE"
3117 ;; The first "+n" has 0 lines before it
3120 (test-org-gen-loc-list "#+BEGIN_EXAMPLE +n\n Text\n#+END_EXAMPLE"
3122 ;; "-n 10" resets line number but has "9 lines" before it.
3125 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n Text\n#+END_EXAMPLE"
3127 ;; -n10 with two lines then +n 15
3130 (test-org-gen-loc-list "
3131 #+BEGIN_EXAMPLE -n 10
3135 #+BEGIN_EXAMPLE +n 15
3141 (test-org-gen-loc-list "
3142 #+BEGIN_EXAMPLE -n 10
3145 #+BEGIN_EXAMPLE +n 10
3153 ;; an Example Block without -n does not add to the line count.
3155 (equal '(9 no-loc
19)
3156 (test-org-gen-loc-list "
3157 #+BEGIN_EXAMPLE -n 10
3163 #+BEGIN_EXAMPLE +n 10
3167 ;; "-n" resets line number.
3171 (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n \n (- 1 1) \n#+END_SRC"
3173 ;; The first "+n" has 0 lines before it.
3176 (test-org-gen-loc-list
3177 "#+BEGIN_SRC emacs-lisp +n \n (+ 0 (- 1 1))\n#+END_SRC"
3179 ;; "-n 10" resets line number but has "9 lines" before it.
3182 (test-org-gen-loc-list
3183 "#+BEGIN_SRC emacs-lisp -n 10\n (- 10 1)\n#+END_SRC"
3187 (test-org-gen-loc-list "
3188 #+BEGIN_SRC emacs-lisp -n 10
3192 #+BEGIN_SRC emacs-lisp +n 15
3193 (+ (- 10 1) 2 (- 15 1))
3198 (test-org-gen-loc-list "
3199 #+BEGIN_SRC emacs-lisp -n 10
3202 #+BEGIN_SRC emacs-lisp +n 10
3203 (+ (- 10 1) 1 (- 10 1))
3205 #+BEGIN_SRC emacs-lisp -n
3209 ;; A SRC Block without -n does not add to the line count.
3211 (equal '(9 no-loc
19)
3212 (test-org-gen-loc-list
3213 "#+BEGIN_SRC emacs-lisp -n 10
3216 #+BEGIN_SRC emacs-lisp
3219 #+BEGIN_SRC emacs-lisp +n 10
3220 (+ (- 10 1) 1 (- 10 1))
3224 (ert-deftest test-org-export
/resolve-coderef
()
3225 "Test `org-export-resolve-coderef' specifications."
3226 (let ((org-coderef-label-format "(ref:%s)"))
3227 ;; A link to a "-n -k -r" block returns line number.
3230 (org-test-with-parsed-data
3231 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3232 (org-export-resolve-coderef "coderef" info
))))
3235 (org-test-with-parsed-data
3236 "#+BEGIN_EXAMPLE -n 10 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3237 (org-export-resolve-coderef "coderef" info
))))
3240 (org-test-with-parsed-data
3241 "#+BEGIN_EXAMPLE -n 10 -k -r\nText \n#+END_EXAMPLE\n
3242 #+BEGIN_EXAMPLE +n 125 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3243 (org-export-resolve-coderef "coderef" info
))))
3246 (org-test-with-parsed-data
3247 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3248 (org-export-resolve-coderef "coderef" info
))))
3251 (org-test-with-parsed-data
3252 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3253 (org-export-resolve-coderef "coderef" info
))))
3256 (org-test-with-parsed-data
3257 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) \n#+END_SRC\n
3258 #+BEGIN_SRC emacs-lisp +n 125 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3259 (org-export-resolve-coderef "coderef" info
))))
3260 ;; A link to a "-n -r" block returns line number.
3263 (org-test-with-parsed-data
3264 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
3265 (org-export-resolve-coderef "coderef" info
))))
3268 (org-test-with-parsed-data
3269 "#+BEGIN_EXAMPLE -n 10 -r\nText (ref:coderef)\n#+END_EXAMPLE"
3270 (org-export-resolve-coderef "coderef" info
))))
3273 (org-test-with-parsed-data
3274 "#+BEGIN_EXAMPLE +n 10 -r\nText \n#+END_EXAMPLE
3275 #+BEGIN_EXAMPLE +n 125 -r\nText (ref:coderef)\n#+END_EXAMPLE"
3276 (org-export-resolve-coderef "coderef" info
))))
3280 (org-test-with-parsed-data
3281 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3282 (org-export-resolve-coderef "coderef" info
))))
3285 (org-test-with-parsed-data
3286 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3287 (org-export-resolve-coderef "coderef" info
))))
3290 (org-test-with-parsed-data
3291 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) \n#+END_SRC
3292 #+BEGIN_SRC emacs-lisp +n125 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3293 (org-export-resolve-coderef "coderef" info
))))
3294 ;; A link to a "-n" block returns coderef.
3297 (org-test-with-parsed-data
3298 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3299 (org-export-resolve-coderef "coderef" info
))))
3302 (org-test-with-parsed-data
3303 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
3304 (org-export-resolve-coderef "coderef" info
))))
3305 ;; A link to a "-r" block returns line number.
3308 (org-test-with-parsed-data
3309 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3310 (org-export-resolve-coderef "coderef" info
))))
3313 (org-test-with-parsed-data
3314 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
3315 (org-export-resolve-coderef "coderef" info
))))
3316 ;; A link to a block without a switch returns coderef.
3319 (org-test-with-parsed-data
3320 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3321 (org-export-resolve-coderef "coderef" info
))))
3322 (org-test-with-parsed-data
3323 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
3324 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
3325 ;; Correctly handle continued line numbers. A "+n" switch should
3326 ;; resume numbering from previous block with numbered lines,
3327 ;; ignoring blocks not numbering lines in the process. A "-n"
3328 ;; switch resets count.
3331 (org-test-with-parsed-data "
3336 #+BEGIN_SRC emacs-lisp
3340 #+BEGIN_SRC emacs-lisp +n -r
3341 \(+ 1 1) (ref:addition)
3344 #+BEGIN_EXAMPLE -n -r
3345 Another text. (ref:text)
3347 (list (org-export-resolve-coderef "addition" info
)
3348 (org-export-resolve-coderef "text" info
)))))
3349 ;; Recognize coderef with user-specified syntax.
3353 (org-test-with-parsed-data
3354 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
3355 (org-export-resolve-coderef "text" info
))))
3356 ;; Unresolved coderefs raise a `org-link-broken' signal.
3359 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3360 (org-export-resolve-coderef "unknown" info
))
3361 (org-link-broken t
)))))
3363 (ert-deftest test-org-export
/resolve-fuzzy-link
()
3364 "Test `org-export-resolve-fuzzy-link' specifications."
3365 ;; Match target objects.
3367 (org-test-with-parsed-data "<<target>> [[target]]"
3368 (org-export-resolve-fuzzy-link
3369 (org-element-map tree
'link
'identity info t
) info
)))
3370 ;; Match named elements.
3372 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
3373 (org-export-resolve-fuzzy-link
3374 (org-element-map tree
'link
'identity info t
) info
)))
3375 ;; Match exact headline's name.
3377 (org-test-with-parsed-data "* My headline\n[[My headline]]"
3378 (org-export-resolve-fuzzy-link
3379 (org-element-map tree
'link
'identity info t
) info
)))
3380 ;; Targets objects have priority over headline titles.
3383 (org-test-with-parsed-data "* target\n<<target>>[[target]]"
3385 (org-export-resolve-fuzzy-link
3386 (org-element-map tree
'link
'identity info t
) info
)))))
3387 ;; Named elements have priority over headline titles.
3390 (org-test-with-parsed-data
3391 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
3393 (org-export-resolve-fuzzy-link
3394 (org-element-map tree
'link
'identity info t
) info
)))))
3395 ;; If link's path starts with a "*", only match headline titles,
3399 (org-test-with-parsed-data
3400 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
3402 (org-export-resolve-fuzzy-link
3403 (org-element-map tree
'link
'identity info t
) info
)))))
3404 ;; Raise a `org-link-broken' signal if no match.
3406 (org-test-with-parsed-data "[[target]]"
3408 (org-export-resolve-fuzzy-link
3409 (org-element-map tree
'link
#'identity info t
) info
)
3410 (org-link-broken t
))))
3411 ;; Match fuzzy link even when before first headline.
3414 (org-test-with-parsed-data "[[hl]]\n* hl"
3416 (org-export-resolve-fuzzy-link
3417 (org-element-map tree
'link
'identity info t
) info
)))))
3418 ;; Handle url-encoded fuzzy links.
3420 (org-test-with-parsed-data "* A B\n[[A%20B]]"
3421 (org-export-resolve-fuzzy-link
3422 (org-element-map tree
'link
#'identity info t
) info
))))
3424 (ert-deftest test-org-export
/resolve-id-link
()
3425 "Test `org-export-resolve-id-link' specifications."
3426 ;; Regular test for custom-id link.
3428 (equal '("Headline1")
3429 (org-test-with-parsed-data "* Headline1
3435 (org-element-property
3437 (org-export-resolve-id-link
3438 (org-element-map tree
'link
'identity info t
) info
)))))
3439 ;; Raise a `org-link-broken' signal on failing searches.
3441 (org-test-with-parsed-data "* Headline1
3448 (org-export-resolve-id-link
3449 (org-element-map tree
'link
#'identity info t
) info
)
3450 (org-link-broken t
))))
3451 ;; Test for internal id target.
3453 (equal '("Headline1")
3454 (org-test-with-parsed-data "* Headline1
3460 (org-element-property
3462 (org-export-resolve-id-link
3463 (org-element-map tree
'link
'identity info t
) info
)))))
3464 ;; Test for external id target.
3468 (org-test-with-parsed-data "[[id:aaaa]]"
3469 (org-export-resolve-id-link
3470 (org-element-map tree
'link
'identity info t
)
3471 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
3473 (ert-deftest test-org-export
/resolve-radio-link
()
3474 "Test `org-export-resolve-radio-link' specifications."
3477 (org-test-with-temp-text "<<<radio>>> radio"
3478 (org-update-radio-target-regexp)
3479 (let* ((tree (org-element-parse-buffer))
3480 (info `(:parse-tree
,tree
)))
3481 (org-export-resolve-radio-link
3482 (org-element-map tree
'link
'identity info t
)
3484 ;; Radio targets are case-insensitive.
3486 (org-test-with-temp-text "<<<RADIO>>> radio"
3487 (org-update-radio-target-regexp)
3488 (let* ((tree (org-element-parse-buffer))
3489 (info `(:parse-tree
,tree
)))
3490 (org-export-resolve-radio-link
3491 (org-element-map tree
'link
'identity info t
)
3493 ;; Radio target with objects.
3495 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
3496 (org-update-radio-target-regexp)
3497 (let* ((tree (org-element-parse-buffer))
3498 (info `(:parse-tree
,tree
)))
3499 (org-export-resolve-radio-link
3500 (org-element-map tree
'link
'identity info t
)
3502 ;; Radio target with objects at its beginning.
3504 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
3505 (org-update-radio-target-regexp)
3506 (let* ((tree (org-element-parse-buffer))
3507 (info `(:parse-tree
,tree
)))
3508 (org-export-resolve-radio-link
3509 (org-element-map tree
'link
'identity info t
)
3511 ;; Radio link next to an apostrophe.
3513 (org-test-with-temp-text "<<<radio>>> radio's"
3514 (org-update-radio-target-regexp)
3515 (let* ((tree (org-element-parse-buffer))
3516 (info `(:parse-tree
,tree
)))
3517 (org-export-resolve-radio-link
3518 (org-element-map tree
'link
'identity info t
)
3520 ;; Multiple radio targets.
3522 (equal '("radio1" "radio2")
3523 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
3524 (org-update-radio-target-regexp)
3525 (let* ((tree (org-element-parse-buffer))
3526 (info `(:parse-tree
,tree
)))
3527 (org-element-map tree
'link
3529 (org-element-property
3530 :value
(org-export-resolve-radio-link link info
)))
3532 ;; Radio target is whitespace insensitive.
3534 (org-test-with-temp-text "<<<a radio>>> a\n radio"
3535 (org-update-radio-target-regexp)
3536 (let* ((tree (org-element-parse-buffer))
3537 (info `(:parse-tree
,tree
)))
3538 (org-element-map tree
'link
3539 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
3541 (ert-deftest test-org-export
/file-uri
()
3542 "Test `org-export-file-uri' specifications."
3543 ;; Preserve relative filenames.
3544 (should (equal "relative.org" (org-export-file-uri "relative.org")))
3545 ;; Local files start with "file://"
3546 (should (equal (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "/local.org"))
3547 (org-export-file-uri "/local.org")))
3548 ;; Remote files start with "file://"
3549 (should (equal "file://ssh:myself@some.where:papers/last.pdf"
3550 (org-export-file-uri "/ssh:myself@some.where:papers/last.pdf")))
3551 (should (equal "file://localhost/etc/fstab"
3552 (org-export-file-uri "//localhost/etc/fstab")))
3553 ;; Expand filename starting with "~".
3554 (should (equal (org-export-file-uri "~/file.org")
3555 (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "~/file.org")))))
3557 (ert-deftest test-org-export
/get-reference
()
3558 "Test `org-export-get-reference' specifications."
3560 (org-test-with-parsed-data "* Headline"
3561 (org-export-get-reference (org-element-map tree
'headline
#'identity nil t
)
3563 ;; For a given element always return the same reference.
3565 (org-test-with-parsed-data "* Headline"
3566 (let ((headline (org-element-map tree
'headline
#'identity nil t
)))
3567 (equal (org-export-get-reference headline info
)
3568 (org-export-get-reference headline info
)))))
3569 ;; References get through local export back-ends.
3571 (org-test-with-parsed-data "* Headline"
3572 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3574 (org-export-create-backend
3576 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3577 (equal (org-trim (org-export-data-with-backend headline backend info
))
3578 (org-export-get-reference headline info
)))))
3580 (org-test-with-parsed-data "* Headline"
3581 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3583 (org-export-create-backend
3585 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3586 (equal (org-export-with-backend backend headline nil info
)
3587 (org-export-get-reference headline info
)))))
3588 ;; Use search cells defined in `:crossrefs'. However, handle
3589 ;; duplicate search cells.
3592 (org-test-with-parsed-data "* Headline"
3593 (let* ((headline (org-element-map tree
'headline
#'identity nil t
))
3594 (search-cell (car (org-export-search-cells headline
))))
3596 (plist-put info
:crossrefs
(list (cons search-cell
1))))
3597 (org-export-get-reference headline info
)))))
3599 (equal '("org0000001" "org0000001")
3600 (org-test-with-parsed-data "* H\n** H"
3601 (org-element-map tree
'headline
3603 (let* ((search-cell (car (org-export-search-cells h
)))
3604 (info (plist-put info
:crossrefs
3605 (list (cons search-cell
1)))))
3606 (org-export-get-reference h info
))))))))
3609 ;;; Pseudo objects and pseudo elements
3611 (ert-deftest test-org-export
/pseudo-elements
()
3612 "Test exporting pseudo-elements."
3613 ;; Handle blank lines after pseudo-elements. In particular, do not
3614 ;; replace them with white spaces.
3616 (equal "contents\n\nparagraph\n"
3617 (let ((backend (org-export-create-backend
3619 '((pseudo-element .
(lambda (_p c _i
) c
))
3620 (paragraph .
(lambda (_p c _i
) c
))
3621 (plain-text .
(lambda (c _i
) c
)))))
3622 (element '(pseudo-element (:post-blank
1) "contents"))
3623 (paragraph '(paragraph nil
"paragraph"))
3624 (data '(org-data nil
)))
3625 (org-element-adopt-elements data element paragraph
)
3626 (org-export-data-with-backend data backend nil
)))))
3628 (ert-deftest test-org-export
/pseudo-objects
()
3629 "Test exporting pseudo-objects."
3630 ;; Handle blank spaces after pseudo-objects. In particular, do not
3631 ;; replace them with newlines.
3633 (equal "begin x end\n"
3634 (let ((backend (org-export-create-backend
3636 '((pseudo-object .
(lambda (_p c _i
) c
))
3637 (paragraph .
(lambda (_p c _i
) c
))
3638 (plain-text .
(lambda (c _i
) c
)))))
3639 (object '(pseudo-object (:post-blank
1) "x"))
3640 (paragraph '(paragraph nil
)))
3641 (org-element-adopt-elements paragraph
"begin " object
"end")
3642 (org-export-data-with-backend paragraph backend nil
)))))
3645 ;;; Src-block and example-block
3647 (ert-deftest test-org-export
/unravel-code
()
3648 "Test `org-export-unravel-code' function."
3649 ;; Code without reference.
3652 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3653 (org-export-unravel-code (org-element-at-point)))))
3654 ;; Code with reference.
3656 (equal '("(+ 1 1)" (1 .
"test"))
3657 (org-test-with-temp-text
3658 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
3659 (let ((org-coderef-label-format "(ref:%s)"))
3660 (org-export-unravel-code (org-element-at-point))))))
3661 ;; Code with user-defined reference.
3664 '("(+ 1 1)" (1 .
"test"))
3665 (org-test-with-temp-text
3666 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
3667 (let ((org-coderef-label-format "(ref:%s)"))
3668 (org-export-unravel-code (org-element-at-point))))))
3669 ;; Code references keys are relative to the current block.
3671 (equal '("(+ 2 2)\n(+ 3 3)" (2 .
"one"))
3672 (org-test-with-temp-text "
3681 (let ((org-coderef-label-format "(ref:%s)"))
3682 (org-export-unravel-code (org-element-at-point)))))\x14))
3684 (ert-deftest test-org-export
/format-code-default
()
3685 "Test `org-export-format-code-default' specifications."
3686 ;; Preserve blank lines, even when code is empty.
3689 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
3690 (org-export-format-code-default
3691 (org-element-map tree
'src-block
#'identity info t
) info
))))
3692 ;; Likewise, preserve leading and trailing blank lines in the code.
3694 (equal "\n(+ 1 1)\n"
3695 (org-test-with-parsed-data
3696 "#+BEGIN_SRC emacs-lisp\n\n(+ 1 1)\n#+END_SRC"
3697 (org-export-format-code-default
3698 (org-element-map tree
'src-block
#'identity info t
) info
))))
3700 (equal "(+ 1 1)\n\n"
3701 (org-test-with-parsed-data
3702 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n\n#+END_SRC"
3703 (org-export-format-code-default
3704 (org-element-map tree
'src-block
#'identity info t
) info
))))
3705 ;; Number lines, two whitespace characters before the actual loc.
3708 (org-test-with-parsed-data
3709 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
3710 (org-export-format-code-default
3711 (org-element-map tree
'src-block
#'identity info t
) info
))))
3712 ;; Numbering includes blank lines.
3714 (equal "1 \n2 a\n3 \n4 b\n5 \n"
3715 (org-test-with-parsed-data
3716 "#+BEGIN_SRC emacs-lisp +n\n\na\n\nb\n\n#+END_SRC"
3717 (org-export-format-code-default
3718 (org-element-map tree
'src-block
#'identity info t
) info
))))
3719 ;; Put references 6 whitespace characters after the widest line,
3720 ;; wrapped within parenthesis.
3722 (equal "123 (a)\n1 (b)\n"
3723 (let ((org-coderef-label-format "(ref:%s)"))
3724 (org-test-with-parsed-data
3725 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
3726 (org-export-format-code-default
3727 (org-element-map tree
'src-block
#'identity info t
) info
))))))
3733 (ert-deftest test-org-export
/activate-smart-quotes
()
3734 "Test `org-export-activate-smart-quotes' specifications."
3735 ;; Double quotes: standard test.
3738 '("some “quoted” text")
3739 (let ((org-export-default-language "en"))
3740 (org-test-with-parsed-data "some \"quoted\" text"
3741 (org-element-map tree
'plain-text
3742 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3744 ;; Opening quotes: at the beginning of a paragraph.
3748 (let ((org-export-default-language "en"))
3749 (org-test-with-parsed-data "\"begin"
3750 (org-element-map tree
'plain-text
3751 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3753 ;; Opening quotes: after an object.
3756 '("“quoted” text")
3757 (let ((org-export-default-language "en"))
3758 (org-test-with-parsed-data "=verb= \"quoted\" text"
3759 (org-element-map tree
'plain-text
3760 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3762 ;; Closing quotes: at the end of a paragraph.
3765 '("Quoted “text”")
3766 (let ((org-export-default-language "en"))
3767 (org-test-with-parsed-data "Quoted \"text\""
3768 (org-element-map tree
'plain-text
3769 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3771 ;; Inner quotes: standard test.
3773 (equal '("« outer « inner » outer »")
3774 (let ((org-export-default-language "fr"))
3775 (org-test-with-parsed-data "\"outer 'inner' outer\""
3776 (org-element-map tree
'plain-text
3777 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3779 ;; Inner quotes: close to special symbols.
3781 (equal '("« outer (« inner ») outer »")
3782 (let ((org-export-default-language "fr"))
3783 (org-test-with-parsed-data "\"outer ('inner') outer\""
3784 (org-element-map tree
'plain-text
3785 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3788 (equal '("« « inner » »")
3789 (let ((org-export-default-language "fr"))
3790 (org-test-with-parsed-data "\"'inner'\""
3791 (org-element-map tree
'plain-text
3792 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3794 ;; Apostrophe: standard test.
3796 (equal '("It « shouldn’t » fail")
3797 (let ((org-export-default-language "fr"))
3798 (org-test-with-parsed-data "It \"shouldn't\" fail"
3799 (org-element-map tree
'plain-text
3800 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3803 (equal '("It shouldn’t fail")
3804 (let ((org-export-default-language "fr"))
3805 (org-test-with-parsed-data "It shouldn't fail"
3806 (org-element-map tree
'plain-text
3807 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3809 ;; Apostrophe: before an object.
3812 '("« a’" " »")
3813 (let ((org-export-default-language "fr"))
3814 (org-test-with-parsed-data "\"a'=b=\""
3815 (org-element-map tree
'plain-text
3816 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3818 ;; Apostrophe: after an object.
3820 (equal '("« " "’s »")
3821 (let ((org-export-default-language "fr"))
3822 (org-test-with-parsed-data "\"=code='s\""
3823 (org-element-map tree
'plain-text
3824 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3826 ;; Special case: isolated quotes.
3828 (equal '("“" "”")
3829 (let ((org-export-default-language "en"))
3830 (org-test-with-parsed-data "\"$x$\""
3831 (org-element-map tree
'plain-text
3832 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3834 ;; Smart quotes in secondary strings.
3836 (equal '("“" "”")
3837 (let ((org-export-default-language "en"))
3838 (org-test-with-parsed-data "* \"$x$\""
3839 (org-element-map tree
'plain-text
3840 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3842 ;; Smart quotes in document keywords.
3844 (equal '("“" "”")
3845 (let ((org-export-default-language "en"))
3846 (org-test-with-parsed-data "#+TITLE: \"$x$\""
3847 (org-element-map (plist-get info
:title
) 'plain-text
3848 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3850 ;; Smart quotes in parsed affiliated keywords.
3852 (equal '("“" "”" "Paragraph")
3853 (let ((org-export-default-language "en"))
3854 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
3855 (org-element-map tree
'plain-text
3856 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3858 ;; Smart quotes within objects.
3860 (equal '("“foo”")
3861 (let ((org-export-default-language "en"))
3862 (org-test-with-parsed-data "| \"foo\" |"
3863 (org-element-map tree
'plain-text
3864 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3866 ;; FIXME: Test failing non-interactively.
3869 ;; (equal '("“foo”")
3870 ;; (let ((org-export-default-language "en"))
3871 ;; (org-test-with-parsed-data "*\"foo\"*"
3872 ;; (org-element-map tree 'plain-text
3873 ;; (lambda (s) (org-export-activate-smart-quotes s :html info))
3874 ;; info nil nil t)))))
3881 (ert-deftest test-org-export
/special-column
()
3882 "Test if the table's special column is properly recognized."
3883 ;; 1. First column is special if it contains only a special marking
3884 ;; characters or empty cells.
3885 (org-test-with-temp-text "
3889 (org-export-table-has-special-column-p
3891 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3892 ;; 2. If the column contains anything else, it isn't special.
3893 (org-test-with-temp-text "
3897 (org-export-table-has-special-column-p
3899 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3900 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
3902 (org-test-with-temp-text "
3911 (org-export-table-has-special-column-p
3913 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3914 ;; 4. A first column with only empty cells isn't considered as
3916 (org-test-with-temp-text "
3920 (org-export-table-has-special-column-p
3922 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
3924 (ert-deftest test-org-export
/table-row-is-special-p
()
3925 "Test `org-export-table-row-is-special-p' specifications."
3926 ;; 1. A row is special if it has a special marking character in the
3928 (org-test-with-parsed-data "| ! | 1 |"
3930 (org-export-table-row-is-special-p
3931 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3932 ;; 2. A row is special when its first field is "/"
3933 (org-test-with-parsed-data "
3937 (org-export-table-row-is-special-p
3938 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3939 ;; 3. A row only containing alignment cookies is also considered as
3941 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
3943 (org-export-table-row-is-special-p
3944 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3945 ;; 4. Everything else isn't considered as special.
3946 (org-test-with-parsed-data "| \alpha | | c |"
3948 (org-export-table-row-is-special-p
3949 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3950 ;; 5. Table's rules are never considered as special rows.
3951 (org-test-with-parsed-data "|---+---|"
3953 (org-export-table-row-is-special-p
3954 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
3956 (ert-deftest test-org-export
/has-header-p
()
3957 "Test `org-export-table-has-header-p' specifications."
3960 (org-test-with-parsed-data "
3964 (org-export-table-has-header-p
3965 (org-element-map tree
'table
'identity info
'first-match
)
3967 ;; Without an header.
3969 (org-test-with-parsed-data "
3972 (org-export-table-has-header-p
3973 (org-element-map tree
'table
'identity info
'first-match
)
3975 ;; Don't get fooled with starting and ending rules.
3977 (org-test-with-parsed-data "
3982 (org-export-table-has-header-p
3983 (org-element-map tree
'table
'identity info
'first-match
)
3986 (ert-deftest test-org-export
/table-row-group
()
3987 "Test `org-export-table-row-group' specifications."
3988 ;; A rule creates a new group.
3991 (org-test-with-parsed-data "
3995 (org-element-map tree
'table-row
3997 (if (eq (org-element-property :type row
) 'rule
) 'rule
3998 (org-export-table-row-group row info
)))))))
3999 ;; Special rows are ignored in count.
4003 (org-test-with-parsed-data "
4007 (org-element-map tree
'table-row
4009 (if (eq (org-element-property :type row
) 'rule
) 'rule
4010 (org-export-table-row-group row info
)))
4012 ;; Double rules also are ignored in count.
4014 (equal '(1 rule rule
2)
4015 (org-test-with-parsed-data "
4020 (org-element-map tree
'table-row
4022 (if (eq (org-element-property :type row
) 'rule
) 'rule
4023 (org-export-table-row-group row info
))))))))
4025 (ert-deftest test-org-export
/table-row-number
()
4026 "Test `org-export-table-row-number' specifications."
4027 ;; Standard test. Number is 0-indexed.
4030 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
4031 (org-element-map tree
'table-row
4032 (lambda (row) (org-export-table-row-number row info
)) info
))))
4033 ;; Number ignores separators.
4036 (org-test-with-parsed-data "
4040 (org-element-map tree
'table-row
4041 (lambda (row) (org-export-table-row-number row info
)) info
))))
4042 ;; Number ignores special rows.
4045 (org-test-with-parsed-data "
4051 (org-element-map tree
'table-row
4052 (lambda (row) (org-export-table-row-number row info
)) info
)))))
4054 (ert-deftest test-org-export
/table-cell-width
()
4055 "Test `org-export-table-cell-width' specifications."
4056 ;; 1. Width is primarily determined by width cookies. If no cookie
4057 ;; is found, cell's width is nil.
4058 (org-test-with-parsed-data "
4059 | / | <l> | <6> | <l7> |
4064 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
4065 (org-element-map tree
'table-cell
'identity info
)))))
4066 ;; 2. The last width cookie has precedence.
4067 (org-test-with-parsed-data "
4074 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
4075 (org-element-map tree
'table-cell
'identity info
)))))
4076 ;; 3. Valid width cookies must have a specific row.
4077 (org-test-with-parsed-data "| <6> | cell |"
4081 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
4082 (org-element-map tree
'table-cell
'identity
))))))
4084 (ert-deftest test-org-export
/table-cell-alignment
()
4085 "Test `org-export-table-cell-alignment' specifications."
4086 ;; 1. Alignment is primarily determined by alignment cookies.
4088 (equal '(left center right
)
4089 (let ((org-table-number-fraction 0.5)
4090 (org-table-number-regexp "^[0-9]+$"))
4091 (org-test-with-parsed-data "| <l> | <c> | <r> |"
4092 (mapcar (lambda (cell)
4093 (org-export-table-cell-alignment cell info
))
4094 (org-element-map tree
'table-cell
'identity
))))))
4095 ;; 2. The last alignment cookie has precedence.
4097 (equal '(right right right
)
4098 (org-test-with-parsed-data "
4102 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
4103 (org-element-map tree
'table-cell
'identity
)))))
4104 ;; 3. If there's no cookie, cell's contents determine alignment.
4105 ;; A column mostly made of cells containing numbers will align
4106 ;; its cells to the right.
4108 (equal '(right right right
)
4109 (let ((org-table-number-fraction 0.5)
4110 (org-table-number-regexp "^[0-9]+$"))
4111 (org-test-with-parsed-data "
4115 (mapcar (lambda (cell)
4116 (org-export-table-cell-alignment cell info
))
4117 (org-element-map tree
'table-cell
'identity
))))))
4118 ;; 4. Otherwise, they will be aligned to the left.
4120 (equal '(left left left
)
4121 (org-test-with-parsed-data "
4125 (mapcar (lambda (cell)
4126 (org-export-table-cell-alignment cell info
))
4127 (org-element-map tree
'table-cell
'identity info
))))))
4129 (ert-deftest test-org-export
/table-cell-borders
()
4130 "Test `org-export-table-cell-borders' specifications."
4131 ;; 1. Recognize various column groups indicators.
4132 (org-test-with-parsed-data "| / | < | > | <> |"
4135 '((right bottom top
) (left bottom top
) (right bottom top
)
4136 (right left bottom top
))
4137 (mapcar (lambda (cell)
4138 (org-export-table-cell-borders cell info
))
4139 (org-element-map tree
'table-cell
'identity
)))))
4140 ;; 2. Accept shortcuts to define column groups.
4141 (org-test-with-parsed-data "| / | < | < |"
4144 '((right bottom top
) (right left bottom top
) (left bottom top
))
4145 (mapcar (lambda (cell)
4146 (org-export-table-cell-borders cell info
))
4147 (org-element-map tree
'table-cell
'identity
)))))
4148 ;; 3. A valid column groups row must start with a "/".
4149 (org-test-with-parsed-data "
4153 (equal '((top) (top) (bottom) (bottom))
4154 (mapcar (lambda (cell)
4155 (org-export-table-cell-borders cell info
))
4156 (org-element-map tree
'table-cell
'identity
)))))
4157 ;; 4. Take table rules into consideration.
4158 (org-test-with-parsed-data "
4163 (equal '((below top
) (bottom above
))
4164 (mapcar (lambda (cell)
4165 (org-export-table-cell-borders cell info
))
4166 (org-element-map tree
'table-cell
'identity
)))))
4167 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
4168 ;; (resp. `bottom' and `below') borders. Any special row is
4170 (org-test-with-parsed-data "
4176 (equal '((bottom below top above
))
4178 (mapcar (lambda (cell)
4179 (org-export-table-cell-borders cell info
))
4180 (org-element-map tree
'table-cell
'identity
)))))))
4182 (ert-deftest test-org-export
/table-dimensions
()
4183 "Test `org-export-table-dimensions' specifications."
4184 ;; 1. Standard test.
4185 (org-test-with-parsed-data "
4190 (org-export-table-dimensions
4191 (org-element-map tree
'table
'identity info
'first-match
) info
))))
4192 ;; 2. Ignore horizontal rules and special columns.
4193 (org-test-with-parsed-data "
4200 (org-export-table-dimensions
4201 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
4203 (ert-deftest test-org-export
/table-cell-address
()
4204 "Test `org-export-table-cell-address' specifications."
4205 ;; 1. Standard test: index is 0-based.
4206 (org-test-with-parsed-data "| a | b |"
4208 (equal '((0 .
0) (0 .
1))
4209 (org-element-map tree
'table-cell
4210 (lambda (cell) (org-export-table-cell-address cell info
))
4212 ;; 2. Special column isn't counted, nor are special rows.
4213 (org-test-with-parsed-data "
4218 (org-export-table-cell-address
4219 (car (last (org-element-map tree
'table-cell
'identity info
)))
4221 ;; 3. Tables rules do not count either.
4222 (org-test-with-parsed-data "
4230 (org-export-table-cell-address
4231 (car (last (org-element-map tree
'table-cell
'identity info
)))
4233 ;; 4. Return nil for special cells.
4234 (org-test-with-parsed-data "| / | a |"
4236 (org-export-table-cell-address
4237 (org-element-map tree
'table-cell
'identity nil
'first-match
)
4240 (ert-deftest test-org-export
/get-table-cell-at
()
4241 "Test `org-export-get-table-cell-at' specifications."
4242 ;; 1. Address ignores special columns, special rows and rules.
4243 (org-test-with-parsed-data "
4250 (org-element-contents
4251 (org-export-get-table-cell-at
4253 (org-element-map tree
'table
'identity info
'first-match
)
4255 ;; 2. Return value for a non-existent address is nil.
4256 (org-test-with-parsed-data "| a |"
4258 (org-export-get-table-cell-at
4260 (org-element-map tree
'table
'identity info
'first-match
)
4262 (org-test-with-parsed-data "| / |"
4264 (org-export-get-table-cell-at
4266 (org-element-map tree
'table
'identity info
'first-match
)
4269 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
4270 "Test `org-export-table-cell-starts-colgroup-p' specifications."
4271 ;; 1. A cell at a beginning of a row always starts a column group.
4272 (org-test-with-parsed-data "| a |"
4274 (org-export-table-cell-starts-colgroup-p
4275 (org-element-map tree
'table-cell
'identity info
'first-match
)
4277 ;; 2. Special column should be ignored when determining the
4278 ;; beginning of the row.
4279 (org-test-with-parsed-data "
4283 (org-export-table-cell-starts-colgroup-p
4284 (org-element-map tree
'table-cell
'identity info
'first-match
)
4286 ;; 2. Explicit column groups.
4287 (org-test-with-parsed-data "
4293 (org-element-map tree
'table-cell
4295 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
4298 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
4299 "Test `org-export-table-cell-ends-colgroup-p' specifications."
4300 ;; 1. A cell at the end of a row always ends a column group.
4301 (org-test-with-parsed-data "| a |"
4303 (org-export-table-cell-ends-colgroup-p
4304 (org-element-map tree
'table-cell
'identity info
'first-match
)
4306 ;; 2. Special column should be ignored when determining the
4307 ;; beginning of the row.
4308 (org-test-with-parsed-data "
4312 (org-export-table-cell-ends-colgroup-p
4313 (org-element-map tree
'table-cell
'identity info
'first-match
)
4315 ;; 3. Explicit column groups.
4316 (org-test-with-parsed-data "
4322 (org-element-map tree
'table-cell
4324 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
4327 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
4328 "Test `org-export-table-row-starts-rowgroup-p' specifications."
4329 ;; 1. A row at the beginning of a table always starts a row group.
4330 ;; So does a row following a table rule.
4331 (org-test-with-parsed-data "
4338 (org-element-map tree
'table-row
4340 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4342 ;; 2. Special rows should be ignored when determining the beginning
4344 (org-test-with-parsed-data "
4353 (org-element-map tree
'table-row
4355 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4358 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
4359 "Test `org-export-table-row-ends-rowgroup-p' specifications."
4360 ;; 1. A row at the end of a table always ends a row group. So does
4361 ;; a row preceding a table rule.
4362 (org-test-with-parsed-data "
4369 (org-element-map tree
'table-row
4371 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4373 ;; 2. Special rows should be ignored when determining the beginning
4375 (org-test-with-parsed-data "
4384 (org-element-map tree
'table-row
4386 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4389 (ert-deftest test-org-export
/table-row-in-header-p
()
4390 "Test `org-export-table-row-in-header-p' specifications."
4391 ;; Standard test. Separators are always nil.
4395 (org-test-with-parsed-data "| a |\n|---|\n| b |"
4396 (org-element-map tree
'table-row
4398 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
4399 ;; Nil when there is no header.
4403 (org-test-with-parsed-data "| a |\n| b |"
4404 (org-element-map tree
'table-row
4406 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
4408 (ert-deftest test-org-export
/table-row-starts-header-p
()
4409 "Test `org-export-table-row-starts-header-p' specifications."
4410 ;; 1. Only the row starting the first row group starts the table
4412 (org-test-with-parsed-data "
4420 (org-element-map tree
'table-row
4422 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
4424 ;; 2. A row cannot start an header if there's no header in the
4426 (org-test-with-parsed-data "
4430 (org-export-table-row-starts-header-p
4431 (org-element-map tree
'table-row
'identity info
'first-match
)
4434 (ert-deftest test-org-export
/table-row-ends-header-p
()
4435 "Test `org-export-table-row-ends-header-p' specifications."
4436 ;; 1. Only the row starting the first row group starts the table
4438 (org-test-with-parsed-data "
4446 (org-element-map tree
'table-row
4448 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
4450 ;; 2. A row cannot start an header if there's no header in the
4452 (org-test-with-parsed-data "
4456 (org-export-table-row-ends-header-p
4457 (org-element-map tree
'table-row
'identity info
'first-match
)
4462 ;;; Tables of Contents
4464 (ert-deftest test-org-export
/collect-headlines
()
4465 "Test `org-export-collect-headlines' specifications."
4469 (org-test-with-parsed-data "* H1\n** H2"
4470 (mapcar (lambda (h) (org-element-property :raw-value h
))
4471 (org-export-collect-headlines info
)))))
4472 ;; Do not collect headlines below optional argument.
4475 (org-test-with-parsed-data "* H1\n** H2"
4476 (mapcar (lambda (h) (org-element-property :raw-value h
))
4477 (org-export-collect-headlines info
1)))))
4478 ;; Never collect headlines below maximum headline level.
4481 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4482 (mapcar (lambda (h) (org-element-property :raw-value h
))
4483 (org-export-collect-headlines info
)))))
4486 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4487 (mapcar (lambda (h) (org-element-property :raw-value h
))
4488 (org-export-collect-headlines info
2)))))
4489 ;; Do not collect footnote section.
4492 (let ((org-footnote-section "Footnotes"))
4493 (org-test-with-parsed-data "* H1\n** Footnotes"
4494 (mapcar (lambda (h) (org-element-property :raw-value h
))
4495 (org-export-collect-headlines info
))))))
4496 ;; Do not collect headlines with UNNUMBERED property set to "notoc".
4497 ;; Headlines with another value for the property are still
4498 ;; collected. UNNUMBERED property is inherited.
4501 (org-test-with-parsed-data
4502 "* H1\n* H2\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:"
4503 (mapcar (lambda (h) (org-element-property :raw-value h
))
4504 (org-export-collect-headlines info
)))))
4506 (org-test-with-parsed-data
4507 "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:\n** H2"
4508 (mapcar (lambda (h) (org-element-property :raw-value h
))
4509 (org-export-collect-headlines info
))))
4512 (org-test-with-parsed-data
4513 "* H1\n* H2\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
4514 (mapcar (lambda (h) (org-element-property :raw-value h
))
4515 (org-export-collect-headlines info
)))))
4516 ;; Collect headlines locally.
4519 (org-test-with-parsed-data "* H1\n** H2\n** H3"
4520 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4521 (mapcar (lambda (h) (org-element-property :raw-value h
))
4522 (org-export-collect-headlines info nil scope
))))))
4523 ;; When collecting locally, optional level is relative.
4526 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
4527 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4528 (mapcar (lambda (h) (org-element-property :raw-value h
))
4529 (org-export-collect-headlines info
1 scope
)))))))
4531 (ert-deftest test-org-export
/excluded-from-toc-p
()
4532 "Test `org-export-excluded-from-toc-p' specifications."
4533 ;; By default, headlines are not excluded.
4535 (org-test-with-parsed-data "* H1"
4536 (org-element-map tree
'headline
4537 (lambda (h) (org-export-excluded-from-toc-p h info
)) info t
)))
4538 ;; Exclude according to a maximum level.
4541 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4542 (org-element-map tree
'headline
4543 (lambda (h) (if (org-export-excluded-from-toc-p h info
) 'out
'in
))
4545 ;; Exclude according to UNNUMBERED property.
4547 (org-test-with-parsed-data "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:"
4548 (org-element-map tree
'headline
4549 (lambda (h) (org-export-excluded-from-toc-p h info
)) info t
)))
4550 ;; UNNUMBERED property is inherited, so is "notoc" value.
4553 (org-test-with-parsed-data
4554 "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:\n** H2"
4555 (org-element-map tree
'headline
4556 (lambda (h) (if (org-export-excluded-from-toc-p h info
) 'out
'in
))
4559 (ert-deftest test-org-export
/toc-entry-backend
()
4560 "Test `org-export-toc-entry-backend' specifications."
4564 (org-test-with-temp-text "* H <<target>>"
4565 (let (org-export-registered-backends)
4566 (org-export-define-backend 'test
4567 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4568 (org-element-property :title h
)
4569 (org-export-toc-entry-backend 'test
)
4571 (org-export-as 'test
)))))
4572 ;; Ignore footnote references.
4575 (org-test-with-temp-text "[fn:1] Definition\n* H [fn:1]"
4576 (let (org-export-registered-backends)
4577 (org-export-define-backend 'test
4578 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4579 (org-element-property :title h
)
4580 (org-export-toc-entry-backend 'test
)
4582 (org-export-as 'test
)))))
4583 ;; Replace plain links with contents, or with path.
4585 (equal "H Org mode\n"
4586 (org-test-with-temp-text "* H [[https://orgmode.org][Org mode]]"
4587 (let (org-export-registered-backends)
4588 (org-export-define-backend 'test
4589 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4590 (org-element-property :title h
)
4591 (org-export-toc-entry-backend 'test
)
4593 (org-export-as 'test
)))))
4595 (equal "H https://orgmode.org\n"
4596 (org-test-with-temp-text "* H [[https://orgmode.org]]"
4597 (let (org-export-registered-backends)
4598 (org-export-define-backend 'test
4599 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4600 (org-element-property :title h
)
4601 (org-export-toc-entry-backend 'test
)
4603 (org-export-as 'test
)))))
4604 ;; Replace radio targets with contents.
4607 (org-test-with-temp-text "* H <<<radio>>>"
4608 (let (org-export-registered-backends)
4609 (org-export-define-backend 'test
4610 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4611 (org-element-property :title h
)
4612 (org-export-toc-entry-backend 'test
)
4614 (org-export-as 'test
)))))
4615 ;; With optional argument TRANSCODERS, specify other
4619 (org-test-with-temp-text "* H *bold*"
4620 (let (org-export-registered-backends)
4621 (org-export-define-backend 'test
4622 '((headline .
(lambda (h _c i
) (org-export-data-with-backend
4623 (org-element-property :title h
)
4624 (org-export-toc-entry-backend 'test
4625 '(bold .
(lambda (_b c _i
) c
)))
4627 (org-export-as 'test
))))))
4633 (ert-deftest test-org-export
/inner-template
()
4634 "Test `inner-template' translator specifications."
4637 (org-test-with-temp-text "* Headline"
4639 (org-export-create-backend
4641 '((inner-template .
(lambda (contents info
) "Success!"))
4642 (headline .
(lambda (h c i
) "Headline"))))))))
4643 ;; Inner template is applied even in a "body-only" export.
4646 (org-test-with-temp-text "* Headline"
4648 (org-export-create-backend
4649 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
4650 (headline .
(lambda (h c i
) "Headline"))))
4651 nil nil
'body-only
)))))
4653 (ert-deftest test-org-export
/template
()
4654 "Test `template' translator specifications."
4657 (org-test-with-temp-text "* Headline"
4659 (org-export-create-backend
4660 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4661 (headline .
(lambda (h c i
) "Headline"))))))))
4662 ;; Template is not applied in a "body-only" export.
4665 (org-test-with-temp-text "* Headline"
4667 (org-export-create-backend
4668 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4669 (headline .
(lambda (h c i
) "Headline"))))
4670 nil nil
'body-only
)))))
4676 (ert-deftest test-org-export
/get-next-element
()
4677 "Test `org-export-get-next-element' specifications."
4681 (org-test-with-parsed-data "* Headline\n*a* b"
4682 (org-export-get-next-element
4683 (org-element-map tree
'bold
'identity info t
) info
))))
4684 ;; Return nil when no previous element.
4686 (org-test-with-parsed-data "* Headline\na *b*"
4687 (org-export-get-next-element
4688 (org-element-map tree
'bold
'identity info t
) info
)))
4689 ;; Non-exportable elements are ignored.
4691 (let ((org-export-with-timestamps nil
))
4692 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
4693 (org-export-get-next-element
4694 (org-element-map tree
'entity
'identity info t
) info
))))
4695 ;; Find next element in secondary strings.
4698 (org-test-with-parsed-data "* a =verb="
4700 (org-export-get-next-element
4701 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4704 (org-test-with-parsed-data "* /italic/ =verb="
4706 (org-export-get-next-element
4707 (org-element-map tree
'italic
'identity info t
) info
)))))
4708 ;; Find next element in document keywords.
4711 (org-test-with-parsed-data "#+TITLE: a =verb="
4713 (org-export-get-next-element
4715 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4716 ;; Find next element in parsed affiliated keywords.
4719 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
4721 (org-export-get-next-element
4722 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4723 ;; With optional argument N, return a list containing all the
4724 ;; following elements.
4727 '(bold code underline
)
4728 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4730 (org-export-get-next-element
4731 (org-element-map tree
'italic
'identity info t
) info t
)))))
4732 ;; When N is a positive integer, return a list containing up to
4733 ;; N following elements.
4737 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4739 (org-export-get-next-element
4740 (org-element-map tree
'italic
'identity info t
) info
2))))))
4742 (ert-deftest test-org-export
/get-previous-element
()
4743 "Test `org-export-get-previous-element' specifications."
4747 (org-test-with-parsed-data "* Headline\na *b*"
4748 (org-export-get-previous-element
4749 (org-element-map tree
'bold
'identity info t
) info
))))
4750 ;; Return nil when no previous element.
4752 (org-test-with-parsed-data "* Headline\n*a* b"
4753 (org-export-get-previous-element
4754 (org-element-map tree
'bold
'identity info t
) info
)))
4755 ;; Non-exportable elements are ignored.
4757 (let ((org-export-with-timestamps nil
))
4758 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
4759 (org-export-get-previous-element
4760 (org-element-map tree
'entity
'identity info t
) info
))))
4761 ;; Find previous element in secondary strings.
4764 (org-test-with-parsed-data "* =verb= a"
4766 (org-export-get-previous-element
4767 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4770 (org-test-with-parsed-data "* =verb= /italic/"
4772 (org-export-get-previous-element
4773 (org-element-map tree
'italic
'identity info t
) info
)))))
4774 ;; Find previous element in document keywords.
4777 (org-test-with-parsed-data "#+TITLE: =verb= a"
4779 (org-export-get-previous-element
4781 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4782 ;; Find previous element in parsed affiliated keywords.
4785 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
4787 (org-export-get-previous-element
4788 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4789 ;; With optional argument N, return a list containing up to
4790 ;; N previous elements.
4792 (equal '(underline italic bold
)
4793 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4795 (org-export-get-previous-element
4796 (org-element-map tree
'code
'identity info t
) info t
)))))
4797 ;; When N is a positive integer, return a list containing up to
4798 ;; N previous elements.
4800 (equal '(italic bold
)
4801 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4803 (org-export-get-previous-element
4804 (org-element-map tree
'code
'identity info t
) info
2))))))
4808 ;;; test-org-export.el end here