1 ;;; test-ox.el --- Tests for ox.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2015 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-comments)
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 ;; More than one property can refer to the same buffer keyword.
237 (equal '(:k2
"value" :k1
"value")
238 (let ((backend (org-export-create-backend
239 :options
'((:k1
"KEYWORD")
241 (org-test-with-temp-text "#+KEYWORD: value"
242 (org-export--get-inbuffer-options backend
)))))
243 ;; Keywords in commented subtrees are ignored.
246 (org-test-with-parsed-data "* COMMENT H1\n#+AUTHOR: Me"
247 (plist-get info
:author
))))
250 (org-test-with-parsed-data "* COMMENT H1\n** H2\n#+EMAIL: Mine"
251 (plist-get info
:email
)))))
253 (ert-deftest test-org-export
/get-subtree-options
()
254 "Test setting options from headline's properties."
257 (equal '("Subtree Title")
258 (org-test-with-temp-text "#+TITLE: Title
261 :EXPORT_TITLE: Subtree Title
264 (plist-get (org-export-get-environment nil t
) :title
))))
268 (org-test-with-temp-text "#+OPTIONS: H:1
274 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
277 (equal '("29-03-2012")
278 (org-test-with-temp-text "#+DATE: today
281 :EXPORT_DATE: 29-03-2012
284 (plist-get (org-export-get-environment nil t
) :date
))))
285 ;; Properties with `split' behaviour are stored as a list of
289 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
292 :EXPORT_EXCLUDE_TAGS: a b
295 (plist-get (org-export-get-environment nil t
) :exclude-tags
))))
296 ;; Handle :PROPERTY+: syntax.
299 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
302 :EXPORT_EXCLUDE_TAGS: a
303 :EXPORT_EXCLUDE_TAGS+: b
306 (plist-get (org-export-get-environment nil t
) :exclude-tags
))))
307 ;; Export properties are case-insensitive.
309 (equal '("29-03-2012")
310 (org-test-with-temp-text "* Headline
312 :EXPORT_Date: 29-03-2012
315 (plist-get (org-export-get-environment nil t
) :date
))))
316 ;; Still grab correct options when section above is empty.
319 (org-test-with-temp-text "* H1\n** H11\n** H12<point>"
320 (plist-get (org-export-get-environment nil t
) :title
))))
321 ;; More than one property can refer to the same node property.
324 (org-test-with-temp-text
325 "* H\n:PROPERTIES:\n:EXPORT_A: 1\n:END:\n<point>"
326 (let* ((backend (org-export-create-backend
329 (options (org-export-get-environment backend t
)))
330 (list (plist-get options
:k1
) (plist-get options
:k2
)))))))
332 (ert-deftest test-org-export
/set-title
()
333 "Test title setting."
334 ;; Without TITLE keyword.
338 (let (org-export-filter-body-functions
339 org-export-filter-final-output-functions
)
340 (org-test-with-temp-text "Test"
342 (org-export-create-backend
344 '((template .
(lambda (text info
)
345 (org-element-interpret-data
346 (plist-get info
:title
)))))))))))
347 ;; With a blank TITLE keyword.
351 (let (org-export-filter-body-functions
352 org-export-filter-final-output-functions
)
353 (org-test-with-temp-text "#+TITLE:\nTest"
355 (org-export-create-backend
357 '((template .
(lambda (text info
)
358 (org-element-interpret-data
359 (plist-get info
:title
)))))))))))
360 ;; With a non-empty TITLE keyword.
364 (org-test-with-temp-text "#+TITLE: Title\nTest"
366 (org-export-create-backend
368 '((template .
(lambda (text info
)
369 (org-element-interpret-data
370 (plist-get info
:title
))))))))))
371 ;; When exporting a subtree, its heading becomes the headline of the
376 (org-test-with-temp-text "* Headline\nBody"
378 (org-export-create-backend
380 '((template .
(lambda (text info
)
381 (org-element-interpret-data
382 (plist-get info
:title
))))))
384 ;; ... unless there is an EXPORT_TITLE property at the root of the
389 (org-test-with-temp-text
390 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
392 (org-export-create-backend
394 '((template .
(lambda (text info
)
395 (org-element-interpret-data
396 (plist-get info
:title
))))))
399 (ert-deftest test-org-export
/handle-options
()
400 "Test if export options have an impact on output."
401 ;; Test exclude tags for headlines and inlinetasks.
404 (let (org-export-filter-body-functions
405 org-export-filter-final-output-functions
)
406 (org-test-with-temp-text "* Head1 :noexp:"
407 (org-export-as (org-test-default-backend)
408 nil nil nil
'(:exclude-tags
("noexp")))))))
410 (equal "#+FILETAGS: noexp\n"
411 (let (org-export-filter-body-functions
412 org-export-filter-final-output-functions
)
413 (org-test-with-temp-text "#+FILETAGS: noexp\n* Head1"
414 (org-export-as (org-test-default-backend)
415 nil nil nil
'(:exclude-tags
("noexp")))))))
416 ;; Test include tags for headlines and inlinetasks.
418 (equal (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
419 (let ((org-tags-column 0))
420 (org-export-as (org-test-default-backend)
421 nil nil nil
'(:select-tags
("exp")))))
422 "* H2\n** Sub :exp:\n*** Sub Sub\n"))
423 ;; If there is an include tag, ignore the section before the first
426 (equal (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
427 (let ((org-tags-column 0))
428 (org-export-as (org-test-default-backend)
429 nil nil nil
'(:select-tags
("exp")))))
430 "* H1 :exp:\nBody\n"))
432 (equal (org-test-with-temp-text "#+FILETAGS: exp\nFirst section\n* H1\nBody"
433 (org-export-as (org-test-default-backend)
434 nil nil nil
'(:select-tags
("exp"))))
437 (equal (org-test-with-temp-text "* H1 :exp:\nBody"
438 (let ((org-tags-column 0))
439 (org-export-as (org-test-default-backend)
440 nil nil nil
'(:select-tags
("exp")))))
442 ;; Test mixing include tags and exclude tags.
445 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
446 (org-test-with-temp-text "
448 ** Sub-Head1 :noexport:
451 ** Sub-Head1 :export:"
452 (org-export-as (org-test-default-backend) nil nil nil
453 '(:select-tags
("export") :exclude-tags
("noexport"))))))
457 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
458 org-export-filter-body-functions
459 org-export-filter-final-output-functions
)
460 (org-test-with-temp-text "* TODO Head1"
461 (org-export-as (org-test-default-backend)
462 nil nil nil
'(:with-tasks nil
))))))
464 (equal "* TODO Head1\n"
465 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
466 (org-test-with-temp-text "* TODO Head1"
467 (org-export-as (org-test-default-backend)
468 nil nil nil
'(:with-tasks t
))))))
472 (let (org-export-filter-body-functions
473 org-export-filter-final-output-functions
)
474 (org-test-with-temp-text "* Head1 :archive:"
475 (let ((org-archive-tag "archive"))
476 (org-export-as (org-test-default-backend)
477 nil nil nil
'(:with-archived-trees nil
)))))))
480 "\\* Head1[ \t]+:archive:"
481 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
482 (let ((org-archive-tag "archive"))
483 (org-export-as (org-test-default-backend) nil nil nil
484 '(:with-archived-trees headline
))))))
487 "\\`\\* Head1[ \t]+:archive:\n\\'"
488 (org-test-with-temp-text "* Head1 :archive:"
489 (let ((org-archive-tag "archive"))
490 (org-export-as (org-test-default-backend)
491 nil nil nil
'(:with-archived-trees t
))))))
492 ;; Broken links. Depending on `org-export-with-broken-links', raise
493 ;; an error, ignore link or mark is as broken in output.
495 (org-test-with-temp-text "[[#broken][link]]"
497 (org-export-create-backend
499 '((section .
(lambda (_e c _i
) c
))
500 (paragraph .
(lambda (_e c _i
) c
))
501 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
502 (org-export-as backend nil nil nil
'(:with-broken-links nil
)))))
504 (org-test-with-temp-text "[[#broken][link]]"
506 (org-export-create-backend
508 '((section .
(lambda (_e c _i
) c
))
509 (paragraph .
(lambda (_e c _i
) c
))
510 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
511 (org-export-as backend nil nil nil
'(:with-broken-links t
)))))
513 (org-test-with-temp-text "[[#broken][link]]"
515 (org-export-create-backend
517 '((section .
(lambda (_e c _i
) c
))
518 (paragraph .
(lambda (_e c _i
) c
))
519 (link .
(lambda (l c i
) (org-export-resolve-id-link l i
)))))))
521 (org-export-as backend nil nil nil
'(:with-broken-links mark
))))))
524 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
525 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
526 (org-export-as (org-test-default-backend)
527 nil nil nil
'(:with-clocks t
)))))
530 (let (org-export-filter-body-functions
531 org-export-filter-final-output-functions
)
532 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
533 (org-export-as (org-test-default-backend)
534 nil nil nil
'(:with-clocks nil
))))))
538 (let (org-export-filter-body-functions
539 org-export-filter-final-output-functions
)
540 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
541 (org-export-as (org-test-default-backend)
542 nil nil nil
'(:with-drawers nil
))))))
544 (equal ":TEST:\ncontents\n:END:\n"
545 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
546 (org-export-as (org-test-default-backend)
547 nil nil nil
'(:with-drawers t
)))))
549 (equal ":FOO:\nkeep\n:END:\n"
550 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
551 (org-export-as (org-test-default-backend)
552 nil nil nil
'(:with-drawers
("FOO"))))))
554 (equal ":FOO:\nkeep\n:END:\n"
555 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
556 (org-export-as (org-test-default-backend)
557 nil nil nil
'(:with-drawers
(not "BAR"))))))
561 (org-test-with-temp-text ": A"
562 (org-export-as (org-test-default-backend) nil nil nil
563 '(:with-fixed-width t
)))))
566 (let (org-export-filter-body-functions
567 org-export-filter-final-output-functions
)
568 (org-test-with-temp-text ": A"
569 (org-export-as (org-test-default-backend) nil nil nil
570 '(:with-fixed-width nil
))))))
574 (let ((org-footnote-section nil
))
575 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
576 (org-trim (org-export-as (org-test-default-backend)
577 nil nil nil
'(:with-footnotes nil
)))))))
579 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
580 (let ((org-footnote-section nil
))
581 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
582 (org-trim (org-export-as (org-test-default-backend)
583 nil nil nil
'(:with-footnotes t
)))))))
585 (when (featurep 'org-inlinetask
)
589 (let ((org-inlinetask-min-level 15)
590 org-export-filter-body-functions
591 org-export-filter-final-output-functions
)
592 (org-test-with-temp-text "*************** Task"
593 (org-export-as (org-test-default-backend)
594 nil nil nil
'(:with-inlinetasks nil
))))))
598 (let ((org-inlinetask-min-level 15)
599 org-export-filter-body-functions
600 org-export-filter-final-output-functions
)
601 (org-test-with-temp-text
602 "*************** Task\nContents\n*************** END"
603 (org-export-as (org-test-default-backend)
604 nil nil nil
'(:with-inlinetasks nil
)))))))
608 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
609 (let ((org-closed-string "CLOSED:"))
610 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
611 (org-export-as (org-test-default-backend)
612 nil nil nil
'(:with-planning t
))))))
615 (let ((org-closed-string "CLOSED:"))
616 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
617 (org-export-as (org-test-default-backend)
618 nil nil nil
'(:with-planning nil
))))))
622 (org-test-with-temp-text
623 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
624 (org-export-as (org-test-default-backend)
625 nil nil nil
'(:with-properties nil
)))))
627 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
628 (org-test-with-temp-text
629 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
630 (org-export-as (org-test-default-backend)
631 nil nil nil
'(:with-properties t
)))))
633 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
634 (org-test-with-temp-text
635 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
636 (org-export-as (org-test-default-backend)
637 nil nil nil
'(:with-properties
("B"))))))
638 ;; Statistics cookies.
641 (let (org-export-filter-body-functions
642 org-export-filter-final-output-functions
)
644 (org-test-with-temp-text "* Stats [0/0]"
645 (org-export-as (org-test-default-backend)
646 nil nil nil
'(:with-statistics-cookies nil
)))))))
650 (org-test-with-temp-text "| A |"
651 (org-export-as (org-test-default-backend) nil nil nil
652 '(:with-tables t
)))))
655 (let (org-export-filter-body-functions
656 org-export-filter-final-output-functions
)
657 (org-test-with-temp-text "| A |"
658 (org-export-as (org-test-default-backend) nil nil nil
659 '(:with-tables nil
)))))))
661 (ert-deftest test-org-export
/with-timestamps
()
662 "Test `org-export-with-timestamps' specifications."
666 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
667 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
668 (org-export-as (org-test-default-backend)
669 nil nil nil
'(:with-timestamps t
)))))
674 (let (org-export-filter-body-functions
675 org-export-filter-final-output-functions
)
677 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
678 (org-export-as (org-test-default-backend)
679 nil nil nil
'(:with-timestamps nil
)))))))
683 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
684 (org-test-with-temp-text
685 "<2012-03-29 Thu>[2012-03-29 Thu]
687 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
688 (org-export-as (org-test-default-backend)
689 nil nil nil
'(:with-timestamps active
)))))
693 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
694 (org-test-with-temp-text
695 "<2012-03-29 Thu>[2012-03-29 Thu]
697 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
698 (org-export-as (org-test-default-backend)
699 nil nil nil
'(:with-timestamps inactive
))))))
701 (ert-deftest test-org-export
/comment-tree
()
702 "Test if export process ignores commented trees."
705 (let (org-export-filter-body-functions
706 org-export-filter-final-output-functions
)
707 (org-test-with-temp-text "* COMMENT Head1"
708 (org-export-as (org-test-default-backend)))))))
710 (ert-deftest test-org-export
/uninterpreted
()
711 "Test handling of uninterpreted elements."
715 (org-test-with-temp-text "\\alpha"
717 (org-export-create-backend
718 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
719 (paragraph .
(lambda (p c i
) c
))
720 (section .
(lambda (s c i
) c
))))
721 nil nil nil
'(:with-entities t
)))))
724 (org-test-with-temp-text "\\alpha"
726 (org-export-create-backend
727 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
728 (paragraph .
(lambda (p c i
) c
))
729 (section .
(lambda (s c i
) c
))))
730 nil nil nil
'(:with-entities nil
)))))
734 (org-test-with-temp-text "*bold*"
736 (org-export-create-backend
737 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
738 (paragraph .
(lambda (p c i
) c
))
739 (section .
(lambda (s c i
) c
))))
740 nil nil nil
'(:with-emphasize t
)))))
743 (org-test-with-temp-text "*bold*"
745 (org-export-create-backend
746 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
747 (paragraph .
(lambda (p c i
) c
))
748 (section .
(lambda (s c i
) c
))))
749 nil nil nil
'(:with-emphasize nil
)))))
750 ;; LaTeX environment.
753 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
755 (org-export-create-backend
756 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
757 (section .
(lambda (s c i
) c
))))
758 nil nil nil
'(:with-latex t
)))))
760 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
761 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
763 (org-export-create-backend
764 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
765 (section .
(lambda (s c i
) c
))))
766 nil nil nil
'(:with-latex verbatim
)))))
770 (org-test-with-temp-text "$1$"
772 (org-export-create-backend
773 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
774 (paragraph .
(lambda (p c i
) c
))
775 (section .
(lambda (s c i
) c
))))
776 nil nil nil
'(:with-latex t
)))))
779 (org-test-with-temp-text "$1$"
781 (org-export-create-backend
782 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
783 (paragraph .
(lambda (p c i
) c
))
784 (section .
(lambda (s c i
) c
))))
785 nil nil nil
'(:with-latex verbatim
)))))
789 (org-test-with-temp-text "a_b"
791 (org-export-create-backend
792 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
793 (paragraph .
(lambda (p c i
) c
))
794 (section .
(lambda (s c i
) c
))))
795 nil nil nil
'(:with-sub-superscript t
)))))
798 (org-test-with-temp-text "a_b"
800 (org-export-create-backend
801 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
802 (paragraph .
(lambda (p c i
) c
))
803 (section .
(lambda (s c i
) c
))))
804 nil nil nil
'(:with-sub-superscript nil
)))))
807 (org-test-with-temp-text "a_b"
809 (org-export-create-backend
810 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
811 (paragraph .
(lambda (p c i
) c
))
812 (section .
(lambda (s c i
) c
))))
813 nil nil nil
'(:with-sub-superscript
{})))))
816 (org-test-with-temp-text "a_{b}"
818 (org-export-create-backend
819 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
820 (paragraph .
(lambda (p c i
) c
))
821 (section .
(lambda (s c i
) c
))))
822 nil nil nil
'(:with-sub-superscript
{})))))
825 (org-test-with-temp-text "a_\\alpha"
827 (org-export-create-backend
828 :transcoders
'((entity .
(lambda (e c i
) "entity"))
829 (subscript .
(lambda (s c i
) "dummy"))
830 (paragraph .
(lambda (p c i
) c
))
831 (section .
(lambda (s c i
) c
))))
832 nil nil nil
'(:with-sub-superscript nil
)))))
833 ;; Also handle uninterpreted objects in title.
836 (org-test-with-temp-text "#+TITLE: a_b"
838 (org-export-create-backend
840 '((subscript .
(lambda (s c i
) "dummy"))
841 (template .
(lambda (c i
) (org-export-data
842 (plist-get i
:title
) i
)))
843 (section .
(lambda (s c i
) c
))))
844 nil nil nil
'(:with-sub-superscript nil
)))))
845 ;; Handle uninterpreted objects in captions.
848 (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
850 (org-export-create-backend
852 '((subscript .
(lambda (s c i
) "dummy"))
853 (paragraph .
(lambda (p c i
)
854 (org-export-data (org-export-get-caption p
) i
)))
855 (section .
(lambda (s c i
) c
))))
856 nil nil nil
'(:with-sub-superscript t
)))))
859 (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
861 (org-export-create-backend
863 '((subscript .
(lambda (s c i
) "dummy"))
864 (paragraph .
(lambda (p c i
)
865 (org-export-data (org-export-get-caption p
) i
)))
866 (section .
(lambda (s c i
) c
))))
867 nil nil nil
'(:with-sub-superscript nil
)))))
868 ;; Special case: multiples uninterpreted objects in a row.
871 (org-test-with-temp-text "a_b_c_d"
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
{}))))))
879 (ert-deftest test-org-export
/export-scope
()
880 "Test all export scopes."
881 (org-test-with-temp-text "
888 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
889 "text\n*** Head3\n"))
891 (goto-char (point-min))
894 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
897 (goto-char (point-min))
899 (transient-mark-mode 1)
900 (push-mark (point) t t
)
901 (goto-char (point-at-eol))
902 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
903 ;; Subtree with a code block calling another block outside.
904 (let ((org-export-babel-evaluate t
))
907 (org-test-with-temp-text "
909 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
914 #+BEGIN_SRC emacs-lisp
918 (org-export-as (org-test-default-backend) 'subtree
)))))
920 (let ((backend (org-test-default-backend)))
921 (setf (org-export-backend-transcoders backend
)
922 (cons '(template .
(lambda (body i
)
923 (format "BEGIN\n%sEND" body
)))
924 (org-export-backend-transcoders backend
)))
925 (org-test-with-temp-text "Text"
926 (should (equal (org-export-as backend nil nil
'body-only
)
928 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
930 (ert-deftest test-org-export
/output-file-name
()
931 "Test `org-export-output-file-name' specifications."
932 ;; Export from a file: name is built from original file name.
934 (org-test-with-temp-text-in-file "Test"
935 (equal (concat (file-name-as-directory ".")
936 (file-name-nondirectory
937 (file-name-sans-extension (buffer-file-name))))
938 (file-name-sans-extension (org-export-output-file-name ".ext")))))
939 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
941 (org-test-with-temp-text-in-file
942 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
943 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
944 ;; From a buffer not associated to a file, too.
946 (org-test-with-temp-text
947 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
948 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
949 ;; When provided name is absolute, preserve it.
951 (org-test-with-temp-text
952 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
953 (expand-file-name "test"))
954 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
955 ;; When PUB-DIR argument is provided, use it.
957 (org-test-with-temp-text-in-file "Test"
958 (equal (file-name-directory
959 (org-export-output-file-name ".ext" nil
"dir/"))
961 ;; When returned name would overwrite original file, add EXTENSION
964 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
965 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
967 (ert-deftest test-org-export
/expand-include
()
968 "Test file inclusion in an Org buffer."
969 ;; Error when file isn't specified.
971 (org-test-with-temp-text "#+INCLUDE: dummy.org"
972 (org-export-expand-include-keyword)))
973 ;; Full insertion with recursive inclusion.
978 (expand-file-name "examples/include.org" org-test-dir
))
979 (replace-regexp-in-string
980 (regexp-quote "#+INCLUDE: \"include2.org\"")
981 "Success!" (buffer-string)))
982 (org-test-with-temp-text
983 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
984 (org-export-expand-include-keyword)
986 ;; Localized insertion.
987 (org-test-with-temp-text
988 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
990 (org-export-expand-include-keyword)
991 (should (equal (buffer-string)
992 "Small Org file with an include keyword.\n")))
993 ;; Insertion with constraints on headlines level.
996 "* Top heading\n** Heading\nbody\n"
997 (org-test-with-temp-text
999 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
1001 (org-export-expand-include-keyword)
1005 "* Top heading\n* Heading\nbody\n"
1006 (org-test-with-temp-text
1008 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
1010 (org-export-expand-include-keyword)
1012 ;; Inclusion within an example block.
1015 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
1016 (org-test-with-temp-text
1017 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
1019 (org-export-expand-include-keyword)
1021 ;; Inclusion within a src-block.
1024 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
1025 (org-test-with-temp-text
1027 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
1029 (org-export-expand-include-keyword)
1031 ;; Inclusion within an html export-block.
1034 "#+BEGIN_EXPORT html\n<p>HTML!</p>\n#+END_EXPORT\n"
1035 (org-test-with-temp-text
1037 "#+INCLUDE: \"%s/examples/include.html\" EXPORT html"
1039 (org-export-expand-include-keyword)
1041 ;; Inclusion within an center paragraph
1044 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
1045 (org-test-with-temp-text
1047 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
1049 (org-export-expand-include-keyword)
1051 ;; Footnotes labels are local to each included file.
1057 Footnotes[fn:1], [fn:test], [fn:test] and [fn:inline:inline footnote].
1059 \[fn:test] Footnote \"test\""))
1060 (org-test-with-temp-text-in-file contents
1061 (let ((file1 (buffer-file-name)))
1062 (org-test-with-temp-text-in-file contents
1063 (let ((file2 (buffer-file-name)))
1064 (org-test-with-temp-text
1065 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
1067 (org-export-expand-include-keyword)
1068 (org-element-map (org-element-parse-buffer)
1070 (lambda (r) (org-element-property :label r
)))))))))))))
1071 ;; Footnotes labels are not local to each include keyword.
1077 Footnotes[fn:1], [fn:test] and [fn:inline:inline footnote].
1079 \[fn:test] Footnote \"test\""))
1080 (org-test-with-temp-text-in-file contents
1081 (let ((file (buffer-file-name)))
1082 (org-test-with-temp-text
1083 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
1084 (org-export-expand-include-keyword)
1085 (org-element-map (org-element-parse-buffer)
1087 (lambda (ref) (org-element-property :label ref
)))))))))))
1088 ;; Footnotes are supported by :lines-like elements and unnecessary
1089 ;; footnotes are dropped.
1098 Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
1103 \[fn:test] Footnote \"test\"
1105 (org-test-with-temp-text-in-file contents
1106 (let ((file (buffer-file-name)))
1107 (org-test-with-temp-text
1108 (format "#+INCLUDE: \"%s::*bar\"\n" file
)
1109 (org-export-expand-include-keyword)
1110 (org-element-map (org-element-parse-buffer)
1111 'footnote-definition
1112 (lambda (ref) (org-element-property :label ref
)))))))))))
1113 ;; If only-contents is non-nil only include contents of element.
1117 (org-test-with-temp-text
1119 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" "
1122 (org-export-expand-include-keyword)
1124 ;; Headings can be included via CUSTOM_ID.
1126 (org-test-with-temp-text
1127 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1128 (org-export-expand-include-keyword)
1129 (goto-char (point-min))
1130 (looking-at "* Another heading")))
1131 ;; Named objects can be included.
1135 (org-test-with-temp-text
1136 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t"
1138 (org-export-expand-include-keyword)
1140 ;; Including non-existing elements should result in an error.
1142 (org-test-with-temp-text
1143 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\""
1145 (org-export-expand-include-keyword)))
1146 ;; Lines work relatively to an included element.
1150 (org-test-with-temp-text
1151 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t \
1154 (org-export-expand-include-keyword)
1156 ;; Properties should be dropped from headlines.
1159 (org-test-with-temp-text
1160 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t"
1162 (org-export-expand-include-keyword)
1164 (org-test-with-temp-text
1165 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1166 (org-export-expand-include-keyword)
1168 ;; Properties should be dropped, drawers should not be.
1171 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1172 (org-test-with-temp-text
1173 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t"
1175 (org-export-expand-include-keyword)
1177 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1179 (cl-every (lambda (level) (zerop (1- level
)))
1180 (org-test-with-temp-text
1182 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n"
1184 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\""
1186 (org-export-expand-include-keyword)
1187 (org-element-map (org-element-parse-buffer) 'headline
1188 (lambda (head) (org-element-property :level head
))))))
1189 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1192 (org-test-with-temp-text
1193 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp"
1195 (org-export-expand-include-keyword)
1197 (org-test-with-temp-text
1199 "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1"
1201 (org-export-expand-include-keyword)
1203 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1205 (org-test-with-temp-text-in-file
1206 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\""
1208 (narrow-to-region (point) (point-max))
1209 (org-export-expand-include-keyword)
1210 (eq 1 (org-current-level))))
1211 ;; If :minlevel is present do not alter it.
1213 (org-test-with-temp-text
1215 "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3"
1217 (narrow-to-region (point) (point-max))
1218 (org-export-expand-include-keyword)
1219 (eq 3 (org-current-level)))))
1221 (ert-deftest test-org-export
/expand-macro
()
1222 "Test macro expansion in an Org buffer."
1224 ;; Standard macro expansion.
1226 (equal "#+MACRO: macro1 value\nvalue\n"
1227 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1228 (org-export-as (org-test-default-backend)))))
1229 ;; Allow macro in parsed keywords and associated properties.
1230 ;; Standard macro expansion.
1234 (let ((backend (org-export-create-backend
1236 :options
'((:k
"K" nil nil parse
)))))
1237 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1238 (org-export-as backend
)))))
1242 (let ((backend (org-export-create-backend
1244 :options
'((:k
"K" nil nil parse
)))))
1245 (org-test-with-temp-text
1246 "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1247 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1248 ;; Expand specific macros.
1250 (equal "me 2012-03-29 me@here Title\n"
1251 (org-test-with-temp-text
1257 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1258 (let ((output (org-export-as (org-test-default-backend))))
1259 (substring output
(string-match ".*\n\\'" output
))))))
1260 ;; Expand specific macros when property contained a regular macro
1264 (org-test-with-temp-text "
1265 #+MACRO: macro1 value
1266 #+TITLE: {{{macro1}}}
1268 (let ((output (org-export-as (org-test-default-backend))))
1269 (substring output
(string-match ".*\n\\'" output
))))))
1270 ;; Expand macros with templates in included files.
1273 (org-test-with-temp-text
1274 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1275 {{{included-macro}}}" org-test-dir
)
1276 (let ((output (org-export-as (org-test-default-backend))))
1277 (substring output
(string-match ".*\n\\'" output
))))))
1278 ;; Date macro takes a optional formatting argument
1281 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1282 (org-export-as (org-test-default-backend)))))
1283 ;; Only single timestamps are formatted
1285 (equal "<2015-02x-09>\n"
1286 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1287 (org-export-as (org-test-default-backend)))))
1288 ;; Throw an error when a macro definition is missing.
1290 (org-test-with-temp-text "{{{missing}}}"
1291 (org-export-as (org-test-default-backend))))
1292 ;; Macros defined in commented subtrees are ignored.
1294 (org-test-with-temp-text
1295 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1296 (org-export-as (org-test-default-backend))))
1298 (org-test-with-temp-text
1299 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1300 (org-export-as (org-test-default-backend)))))
1302 (ert-deftest test-org-export
/before-processing-hook
()
1303 "Test `org-export-before-processing-hook'."
1306 "#+MACRO: mac val\nTest\n"
1307 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1308 (let ((org-export-before-processing-hook
1310 (while (re-search-forward "{{{" nil t
)
1311 (let ((object (org-element-context)))
1312 (when (eq (org-element-type object
) 'macro
)
1314 (org-element-property :begin object
)
1315 (org-element-property :end object
)))))))))
1316 (org-export-as (org-test-default-backend)))))))
1318 (ert-deftest test-org-export
/before-parsing-hook
()
1319 "Test `org-export-before-parsing-hook'."
1321 (equal "Body 1\nBody 2\n"
1322 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1323 (let ((org-export-before-parsing-hook
1325 (goto-char (point-min))
1326 (while (re-search-forward org-outline-regexp-bol nil t
)
1328 (point-at-bol) (progn (forward-line) (point))))))))
1329 (org-export-as (org-test-default-backend)))))))
1333 ;;; Affiliated Keywords
1335 (ert-deftest test-org-export
/read-attribute
()
1336 "Test `org-export-read-attribute' specifications."
1340 (org-export-read-attribute
1342 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1343 (org-element-at-point)))
1345 ;; Return nil on empty attribute.
1347 (org-export-read-attribute
1349 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1350 ;; Return nil on "nil" string.
1352 (equal '(:a nil
:b nil
)
1353 (org-export-read-attribute
1355 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1356 (org-element-at-point)))))
1357 ;; Return nil on empty string.
1359 (equal '(:a nil
:b nil
)
1360 (org-export-read-attribute
1362 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1363 (org-element-at-point)))))
1364 ;; Return empty string when value is "".
1367 (org-export-read-attribute
1369 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1370 (org-element-at-point)))))
1371 ;; Return \"\" when value is """".
1374 (org-export-read-attribute
1376 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1377 (org-element-at-point)))))
1378 ;; Ignore text before first property.
1381 (org-export-read-attribute
1383 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1384 (org-element-at-point))))))
1386 (ert-deftest test-org-export
/get-caption
()
1387 "Test `org-export-get-caption' specifications."
1388 ;; Without optional argument, return long caption
1392 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1393 (org-export-get-caption (org-element-at-point)))))
1394 ;; With optional argument, return short caption.
1398 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1399 (org-export-get-caption (org-element-at-point) t
))))
1400 ;; Multiple lines are separated by white spaces.
1404 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1405 (org-export-get-caption (org-element-at-point))))))
1411 (ert-deftest test-org-export
/define-backend
()
1412 "Test back-end definition and accessors."
1415 (equal '((headline . my-headline-test
))
1416 (let (org-export-registered-backends)
1417 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1418 (org-export-get-all-transcoders 'test
))))
1421 (equal '((:filter-headline . my-filter
))
1422 (let (org-export-registered-backends)
1423 (org-export-define-backend 'test
1424 '((headline . my-headline-test
))
1425 :filters-alist
'((:filter-headline . my-filter
)))
1426 (org-export-backend-filters (org-export-get-backend 'test
)))))
1429 (equal '((:prop value
))
1430 (let (org-export-registered-backends)
1431 (org-export-define-backend 'test
1432 '((headline . my-headline-test
))
1433 :options-alist
'((:prop value
)))
1434 (org-export-backend-options (org-export-get-backend 'test
)))))
1437 (equal '(?k
"Test Export" test
)
1438 (let (org-export-registered-backends)
1439 (org-export-define-backend 'test
1440 '((headline . my-headline-test
))
1441 :menu-entry
'(?k
"Test Export" test
))
1442 (org-export-backend-menu (org-export-get-backend 'test
))))))
1444 (ert-deftest test-org-export
/define-derived-backend
()
1445 "Test `org-export-define-derived-backend' specifications."
1446 ;; Error when parent back-end is not defined.
1448 (let (org-export-registered-backends)
1449 (org-export-define-derived-backend 'test
'parent
)))
1450 ;; Append translation table to parent's.
1452 (equal '((:headline . test
) (:headline . parent
))
1453 (let (org-export-registered-backends)
1454 (org-export-define-backend 'parent
'((:headline . parent
)))
1455 (org-export-define-derived-backend 'test
'parent
1456 :translate-alist
'((:headline . test
)))
1457 (org-export-get-all-transcoders 'test
))))
1458 ;; Options defined in the new back have priority over those defined
1462 (let (org-export-registered-backends)
1463 (org-export-define-backend 'parent
1464 '((:headline . parent
))
1465 :options-alist
'((:a nil nil
'parent
)))
1466 (org-export-define-derived-backend 'test
'parent
1467 :options-alist
'((:a nil nil
'test
)))
1468 (plist-get (org-export--get-global-options
1469 (org-export-get-backend 'test
))
1472 (ert-deftest test-org-export
/derived-backend-p
()
1473 "Test `org-export-derived-backend-p' specifications."
1474 ;; Non-nil with direct match.
1476 (let (org-export-registered-backends)
1477 (org-export-define-backend 'test
'((headline . test
)))
1478 (org-export-derived-backend-p 'test
'test
)))
1480 (let (org-export-registered-backends)
1481 (org-export-define-backend 'test
'((headline . test
)))
1482 (org-export-define-derived-backend 'test2
'test
)
1483 (org-export-derived-backend-p 'test2
'test2
)))
1484 ;; Non-nil with a direct parent.
1486 (let (org-export-registered-backends)
1487 (org-export-define-backend 'test
'((headline . test
)))
1488 (org-export-define-derived-backend 'test2
'test
)
1489 (org-export-derived-backend-p 'test2
'test
)))
1490 ;; Non-nil with an indirect parent.
1492 (let (org-export-registered-backends)
1493 (org-export-define-backend 'test
'((headline . test
)))
1494 (org-export-define-derived-backend 'test2
'test
)
1495 (org-export-define-derived-backend 'test3
'test2
)
1496 (org-export-derived-backend-p 'test3
'test
)))
1499 (let (org-export-registered-backends)
1500 (org-export-define-backend 'test
'((headline . test
)))
1501 (org-export-define-backend 'test2
'((headline . test2
)))
1502 (org-export-derived-backend-p 'test2
'test
)))
1504 (let (org-export-registered-backends)
1505 (org-export-define-backend 'test
'((headline . test
)))
1506 (org-export-define-backend 'test2
'((headline . test2
)))
1507 (org-export-define-derived-backend 'test3
'test2
)
1508 (org-export-derived-backend-p 'test3
'test
))))
1510 (ert-deftest test-org-export
/get-all-transcoders
()
1511 "Test `org-export-get-all-transcoders' specifications."
1512 ;; Return nil when back-end cannot be found.
1513 (should-not (org-export-get-all-transcoders nil
))
1514 ;; Same as `org-export-transcoders' if no parent.
1516 (equal '((headline . ignore
))
1517 (org-export-get-all-transcoders
1518 (org-export-create-backend
1519 :transcoders
'((headline . ignore
))))))
1520 ;; But inherit from all ancestors whenever possible.
1522 (equal '((section . ignore
) (headline . ignore
))
1523 (let (org-export-registered-backends)
1524 (org-export-define-backend 'b1
'((headline . ignore
)))
1525 (org-export-get-all-transcoders
1526 (org-export-create-backend
1527 :parent
'b1
:transcoders
'((section . ignore
)))))))
1529 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1530 (let (org-export-registered-backends)
1531 (org-export-define-backend 'b1
'((headline . ignore
)))
1532 (org-export-define-derived-backend 'b2
'b1
1533 :translate-alist
'((section . ignore
)))
1534 (org-export-get-all-transcoders
1535 (org-export-create-backend
1536 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1537 ;; Back-end transcoders overrule inherited ones.
1540 (let (org-export-registered-backends)
1541 (org-export-define-backend 'b1
'((headline . a
)))
1542 (cdr (assq 'headline
1543 (org-export-get-all-transcoders
1544 (org-export-create-backend
1545 :parent
'b1
:transcoders
'((headline . b
))))))))))
1547 (ert-deftest test-org-export
/get-all-options
()
1548 "Test `org-export-get-all-options' specifications."
1549 ;; Return nil when back-end cannot be found.
1550 (should-not (org-export-get-all-options nil
))
1551 ;; Same as `org-export-options' if no parent.
1553 (equal '((headline . ignore
))
1554 (org-export-get-all-options
1555 (org-export-create-backend
1556 :options
'((headline . ignore
))))))
1557 ;; But inherit from all ancestors whenever possible.
1559 (equal '((:key2 value2
) (:key1 value1
))
1560 (let (org-export-registered-backends)
1561 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1562 (org-export-get-all-options
1563 (org-export-create-backend
1564 :parent
'b1
:options
'((:key2 value2
)))))))
1566 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1567 (let (org-export-registered-backends)
1568 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1569 (org-export-define-derived-backend 'b2
'b1
1570 :options-alist
'((:key2 value2
)))
1571 (org-export-get-all-options
1572 (org-export-create-backend
1573 :parent
'b2
:options
'((:key3 value3
)))))))
1574 ;; Back-end options overrule inherited ones.
1577 (let (org-export-registered-backends)
1578 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1580 (org-export-get-all-options
1581 (org-export-create-backend
1582 :parent
'b1
:options
'((:key1 . b
))))))))))
1584 (ert-deftest test-org-export
/get-all-filters
()
1585 "Test `org-export-get-all-filters' specifications."
1586 ;; Return nil when back-end cannot be found.
1587 (should-not (org-export-get-all-filters nil
))
1588 ;; Same as `org-export-filters' if no parent.
1590 (equal '((:filter-headline . ignore
))
1591 (org-export-get-all-filters
1592 (org-export-create-backend
1593 :filters
'((:filter-headline . ignore
))))))
1594 ;; But inherit from all ancestors whenever possible.
1596 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1597 (let (org-export-registered-backends)
1598 (org-export-define-backend 'b1
1599 nil
:filters-alist
'((:filter-headline . ignore
)))
1600 (org-export-get-all-filters
1601 (org-export-create-backend
1602 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1604 (equal '((:filter-paragraph . ignore
)
1605 (:filter-section . ignore
)
1606 (:filter-headline . ignore
))
1607 (let (org-export-registered-backends)
1608 (org-export-define-backend 'b1
1609 nil
:filters-alist
'((:filter-headline . ignore
)))
1610 (org-export-define-derived-backend 'b2
'b1
1611 :filters-alist
'((:filter-section . ignore
)))
1612 (org-export-get-all-filters
1613 (org-export-create-backend
1614 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1615 ;; Back-end filters overrule inherited ones.
1618 (let (org-export-registered-backends)
1619 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1620 (cdr (assq :filter-headline
1621 (org-export-get-all-filters
1622 (org-export-create-backend
1623 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1625 (ert-deftest test-org-export
/with-backend
()
1626 "Test `org-export-with-backend' definition."
1627 ;; Error when calling an undefined back-end
1628 (should-error (org-export-with-backend nil
"Test"))
1629 ;; Error when called back-end doesn't have an appropriate
1632 (org-export-with-backend
1633 (org-export-create-backend :transcoders
'((headline . ignore
)))
1635 ;; Otherwise, export using correct transcoder
1638 (let (org-export-registered-backends)
1639 (org-export-define-backend 'test
1640 '((plain-text .
(lambda (text contents info
) "Failure"))))
1641 (org-export-define-backend 'test2
1642 '((plain-text .
(lambda (text contents info
) "Success"))))
1643 (org-export-with-backend 'test2
"Test"))))
1644 ;; Provide correct back-end if transcoder needs to use recursive
1648 (let ((test-back-end
1649 (org-export-create-backend
1651 (list (cons 'headline
1652 (lambda (headline contents info
)
1654 (org-element-property :title headline
)
1656 (cons 'plain-text
(lambda (text info
) "Success"))))))
1657 (org-export-string-as
1659 (org-export-create-backend
1661 (list (cons 'headline
1662 (lambda (headline contents info
)
1663 (org-export-with-backend
1664 test-back-end headline contents info
))))))))))
1666 (ert-deftest test-org-export
/data-with-backend
()
1667 "Test `org-export-data-with-backend' specifications."
1668 ;; Error when calling an undefined back-end.
1669 (should-error (org-export-data-with-backend nil
"nil" nil
))
1670 ;; Otherwise, export data recursively, using correct back-end.
1674 (org-export-data-with-backend
1676 (org-export-create-backend
1678 '((plain-text .
(lambda (text info
) "Success"))
1679 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1680 '(:with-emphasize t
)))))
1686 (ert-deftest test-org-export
/comments
()
1687 "Test comments handling during export.
1688 In particular, structure of the document mustn't be altered after
1691 (equal (org-test-with-temp-text "
1697 (org-export-as (org-test-default-backend)))
1698 "Para1\n\nPara2\n"))
1700 (equal (org-test-with-temp-text "
1704 (org-export-as (org-test-default-backend)))
1705 "Para1\n\nPara2\n"))
1707 (equal (org-test-with-temp-text "
1712 # Outside definition
1714 (org-export-as (org-test-default-backend)))
1715 "[fn:1] Para1\n\n\nPara2\n"))
1717 (equal (org-test-with-temp-text "
1725 (org-export-as (org-test-default-backend)))
1726 "[fn:1] Para1\n\nPara2\n"))
1728 (equal (org-test-with-temp-text "
1733 (org-export-as (org-test-default-backend)))
1734 "[fn:1] Para1\n\nPara2\n"))
1736 (equal (org-test-with-temp-text "
1741 (org-export-as (org-test-default-backend)))
1742 "[fn:1] Para1\n\nPara2\n")))
1748 (ert-deftest test-org-export
/export-block
()
1749 "Test export blocks transcoding."
1752 (org-test-with-temp-text
1753 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1755 (org-export-create-backend
1756 :transcoders
'((export-block .
(lambda (b _c _i
)
1757 (org-element-property :value b
)))
1758 (section .
(lambda (_s c _i
) c
))))))))
1761 (org-test-with-temp-text
1762 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1764 (org-export-create-backend
1769 (and (equal (org-element-property :type b
) "BACKEND")
1770 (org-element-property :value b
))))
1771 (cons 'section
(lambda (_s c _i
) c
)))))))))
1776 (ert-deftest test-org-export
/export-snippet
()
1777 "Test export snippets transcoding."
1779 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1780 (let ((backend (org-test-default-backend)))
1781 (setf (org-export-backend-name backend
) 'test
)
1782 (setf (org-export-backend-transcoders backend
)
1783 (cons (cons 'export-snippet
1784 (lambda (snippet contents info
)
1785 (when (eq (org-export-snippet-backend snippet
) 'test
)
1786 (org-element-property :value snippet
))))
1787 (org-export-backend-transcoders backend
)))
1788 (let ((org-export-snippet-translation-alist nil
))
1789 (should (equal (org-export-as backend
) "A\n")))
1790 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1791 (should (equal (org-export-as backend
) "AB\n")))))
1792 ;; Ignored export snippets do not remove any blank.
1794 (equal "begin end\n"
1795 (org-test-with-parsed-data "begin @@test:A@@ end"
1796 (org-export-data-with-backend
1798 (org-export-create-backend
1800 '((paragraph .
(lambda (paragraph contents info
) contents
))
1801 (section .
(lambda (section contents info
) contents
))))
1808 (ert-deftest test-org-export
/footnote-first-reference-p
()
1809 "Test `org-export-footnote-first-reference-p' specifications."
1813 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1816 (org-export-create-backend
1818 `(,(cons 'footnote-reference
1820 (push (org-export-footnote-first-reference-p f i
)
1823 (section .
(lambda (s c i
) c
))
1824 (paragraph .
(lambda (p c i
) c
))))
1825 nil nil nil
'(:with-footnotes t
))
1826 (nreverse result
)))))
1827 ;; Limit check to DATA, when non-nil.
1831 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1833 (org-element-map tree
'footnote-reference
1836 (org-export-footnote-first-reference-p
1837 ref info
(org-element-map tree
'headline
#'identity info t
))
1840 (nreverse result
)))))
1844 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1846 (org-element-map tree
'footnote-reference
1848 (push (org-export-footnote-first-reference-p ref info
) result
))
1850 (nreverse result
)))))
1851 ;; If optional argument BODY-FIRST is non-nil, first find footnote
1852 ;; in the main body of the document. Otherwise, enter footnote
1853 ;; definitions when they are encountered.
1857 (org-test-with-temp-text
1858 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1861 (org-export-create-backend
1863 `(,(cons 'footnote-reference
1865 (when (org-element-lineage f
'(drawer))
1866 (push (org-export-footnote-first-reference-p f i nil
)
1869 (drawer .
(lambda (d c i
) c
))
1870 (footnote-definition .
(lambda (d c i
) c
))
1871 (section .
(lambda (s c i
) c
))
1872 (paragraph .
(lambda (p c i
) c
))))
1873 nil nil nil
'(:with-footnotes t
))
1874 (nreverse result
)))))
1878 (org-test-with-temp-text
1879 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1882 (org-export-create-backend
1884 `(,(cons 'footnote-reference
1886 (when (org-element-lineage f
'(drawer))
1887 (push (org-export-footnote-first-reference-p f i nil t
)
1890 (drawer .
(lambda (d c i
) c
))
1891 (footnote-definition .
(lambda (d c i
) c
))
1892 (section .
(lambda (s c i
) c
))
1893 (paragraph .
(lambda (p c i
) c
))))
1894 nil nil nil
'(:with-footnotes t
))
1895 (nreverse result
))))))
1897 (ert-deftest test-org-export
/get-footnote-number
()
1898 "Test `org-export-get-footnote-number' specifications."
1901 (org-test-with-parsed-data
1902 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
1903 (org-element-map tree
'footnote-reference
1904 (lambda (ref) (org-export-get-footnote-number ref info
))
1906 ;; Anonymous footnotes all get a new number.
1909 (org-test-with-parsed-data
1910 "Text[fn::anon1][fn::anon2]"
1911 (org-element-map tree
'footnote-reference
1912 (lambda (ref) (org-export-get-footnote-number ref info
))
1914 ;; Test nested footnotes order.
1917 '((1 .
"1") (2 .
"2") (3 .
"3") (3 .
"3") (4))
1918 (org-test-with-parsed-data
1919 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1920 (org-element-map tree
'footnote-reference
1922 (cons (org-export-get-footnote-number ref info
)
1923 (org-element-property :label ref
)))
1925 ;; Limit number to provided DATA, when non-nil.
1929 (org-test-with-parsed-data
1930 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1931 (org-element-map tree
'footnote-reference
1933 (org-export-get-footnote-number
1934 ref info
(org-element-map tree
'headline
#'identity info t
)))
1939 (org-test-with-parsed-data
1940 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
1941 (org-element-map tree
'footnote-reference
1942 (lambda (ref) (org-export-get-footnote-number ref info
))
1944 ;; With a non-nil BODY-FIRST optional argument, first check body,
1945 ;; then footnote definitions.
1948 '(("1" .
1) ("2" .
2) ("3" .
3) ("3" .
3))
1949 (org-test-with-parsed-data
1950 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1951 (org-element-map tree
'footnote-reference
1953 (cons (org-element-property :label ref
)
1954 (org-export-get-footnote-number ref info nil t
)))
1958 '(("1" .
1) ("2" .
3) ("3" .
2) ("3" .
2))
1959 (org-test-with-parsed-data
1960 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1961 (org-element-map tree
'footnote-reference
1963 (cons (org-element-property :label ref
)
1964 (org-export-get-footnote-number ref info nil
)))
1967 (ert-deftest test-org-export
/collect-footnote-definitions
()
1968 "Test `org-export-collect-footnote-definitions' specifications."
1971 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1973 \[fn:2] B [fn:3] [fn::D].
1976 (length (org-export-collect-footnote-definitions info
)))))
1977 ;; Limit number to provided DATA, when non-nil.
1981 (org-test-with-parsed-data
1982 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1984 (org-export-collect-footnote-definitions
1985 info
(org-element-map tree
'headline
#'identity info t
))))))
1989 (org-test-with-parsed-data
1990 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1991 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
1992 ;; With optional argument BODY-FIRST, first check body, then
1993 ;; footnote definitions.
1995 (equal '("1" "3" "2" nil
)
1996 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1998 \[fn:2] B [fn:3] [fn::D].
2001 (mapcar (lambda (e) (nth 1 e
))
2002 (org-export-collect-footnote-definitions info nil t
)))))
2004 (equal '("1" "3" "2" nil
)
2005 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2007 \[fn:2] B [fn:3] [fn::D].
2010 (mapcar (lambda (e) (nth 1 e
))
2011 (org-export-collect-footnote-definitions info
))))))
2013 (ert-deftest test-org-export
/footnotes
()
2014 "Miscellaneous tests on footnotes."
2015 (let ((org-footnote-section nil
)
2016 (org-export-with-footnotes t
))
2017 ;; Read every type of footnote.
2020 '((1 .
"A\n") (2 .
"C") (3 .
"D"))
2021 (org-test-with-parsed-data
2022 "Text[fn:1] [fn:label:C] [fn::D]\n\n[fn:1] A\n"
2023 (org-element-map tree
'footnote-reference
2025 (let ((def (org-export-get-footnote-definition ref info
)))
2026 (cons (org-export-get-footnote-number ref info
)
2027 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
2028 (car (org-element-contents
2029 (car (org-element-contents def
))))))))
2031 ;; Test nested footnote in invisible definitions.
2034 (org-test-with-temp-text "Text[fn:1]\n\n[fn:1] B [fn:2]\n\n[fn:2] C."
2035 (narrow-to-region (point) (line-end-position))
2038 (org-export-create-backend
2043 (throw 'exit
(length
2044 (org-export-collect-footnote-definitions
2046 ;; Test export of footnotes defined outside parsing scope.
2049 "ParagraphOut of scope\n"
2050 (org-test-with-temp-text "[fn:1] Out of scope
2052 <point>Paragraph[fn:1]"
2053 (let ((backend (org-test-default-backend)))
2054 (setf (org-export-backend-transcoders backend
)
2056 (list (cons 'footnote-reference
2057 (lambda (fn contents info
)
2058 (org-element-interpret-data
2059 (org-export-get-footnote-definition fn info
))))
2060 (cons 'footnote-definition
#'ignore
)
2061 (cons 'headline
#'ignore
))
2062 (org-export-backend-transcoders backend
)))
2063 (org-export-as backend
'subtree
)))))
2064 ;; Footnotes without a definition should throw an error.
2066 (org-test-with-parsed-data "Text[fn:1]"
2067 (org-export-get-footnote-definition
2068 (org-element-map tree
'footnote-reference
#'identity info t
) info
)))
2069 ;; Footnote section should be ignored in TOC and in headlines
2072 (= 1 (let ((org-footnote-section "Footnotes"))
2073 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
2074 (org-export-collect-headlines info
))))))
2077 (let ((org-footnote-section "Footnotes"))
2078 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
2079 (org-element-map tree
'headline
2081 (when (equal (org-element-property :raw-value hl
) "H2")
2082 (org-export-get-headline-number hl info
)))
2087 ;;; Headlines and Inlinetasks
2089 (ert-deftest test-org-export
/get-relative-level
()
2090 "Test `org-export-get-relative-level' specifications."
2094 (let ((org-odd-levels-only nil
))
2095 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2096 (org-element-map tree
'headline
2097 (lambda (h) (org-export-get-relative-level h info
))
2102 (let ((org-odd-levels-only nil
))
2103 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
2104 (org-element-map tree
'headline
2105 (lambda (h) (org-export-get-relative-level h info
))
2108 (ert-deftest test-org-export
/low-level-p
()
2109 "Test `org-export-low-level-p' specifications."
2113 (let ((org-odd-levels-only nil
))
2114 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2115 (org-element-map tree
'headline
2116 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
2117 (plist-put info
:headline-levels
1)))))))
2119 (ert-deftest test-org-export
/get-headline-number
()
2120 "Test `org-export-get-headline-number' specifications."
2125 (let ((org-odd-levels-only nil
))
2126 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2127 (org-element-map tree
'headline
2128 (lambda (h) (org-export-get-headline-number h info
))
2130 ;; Missing levels are replaced with 0.
2134 (let ((org-odd-levels-only nil
))
2135 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
2136 (org-element-map tree
'headline
2137 (lambda (h) (org-export-get-headline-number h info
))
2140 (ert-deftest test-org-export
/numbered-headline-p
()
2141 "Test `org-export-numbered-headline-p' specifications."
2142 ;; If `:section-numbers' is nil, never number headlines.
2144 (org-test-with-parsed-data "* Headline"
2145 (org-element-map tree
'headline
2146 (lambda (h) (org-export-numbered-headline-p h info
))
2147 (plist-put info
:section-numbers nil
))))
2148 ;; If `:section-numbers' is a number, only number headlines with
2149 ;; a level greater that it.
2153 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2154 (org-element-map tree
'headline
2155 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
2156 (plist-put info
:section-numbers
1)))))
2157 ;; Otherwise, headlines are always numbered.
2159 (org-test-with-parsed-data "* Headline"
2160 (org-element-map tree
'headline
2161 (lambda (h) (org-export-numbered-headline-p h info
))
2162 (plist-put info
:section-numbers t
))))
2163 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
2165 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
2166 (org-export-numbered-headline-p
2167 (org-element-map tree
'headline
'identity info t
)
2169 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
2171 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
2172 (org-export-numbered-headline-p
2173 (org-element-map tree
'headline
#'identity info t
)
2175 ;; UNNUMBERED ignores inheritance. Any non-nil value among
2176 ;; ancestors disables numbering.
2178 (org-test-with-parsed-data
2189 (lambda (h) (not (org-export-numbered-headline-p h info
)))
2190 (org-element-map tree
'headline
#'identity info
)))))
2192 (ert-deftest test-org-export
/number-to-roman
()
2193 "Test `org-export-number-to-roman' specifications."
2194 ;; If number is negative, return it as a string.
2195 (should (equal (org-export-number-to-roman -
1) "-1"))
2196 ;; Otherwise, return it as a roman number.
2197 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
2199 (ert-deftest test-org-export
/get-optional-title
()
2200 "Test `org-export-get-alt-title' specifications."
2201 ;; If ALT_TITLE property is defined, use it.
2204 (org-test-with-parsed-data
2205 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
2206 (org-export-get-alt-title
2207 (org-element-map tree
'headline
'identity info t
)
2209 ;; Otherwise, fall-back to regular title.
2211 (equal '("Headline")
2212 (org-test-with-parsed-data "* Headline"
2213 (org-export-get-alt-title
2214 (org-element-map tree
'headline
'identity info t
)
2217 (ert-deftest test-org-export
/get-tags
()
2218 "Test `org-export-get-tags' specifications."
2219 ;; Standard test: tags which are not a select tag, an exclude tag,
2220 ;; or specified as optional argument shouldn't be ignored.
2222 (org-test-with-parsed-data "* Headline :tag:"
2223 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2225 ;; Tags provided in the optional argument are ignored.
2227 (org-test-with-parsed-data "* Headline :ignore:"
2228 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2230 ;; Allow tag inheritance.
2234 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2235 (org-element-map tree
'headline
2236 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2237 ;; Tag inheritance checks FILETAGS keywords.
2241 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2242 (org-element-map tree
'headline
2243 (lambda (hl) (org-export-get-tags hl info nil t
)) info
)))))
2245 (ert-deftest test-org-export
/get-node-property
()
2246 "Test`org-export-get-node-property' specifications."
2250 (org-test-with-parsed-data "* Headline
2254 (org-export-get-node-property
2255 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2256 ;; Test inheritance.
2259 (org-test-with-parsed-data "* Parent
2265 (org-export-get-node-property
2266 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2267 ;; Cannot return a value before the first headline.
2269 (org-test-with-parsed-data "Paragraph
2274 (org-export-get-node-property
2275 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2277 (ert-deftest test-org-export
/get-category
()
2278 "Test `org-export-get-category' specifications."
2282 (org-test-with-parsed-data "* Headline
2286 (org-export-get-category
2287 (org-element-map tree
'headline
'identity nil t
) info
))))
2288 ;; Test inheritance from a parent headline.
2290 (equal '("value" "value")
2291 (org-test-with-parsed-data "* Headline1
2296 (org-element-map tree
'headline
2297 (lambda (hl) (org-export-get-category hl info
)) info
))))
2298 ;; Test inheritance from #+CATEGORY keyword
2301 (org-test-with-parsed-data "#+CATEGORY: value
2303 (org-export-get-category
2304 (org-element-map tree
'headline
'identity nil t
) info
))))
2305 ;; Test inheritance from file name.
2308 (org-test-with-parsed-data "* Headline"
2309 (let ((info (plist-put info
:input-file
"~/test.org")))
2310 (org-export-get-category
2311 (org-element-map tree
'headline
'identity nil t
) info
)))))
2315 (org-test-with-parsed-data "* Headline"
2316 (org-export-get-category
2317 (org-element-map tree
'headline
'identity nil t
) info
)))))
2319 (ert-deftest test-org-export
/first-sibling-p
()
2320 "Test `org-export-first-sibling-p' specifications."
2325 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2326 (org-element-map tree
'headline
2327 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2331 (org-test-with-parsed-data "- item\n\n para"
2332 (org-element-map tree
'paragraph
2333 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2335 ;; Ignore sections for headlines.
2338 (org-test-with-parsed-data "* H\nSection\n** H 2"
2339 (org-element-map tree
'headline
2340 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2342 ;; Ignore headlines not exported.
2346 (let ((org-export-exclude-tags '("ignore")))
2347 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2348 (org-element-map tree
'headline
2349 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2352 (ert-deftest test-org-export
/last-sibling-p
()
2353 "Test `org-export-last-sibling-p' specifications."
2358 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2359 (org-element-map tree
'headline
2360 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2364 (org-test-with-parsed-data "- item\n\n para"
2365 (org-element-map tree
'paragraph
2366 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2368 ;; Ignore headlines not exported.
2372 (let ((org-export-exclude-tags '("ignore")))
2373 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2374 (org-element-map tree
'headline
2375 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2378 (ert-deftest test-org-export
/handle-inlinetasks
()
2379 "Test inlinetask export."
2380 ;; Inlinetask with an exclude tag.
2381 (when (featurep 'org-inlinetask
)
2385 (let ((org-inlinetask-min-level 3)
2386 org-export-filter-body-functions
2387 org-export-filter-final-output-functions
)
2388 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2389 (org-export-as (org-test-default-backend)
2390 nil nil nil
'(:exclude-tags
("noexp")))))))
2391 ;; Inlinetask with an include tag.
2394 "* H2\n*** Inline :exp:\n"
2395 (let ((org-inlinetask-min-level 3)
2396 (org-tags-column 0))
2397 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2398 (org-export-as (org-test-default-backend)
2399 nil nil nil
'(:select-tags
("exp")))))))
2400 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2403 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2404 (org-inlinetask-min-level 3)
2405 org-export-filter-body-functions
2406 org-export-filter-final-output-functions
)
2407 (org-test-with-temp-text "*** TODO Inline"
2408 (org-export-as (org-test-default-backend)
2409 nil nil nil
'(:with-tasks nil
))))))))
2415 (ert-deftest test-org-export
/get-date
()
2416 "Test `org-export-get-date' specifications."
2417 ;; Return a properly formatted string when
2418 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2419 ;; consists in a single timestamp.
2422 (let ((org-export-date-timestamp-format "%d %m %Y"))
2423 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2424 (org-export-get-date info
)))))
2425 ;; Return a secondary string otherwise.
2428 (let ((org-export-date-timestamp-format nil
))
2429 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2430 (org-export-get-date info
)))))
2433 (org-test-with-parsed-data "#+DATE: Date"
2434 (org-export-get-date info
))))
2435 ;; Optional argument has precedence over
2436 ;; `org-export-date-timestamp-format'.
2439 (let ((org-export-date-timestamp-format "%d %m %Y"))
2440 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2441 (org-export-get-date info
"%d %m"))))))
2447 (ert-deftest test-org-export
/custom-protocol-maybe
()
2448 "Test `org-export-custom-protocol-maybe' specifications."
2452 (let ((org-link-types (copy-sequence org-link-types
)))
2453 (org-add-link-type "foo" nil
(lambda (p d f
) "success"))
2454 (org-export-string-as
2456 (org-export-create-backend
2459 '((section .
(lambda (s c i
) c
))
2460 (paragraph .
(lambda (p c i
) c
))
2461 (link .
(lambda (l c i
)
2462 (or (org-export-custom-protocol-maybe l c
'test
)
2467 (let ((org-link-types (copy-sequence org-link-types
)))
2469 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2470 (org-export-string-as
2472 (org-export-create-backend
2475 '((section .
(lambda (s c i
) c
))
2476 (paragraph .
(lambda (p c i
) c
))
2477 (link .
(lambda (l c i
)
2478 (or (org-export-custom-protocol-maybe l c
'no-test
)
2480 ;; Ignore anonymous back-ends.
2484 (let ((org-link-types (copy-sequence org-link-types
)))
2486 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2487 (org-export-string-as
2489 (org-export-create-backend
2491 '((section .
(lambda (s c i
) c
))
2492 (paragraph .
(lambda (p c i
) c
))
2493 (link .
(lambda (l c i
)
2494 (or (org-export-custom-protocol-maybe l c nil
)
2497 (ert-deftest test-org-export
/get-coderef-format
()
2498 "Test `org-export-get-coderef-format' specifications."
2499 ;; A link without description returns "%s"
2500 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2502 ;; Return "%s" when path is matched within description.
2503 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2505 ;; Otherwise return description.
2506 (should (equal (org-export-get-coderef-format "path" "desc")
2509 (ert-deftest test-org-export
/inline-image-p
()
2510 "Test `org-export-inline-image-p' specifications."
2512 (org-export-inline-image-p
2513 (org-test-with-temp-text "[[#id]]"
2514 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2515 '(("custom-id" .
"id")))))
2517 (ert-deftest test-org-export
/fuzzy-link
()
2518 "Test fuzzy links specifications."
2519 ;; Link to an headline should return headline's number.
2520 (org-test-with-parsed-data
2521 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2523 ;; Note: Headline's number is in fact a list of numbers.
2525 (org-element-map tree
'link
2527 (org-export-get-ordinal
2528 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2529 ;; Link to a target in an item should return item's number.
2530 (org-test-with-parsed-data
2531 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2533 ;; Note: Item's number is in fact a list of numbers.
2535 (org-element-map tree
'link
2537 (org-export-get-ordinal
2538 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2539 ;; Link to a target in a footnote should return footnote's number.
2540 (org-test-with-parsed-data "
2541 Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
2547 (org-element-map tree
'link
2549 (org-export-get-ordinal
2550 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2551 ;; Link to a named element should return sequence number of that
2553 (org-test-with-parsed-data
2554 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2557 (org-element-map tree
'link
2559 (org-export-get-ordinal
2560 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2561 ;; Link to a target not within an item, a table, a footnote
2562 ;; reference or definition should return section number.
2563 (org-test-with-parsed-data
2564 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2567 (org-element-map tree
'link
2569 (org-export-get-ordinal
2570 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2571 ;; Space are not significant when matching a fuzzy link.
2573 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2574 (org-element-map tree
'link
2575 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2577 ;; Statistics cookies are ignored for headline match.
2579 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2580 (org-element-map tree
'link
2581 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2584 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2585 (org-element-map tree
'link
2586 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2589 (ert-deftest test-org-export
/resolve-coderef
()
2590 "Test `org-export-resolve-coderef' specifications."
2591 (let ((org-coderef-label-format "(ref:%s)"))
2592 ;; A link to a "-n -k -r" block returns line number.
2595 (org-test-with-parsed-data
2596 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2597 (org-export-resolve-coderef "coderef" info
))))
2600 (org-test-with-parsed-data
2601 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2602 (org-export-resolve-coderef "coderef" info
))))
2603 ;; A link to a "-n -r" block returns line number.
2606 (org-test-with-parsed-data
2607 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2608 (org-export-resolve-coderef "coderef" info
))))
2611 (org-test-with-parsed-data
2612 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2613 (org-export-resolve-coderef "coderef" info
))))
2614 ;; A link to a "-n" block returns coderef.
2617 (org-test-with-parsed-data
2618 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2619 (org-export-resolve-coderef "coderef" info
))))
2622 (org-test-with-parsed-data
2623 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2624 (org-export-resolve-coderef "coderef" info
))))
2625 ;; A link to a "-r" block returns line number.
2628 (org-test-with-parsed-data
2629 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2630 (org-export-resolve-coderef "coderef" info
))))
2633 (org-test-with-parsed-data
2634 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2635 (org-export-resolve-coderef "coderef" info
))))
2636 ;; A link to a block without a switch returns coderef.
2639 (org-test-with-parsed-data
2640 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2641 (org-export-resolve-coderef "coderef" info
))))
2642 (org-test-with-parsed-data
2643 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2644 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2645 ;; Correctly handle continued line numbers. A "+n" switch should
2646 ;; resume numbering from previous block with numbered lines,
2647 ;; ignoring blocks not numbering lines in the process. A "-n"
2648 ;; switch resets count.
2651 (org-test-with-parsed-data "
2656 #+BEGIN_SRC emacs-lisp
2660 #+BEGIN_SRC emacs-lisp +n -r
2661 \(+ 1 1) (ref:addition)
2664 #+BEGIN_EXAMPLE -n -r
2665 Another text. (ref:text)
2667 (list (org-export-resolve-coderef "addition" info
)
2668 (org-export-resolve-coderef "text" info
)))))
2669 ;; Recognize coderef with user-specified syntax.
2673 (org-test-with-parsed-data
2674 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2675 (org-export-resolve-coderef "text" info
))))
2676 ;; Unresolved coderefs raise a `org-link-broken' signal.
2679 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2680 (org-export-resolve-coderef "unknown" info
))
2681 (org-link-broken t
)))))
2683 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2684 "Test `org-export-resolve-fuzzy-link' specifications."
2685 ;; Match target objects.
2687 (org-test-with-parsed-data "<<target>> [[target]]"
2688 (org-export-resolve-fuzzy-link
2689 (org-element-map tree
'link
'identity info t
) info
)))
2690 ;; Match named elements.
2692 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2693 (org-export-resolve-fuzzy-link
2694 (org-element-map tree
'link
'identity info t
) info
)))
2695 ;; Match exact headline's name.
2697 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2698 (org-export-resolve-fuzzy-link
2699 (org-element-map tree
'link
'identity info t
) info
)))
2700 ;; Targets objects have priority over named elements and headline
2704 (org-test-with-parsed-data
2705 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2707 (org-export-resolve-fuzzy-link
2708 (org-element-map tree
'link
'identity info t
) info
)))))
2709 ;; Named elements have priority over headline titles.
2712 (org-test-with-parsed-data
2713 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2715 (org-export-resolve-fuzzy-link
2716 (org-element-map tree
'link
'identity info t
) info
)))))
2717 ;; If link's path starts with a "*", only match headline titles,
2721 (org-test-with-parsed-data
2722 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2724 (org-export-resolve-fuzzy-link
2725 (org-element-map tree
'link
'identity info t
) info
)))))
2726 ;; Raise a `org-link-broken' signal if no match.
2728 (org-test-with-parsed-data "[[target]]"
2730 (org-export-resolve-fuzzy-link
2731 (org-element-map tree
'link
#'identity info t
) info
)
2732 (org-link-broken t
))))
2733 ;; Match fuzzy link even when before first headline.
2736 (org-test-with-parsed-data "[[hl]]\n* hl"
2738 (org-export-resolve-fuzzy-link
2739 (org-element-map tree
'link
'identity info t
) info
)))))
2740 ;; Handle url-encoded fuzzy links.
2742 (org-test-with-parsed-data "* A B\n[[A%20B]]"
2743 (org-export-resolve-fuzzy-link
2744 (org-element-map tree
'link
#'identity info t
) info
))))
2746 (ert-deftest test-org-export
/resolve-id-link
()
2747 "Test `org-export-resolve-id-link' specifications."
2748 ;; Regular test for custom-id link.
2750 (equal '("Headline1")
2751 (org-test-with-parsed-data "* Headline1
2757 (org-element-property
2759 (org-export-resolve-id-link
2760 (org-element-map tree
'link
'identity info t
) info
)))))
2761 ;; Raise a `org-link-broken' signal on failing searches.
2763 (org-test-with-parsed-data "* Headline1
2770 (org-export-resolve-id-link
2771 (org-element-map tree
'link
#'identity info t
) info
)
2772 (org-link-broken t
))))
2773 ;; Test for internal id target.
2775 (equal '("Headline1")
2776 (org-test-with-parsed-data "* Headline1
2782 (org-element-property
2784 (org-export-resolve-id-link
2785 (org-element-map tree
'link
'identity info t
) info
)))))
2786 ;; Test for external id target.
2790 (org-test-with-parsed-data "[[id:aaaa]]"
2791 (org-export-resolve-id-link
2792 (org-element-map tree
'link
'identity info t
)
2793 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
2795 (ert-deftest test-org-export
/resolve-radio-link
()
2796 "Test `org-export-resolve-radio-link' specifications."
2799 (org-test-with-temp-text "<<<radio>>> radio"
2800 (org-update-radio-target-regexp)
2801 (let* ((tree (org-element-parse-buffer))
2802 (info `(:parse-tree
,tree
)))
2803 (org-export-resolve-radio-link
2804 (org-element-map tree
'link
'identity info t
)
2806 ;; Radio targets are case-insensitive.
2808 (org-test-with-temp-text "<<<RADIO>>> radio"
2809 (org-update-radio-target-regexp)
2810 (let* ((tree (org-element-parse-buffer))
2811 (info `(:parse-tree
,tree
)))
2812 (org-export-resolve-radio-link
2813 (org-element-map tree
'link
'identity info t
)
2815 ;; Radio target with objects.
2817 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2818 (org-update-radio-target-regexp)
2819 (let* ((tree (org-element-parse-buffer))
2820 (info `(:parse-tree
,tree
)))
2821 (org-export-resolve-radio-link
2822 (org-element-map tree
'link
'identity info t
)
2824 ;; Radio target with objects at its beginning.
2826 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2827 (org-update-radio-target-regexp)
2828 (let* ((tree (org-element-parse-buffer))
2829 (info `(:parse-tree
,tree
)))
2830 (org-export-resolve-radio-link
2831 (org-element-map tree
'link
'identity info t
)
2833 ;; Radio link next to an apostrophe.
2835 (org-test-with-temp-text "<<<radio>>> radio's"
2836 (org-update-radio-target-regexp)
2837 (let* ((tree (org-element-parse-buffer))
2838 (info `(:parse-tree
,tree
)))
2839 (org-export-resolve-radio-link
2840 (org-element-map tree
'link
'identity info t
)
2842 ;; Multiple radio targets.
2844 (equal '("radio1" "radio2")
2845 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2846 (org-update-radio-target-regexp)
2847 (let* ((tree (org-element-parse-buffer))
2848 (info `(:parse-tree
,tree
)))
2849 (org-element-map tree
'link
2851 (org-element-property
2852 :value
(org-export-resolve-radio-link link info
)))
2854 ;; Radio target is whitespace insensitive.
2856 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2857 (org-update-radio-target-regexp)
2858 (let* ((tree (org-element-parse-buffer))
2859 (info `(:parse-tree
,tree
)))
2860 (org-element-map tree
'link
2861 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2863 (ert-deftest test-org-export
/file-uri
()
2864 "Test `org-export-file-uri' specifications."
2865 ;; Preserve relative filenames.
2866 (should (equal "relative.org" (org-export-file-uri "relative.org")))
2867 ;; Local files start with "file:///"
2868 (should (equal "file:///local.org" (org-export-file-uri "/local.org")))
2869 ;; Remote files start with "file://"
2870 (should (equal "file://myself@some.where:papers/last.pdf"
2871 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
2872 (should (equal "file://localhost/etc/fstab"
2873 (org-export-file-uri "//localhost/etc/fstab")))
2874 ;; Expand filename starting with "~".
2875 (should (equal (org-export-file-uri "~/file.org")
2876 (concat "file://" (expand-file-name "~/file.org")))))
2880 ;;; Src-block and example-block
2882 (ert-deftest test-org-export
/unravel-code
()
2883 "Test `org-export-unravel-code' function."
2884 ;; Code without reference.
2886 (equal '("(+ 1 1)\n")
2887 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2888 (org-export-unravel-code (org-element-at-point)))))
2889 ;; Code with reference.
2891 (equal '("(+ 1 1)\n" (1 .
"test"))
2892 (org-test-with-temp-text
2893 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2894 (let ((org-coderef-label-format "(ref:%s)"))
2895 (org-export-unravel-code (org-element-at-point))))))
2896 ;; Code with user-defined reference.
2899 '("(+ 1 1)\n" (1 .
"test"))
2900 (org-test-with-temp-text
2901 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2902 (let ((org-coderef-label-format "(ref:%s)"))
2903 (org-export-unravel-code (org-element-at-point))))))
2904 ;; Code references keys are relative to the current block.
2906 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2907 (org-test-with-temp-text "
2916 (let ((org-coderef-label-format "(ref:%s)"))
2917 (org-export-unravel-code (org-element-at-point)))))))
2919 (ert-deftest test-org-export
/format-code-default
()
2920 "Test `org-export-format-code-default' specifications."
2921 ;; Return the empty string when code is empty.
2924 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2925 (org-export-format-code-default
2926 (org-element-map tree
'src-block
'identity info t
) info
))))
2927 ;; Number lines, two whitespace characters before the actual loc.
2930 (org-test-with-parsed-data
2931 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2932 (org-export-format-code-default
2933 (org-element-map tree
'src-block
'identity info t
) info
))))
2934 ;; Put references 6 whitespace characters after the widest line,
2935 ;; wrapped within parenthesis.
2937 (equal "123 (a)\n1 (b)\n"
2938 (let ((org-coderef-label-format "(ref:%s)"))
2939 (org-test-with-parsed-data
2940 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2941 (org-export-format-code-default
2942 (org-element-map tree
'src-block
'identity info t
) info
))))))
2948 (ert-deftest test-org-export
/activate-smart-quotes
()
2949 "Test `org-export-activate-smart-quotes' specifications."
2950 ;; Double quotes: standard test.
2953 '("some “quoted” text")
2954 (let ((org-export-default-language "en"))
2955 (org-test-with-parsed-data "some \"quoted\" text"
2956 (org-element-map tree
'plain-text
2957 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2959 ;; Opening quotes: at the beginning of a paragraph.
2963 (let ((org-export-default-language "en"))
2964 (org-test-with-parsed-data "\"begin"
2965 (org-element-map tree
'plain-text
2966 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2968 ;; Opening quotes: after an object.
2971 '("“quoted” text")
2972 (let ((org-export-default-language "en"))
2973 (org-test-with-parsed-data "=verb= \"quoted\" text"
2974 (org-element-map tree
'plain-text
2975 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2977 ;; Closing quotes: at the end of a paragraph.
2980 '("Quoted “text”")
2981 (let ((org-export-default-language "en"))
2982 (org-test-with-parsed-data "Quoted \"text\""
2983 (org-element-map tree
'plain-text
2984 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2986 ;; Inner quotes: standard test.
2988 (equal '("« outer « inner » outer »")
2989 (let ((org-export-default-language "fr"))
2990 (org-test-with-parsed-data "\"outer 'inner' outer\""
2991 (org-element-map tree
'plain-text
2992 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2994 ;; Inner quotes: close to special symbols.
2996 (equal '("« outer (« inner ») outer »")
2997 (let ((org-export-default-language "fr"))
2998 (org-test-with-parsed-data "\"outer ('inner') outer\""
2999 (org-element-map tree
'plain-text
3000 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3003 (equal '("« « inner » »")
3004 (let ((org-export-default-language "fr"))
3005 (org-test-with-parsed-data "\"'inner'\""
3006 (org-element-map tree
'plain-text
3007 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3009 ;; Apostrophe: standard test.
3011 (equal '("It « shouldn’t » fail")
3012 (let ((org-export-default-language "fr"))
3013 (org-test-with-parsed-data "It \"shouldn't\" fail"
3014 (org-element-map tree
'plain-text
3015 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3018 (equal '("It shouldn’t fail")
3019 (let ((org-export-default-language "fr"))
3020 (org-test-with-parsed-data "It shouldn't fail"
3021 (org-element-map tree
'plain-text
3022 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3024 ;; Apostrophe: before an object.
3027 '("« a’" " »")
3028 (let ((org-export-default-language "fr"))
3029 (org-test-with-parsed-data "\"a'=b=\""
3030 (org-element-map tree
'plain-text
3031 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3033 ;; Apostrophe: after an object.
3035 (equal '("« " "’s »")
3036 (let ((org-export-default-language "fr"))
3037 (org-test-with-parsed-data "\"=code='s\""
3038 (org-element-map tree
'plain-text
3039 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3041 ;; Special case: isolated quotes.
3043 (equal '("“" "”")
3044 (let ((org-export-default-language "en"))
3045 (org-test-with-parsed-data "\"$x$\""
3046 (org-element-map tree
'plain-text
3047 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3049 ;; Smart quotes in secondary strings.
3051 (equal '("“" "”")
3052 (let ((org-export-default-language "en"))
3053 (org-test-with-parsed-data "* \"$x$\""
3054 (org-element-map tree
'plain-text
3055 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3057 ;; Smart quotes in document keywords.
3059 (equal '("“" "”")
3060 (let ((org-export-default-language "en"))
3061 (org-test-with-parsed-data "#+TITLE: \"$x$\""
3062 (org-element-map (plist-get info
:title
) 'plain-text
3063 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3065 ;; Smart quotes in parsed affiliated keywords.
3067 (equal '("“" "”" "Paragraph")
3068 (let ((org-export-default-language "en"))
3069 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
3070 (org-element-map tree
'plain-text
3071 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3072 info nil nil t
))))))
3078 (ert-deftest test-org-export
/special-column
()
3079 "Test if the table's special column is properly recognized."
3080 ;; 1. First column is special if it contains only a special marking
3081 ;; characters or empty cells.
3082 (org-test-with-temp-text "
3086 (org-export-table-has-special-column-p
3088 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3089 ;; 2. If the column contains anything else, it isn't special.
3090 (org-test-with-temp-text "
3094 (org-export-table-has-special-column-p
3096 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3097 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
3099 (org-test-with-temp-text "
3108 (org-export-table-has-special-column-p
3110 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3111 ;; 4. A first column with only empty cells isn't considered as
3113 (org-test-with-temp-text "
3117 (org-export-table-has-special-column-p
3119 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
3121 (ert-deftest test-org-export
/table-row-is-special-p
()
3122 "Test `org-export-table-row-is-special-p' specifications."
3123 ;; 1. A row is special if it has a special marking character in the
3125 (org-test-with-parsed-data "| ! | 1 |"
3127 (org-export-table-row-is-special-p
3128 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3129 ;; 2. A row is special when its first field is "/"
3130 (org-test-with-parsed-data "
3134 (org-export-table-row-is-special-p
3135 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3136 ;; 3. A row only containing alignment cookies is also considered as
3138 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
3140 (org-export-table-row-is-special-p
3141 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3142 ;; 4. Everything else isn't considered as special.
3143 (org-test-with-parsed-data "| \alpha | | c |"
3145 (org-export-table-row-is-special-p
3146 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3147 ;; 5. Table's rules are never considered as special rows.
3148 (org-test-with-parsed-data "|---+---|"
3150 (org-export-table-row-is-special-p
3151 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
3153 (ert-deftest test-org-export
/has-header-p
()
3154 "Test `org-export-table-has-header-p' specifications."
3155 ;; 1. With an header.
3156 (org-test-with-parsed-data "
3161 (org-export-table-has-header-p
3162 (org-element-map tree
'table
'identity info
'first-match
)
3164 ;; 2. Without an header.
3165 (org-test-with-parsed-data "
3169 (org-export-table-has-header-p
3170 (org-element-map tree
'table
'identity info
'first-match
)
3172 ;; 3. Don't get fooled with starting and ending rules.
3173 (org-test-with-parsed-data "
3179 (org-export-table-has-header-p
3180 (org-element-map tree
'table
'identity info
'first-match
)
3183 (ert-deftest test-org-export
/table-row-group
()
3184 "Test `org-export-table-row-group' specifications."
3185 ;; 1. A rule creates a new group.
3188 (org-test-with-parsed-data "
3192 (org-element-map tree
'table-row
3194 (if (eq (org-element-property :type row
) 'rule
) 'rule
3195 (org-export-table-row-group row info
)))))))
3196 ;; 2. Special rows are ignored in count.
3200 (org-test-with-parsed-data "
3204 (org-element-map tree
'table-row
3206 (if (eq (org-element-property :type row
) 'rule
) 'rule
3207 (org-export-table-row-group row info
)))
3209 ;; 3. Double rules also are ignored in count.
3211 (equal '(1 rule rule
2)
3212 (org-test-with-parsed-data "
3217 (org-element-map tree
'table-row
3219 (if (eq (org-element-property :type row
) 'rule
) 'rule
3220 (org-export-table-row-group row info
))))))))
3222 (ert-deftest test-org-export
/table-row-number
()
3223 "Test `org-export-table-row-number' specifications."
3224 ;; Standard test. Number is 0-indexed.
3227 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3228 (org-element-map tree
'table-row
3229 (lambda (row) (org-export-table-row-number row info
)) info
))))
3230 ;; Number ignores separators.
3233 (org-test-with-parsed-data "
3237 (org-element-map tree
'table-row
3238 (lambda (row) (org-export-table-row-number row info
)) info
))))
3239 ;; Number ignores special rows.
3242 (org-test-with-parsed-data "
3248 (org-element-map tree
'table-row
3249 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3251 (ert-deftest test-org-export
/table-cell-width
()
3252 "Test `org-export-table-cell-width' specifications."
3253 ;; 1. Width is primarily determined by width cookies. If no cookie
3254 ;; is found, cell's width is nil.
3255 (org-test-with-parsed-data "
3256 | / | <l> | <6> | <l7> |
3261 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3262 (org-element-map tree
'table-cell
'identity info
)))))
3263 ;; 2. The last width cookie has precedence.
3264 (org-test-with-parsed-data "
3271 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3272 (org-element-map tree
'table-cell
'identity info
)))))
3273 ;; 3. Valid width cookies must have a specific row.
3274 (org-test-with-parsed-data "| <6> | cell |"
3278 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3279 (org-element-map tree
'table-cell
'identity
))))))
3281 (ert-deftest test-org-export
/table-cell-alignment
()
3282 "Test `org-export-table-cell-alignment' specifications."
3283 ;; 1. Alignment is primarily determined by alignment cookies.
3285 (equal '(left center right
)
3286 (let ((org-table-number-fraction 0.5)
3287 (org-table-number-regexp "^[0-9]+$"))
3288 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3289 (mapcar (lambda (cell)
3290 (org-export-table-cell-alignment cell info
))
3291 (org-element-map tree
'table-cell
'identity
))))))
3292 ;; 2. The last alignment cookie has precedence.
3294 (equal '(right right right
)
3295 (org-test-with-parsed-data "
3299 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3300 (org-element-map tree
'table-cell
'identity
)))))
3301 ;; 3. If there's no cookie, cell's contents determine alignment.
3302 ;; A column mostly made of cells containing numbers will align
3303 ;; its cells to the right.
3305 (equal '(right right right
)
3306 (let ((org-table-number-fraction 0.5)
3307 (org-table-number-regexp "^[0-9]+$"))
3308 (org-test-with-parsed-data "
3312 (mapcar (lambda (cell)
3313 (org-export-table-cell-alignment cell info
))
3314 (org-element-map tree
'table-cell
'identity
))))))
3315 ;; 4. Otherwise, they will be aligned to the left.
3317 (equal '(left left left
)
3318 (org-test-with-parsed-data "
3322 (mapcar (lambda (cell)
3323 (org-export-table-cell-alignment cell info
))
3324 (org-element-map tree
'table-cell
'identity info
))))))
3326 (ert-deftest test-org-export
/table-cell-borders
()
3327 "Test `org-export-table-cell-borders' specifications."
3328 ;; 1. Recognize various column groups indicators.
3329 (org-test-with-parsed-data "| / | < | > | <> |"
3332 '((right bottom top
) (left bottom top
) (right bottom top
)
3333 (right left bottom top
))
3334 (mapcar (lambda (cell)
3335 (org-export-table-cell-borders cell info
))
3336 (org-element-map tree
'table-cell
'identity
)))))
3337 ;; 2. Accept shortcuts to define column groups.
3338 (org-test-with-parsed-data "| / | < | < |"
3341 '((right bottom top
) (right left bottom top
) (left bottom top
))
3342 (mapcar (lambda (cell)
3343 (org-export-table-cell-borders cell info
))
3344 (org-element-map tree
'table-cell
'identity
)))))
3345 ;; 3. A valid column groups row must start with a "/".
3346 (org-test-with-parsed-data "
3350 (equal '((top) (top) (bottom) (bottom))
3351 (mapcar (lambda (cell)
3352 (org-export-table-cell-borders cell info
))
3353 (org-element-map tree
'table-cell
'identity
)))))
3354 ;; 4. Take table rules into consideration.
3355 (org-test-with-parsed-data "
3360 (equal '((below top
) (bottom above
))
3361 (mapcar (lambda (cell)
3362 (org-export-table-cell-borders cell info
))
3363 (org-element-map tree
'table-cell
'identity
)))))
3364 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3365 ;; (resp. `bottom' and `below') borders. Any special row is
3367 (org-test-with-parsed-data "
3373 (equal '((bottom below top above
))
3375 (mapcar (lambda (cell)
3376 (org-export-table-cell-borders cell info
))
3377 (org-element-map tree
'table-cell
'identity
)))))))
3379 (ert-deftest test-org-export
/table-dimensions
()
3380 "Test `org-export-table-dimensions' specifications."
3381 ;; 1. Standard test.
3382 (org-test-with-parsed-data "
3387 (org-export-table-dimensions
3388 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3389 ;; 2. Ignore horizontal rules and special columns.
3390 (org-test-with-parsed-data "
3397 (org-export-table-dimensions
3398 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3400 (ert-deftest test-org-export
/table-cell-address
()
3401 "Test `org-export-table-cell-address' specifications."
3402 ;; 1. Standard test: index is 0-based.
3403 (org-test-with-parsed-data "| a | b |"
3405 (equal '((0 .
0) (0 .
1))
3406 (org-element-map tree
'table-cell
3407 (lambda (cell) (org-export-table-cell-address cell info
))
3409 ;; 2. Special column isn't counted, nor are special rows.
3410 (org-test-with-parsed-data "
3415 (org-export-table-cell-address
3416 (car (last (org-element-map tree
'table-cell
'identity info
)))
3418 ;; 3. Tables rules do not count either.
3419 (org-test-with-parsed-data "
3427 (org-export-table-cell-address
3428 (car (last (org-element-map tree
'table-cell
'identity info
)))
3430 ;; 4. Return nil for special cells.
3431 (org-test-with-parsed-data "| / | a |"
3433 (org-export-table-cell-address
3434 (org-element-map tree
'table-cell
'identity nil
'first-match
)
3437 (ert-deftest test-org-export
/get-table-cell-at
()
3438 "Test `org-export-get-table-cell-at' specifications."
3439 ;; 1. Address ignores special columns, special rows and rules.
3440 (org-test-with-parsed-data "
3447 (org-element-contents
3448 (org-export-get-table-cell-at
3450 (org-element-map tree
'table
'identity info
'first-match
)
3452 ;; 2. Return value for a non-existent address is nil.
3453 (org-test-with-parsed-data "| a |"
3455 (org-export-get-table-cell-at
3457 (org-element-map tree
'table
'identity info
'first-match
)
3459 (org-test-with-parsed-data "| / |"
3461 (org-export-get-table-cell-at
3463 (org-element-map tree
'table
'identity info
'first-match
)
3466 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
3467 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3468 ;; 1. A cell at a beginning of a row always starts a column group.
3469 (org-test-with-parsed-data "| a |"
3471 (org-export-table-cell-starts-colgroup-p
3472 (org-element-map tree
'table-cell
'identity info
'first-match
)
3474 ;; 2. Special column should be ignored when determining the
3475 ;; beginning of the row.
3476 (org-test-with-parsed-data "
3480 (org-export-table-cell-starts-colgroup-p
3481 (org-element-map tree
'table-cell
'identity info
'first-match
)
3483 ;; 2. Explicit column groups.
3484 (org-test-with-parsed-data "
3490 (org-element-map tree
'table-cell
3492 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3495 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3496 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3497 ;; 1. A cell at the end of a row always ends a column group.
3498 (org-test-with-parsed-data "| a |"
3500 (org-export-table-cell-ends-colgroup-p
3501 (org-element-map tree
'table-cell
'identity info
'first-match
)
3503 ;; 2. Special column should be ignored when determining the
3504 ;; beginning of the row.
3505 (org-test-with-parsed-data "
3509 (org-export-table-cell-ends-colgroup-p
3510 (org-element-map tree
'table-cell
'identity info
'first-match
)
3512 ;; 3. Explicit column groups.
3513 (org-test-with-parsed-data "
3519 (org-element-map tree
'table-cell
3521 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
3524 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
3525 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3526 ;; 1. A row at the beginning of a table always starts a row group.
3527 ;; So does a row following a table rule.
3528 (org-test-with-parsed-data "
3535 (org-element-map tree
'table-row
3537 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3539 ;; 2. Special rows should be ignored when determining the beginning
3541 (org-test-with-parsed-data "
3550 (org-element-map tree
'table-row
3552 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3555 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
3556 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3557 ;; 1. A row at the end of a table always ends a row group. So does
3558 ;; a row preceding a table rule.
3559 (org-test-with-parsed-data "
3566 (org-element-map tree
'table-row
3568 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3570 ;; 2. Special rows should be ignored when determining the beginning
3572 (org-test-with-parsed-data "
3581 (org-element-map tree
'table-row
3583 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3586 (ert-deftest test-org-export
/table-row-in-header-p
()
3587 "Test `org-export-table-row-in-header-p' specifications."
3588 ;; Standard test. Separators are always nil.
3592 (org-test-with-parsed-data "| a |\n|---|\n| b |"
3593 (org-element-map tree
'table-row
3595 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
3596 ;; Nil when there is no header.
3600 (org-test-with-parsed-data "| a |\n| b |"
3601 (org-element-map tree
'table-row
3603 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
3605 (ert-deftest test-org-export
/table-row-starts-header-p
()
3606 "Test `org-export-table-row-starts-header-p' specifications."
3607 ;; 1. Only the row starting the first row group starts the table
3609 (org-test-with-parsed-data "
3617 (org-element-map tree
'table-row
3619 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
3621 ;; 2. A row cannot start an header if there's no header in the
3623 (org-test-with-parsed-data "
3627 (org-export-table-row-starts-header-p
3628 (org-element-map tree
'table-row
'identity info
'first-match
)
3631 (ert-deftest test-org-export
/table-row-ends-header-p
()
3632 "Test `org-export-table-row-ends-header-p' specifications."
3633 ;; 1. Only the row starting the first row group starts the table
3635 (org-test-with-parsed-data "
3643 (org-element-map tree
'table-row
3645 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
3647 ;; 2. A row cannot start an header if there's no header in the
3649 (org-test-with-parsed-data "
3653 (org-export-table-row-ends-header-p
3654 (org-element-map tree
'table-row
'identity info
'first-match
)
3659 ;;; Tables of Contents
3661 (ert-deftest test-org-export
/collect-headlines
()
3662 "Test `org-export-collect-headlines' specifications."
3667 (org-test-with-parsed-data "* H1\n** H2"
3668 (org-export-collect-headlines info
)))))
3669 ;; Do not collect headlines below optional argument.
3673 (org-test-with-parsed-data "* H1\n** H2"
3674 (org-export-collect-headlines info
1)))))
3675 ;; Never collect headlines below maximum headline level.
3679 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3680 (org-export-collect-headlines info
)))))
3684 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3685 (org-export-collect-headlines info
2)))))
3686 ;; Collect headlines locally.
3689 (org-test-with-parsed-data "* H1\n** H2\n** H3"
3690 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3691 (length (org-export-collect-headlines info nil scope
))))))
3692 ;; When collecting locally, optional level is relative.
3695 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
3696 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3697 (length (org-export-collect-headlines info
1 scope
)))))))
3703 (ert-deftest test-org-export
/inner-template
()
3704 "Test `inner-template' translator specifications."
3707 (org-test-with-temp-text "* Headline"
3709 (org-export-create-backend
3711 '((inner-template .
(lambda (contents info
) "Success!"))
3712 (headline .
(lambda (h c i
) "Headline"))))))))
3713 ;; Inner template is applied even in a "body-only" export.
3716 (org-test-with-temp-text "* Headline"
3718 (org-export-create-backend
3719 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3720 (headline .
(lambda (h c i
) "Headline"))))
3721 nil nil
'body-only
)))))
3723 (ert-deftest test-org-export
/template
()
3724 "Test `template' translator specifications."
3727 (org-test-with-temp-text "* Headline"
3729 (org-export-create-backend
3730 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3731 (headline .
(lambda (h c i
) "Headline"))))))))
3732 ;; Template is not applied in a "body-only" export.
3735 (org-test-with-temp-text "* Headline"
3737 (org-export-create-backend
3738 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3739 (headline .
(lambda (h c i
) "Headline"))))
3740 nil nil
'body-only
)))))
3746 (ert-deftest test-org-export
/get-next-element
()
3747 "Test `org-export-get-next-element' specifications."
3751 (org-test-with-parsed-data "* Headline\n*a* b"
3752 (org-export-get-next-element
3753 (org-element-map tree
'bold
'identity info t
) info
))))
3754 ;; Return nil when no previous element.
3756 (org-test-with-parsed-data "* Headline\na *b*"
3757 (org-export-get-next-element
3758 (org-element-map tree
'bold
'identity info t
) info
)))
3759 ;; Non-exportable elements are ignored.
3761 (let ((org-export-with-timestamps nil
))
3762 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3763 (org-export-get-next-element
3764 (org-element-map tree
'entity
'identity info t
) info
))))
3765 ;; Find next element in secondary strings.
3768 (org-test-with-parsed-data "* a =verb="
3770 (org-export-get-next-element
3771 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3774 (org-test-with-parsed-data "* /italic/ =verb="
3776 (org-export-get-next-element
3777 (org-element-map tree
'italic
'identity info t
) info
)))))
3778 ;; Find next element in document keywords.
3781 (org-test-with-parsed-data "#+TITLE: a =verb="
3783 (org-export-get-next-element
3785 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3786 ;; Find next element in parsed affiliated keywords.
3789 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3791 (org-export-get-next-element
3792 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3793 ;; With optional argument N, return a list containing all the
3794 ;; following elements.
3797 '(bold code underline
)
3798 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3800 (org-export-get-next-element
3801 (org-element-map tree
'italic
'identity info t
) info t
)))))
3802 ;; When N is a positive integer, return a list containing up to
3803 ;; N following elements.
3807 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3809 (org-export-get-next-element
3810 (org-element-map tree
'italic
'identity info t
) info
2))))))
3812 (ert-deftest test-org-export
/get-previous-element
()
3813 "Test `org-export-get-previous-element' specifications."
3817 (org-test-with-parsed-data "* Headline\na *b*"
3818 (org-export-get-previous-element
3819 (org-element-map tree
'bold
'identity info t
) info
))))
3820 ;; Return nil when no previous element.
3822 (org-test-with-parsed-data "* Headline\n*a* b"
3823 (org-export-get-previous-element
3824 (org-element-map tree
'bold
'identity info t
) info
)))
3825 ;; Non-exportable elements are ignored.
3827 (let ((org-export-with-timestamps nil
))
3828 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3829 (org-export-get-previous-element
3830 (org-element-map tree
'entity
'identity info t
) info
))))
3831 ;; Find previous element in secondary strings.
3834 (org-test-with-parsed-data "* =verb= a"
3836 (org-export-get-previous-element
3837 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3840 (org-test-with-parsed-data "* =verb= /italic/"
3842 (org-export-get-previous-element
3843 (org-element-map tree
'italic
'identity info t
) info
)))))
3844 ;; Find previous element in document keywords.
3847 (org-test-with-parsed-data "#+TITLE: =verb= a"
3849 (org-export-get-previous-element
3851 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3852 ;; Find previous element in parsed affiliated keywords.
3855 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3857 (org-export-get-previous-element
3858 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3859 ;; With optional argument N, return a list containing up to
3860 ;; N previous elements.
3862 (equal '(underline italic bold
)
3863 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3865 (org-export-get-previous-element
3866 (org-element-map tree
'code
'identity info t
) info t
)))))
3867 ;; When N is a positive integer, return a list containing up to
3868 ;; N previous elements.
3870 (equal '(italic bold
)
3871 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3873 (org-export-get-previous-element
3874 (org-element-map tree
'code
'identity info t
) info
2))))))
3878 ;;; test-org-export.el end here