1 ;;; test-ox.el --- Tests for ox.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2016 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
26 (unless (featurep 'ox
)
27 (signal 'missing-test-dependency
"org-export"))
29 (defun org-test-default-backend ()
30 "Return a default export back-end.
31 This back-end simply returns parsed data as Org syntax."
32 (org-export-create-backend
34 (mapcar (lambda (type)
38 (intern (format "org-element-%s-interpreter" type
))
40 (append org-element-all-elements org-element-all-objects
))))
42 (defmacro org-test-with-parsed-data
(data &rest body
)
43 "Execute body with parsed data available.
44 DATA is a string containing the data to be parsed. BODY is the
45 body to execute. Parse tree is available under the `tree'
46 variable, and communication channel under `info'."
47 (declare (debug (form body
)) (indent 1))
48 `(org-test-with-temp-text ,data
49 (org-export--delete-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."
883 (equal "text\n*** H3\n"
884 (org-test-with-temp-text "* H1\n<point>** H2\ntext\n*** H3"
885 (org-export-as (org-test-default-backend) 'subtree
))))
887 (equal "text\n*** H3\n"
888 (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
889 (org-export-as (org-test-default-backend) 'subtree
))))
890 ;; Subtree with a code block calling another block outside.
893 (org-test-with-temp-text "
895 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
900 #+BEGIN_SRC emacs-lisp
903 (let ((org-export-babel-evaluate t
))
904 (org-export-as (org-test-default-backend) 'subtree
)))))
905 ;; Subtree export should ignore leading planning line and property
909 (org-test-with-temp-text "
911 SCHEDULED: <2012-03-29 Thu>
916 (org-export-as (org-test-default-backend)
918 '(:with-planning t
:with-properties t
)))))
922 (org-test-with-temp-text "* H1\n** H2\ntext\n*** H3"
924 (org-export-as (org-test-default-backend) nil
'visible
))))
928 (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
929 (transient-mark-mode 1)
930 (push-mark (point) t t
)
932 (org-export-as (org-test-default-backend)))))
936 (org-test-with-temp-text "Text"
938 (org-export-create-backend
940 '((template .
(lambda (b _i
) (format "BEGIN\n%sEND" b
)))
941 (section .
(lambda (_s c _i
) c
))
942 (paragraph .
(lambda (_p c _i
) c
))))
943 nil nil
'body-only
))))
945 (equal "BEGIN\nText\nEND"
946 (org-test-with-temp-text "Text"
948 (org-export-create-backend
950 '((template .
(lambda (b _i
) (format "BEGIN\n%sEND" b
)))
951 (section .
(lambda (_s c _i
) c
))
952 (paragraph .
(lambda (_p c _i
) c
))))))))
953 ;; Pathological case: Body only on an empty buffer is expected to
954 ;; return an empty string, not nil.
956 (org-test-with-temp-text ""
957 (org-export-as (org-test-default-backend) nil nil t
))))
959 (ert-deftest test-org-export
/output-file-name
()
960 "Test `org-export-output-file-name' specifications."
961 ;; Export from a file: name is built from original file name.
963 (org-test-with-temp-text-in-file "Test"
964 (equal (concat (file-name-as-directory ".")
965 (file-name-nondirectory
966 (file-name-sans-extension (buffer-file-name))))
967 (file-name-sans-extension (org-export-output-file-name ".ext")))))
968 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
970 (org-test-with-temp-text-in-file
971 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
972 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
973 ;; From a buffer not associated to a file, too.
975 (org-test-with-temp-text
976 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
977 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
978 ;; When provided name is absolute, preserve it.
980 (org-test-with-temp-text
981 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
982 (expand-file-name "test"))
983 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
984 ;; When PUB-DIR argument is provided, use it.
986 (org-test-with-temp-text-in-file "Test"
987 (equal (file-name-directory
988 (org-export-output-file-name ".ext" nil
"dir/"))
990 ;; When returned name would overwrite original file, add EXTENSION
993 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
994 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
996 (ert-deftest test-org-export
/expand-include
()
997 "Test file inclusion in an Org buffer."
998 ;; Error when file isn't specified.
1000 (org-test-with-temp-text "#+INCLUDE: dummy.org"
1001 (org-export-expand-include-keyword)))
1002 ;; Full insertion with recursive inclusion.
1007 (expand-file-name "examples/include.org" org-test-dir
))
1008 (replace-regexp-in-string
1009 (regexp-quote "#+INCLUDE: \"include2.org\"")
1010 "Success!" (buffer-string)))
1011 (org-test-with-temp-text
1012 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
1013 (org-export-expand-include-keyword)
1015 ;; Localized insertion.
1016 (org-test-with-temp-text
1017 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
1019 (org-export-expand-include-keyword)
1020 (should (equal (buffer-string)
1021 "Small Org file with an include keyword.\n")))
1022 ;; Insertion with constraints on headlines level.
1025 "* Top heading\n** Heading\nbody\n"
1026 (org-test-with-temp-text
1028 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
1030 (org-export-expand-include-keyword)
1034 "* Top heading\n* Heading\nbody\n"
1035 (org-test-with-temp-text
1037 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
1039 (org-export-expand-include-keyword)
1041 ;; Inclusion within an example block.
1044 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
1045 (org-test-with-temp-text
1046 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
1048 (org-export-expand-include-keyword)
1050 ;; Inclusion within a src-block.
1053 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
1054 (org-test-with-temp-text
1056 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
1058 (org-export-expand-include-keyword)
1060 ;; Inclusion within an html export-block.
1063 "#+BEGIN_EXPORT html\n<p>HTML!</p>\n#+END_EXPORT\n"
1064 (org-test-with-temp-text
1066 "#+INCLUDE: \"%s/examples/include.html\" EXPORT html"
1068 (org-export-expand-include-keyword)
1070 ;; Inclusion within an center paragraph
1073 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
1074 (org-test-with-temp-text
1076 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
1078 (org-export-expand-include-keyword)
1080 ;; Footnotes labels are local to each included file.
1086 Footnotes[fn:1], [fn:test], [fn:test] and [fn:inline:inline footnote].
1088 \[fn:test] Footnote \"test\""))
1089 (org-test-with-temp-text-in-file contents
1090 (let ((file1 (buffer-file-name)))
1091 (org-test-with-temp-text-in-file contents
1092 (let ((file2 (buffer-file-name)))
1093 (org-test-with-temp-text
1094 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
1096 (org-export-expand-include-keyword)
1097 (org-element-map (org-element-parse-buffer)
1099 (lambda (r) (org-element-property :label r
)))))))))))))
1100 ;; Footnotes labels are not local to each include keyword.
1106 Footnotes[fn:1], [fn:test] and [fn:inline:inline footnote].
1108 \[fn:test] Footnote \"test\""))
1109 (org-test-with-temp-text-in-file contents
1110 (let ((file (buffer-file-name)))
1111 (org-test-with-temp-text
1112 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
1113 (org-export-expand-include-keyword)
1114 (org-element-map (org-element-parse-buffer)
1116 (lambda (ref) (org-element-property :label ref
)))))))))))
1117 ;; Footnotes are supported by :lines-like elements and unnecessary
1118 ;; footnotes are dropped.
1127 Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
1132 \[fn:test] Footnote \"test\"
1134 (org-test-with-temp-text-in-file contents
1135 (let ((file (buffer-file-name)))
1136 (org-test-with-temp-text
1137 (format "#+INCLUDE: \"%s::*bar\"\n" file
)
1138 (org-export-expand-include-keyword)
1139 (org-element-map (org-element-parse-buffer)
1140 'footnote-definition
1141 (lambda (ref) (org-element-property :label ref
)))))))))))
1142 ;; If only-contents is non-nil only include contents of element.
1146 (org-test-with-temp-text
1148 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" "
1151 (org-export-expand-include-keyword)
1153 ;; Headings can be included via CUSTOM_ID.
1155 (org-test-with-temp-text
1156 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1157 (org-export-expand-include-keyword)
1158 (goto-char (point-min))
1159 (looking-at "* Another heading")))
1160 ;; Named objects can be included.
1164 (org-test-with-temp-text
1165 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t"
1167 (org-export-expand-include-keyword)
1169 ;; Including non-existing elements should result in an error.
1171 (org-test-with-temp-text
1172 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\""
1174 (org-export-expand-include-keyword)))
1175 ;; Lines work relatively to an included element.
1179 (org-test-with-temp-text
1180 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t \
1183 (org-export-expand-include-keyword)
1185 ;; Properties should be dropped from headlines.
1188 (org-test-with-temp-text
1189 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t"
1191 (org-export-expand-include-keyword)
1193 (org-test-with-temp-text
1194 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1195 (org-export-expand-include-keyword)
1197 ;; Properties should be dropped, drawers should not be.
1200 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1201 (org-test-with-temp-text
1202 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t"
1204 (org-export-expand-include-keyword)
1206 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1208 (cl-every (lambda (level) (zerop (1- level
)))
1209 (org-test-with-temp-text
1211 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n"
1213 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\""
1215 (org-export-expand-include-keyword)
1216 (org-element-map (org-element-parse-buffer) 'headline
1217 (lambda (head) (org-element-property :level head
))))))
1218 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1221 (org-test-with-temp-text
1222 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp"
1224 (org-export-expand-include-keyword)
1226 (org-test-with-temp-text
1228 "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1"
1230 (org-export-expand-include-keyword)
1232 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1234 (org-test-with-temp-text-in-file
1235 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\""
1237 (narrow-to-region (point) (point-max))
1238 (org-export-expand-include-keyword)
1239 (eq 1 (org-current-level))))
1240 ;; If :minlevel is present do not alter it.
1242 (org-test-with-temp-text
1244 "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3"
1246 (narrow-to-region (point) (point-max))
1247 (org-export-expand-include-keyword)
1248 (eq 3 (org-current-level)))))
1250 (ert-deftest test-org-export
/expand-macro
()
1251 "Test macro expansion in an Org buffer."
1253 ;; Standard macro expansion.
1255 (equal "#+MACRO: macro1 value\nvalue\n"
1256 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1257 (org-export-as (org-test-default-backend)))))
1258 ;; Allow macro in parsed keywords and associated properties.
1259 ;; Standard macro expansion.
1263 (let ((backend (org-export-create-backend
1265 :options
'((:k
"K" nil nil parse
)))))
1266 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1267 (org-export-as backend
)))))
1271 (let ((backend (org-export-create-backend
1273 :options
'((:k
"K" nil nil parse
)))))
1274 (org-test-with-temp-text
1275 "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1276 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1277 ;; Expand specific macros.
1279 (equal "me 2012-03-29 me@here Title\n"
1280 (org-test-with-temp-text
1286 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1287 (let ((output (org-export-as (org-test-default-backend))))
1288 (substring output
(string-match ".*\n\\'" output
))))))
1289 ;; Expand specific macros when property contained a regular macro
1293 (org-test-with-temp-text "
1294 #+MACRO: macro1 value
1295 #+TITLE: {{{macro1}}}
1297 (let ((output (org-export-as (org-test-default-backend))))
1298 (substring output
(string-match ".*\n\\'" output
))))))
1299 ;; Expand macros with templates in included files.
1302 (org-test-with-temp-text
1303 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1304 {{{included-macro}}}" org-test-dir
)
1305 (let ((output (org-export-as (org-test-default-backend))))
1306 (substring output
(string-match ".*\n\\'" output
))))))
1307 ;; Date macro takes a optional formatting argument
1310 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1311 (org-export-as (org-test-default-backend)))))
1312 ;; Only single timestamps are formatted
1314 (equal "<2015-02x-09>\n"
1315 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1316 (org-export-as (org-test-default-backend)))))
1317 ;; Throw an error when a macro definition is missing.
1319 (org-test-with-temp-text "{{{missing}}}"
1320 (org-export-as (org-test-default-backend))))
1321 ;; Macros defined in commented subtrees are ignored.
1323 (org-test-with-temp-text
1324 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1325 (org-export-as (org-test-default-backend))))
1327 (org-test-with-temp-text
1328 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1329 (org-export-as (org-test-default-backend)))))
1331 (ert-deftest test-org-export
/before-processing-hook
()
1332 "Test `org-export-before-processing-hook'."
1335 "#+MACRO: mac val\nTest\n"
1336 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1337 (let ((org-export-before-processing-hook
1339 (while (re-search-forward "{{{" nil t
)
1340 (let ((object (org-element-context)))
1341 (when (eq (org-element-type object
) 'macro
)
1343 (org-element-property :begin object
)
1344 (org-element-property :end object
)))))))))
1345 (org-export-as (org-test-default-backend)))))))
1347 (ert-deftest test-org-export
/before-parsing-hook
()
1348 "Test `org-export-before-parsing-hook'."
1350 (equal "Body 1\nBody 2\n"
1351 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1352 (let ((org-export-before-parsing-hook
1354 (goto-char (point-min))
1355 (while (re-search-forward org-outline-regexp-bol nil t
)
1357 (point-at-bol) (progn (forward-line) (point))))))))
1358 (org-export-as (org-test-default-backend)))))))
1362 ;;; Affiliated Keywords
1364 (ert-deftest test-org-export
/read-attribute
()
1365 "Test `org-export-read-attribute' specifications."
1369 (org-export-read-attribute
1371 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1372 (org-element-at-point)))
1374 ;; Return nil on empty attribute.
1376 (org-export-read-attribute
1378 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1379 ;; Return nil on "nil" string.
1381 (equal '(:a nil
:b nil
)
1382 (org-export-read-attribute
1384 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1385 (org-element-at-point)))))
1386 ;; Return nil on empty string.
1388 (equal '(:a nil
:b nil
)
1389 (org-export-read-attribute
1391 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1392 (org-element-at-point)))))
1393 ;; Return empty string when value is "".
1396 (org-export-read-attribute
1398 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1399 (org-element-at-point)))))
1400 ;; Return \"\" when value is """".
1403 (org-export-read-attribute
1405 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1406 (org-element-at-point)))))
1407 ;; Ignore text before first property.
1410 (org-export-read-attribute
1412 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1413 (org-element-at-point))))))
1415 (ert-deftest test-org-export
/get-caption
()
1416 "Test `org-export-get-caption' specifications."
1417 ;; Without optional argument, return long caption
1421 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1422 (org-export-get-caption (org-element-at-point)))))
1423 ;; With optional argument, return short caption.
1427 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1428 (org-export-get-caption (org-element-at-point) t
))))
1429 ;; Multiple lines are separated by white spaces.
1433 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1434 (org-export-get-caption (org-element-at-point))))))
1440 (ert-deftest test-org-export
/define-backend
()
1441 "Test back-end definition and accessors."
1444 (equal '((headline . my-headline-test
))
1445 (let (org-export-registered-backends)
1446 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1447 (org-export-get-all-transcoders 'test
))))
1450 (equal '((:filter-headline . my-filter
))
1451 (let (org-export-registered-backends)
1452 (org-export-define-backend 'test
1453 '((headline . my-headline-test
))
1454 :filters-alist
'((:filter-headline . my-filter
)))
1455 (org-export-backend-filters (org-export-get-backend 'test
)))))
1458 (equal '((:prop value
))
1459 (let (org-export-registered-backends)
1460 (org-export-define-backend 'test
1461 '((headline . my-headline-test
))
1462 :options-alist
'((:prop value
)))
1463 (org-export-backend-options (org-export-get-backend 'test
)))))
1466 (equal '(?k
"Test Export" test
)
1467 (let (org-export-registered-backends)
1468 (org-export-define-backend 'test
1469 '((headline . my-headline-test
))
1470 :menu-entry
'(?k
"Test Export" test
))
1471 (org-export-backend-menu (org-export-get-backend 'test
))))))
1473 (ert-deftest test-org-export
/define-derived-backend
()
1474 "Test `org-export-define-derived-backend' specifications."
1475 ;; Error when parent back-end is not defined.
1477 (let (org-export-registered-backends)
1478 (org-export-define-derived-backend 'test
'parent
)))
1479 ;; Append translation table to parent's.
1481 (equal '((:headline . test
) (:headline . parent
))
1482 (let (org-export-registered-backends)
1483 (org-export-define-backend 'parent
'((:headline . parent
)))
1484 (org-export-define-derived-backend 'test
'parent
1485 :translate-alist
'((:headline . test
)))
1486 (org-export-get-all-transcoders 'test
))))
1487 ;; Options defined in the new back have priority over those defined
1491 (let (org-export-registered-backends)
1492 (org-export-define-backend 'parent
1493 '((:headline . parent
))
1494 :options-alist
'((:a nil nil
'parent
)))
1495 (org-export-define-derived-backend 'test
'parent
1496 :options-alist
'((:a nil nil
'test
)))
1497 (plist-get (org-export--get-global-options
1498 (org-export-get-backend 'test
))
1501 (ert-deftest test-org-export
/derived-backend-p
()
1502 "Test `org-export-derived-backend-p' specifications."
1503 ;; Non-nil with direct match.
1505 (let (org-export-registered-backends)
1506 (org-export-define-backend 'test
'((headline . test
)))
1507 (org-export-derived-backend-p 'test
'test
)))
1509 (let (org-export-registered-backends)
1510 (org-export-define-backend 'test
'((headline . test
)))
1511 (org-export-define-derived-backend 'test2
'test
)
1512 (org-export-derived-backend-p 'test2
'test2
)))
1513 ;; Non-nil with a direct parent.
1515 (let (org-export-registered-backends)
1516 (org-export-define-backend 'test
'((headline . test
)))
1517 (org-export-define-derived-backend 'test2
'test
)
1518 (org-export-derived-backend-p 'test2
'test
)))
1519 ;; Non-nil with an indirect parent.
1521 (let (org-export-registered-backends)
1522 (org-export-define-backend 'test
'((headline . test
)))
1523 (org-export-define-derived-backend 'test2
'test
)
1524 (org-export-define-derived-backend 'test3
'test2
)
1525 (org-export-derived-backend-p 'test3
'test
)))
1528 (let (org-export-registered-backends)
1529 (org-export-define-backend 'test
'((headline . test
)))
1530 (org-export-define-backend 'test2
'((headline . test2
)))
1531 (org-export-derived-backend-p 'test2
'test
)))
1533 (let (org-export-registered-backends)
1534 (org-export-define-backend 'test
'((headline . test
)))
1535 (org-export-define-backend 'test2
'((headline . test2
)))
1536 (org-export-define-derived-backend 'test3
'test2
)
1537 (org-export-derived-backend-p 'test3
'test
))))
1539 (ert-deftest test-org-export
/get-all-transcoders
()
1540 "Test `org-export-get-all-transcoders' specifications."
1541 ;; Return nil when back-end cannot be found.
1542 (should-not (org-export-get-all-transcoders nil
))
1543 ;; Same as `org-export-transcoders' if no parent.
1545 (equal '((headline . ignore
))
1546 (org-export-get-all-transcoders
1547 (org-export-create-backend
1548 :transcoders
'((headline . ignore
))))))
1549 ;; But inherit from all ancestors whenever possible.
1551 (equal '((section . ignore
) (headline . ignore
))
1552 (let (org-export-registered-backends)
1553 (org-export-define-backend 'b1
'((headline . ignore
)))
1554 (org-export-get-all-transcoders
1555 (org-export-create-backend
1556 :parent
'b1
:transcoders
'((section . ignore
)))))))
1558 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1559 (let (org-export-registered-backends)
1560 (org-export-define-backend 'b1
'((headline . ignore
)))
1561 (org-export-define-derived-backend 'b2
'b1
1562 :translate-alist
'((section . ignore
)))
1563 (org-export-get-all-transcoders
1564 (org-export-create-backend
1565 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1566 ;; Back-end transcoders overrule inherited ones.
1569 (let (org-export-registered-backends)
1570 (org-export-define-backend 'b1
'((headline . a
)))
1571 (cdr (assq 'headline
1572 (org-export-get-all-transcoders
1573 (org-export-create-backend
1574 :parent
'b1
:transcoders
'((headline . b
))))))))))
1576 (ert-deftest test-org-export
/get-all-options
()
1577 "Test `org-export-get-all-options' specifications."
1578 ;; Return nil when back-end cannot be found.
1579 (should-not (org-export-get-all-options nil
))
1580 ;; Same as `org-export-options' if no parent.
1582 (equal '((headline . ignore
))
1583 (org-export-get-all-options
1584 (org-export-create-backend
1585 :options
'((headline . ignore
))))))
1586 ;; But inherit from all ancestors whenever possible.
1588 (equal '((:key2 value2
) (:key1 value1
))
1589 (let (org-export-registered-backends)
1590 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1591 (org-export-get-all-options
1592 (org-export-create-backend
1593 :parent
'b1
:options
'((:key2 value2
)))))))
1595 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1596 (let (org-export-registered-backends)
1597 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1598 (org-export-define-derived-backend 'b2
'b1
1599 :options-alist
'((:key2 value2
)))
1600 (org-export-get-all-options
1601 (org-export-create-backend
1602 :parent
'b2
:options
'((:key3 value3
)))))))
1603 ;; Back-end options overrule inherited ones.
1606 (let (org-export-registered-backends)
1607 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1609 (org-export-get-all-options
1610 (org-export-create-backend
1611 :parent
'b1
:options
'((:key1 . b
))))))))))
1613 (ert-deftest test-org-export
/get-all-filters
()
1614 "Test `org-export-get-all-filters' specifications."
1615 ;; Return nil when back-end cannot be found.
1616 (should-not (org-export-get-all-filters nil
))
1617 ;; Same as `org-export-filters' if no parent.
1619 (equal '((:filter-headline . ignore
))
1620 (org-export-get-all-filters
1621 (org-export-create-backend
1622 :filters
'((:filter-headline . ignore
))))))
1623 ;; But inherit from all ancestors whenever possible.
1625 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1626 (let (org-export-registered-backends)
1627 (org-export-define-backend 'b1
1628 nil
:filters-alist
'((:filter-headline . ignore
)))
1629 (org-export-get-all-filters
1630 (org-export-create-backend
1631 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1633 (equal '((:filter-paragraph . ignore
)
1634 (:filter-section . ignore
)
1635 (:filter-headline . ignore
))
1636 (let (org-export-registered-backends)
1637 (org-export-define-backend 'b1
1638 nil
:filters-alist
'((:filter-headline . ignore
)))
1639 (org-export-define-derived-backend 'b2
'b1
1640 :filters-alist
'((:filter-section . ignore
)))
1641 (org-export-get-all-filters
1642 (org-export-create-backend
1643 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1644 ;; Back-end filters overrule inherited ones.
1647 (let (org-export-registered-backends)
1648 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1649 (cdr (assq :filter-headline
1650 (org-export-get-all-filters
1651 (org-export-create-backend
1652 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1654 (ert-deftest test-org-export
/with-backend
()
1655 "Test `org-export-with-backend' definition."
1656 ;; Error when calling an undefined back-end
1657 (should-error (org-export-with-backend nil
"Test"))
1658 ;; Error when called back-end doesn't have an appropriate
1661 (org-export-with-backend
1662 (org-export-create-backend :transcoders
'((headline . ignore
)))
1664 ;; Otherwise, export using correct transcoder
1667 (let (org-export-registered-backends)
1668 (org-export-define-backend 'test
1669 '((plain-text .
(lambda (text contents info
) "Failure"))))
1670 (org-export-define-backend 'test2
1671 '((plain-text .
(lambda (text contents info
) "Success"))))
1672 (org-export-with-backend 'test2
"Test"))))
1673 ;; Provide correct back-end if transcoder needs to use recursive
1677 (let ((test-back-end
1678 (org-export-create-backend
1680 (list (cons 'headline
1681 (lambda (headline contents info
)
1683 (org-element-property :title headline
)
1685 (cons 'plain-text
(lambda (text info
) "Success"))))))
1686 (org-export-string-as
1688 (org-export-create-backend
1690 (list (cons 'headline
1691 (lambda (headline contents info
)
1692 (org-export-with-backend
1693 test-back-end headline contents info
))))))))))
1695 (ert-deftest test-org-export
/data-with-backend
()
1696 "Test `org-export-data-with-backend' specifications."
1697 ;; Error when calling an undefined back-end.
1698 (should-error (org-export-data-with-backend nil
"nil" nil
))
1699 ;; Otherwise, export data recursively, using correct back-end.
1703 (org-export-data-with-backend
1705 (org-export-create-backend
1707 '((plain-text .
(lambda (text info
) "Success"))
1708 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1709 '(:with-emphasize t
)))))
1715 (ert-deftest test-org-export
/comments
()
1716 "Test comments handling during export.
1717 In particular, structure of the document mustn't be altered after
1720 (equal (org-test-with-temp-text "
1726 (org-export-as (org-test-default-backend)))
1727 "Para1\n\nPara2\n"))
1729 (equal (org-test-with-temp-text "
1733 (org-export-as (org-test-default-backend)))
1734 "Para1\n\nPara2\n"))
1736 (equal (org-test-with-temp-text "
1741 # Outside definition
1743 (org-export-as (org-test-default-backend)))
1744 "[fn:1] Para1\n\n\nPara2\n"))
1746 (equal (org-test-with-temp-text "
1754 (org-export-as (org-test-default-backend)))
1755 "[fn:1] Para1\n\nPara2\n"))
1757 (equal (org-test-with-temp-text "
1762 (org-export-as (org-test-default-backend)))
1763 "[fn:1] Para1\n\nPara2\n"))
1765 (equal (org-test-with-temp-text "
1770 (org-export-as (org-test-default-backend)))
1771 "[fn:1] Para1\n\nPara2\n")))
1777 (ert-deftest test-org-export
/export-block
()
1778 "Test export blocks transcoding."
1781 (org-test-with-temp-text
1782 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1784 (org-export-create-backend
1785 :transcoders
'((export-block .
(lambda (b _c _i
)
1786 (org-element-property :value b
)))
1787 (section .
(lambda (_s c _i
) c
))))))))
1790 (org-test-with-temp-text
1791 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1793 (org-export-create-backend
1798 (and (equal (org-element-property :type b
) "BACKEND")
1799 (org-element-property :value b
))))
1800 (cons 'section
(lambda (_s c _i
) c
)))))))))
1805 (ert-deftest test-org-export
/export-snippet
()
1806 "Test export snippets transcoding."
1808 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1809 (let ((backend (org-test-default-backend)))
1810 (setf (org-export-backend-name backend
) 'test
)
1811 (setf (org-export-backend-transcoders backend
)
1812 (cons (cons 'export-snippet
1813 (lambda (snippet contents info
)
1814 (when (eq (org-export-snippet-backend snippet
) 'test
)
1815 (org-element-property :value snippet
))))
1816 (org-export-backend-transcoders backend
)))
1817 (let ((org-export-snippet-translation-alist nil
))
1818 (should (equal (org-export-as backend
) "A\n")))
1819 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1820 (should (equal (org-export-as backend
) "AB\n")))))
1821 ;; Ignored export snippets do not remove any blank.
1823 (equal "begin end\n"
1824 (org-test-with-parsed-data "begin @@test:A@@ end"
1825 (org-export-data-with-backend
1827 (org-export-create-backend
1829 '((paragraph .
(lambda (paragraph contents info
) contents
))
1830 (section .
(lambda (section contents info
) contents
))))
1836 (ert-deftest test-org-export
/filter-apply-functions
()
1837 "Test `org-export-filter-apply-functions' specifications."
1838 ;; Functions are applied in order and return values are reduced.
1841 (org-export-filter-apply-functions
1842 (list (lambda (value &rest _
) (concat "1" value
))
1843 (lambda (value &rest _
) (concat "2" value
)))
1845 ;; Functions returning nil are skipped.
1848 (org-export-filter-apply-functions
1849 (list #'ignore
(lambda (value &rest _
) (concat "2" value
)))
1851 ;; If all functions are skipped, return the initial value.
1854 (org-export-filter-apply-functions (list #'ignore
) "0" nil
)))
1855 ;; If any function returns the empty string, final value is the
1859 (org-export-filter-apply-functions
1860 (list (lambda (value &rest _
) "")
1861 (lambda (value &rest _
) (concat "2" value
)))
1863 ;; Any function returning the empty string short-circuits the
1866 (org-export-filter-apply-functions
1867 (list (lambda (value &rest _
) "")
1868 (lambda (value &rest _
) (error "This shouldn't happen")))
1874 (ert-deftest test-org-export
/footnote-first-reference-p
()
1875 "Test `org-export-footnote-first-reference-p' specifications."
1879 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1882 (org-export-create-backend
1884 `(,(cons 'footnote-reference
1886 (push (org-export-footnote-first-reference-p f i
)
1889 (section .
(lambda (s c i
) c
))
1890 (paragraph .
(lambda (p c i
) c
))))
1891 nil nil nil
'(:with-footnotes t
))
1892 (nreverse result
)))))
1893 ;; Limit check to DATA, when non-nil.
1897 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1899 (org-element-map tree
'footnote-reference
1902 (org-export-footnote-first-reference-p
1903 ref info
(org-element-map tree
'headline
#'identity info t
))
1906 (nreverse result
)))))
1910 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1912 (org-element-map tree
'footnote-reference
1914 (push (org-export-footnote-first-reference-p ref info
) result
))
1916 (nreverse result
)))))
1917 ;; If optional argument BODY-FIRST is non-nil, first find footnote
1918 ;; in the main body of the document. Otherwise, enter footnote
1919 ;; definitions when they are encountered.
1923 (org-test-with-temp-text
1924 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1927 (org-export-create-backend
1929 `(,(cons 'footnote-reference
1931 (when (org-element-lineage f
'(drawer))
1932 (push (org-export-footnote-first-reference-p f i nil
)
1935 (drawer .
(lambda (d c i
) c
))
1936 (footnote-definition .
(lambda (d c i
) c
))
1937 (section .
(lambda (s c i
) c
))
1938 (paragraph .
(lambda (p c i
) c
))))
1939 nil nil nil
'(:with-footnotes t
))
1940 (nreverse result
)))))
1944 (org-test-with-temp-text
1945 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1948 (org-export-create-backend
1950 `(,(cons 'footnote-reference
1952 (when (org-element-lineage f
'(drawer))
1953 (push (org-export-footnote-first-reference-p f i nil t
)
1956 (drawer .
(lambda (d c i
) c
))
1957 (footnote-definition .
(lambda (d c i
) c
))
1958 (section .
(lambda (s c i
) c
))
1959 (paragraph .
(lambda (p c i
) c
))))
1960 nil nil nil
'(:with-footnotes t
))
1961 (nreverse result
))))))
1963 (ert-deftest test-org-export
/get-footnote-number
()
1964 "Test `org-export-get-footnote-number' specifications."
1967 (org-test-with-parsed-data
1968 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
1969 (org-element-map tree
'footnote-reference
1970 (lambda (ref) (org-export-get-footnote-number ref info
))
1972 ;; Anonymous footnotes all get a new number.
1975 (org-test-with-parsed-data
1976 "Text[fn::anon1][fn::anon2]"
1977 (org-element-map tree
'footnote-reference
1978 (lambda (ref) (org-export-get-footnote-number ref info
))
1980 ;; Test nested footnotes order.
1983 '((1 .
"1") (2 .
"2") (3 .
"3") (3 .
"3") (4))
1984 (org-test-with-parsed-data
1985 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1986 (org-element-map tree
'footnote-reference
1988 (cons (org-export-get-footnote-number ref info
)
1989 (org-element-property :label ref
)))
1991 ;; Limit number to provided DATA, when non-nil.
1995 (org-test-with-parsed-data
1996 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1997 (org-element-map tree
'footnote-reference
1999 (org-export-get-footnote-number
2000 ref info
(org-element-map tree
'headline
#'identity info t
)))
2005 (org-test-with-parsed-data
2006 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
2007 (org-element-map tree
'footnote-reference
2008 (lambda (ref) (org-export-get-footnote-number ref info
))
2010 ;; With a non-nil BODY-FIRST optional argument, first check body,
2011 ;; then footnote definitions.
2014 '(("1" .
1) ("2" .
2) ("3" .
3) ("3" .
3))
2015 (org-test-with-parsed-data
2016 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2017 (org-element-map tree
'footnote-reference
2019 (cons (org-element-property :label ref
)
2020 (org-export-get-footnote-number ref info nil t
)))
2024 '(("1" .
1) ("2" .
3) ("3" .
2) ("3" .
2))
2025 (org-test-with-parsed-data
2026 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2027 (org-element-map tree
'footnote-reference
2029 (cons (org-element-property :label ref
)
2030 (org-export-get-footnote-number ref info nil
)))
2033 (ert-deftest test-org-export
/get-footnote-definition
()
2034 "Test `org-export-get-footnote-definition' specifications."
2038 (org-element-interpret-data
2039 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1] A"
2040 (org-export-get-footnote-definition
2041 (org-element-map tree
'footnote-reference
#'identity nil t
)
2043 ;; Raise an error if no definition is found.
2045 (org-test-with-parsed-data "Text[fn:1]"
2046 (org-export-get-footnote-definition
2047 (org-element-map tree
'footnote-reference
#'identity nil t
)
2049 ;; Find inline definitions.
2052 (org-element-interpret-data
2053 (org-test-with-parsed-data "Text[fn:1:A]"
2054 (org-export-get-footnote-definition
2055 (org-element-map tree
'footnote-reference
#'identity nil t
)
2057 ;; Find anonymous definitions.
2060 (org-element-interpret-data
2061 (org-test-with-parsed-data "Text[fn::A]"
2062 (org-export-get-footnote-definition
2063 (org-element-map tree
'footnote-reference
#'identity nil t
)
2065 ;; Find empty definitions.
2068 (org-element-interpret-data
2069 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1]"
2070 (org-export-get-footnote-definition
2071 (org-element-map tree
'footnote-reference
#'identity nil t
)
2075 (org-element-interpret-data
2076 (org-test-with-parsed-data "Text[fn:1:]"
2077 (org-export-get-footnote-definition
2078 (org-element-map tree
'footnote-reference
#'identity nil t
)
2082 (org-element-interpret-data
2083 (org-test-with-parsed-data "Text[fn::]"
2084 (org-export-get-footnote-definition
2085 (org-element-map tree
'footnote-reference
#'identity nil t
)
2088 (ert-deftest test-org-export
/collect-footnote-definitions
()
2089 "Test `org-export-collect-footnote-definitions' specifications."
2092 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2094 \[fn:2] B [fn:3] [fn::D].
2097 (length (org-export-collect-footnote-definitions info
)))))
2098 ;; Limit number to provided DATA, when non-nil.
2102 (org-test-with-parsed-data
2103 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2105 (org-export-collect-footnote-definitions
2106 info
(org-element-map tree
'headline
#'identity info t
))))))
2110 (org-test-with-parsed-data
2111 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2112 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
2113 ;; With optional argument BODY-FIRST, first check body, then
2114 ;; footnote definitions.
2116 (equal '("1" "3" "2" nil
)
2117 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2119 \[fn:2] B [fn:3] [fn::D].
2122 (mapcar (lambda (e) (nth 1 e
))
2123 (org-export-collect-footnote-definitions info nil t
)))))
2125 (equal '("1" "3" "2" nil
)
2126 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2128 \[fn:2] B [fn:3] [fn::D].
2131 (mapcar (lambda (e) (nth 1 e
))
2132 (org-export-collect-footnote-definitions info
))))))
2134 (ert-deftest test-org-export
/footnotes
()
2135 "Miscellaneous tests on footnotes."
2136 (let ((org-footnote-section nil
)
2137 (org-export-with-footnotes t
))
2138 ;; Read every type of footnote.
2141 '((1 .
"A\n") (2 .
"C") (3 .
"D"))
2142 (org-test-with-parsed-data
2143 "Text[fn:1] [fn:label:C] [fn::D]\n\n[fn:1] A\n"
2144 (org-element-map tree
'footnote-reference
2146 (let ((def (org-export-get-footnote-definition ref info
)))
2147 (cons (org-export-get-footnote-number ref info
)
2148 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
2149 (car (org-element-contents
2150 (car (org-element-contents def
))))))))
2152 ;; Export nested footnote in invisible definitions.
2155 (org-test-with-temp-text "Text[fn:1]\n\n[fn:1] B [fn:2]\n\n[fn:2] C."
2156 (narrow-to-region (point) (line-end-position))
2159 (org-export-create-backend
2164 (throw 'exit
(length
2165 (org-export-collect-footnote-definitions
2167 ;; Export footnotes defined outside parsing scope.
2171 (org-test-with-temp-text "[fn:1] Out of scope
2173 <point>Paragraph[fn:1]"
2174 (org-export-as (org-test-default-backend) 'subtree
))))
2178 (org-test-with-temp-text "[fn:1] Out of scope
2180 <point>Paragraph[fn:1]"
2181 (narrow-to-region (point) (point-max))
2182 (org-export-as (org-test-default-backend)))))
2183 ;; Export nested footnotes defined outside parsing scope.
2187 (org-test-with-temp-text "
2188 \[fn:1] Out of scope[fn:2]
2190 \[fn:2] Very out of scope
2192 <point>Paragraph[fn:1]"
2193 (org-export-as (org-test-default-backend) 'subtree
))))
2197 (org-test-with-temp-text "
2198 \[fn:1] Out of scope[fn:2]
2200 \[fn:2] Very out of scope
2202 <point>Paragraph[fn:1]"
2203 (narrow-to-region (point) (point-max))
2204 (org-export-as (org-test-default-backend)))))
2208 (org-test-with-temp-text "
2209 \[fn:1] Out of scope[fn:2:D2]
2211 <point>Paragraph[fn:1]"
2212 (narrow-to-region (point) (point-max))
2213 (org-export-as (org-test-default-backend)))))
2214 ;; Export footnotes in pruned parts of tree.
2218 (let ((org-export-exclude-tags '("noexport")))
2219 (org-test-with-temp-text
2220 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] Definition"
2221 (org-export-as (org-test-default-backend))))))
2225 (let ((org-export-select-tags '("export")))
2226 (org-test-with-temp-text
2227 "* H :export:\nText[fn:1]\n* H2\n[fn:1] Definition"
2228 (org-export-as (org-test-default-backend))))))
2229 ;; Export nested footnotes in pruned parts of tree.
2233 (let ((org-export-exclude-tags '("noexport")))
2234 (org-test-with-temp-text
2235 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2236 (org-export-as (org-test-default-backend))))))
2240 (let ((org-export-select-tags '("export")))
2241 (org-test-with-temp-text
2242 "* H :export:\nText[fn:1]\n* H2\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2243 (org-export-as (org-test-default-backend))))))
2244 ;; Handle uninterpreted data in pruned footnote definitions.
2248 (let ((org-export-with-tables nil
))
2249 (org-test-with-temp-text
2250 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1]\n| a |"
2251 (org-export-as (org-test-default-backend))))))
2252 ;; Footnotes without a definition should throw an error.
2254 (org-test-with-parsed-data "Text[fn:1]"
2255 (org-export-get-footnote-definition
2256 (org-element-map tree
'footnote-reference
#'identity info t
) info
)))
2257 ;; Footnote section should be ignored in TOC and in headlines
2260 (= 1 (let ((org-footnote-section "Footnotes"))
2261 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
2262 (org-export-collect-headlines info
))))))
2265 (let ((org-footnote-section "Footnotes"))
2266 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
2267 (org-element-map tree
'headline
2269 (when (equal (org-element-property :raw-value hl
) "H2")
2270 (org-export-get-headline-number hl info
)))
2275 ;;; Headlines and Inlinetasks
2277 (ert-deftest test-org-export
/get-relative-level
()
2278 "Test `org-export-get-relative-level' specifications."
2282 (let ((org-odd-levels-only nil
))
2283 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2284 (org-element-map tree
'headline
2285 (lambda (h) (org-export-get-relative-level h info
))
2290 (let ((org-odd-levels-only nil
))
2291 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
2292 (org-element-map tree
'headline
2293 (lambda (h) (org-export-get-relative-level h info
))
2296 (ert-deftest test-org-export
/low-level-p
()
2297 "Test `org-export-low-level-p' specifications."
2301 (let ((org-odd-levels-only nil
))
2302 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2303 (org-element-map tree
'headline
2304 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
2305 (plist-put info
:headline-levels
1)))))))
2307 (ert-deftest test-org-export
/get-headline-number
()
2308 "Test `org-export-get-headline-number' specifications."
2313 (let ((org-odd-levels-only nil
))
2314 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2315 (org-element-map tree
'headline
2316 (lambda (h) (org-export-get-headline-number h info
))
2318 ;; Missing levels are replaced with 0.
2322 (let ((org-odd-levels-only nil
))
2323 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
2324 (org-element-map tree
'headline
2325 (lambda (h) (org-export-get-headline-number h info
))
2328 (ert-deftest test-org-export
/numbered-headline-p
()
2329 "Test `org-export-numbered-headline-p' specifications."
2330 ;; If `:section-numbers' is nil, never number headlines.
2332 (org-test-with-parsed-data "* Headline"
2333 (org-element-map tree
'headline
2334 (lambda (h) (org-export-numbered-headline-p h info
))
2335 (plist-put info
:section-numbers nil
))))
2336 ;; If `:section-numbers' is a number, only number headlines with
2337 ;; a level greater that it.
2341 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2342 (org-element-map tree
'headline
2343 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
2344 (plist-put info
:section-numbers
1)))))
2345 ;; Otherwise, headlines are always numbered.
2347 (org-test-with-parsed-data "* Headline"
2348 (org-element-map tree
'headline
2349 (lambda (h) (org-export-numbered-headline-p h info
))
2350 (plist-put info
:section-numbers t
))))
2351 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
2353 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
2354 (org-export-numbered-headline-p
2355 (org-element-map tree
'headline
'identity info t
)
2357 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
2359 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
2360 (org-export-numbered-headline-p
2361 (org-element-map tree
'headline
#'identity info t
)
2363 ;; UNNUMBERED ignores inheritance. Any non-nil value among
2364 ;; ancestors disables numbering.
2366 (org-test-with-parsed-data
2377 (lambda (h) (not (org-export-numbered-headline-p h info
)))
2378 (org-element-map tree
'headline
#'identity info
)))))
2380 (ert-deftest test-org-export
/number-to-roman
()
2381 "Test `org-export-number-to-roman' specifications."
2382 ;; If number is negative, return it as a string.
2383 (should (equal (org-export-number-to-roman -
1) "-1"))
2384 ;; Otherwise, return it as a roman number.
2385 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
2387 (ert-deftest test-org-export
/get-optional-title
()
2388 "Test `org-export-get-alt-title' specifications."
2389 ;; If ALT_TITLE property is defined, use it.
2392 (org-test-with-parsed-data
2393 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
2394 (org-export-get-alt-title
2395 (org-element-map tree
'headline
'identity info t
)
2397 ;; Otherwise, fall-back to regular title.
2399 (equal '("Headline")
2400 (org-test-with-parsed-data "* Headline"
2401 (org-export-get-alt-title
2402 (org-element-map tree
'headline
'identity info t
)
2405 (ert-deftest test-org-export
/get-tags
()
2406 "Test `org-export-get-tags' specifications."
2407 ;; Standard test: tags which are not a select tag, an exclude tag,
2408 ;; or specified as optional argument shouldn't be ignored.
2410 (org-test-with-parsed-data "* Headline :tag:"
2411 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2413 ;; Tags provided in the optional argument are ignored.
2415 (org-test-with-parsed-data "* Headline :ignore:"
2416 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2418 ;; Allow tag inheritance.
2422 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2423 (org-element-map tree
'headline
2424 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2425 ;; Tag inheritance checks FILETAGS keywords.
2429 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2430 (org-element-map tree
'headline
2431 (lambda (hl) (org-export-get-tags hl info nil t
)) info
)))))
2433 (ert-deftest test-org-export
/get-node-property
()
2434 "Test`org-export-get-node-property' specifications."
2438 (org-test-with-parsed-data "* Headline
2442 (org-export-get-node-property
2443 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2444 ;; Test inheritance.
2447 (org-test-with-parsed-data "* Parent
2453 (org-export-get-node-property
2454 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2455 ;; Cannot return a value before the first headline.
2457 (org-test-with-parsed-data "Paragraph
2462 (org-export-get-node-property
2463 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2465 (ert-deftest test-org-export
/get-category
()
2466 "Test `org-export-get-category' specifications."
2470 (org-test-with-parsed-data "* Headline
2474 (org-export-get-category
2475 (org-element-map tree
'headline
'identity nil t
) info
))))
2476 ;; Test inheritance from a parent headline.
2478 (equal '("value" "value")
2479 (org-test-with-parsed-data "* Headline1
2484 (org-element-map tree
'headline
2485 (lambda (hl) (org-export-get-category hl info
)) info
))))
2486 ;; Test inheritance from #+CATEGORY keyword
2489 (org-test-with-parsed-data "#+CATEGORY: value
2491 (org-export-get-category
2492 (org-element-map tree
'headline
'identity nil t
) info
))))
2493 ;; Test inheritance from file name.
2496 (org-test-with-parsed-data "* Headline"
2497 (let ((info (plist-put info
:input-file
"~/test.org")))
2498 (org-export-get-category
2499 (org-element-map tree
'headline
'identity nil t
) info
)))))
2503 (org-test-with-parsed-data "* Headline"
2504 (org-export-get-category
2505 (org-element-map tree
'headline
'identity nil t
) info
)))))
2507 (ert-deftest test-org-export
/first-sibling-p
()
2508 "Test `org-export-first-sibling-p' specifications."
2513 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2514 (org-element-map tree
'headline
2515 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2519 (org-test-with-parsed-data "- item\n\n para"
2520 (org-element-map tree
'paragraph
2521 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2523 ;; Ignore sections for headlines.
2526 (org-test-with-parsed-data "* H\nSection\n** H 2"
2527 (org-element-map tree
'headline
2528 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2530 ;; Ignore headlines not exported.
2534 (let ((org-export-exclude-tags '("ignore")))
2535 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2536 (org-element-map tree
'headline
2537 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2540 (ert-deftest test-org-export
/last-sibling-p
()
2541 "Test `org-export-last-sibling-p' specifications."
2546 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2547 (org-element-map tree
'headline
2548 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2552 (org-test-with-parsed-data "- item\n\n para"
2553 (org-element-map tree
'paragraph
2554 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2556 ;; Ignore headlines not exported.
2560 (let ((org-export-exclude-tags '("ignore")))
2561 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2562 (org-element-map tree
'headline
2563 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2566 (ert-deftest test-org-export
/handle-inlinetasks
()
2567 "Test inlinetask export."
2568 ;; Inlinetask with an exclude tag.
2569 (when (featurep 'org-inlinetask
)
2573 (let ((org-inlinetask-min-level 3)
2574 org-export-filter-body-functions
2575 org-export-filter-final-output-functions
)
2576 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2577 (org-export-as (org-test-default-backend)
2578 nil nil nil
'(:exclude-tags
("noexp")))))))
2579 ;; Inlinetask with an include tag.
2582 "* H2\n*** Inline :exp:\n"
2583 (let ((org-inlinetask-min-level 3)
2584 (org-tags-column 0))
2585 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2586 (org-export-as (org-test-default-backend)
2587 nil nil nil
'(:select-tags
("exp")))))))
2588 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2591 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2592 (org-inlinetask-min-level 3)
2593 org-export-filter-body-functions
2594 org-export-filter-final-output-functions
)
2595 (org-test-with-temp-text "*** TODO Inline"
2596 (org-export-as (org-test-default-backend)
2597 nil nil nil
'(:with-tasks nil
))))))))
2603 (ert-deftest test-org-export
/get-date
()
2604 "Test `org-export-get-date' specifications."
2605 ;; Return a properly formatted string when
2606 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2607 ;; consists in a single timestamp.
2610 (let ((org-export-date-timestamp-format "%d %m %Y"))
2611 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2612 (org-export-get-date info
)))))
2613 ;; Return a secondary string otherwise.
2616 (let ((org-export-date-timestamp-format nil
))
2617 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2618 (org-export-get-date info
)))))
2621 (org-test-with-parsed-data "#+DATE: Date"
2622 (org-export-get-date info
))))
2623 ;; Optional argument has precedence over
2624 ;; `org-export-date-timestamp-format'.
2627 (let ((org-export-date-timestamp-format "%d %m %Y"))
2628 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2629 (org-export-get-date info
"%d %m"))))))
2635 (ert-deftest test-org-export
/custom-protocol-maybe
()
2636 "Test `org-export-custom-protocol-maybe' specifications."
2641 (org-link-set-parameters "foo" :export
(lambda (p d f
) "success"))
2642 (org-export-string-as
2644 (org-export-create-backend
2647 '((section .
(lambda (s c i
) c
))
2648 (paragraph .
(lambda (p c i
) c
))
2649 (link .
(lambda (l c i
)
2650 (or (org-export-custom-protocol-maybe l c
'test
)
2656 (org-link-set-parameters
2657 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2658 (org-export-string-as
2660 (org-export-create-backend
2663 '((section .
(lambda (s c i
) c
))
2664 (paragraph .
(lambda (p c i
) c
))
2665 (link .
(lambda (l c i
)
2666 (or (org-export-custom-protocol-maybe l c
'no-test
)
2668 ;; Ignore anonymous back-ends.
2673 (org-link-set-parameters
2674 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2675 (org-export-string-as
2677 (org-export-create-backend
2679 '((section .
(lambda (s c i
) c
))
2680 (paragraph .
(lambda (p c i
) c
))
2681 (link .
(lambda (l c i
)
2682 (or (org-export-custom-protocol-maybe l c nil
)
2685 (ert-deftest test-org-export
/get-coderef-format
()
2686 "Test `org-export-get-coderef-format' specifications."
2687 ;; A link without description returns "%s"
2688 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2690 ;; Return "%s" when path is matched within description.
2691 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2693 ;; Otherwise return description.
2694 (should (equal (org-export-get-coderef-format "path" "desc")
2697 (ert-deftest test-org-export
/inline-image-p
()
2698 "Test `org-export-inline-image-p' specifications."
2700 (org-export-inline-image-p
2701 (org-test-with-temp-text "[[#id]]"
2702 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2703 '(("custom-id" .
"id")))))
2705 (ert-deftest test-org-export
/fuzzy-link
()
2706 "Test fuzzy links specifications."
2707 ;; Link to an headline should return headline's number.
2709 ;; Note: Headline's number is in fact a list of numbers.
2711 (org-test-with-parsed-data
2712 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2713 (org-element-map tree
'link
2715 (org-export-get-ordinal
2716 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2717 ;; Link to a target in an item should return item's number.
2719 ;; Note: Item's number is in fact a list of numbers.
2721 (org-test-with-parsed-data
2722 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2723 (org-element-map tree
'link
2725 (org-export-get-ordinal
2726 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2727 ;; Link to a target in a footnote should return footnote's number.
2730 (org-test-with-parsed-data "
2731 Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
2735 (org-element-map tree
'link
2737 (org-export-get-ordinal
2738 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2739 ;; Link to a named element should return sequence number of that
2743 (org-test-with-parsed-data
2744 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2745 (org-element-map tree
'link
2747 (org-export-get-ordinal
2748 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2749 ;; Link to a target not within an item, a table, a footnote
2750 ;; reference or definition should return section number.
2753 (org-test-with-parsed-data
2754 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2755 (org-element-map tree
'link
2757 (org-export-get-ordinal
2758 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2759 ;; Space are not significant when matching a fuzzy link.
2761 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2762 (org-element-map tree
'link
2763 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2765 ;; Statistics cookies are ignored for headline match.
2767 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2768 (org-element-map tree
'link
2769 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2772 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2773 (org-element-map tree
'link
2774 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2777 (defun test-org-gen-loc-list(text type
)
2778 (org-test-with-parsed-data text
2779 (org-element-map tree type
2780 (lambda (el) (or (org-export-get-loc el info
) 'no-loc
)))))
2782 (ert-deftest test-org-export
/get-loc
()
2783 "Test `org-export-get-loc' specifications."
2785 ;; "-n" resets line number.
2787 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n\n Text\n#+END_EXAMPLE"
2789 ;; The first "+n" has 0 lines before it
2792 (test-org-gen-loc-list "#+BEGIN_EXAMPLE +n\n Text\n#+END_EXAMPLE"
2794 ;; "-n 10" resets line number but has "9 lines" before it.
2797 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n Text\n#+END_EXAMPLE"
2799 ;; -n10 with two lines then +n 15
2802 (test-org-gen-loc-list "
2803 #+BEGIN_EXAMPLE -n 10
2807 #+BEGIN_EXAMPLE +n 15
2813 (test-org-gen-loc-list "
2814 #+BEGIN_EXAMPLE -n 10
2817 #+BEGIN_EXAMPLE +n 10
2825 ;; an Example Block without -n does not add to the line count.
2827 (equal '(9 no-loc
19)
2828 (test-org-gen-loc-list "
2829 #+BEGIN_EXAMPLE -n 10
2835 #+BEGIN_EXAMPLE +n 10
2839 ;; "-n" resets line number.
2843 (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n \n (- 1 1) \n#+END_SRC"
2845 ;; The first "+n" has 0 lines before it.
2848 (test-org-gen-loc-list
2849 "#+BEGIN_SRC emacs-lisp +n \n (+ 0 (- 1 1))\n#+END_SRC"
2851 ;; "-n 10" resets line number but has "9 lines" before it.
2854 (test-org-gen-loc-list
2855 "#+BEGIN_SRC emacs-lisp -n 10\n (- 10 1)\n#+END_SRC"
2859 (test-org-gen-loc-list "
2860 #+BEGIN_SRC emacs-lisp -n 10
2864 #+BEGIN_SRC emacs-lisp +n 15
2865 (+ (- 10 1) 2 (- 15 1))
2870 (test-org-gen-loc-list "
2871 #+BEGIN_SRC emacs-lisp -n 10
2874 #+BEGIN_SRC emacs-lisp +n 10
2875 (+ (- 10 1) 1 (- 10 1))
2877 #+BEGIN_SRC emacs-lisp -n
2881 ;; A SRC Block without -n does not add to the line count.
2883 (equal '(9 no-loc
19)
2884 (test-org-gen-loc-list
2885 "#+BEGIN_SRC emacs-lisp -n 10
2888 #+BEGIN_SRC emacs-lisp
2891 #+BEGIN_SRC emacs-lisp +n 10
2892 (+ (- 10 1) 1 (- 10 1))
2896 (ert-deftest test-org-export
/resolve-coderef
()
2897 "Test `org-export-resolve-coderef' specifications."
2898 (let ((org-coderef-label-format "(ref:%s)"))
2899 ;; A link to a "-n -k -r" block returns line number.
2902 (org-test-with-parsed-data
2903 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2904 (org-export-resolve-coderef "coderef" info
))))
2907 (org-test-with-parsed-data
2908 "#+BEGIN_EXAMPLE -n 10 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2909 (org-export-resolve-coderef "coderef" info
))))
2912 (org-test-with-parsed-data
2913 "#+BEGIN_EXAMPLE -n 10 -k -r\nText \n#+END_EXAMPLE\n
2914 #+BEGIN_EXAMPLE +n 125 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2915 (org-export-resolve-coderef "coderef" info
))))
2918 (org-test-with-parsed-data
2919 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2920 (org-export-resolve-coderef "coderef" info
))))
2923 (org-test-with-parsed-data
2924 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2925 (org-export-resolve-coderef "coderef" info
))))
2928 (org-test-with-parsed-data
2929 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) \n#+END_SRC\n
2930 #+BEGIN_SRC emacs-lisp +n 125 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2931 (org-export-resolve-coderef "coderef" info
))))
2932 ;; A link to a "-n -r" block returns line number.
2935 (org-test-with-parsed-data
2936 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2937 (org-export-resolve-coderef "coderef" info
))))
2940 (org-test-with-parsed-data
2941 "#+BEGIN_EXAMPLE -n 10 -r\nText (ref:coderef)\n#+END_EXAMPLE"
2942 (org-export-resolve-coderef "coderef" info
))))
2945 (org-test-with-parsed-data
2946 "#+BEGIN_EXAMPLE +n 10 -r\nText \n#+END_EXAMPLE
2947 #+BEGIN_EXAMPLE +n 125 -r\nText (ref:coderef)\n#+END_EXAMPLE"
2948 (org-export-resolve-coderef "coderef" info
))))
2952 (org-test-with-parsed-data
2953 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2954 (org-export-resolve-coderef "coderef" info
))))
2957 (org-test-with-parsed-data
2958 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2959 (org-export-resolve-coderef "coderef" info
))))
2962 (org-test-with-parsed-data
2963 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) \n#+END_SRC
2964 #+BEGIN_SRC emacs-lisp +n125 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2965 (org-export-resolve-coderef "coderef" info
))))
2966 ;; A link to a "-n" block returns coderef.
2969 (org-test-with-parsed-data
2970 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2971 (org-export-resolve-coderef "coderef" info
))))
2974 (org-test-with-parsed-data
2975 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2976 (org-export-resolve-coderef "coderef" info
))))
2977 ;; A link to a "-r" block returns line number.
2980 (org-test-with-parsed-data
2981 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2982 (org-export-resolve-coderef "coderef" info
))))
2985 (org-test-with-parsed-data
2986 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2987 (org-export-resolve-coderef "coderef" info
))))
2988 ;; A link to a block without a switch returns coderef.
2991 (org-test-with-parsed-data
2992 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2993 (org-export-resolve-coderef "coderef" info
))))
2994 (org-test-with-parsed-data
2995 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2996 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2997 ;; Correctly handle continued line numbers. A "+n" switch should
2998 ;; resume numbering from previous block with numbered lines,
2999 ;; ignoring blocks not numbering lines in the process. A "-n"
3000 ;; switch resets count.
3003 (org-test-with-parsed-data "
3008 #+BEGIN_SRC emacs-lisp
3012 #+BEGIN_SRC emacs-lisp +n -r
3013 \(+ 1 1) (ref:addition)
3016 #+BEGIN_EXAMPLE -n -r
3017 Another text. (ref:text)
3019 (list (org-export-resolve-coderef "addition" info
)
3020 (org-export-resolve-coderef "text" info
)))))
3021 ;; Recognize coderef with user-specified syntax.
3025 (org-test-with-parsed-data
3026 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
3027 (org-export-resolve-coderef "text" info
))))
3028 ;; Unresolved coderefs raise a `org-link-broken' signal.
3031 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3032 (org-export-resolve-coderef "unknown" info
))
3033 (org-link-broken t
)))))
3035 (ert-deftest test-org-export
/resolve-fuzzy-link
()
3036 "Test `org-export-resolve-fuzzy-link' specifications."
3037 ;; Match target objects.
3039 (org-test-with-parsed-data "<<target>> [[target]]"
3040 (org-export-resolve-fuzzy-link
3041 (org-element-map tree
'link
'identity info t
) info
)))
3042 ;; Match named elements.
3044 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
3045 (org-export-resolve-fuzzy-link
3046 (org-element-map tree
'link
'identity info t
) info
)))
3047 ;; Match exact headline's name.
3049 (org-test-with-parsed-data "* My headline\n[[My headline]]"
3050 (org-export-resolve-fuzzy-link
3051 (org-element-map tree
'link
'identity info t
) info
)))
3052 ;; Targets objects have priority over headline titles.
3055 (org-test-with-parsed-data "* target\n<<target>>[[target]]"
3057 (org-export-resolve-fuzzy-link
3058 (org-element-map tree
'link
'identity info t
) info
)))))
3059 ;; Named elements have priority over headline titles.
3062 (org-test-with-parsed-data
3063 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
3065 (org-export-resolve-fuzzy-link
3066 (org-element-map tree
'link
'identity info t
) info
)))))
3067 ;; If link's path starts with a "*", only match headline titles,
3071 (org-test-with-parsed-data
3072 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
3074 (org-export-resolve-fuzzy-link
3075 (org-element-map tree
'link
'identity info t
) info
)))))
3076 ;; Raise a `org-link-broken' signal if no match.
3078 (org-test-with-parsed-data "[[target]]"
3080 (org-export-resolve-fuzzy-link
3081 (org-element-map tree
'link
#'identity info t
) info
)
3082 (org-link-broken t
))))
3083 ;; Match fuzzy link even when before first headline.
3086 (org-test-with-parsed-data "[[hl]]\n* hl"
3088 (org-export-resolve-fuzzy-link
3089 (org-element-map tree
'link
'identity info t
) info
)))))
3090 ;; Handle url-encoded fuzzy links.
3092 (org-test-with-parsed-data "* A B\n[[A%20B]]"
3093 (org-export-resolve-fuzzy-link
3094 (org-element-map tree
'link
#'identity info t
) info
))))
3096 (ert-deftest test-org-export
/resolve-id-link
()
3097 "Test `org-export-resolve-id-link' specifications."
3098 ;; Regular test for custom-id link.
3100 (equal '("Headline1")
3101 (org-test-with-parsed-data "* Headline1
3107 (org-element-property
3109 (org-export-resolve-id-link
3110 (org-element-map tree
'link
'identity info t
) info
)))))
3111 ;; Raise a `org-link-broken' signal on failing searches.
3113 (org-test-with-parsed-data "* Headline1
3120 (org-export-resolve-id-link
3121 (org-element-map tree
'link
#'identity info t
) info
)
3122 (org-link-broken t
))))
3123 ;; Test for internal id target.
3125 (equal '("Headline1")
3126 (org-test-with-parsed-data "* Headline1
3132 (org-element-property
3134 (org-export-resolve-id-link
3135 (org-element-map tree
'link
'identity info t
) info
)))))
3136 ;; Test for external id target.
3140 (org-test-with-parsed-data "[[id:aaaa]]"
3141 (org-export-resolve-id-link
3142 (org-element-map tree
'link
'identity info t
)
3143 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
3145 (ert-deftest test-org-export
/resolve-radio-link
()
3146 "Test `org-export-resolve-radio-link' specifications."
3149 (org-test-with-temp-text "<<<radio>>> radio"
3150 (org-update-radio-target-regexp)
3151 (let* ((tree (org-element-parse-buffer))
3152 (info `(:parse-tree
,tree
)))
3153 (org-export-resolve-radio-link
3154 (org-element-map tree
'link
'identity info t
)
3156 ;; Radio targets are case-insensitive.
3158 (org-test-with-temp-text "<<<RADIO>>> radio"
3159 (org-update-radio-target-regexp)
3160 (let* ((tree (org-element-parse-buffer))
3161 (info `(:parse-tree
,tree
)))
3162 (org-export-resolve-radio-link
3163 (org-element-map tree
'link
'identity info t
)
3165 ;; Radio target with objects.
3167 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
3168 (org-update-radio-target-regexp)
3169 (let* ((tree (org-element-parse-buffer))
3170 (info `(:parse-tree
,tree
)))
3171 (org-export-resolve-radio-link
3172 (org-element-map tree
'link
'identity info t
)
3174 ;; Radio target with objects at its beginning.
3176 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
3177 (org-update-radio-target-regexp)
3178 (let* ((tree (org-element-parse-buffer))
3179 (info `(:parse-tree
,tree
)))
3180 (org-export-resolve-radio-link
3181 (org-element-map tree
'link
'identity info t
)
3183 ;; Radio link next to an apostrophe.
3185 (org-test-with-temp-text "<<<radio>>> radio's"
3186 (org-update-radio-target-regexp)
3187 (let* ((tree (org-element-parse-buffer))
3188 (info `(:parse-tree
,tree
)))
3189 (org-export-resolve-radio-link
3190 (org-element-map tree
'link
'identity info t
)
3192 ;; Multiple radio targets.
3194 (equal '("radio1" "radio2")
3195 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
3196 (org-update-radio-target-regexp)
3197 (let* ((tree (org-element-parse-buffer))
3198 (info `(:parse-tree
,tree
)))
3199 (org-element-map tree
'link
3201 (org-element-property
3202 :value
(org-export-resolve-radio-link link info
)))
3204 ;; Radio target is whitespace insensitive.
3206 (org-test-with-temp-text "<<<a radio>>> a\n radio"
3207 (org-update-radio-target-regexp)
3208 (let* ((tree (org-element-parse-buffer))
3209 (info `(:parse-tree
,tree
)))
3210 (org-element-map tree
'link
3211 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
3213 (ert-deftest test-org-export
/file-uri
()
3214 "Test `org-export-file-uri' specifications."
3215 ;; Preserve relative filenames.
3216 (should (equal "relative.org" (org-export-file-uri "relative.org")))
3217 ;; Local files start with "file:///"
3218 (should (equal "file:///local.org" (org-export-file-uri "/local.org")))
3219 ;; Remote files start with "file://"
3220 (should (equal "file://myself@some.where:papers/last.pdf"
3221 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
3222 (should (equal "file://localhost/etc/fstab"
3223 (org-export-file-uri "//localhost/etc/fstab")))
3224 ;; Expand filename starting with "~".
3225 (should (equal (org-export-file-uri "~/file.org")
3226 (concat "file://" (expand-file-name "~/file.org")))))
3228 (ert-deftest test-org-export
/get-reference
()
3229 "Test `org-export-get-reference' specifications."
3231 (org-test-with-parsed-data "* Headline"
3232 (org-export-get-reference (org-element-map tree
'headline
#'identity nil t
)
3234 ;; For a given element always return the same reference.
3236 (org-test-with-parsed-data "* Headline"
3237 (let ((headline (org-element-map tree
'headline
#'identity nil t
)))
3238 (equal (org-export-get-reference headline info
)
3239 (org-export-get-reference headline info
)))))
3240 ;; Use search cells defined in `:crossrefs'. However, handle
3241 ;; duplicate search cells.
3244 (org-test-with-parsed-data "* Headline"
3245 (let* ((headline (org-element-map tree
'headline
#'identity nil t
))
3246 (search-cell (car (org-export-search-cells headline
))))
3248 (plist-put info
:crossrefs
(list (cons search-cell
1))))
3249 (org-export-get-reference headline info
)))))
3251 (equal '("org0000001" "org0000001")
3252 (org-test-with-parsed-data "* H\n** H"
3253 (org-element-map tree
'headline
3255 (let* ((search-cell (car (org-export-search-cells h
)))
3256 (info (plist-put info
:crossrefs
3257 (list (cons search-cell
1)))))
3258 (org-export-get-reference h info
))))))))
3261 ;;; Pseudo objects and pseudo elements
3263 (ert-deftest test-org-export
/pseudo-elements
()
3264 "Test exporting pseudo-elements."
3265 ;; Handle blank lines after pseudo-elements. In particular, do not
3266 ;; replace them with white spaces.
3268 (equal "contents\n\nparagraph\n"
3269 (let ((backend (org-export-create-backend
3271 '((pseudo-element .
(lambda (_p c _i
) c
))
3272 (paragraph .
(lambda (_p c _i
) c
))
3273 (plain-text .
(lambda (c _i
) c
)))))
3274 (element '(pseudo-element (:post-blank
1) "contents"))
3275 (paragraph '(paragraph nil
"paragraph"))
3276 (data '(org-data nil
)))
3277 (org-element-adopt-elements data element paragraph
)
3278 (org-export-data-with-backend data backend nil
)))))
3280 (ert-deftest test-org-export
/pseudo-objects
()
3281 "Test exporting pseudo-objects."
3282 ;; Handle blank spaces after pseudo-objects. In particular, do not
3283 ;; replace them with newlines.
3285 (equal "begin x end\n"
3286 (let ((backend (org-export-create-backend
3288 '((pseudo-object .
(lambda (_p c _i
) c
))
3289 (paragraph .
(lambda (_p c _i
) c
))
3290 (plain-text .
(lambda (c _i
) c
)))))
3291 (object '(pseudo-object (:post-blank
1) "x"))
3292 (paragraph '(paragraph nil
)))
3293 (org-element-adopt-elements paragraph
"begin " object
"end")
3294 (org-export-data-with-backend paragraph backend nil
)))))
3297 ;;; Src-block and example-block
3299 (ert-deftest test-org-export
/unravel-code
()
3300 "Test `org-export-unravel-code' function."
3301 ;; Code without reference.
3303 (equal '("(+ 1 1)\n")
3304 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3305 (org-export-unravel-code (org-element-at-point)))))
3306 ;; Code with reference.
3308 (equal '("(+ 1 1)\n" (1 .
"test"))
3309 (org-test-with-temp-text
3310 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
3311 (let ((org-coderef-label-format "(ref:%s)"))
3312 (org-export-unravel-code (org-element-at-point))))))
3313 ;; Code with user-defined reference.
3316 '("(+ 1 1)\n" (1 .
"test"))
3317 (org-test-with-temp-text
3318 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
3319 (let ((org-coderef-label-format "(ref:%s)"))
3320 (org-export-unravel-code (org-element-at-point))))))
3321 ;; Code references keys are relative to the current block.
3323 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
3324 (org-test-with-temp-text "
3333 (let ((org-coderef-label-format "(ref:%s)"))
3334 (org-export-unravel-code (org-element-at-point)))))))
3336 (ert-deftest test-org-export
/format-code-default
()
3337 "Test `org-export-format-code-default' specifications."
3338 ;; Return the empty string when code is empty.
3341 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
3342 (org-export-format-code-default
3343 (org-element-map tree
'src-block
'identity info t
) info
))))
3344 ;; Number lines, two whitespace characters before the actual loc.
3347 (org-test-with-parsed-data
3348 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
3349 (org-export-format-code-default
3350 (org-element-map tree
'src-block
'identity info t
) info
))))
3351 ;; Put references 6 whitespace characters after the widest line,
3352 ;; wrapped within parenthesis.
3354 (equal "123 (a)\n1 (b)\n"
3355 (let ((org-coderef-label-format "(ref:%s)"))
3356 (org-test-with-parsed-data
3357 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
3358 (org-export-format-code-default
3359 (org-element-map tree
'src-block
'identity info t
) info
))))))
3365 (ert-deftest test-org-export
/activate-smart-quotes
()
3366 "Test `org-export-activate-smart-quotes' specifications."
3367 ;; Double quotes: standard test.
3370 '("some “quoted” text")
3371 (let ((org-export-default-language "en"))
3372 (org-test-with-parsed-data "some \"quoted\" text"
3373 (org-element-map tree
'plain-text
3374 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3376 ;; Opening quotes: at the beginning of a paragraph.
3380 (let ((org-export-default-language "en"))
3381 (org-test-with-parsed-data "\"begin"
3382 (org-element-map tree
'plain-text
3383 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3385 ;; Opening quotes: after an object.
3388 '("“quoted” text")
3389 (let ((org-export-default-language "en"))
3390 (org-test-with-parsed-data "=verb= \"quoted\" text"
3391 (org-element-map tree
'plain-text
3392 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3394 ;; Closing quotes: at the end of a paragraph.
3397 '("Quoted “text”")
3398 (let ((org-export-default-language "en"))
3399 (org-test-with-parsed-data "Quoted \"text\""
3400 (org-element-map tree
'plain-text
3401 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3403 ;; Inner quotes: standard test.
3405 (equal '("« outer « inner » outer »")
3406 (let ((org-export-default-language "fr"))
3407 (org-test-with-parsed-data "\"outer 'inner' outer\""
3408 (org-element-map tree
'plain-text
3409 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3411 ;; Inner quotes: close to special symbols.
3413 (equal '("« outer (« inner ») outer »")
3414 (let ((org-export-default-language "fr"))
3415 (org-test-with-parsed-data "\"outer ('inner') outer\""
3416 (org-element-map tree
'plain-text
3417 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3420 (equal '("« « inner » »")
3421 (let ((org-export-default-language "fr"))
3422 (org-test-with-parsed-data "\"'inner'\""
3423 (org-element-map tree
'plain-text
3424 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3426 ;; Apostrophe: standard test.
3428 (equal '("It « shouldn’t » fail")
3429 (let ((org-export-default-language "fr"))
3430 (org-test-with-parsed-data "It \"shouldn't\" fail"
3431 (org-element-map tree
'plain-text
3432 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3435 (equal '("It shouldn’t fail")
3436 (let ((org-export-default-language "fr"))
3437 (org-test-with-parsed-data "It shouldn't fail"
3438 (org-element-map tree
'plain-text
3439 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3441 ;; Apostrophe: before an object.
3444 '("« a’" " »")
3445 (let ((org-export-default-language "fr"))
3446 (org-test-with-parsed-data "\"a'=b=\""
3447 (org-element-map tree
'plain-text
3448 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3450 ;; Apostrophe: after an object.
3452 (equal '("« " "’s »")
3453 (let ((org-export-default-language "fr"))
3454 (org-test-with-parsed-data "\"=code='s\""
3455 (org-element-map tree
'plain-text
3456 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3458 ;; Special case: isolated quotes.
3460 (equal '("“" "”")
3461 (let ((org-export-default-language "en"))
3462 (org-test-with-parsed-data "\"$x$\""
3463 (org-element-map tree
'plain-text
3464 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3466 ;; Smart quotes in secondary strings.
3468 (equal '("“" "”")
3469 (let ((org-export-default-language "en"))
3470 (org-test-with-parsed-data "* \"$x$\""
3471 (org-element-map tree
'plain-text
3472 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3474 ;; Smart quotes in document keywords.
3476 (equal '("“" "”")
3477 (let ((org-export-default-language "en"))
3478 (org-test-with-parsed-data "#+TITLE: \"$x$\""
3479 (org-element-map (plist-get info
:title
) 'plain-text
3480 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3482 ;; Smart quotes in parsed affiliated keywords.
3484 (equal '("“" "”" "Paragraph")
3485 (let ((org-export-default-language "en"))
3486 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
3487 (org-element-map tree
'plain-text
3488 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3490 ;; Smart quotes within objects.
3492 (equal '("“foo”")
3493 (let ((org-export-default-language "en"))
3494 (org-test-with-parsed-data "| \"foo\" |"
3495 (org-element-map tree
'plain-text
3496 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3498 ;; FIXME: Test failing non-interactively.
3501 ;; (equal '("“foo”")
3502 ;; (let ((org-export-default-language "en"))
3503 ;; (org-test-with-parsed-data "*\"foo\"*"
3504 ;; (org-element-map tree 'plain-text
3505 ;; (lambda (s) (org-export-activate-smart-quotes s :html info))
3506 ;; info nil nil t)))))
3513 (ert-deftest test-org-export
/special-column
()
3514 "Test if the table's special column is properly recognized."
3515 ;; 1. First column is special if it contains only a special marking
3516 ;; characters or empty cells.
3517 (org-test-with-temp-text "
3521 (org-export-table-has-special-column-p
3523 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3524 ;; 2. If the column contains anything else, it isn't special.
3525 (org-test-with-temp-text "
3529 (org-export-table-has-special-column-p
3531 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3532 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
3534 (org-test-with-temp-text "
3543 (org-export-table-has-special-column-p
3545 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3546 ;; 4. A first column with only empty cells isn't considered as
3548 (org-test-with-temp-text "
3552 (org-export-table-has-special-column-p
3554 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
3556 (ert-deftest test-org-export
/table-row-is-special-p
()
3557 "Test `org-export-table-row-is-special-p' specifications."
3558 ;; 1. A row is special if it has a special marking character in the
3560 (org-test-with-parsed-data "| ! | 1 |"
3562 (org-export-table-row-is-special-p
3563 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3564 ;; 2. A row is special when its first field is "/"
3565 (org-test-with-parsed-data "
3569 (org-export-table-row-is-special-p
3570 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3571 ;; 3. A row only containing alignment cookies is also considered as
3573 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
3575 (org-export-table-row-is-special-p
3576 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3577 ;; 4. Everything else isn't considered as special.
3578 (org-test-with-parsed-data "| \alpha | | c |"
3580 (org-export-table-row-is-special-p
3581 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3582 ;; 5. Table's rules are never considered as special rows.
3583 (org-test-with-parsed-data "|---+---|"
3585 (org-export-table-row-is-special-p
3586 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
3588 (ert-deftest test-org-export
/has-header-p
()
3589 "Test `org-export-table-has-header-p' specifications."
3590 ;; 1. With an header.
3591 (org-test-with-parsed-data "
3596 (org-export-table-has-header-p
3597 (org-element-map tree
'table
'identity info
'first-match
)
3599 ;; 2. Without an header.
3600 (org-test-with-parsed-data "
3604 (org-export-table-has-header-p
3605 (org-element-map tree
'table
'identity info
'first-match
)
3607 ;; 3. Don't get fooled with starting and ending rules.
3608 (org-test-with-parsed-data "
3614 (org-export-table-has-header-p
3615 (org-element-map tree
'table
'identity info
'first-match
)
3618 (ert-deftest test-org-export
/table-row-group
()
3619 "Test `org-export-table-row-group' specifications."
3620 ;; 1. A rule creates a new group.
3623 (org-test-with-parsed-data "
3627 (org-element-map tree
'table-row
3629 (if (eq (org-element-property :type row
) 'rule
) 'rule
3630 (org-export-table-row-group row info
)))))))
3631 ;; 2. Special rows are ignored in count.
3635 (org-test-with-parsed-data "
3639 (org-element-map tree
'table-row
3641 (if (eq (org-element-property :type row
) 'rule
) 'rule
3642 (org-export-table-row-group row info
)))
3644 ;; 3. Double rules also are ignored in count.
3646 (equal '(1 rule rule
2)
3647 (org-test-with-parsed-data "
3652 (org-element-map tree
'table-row
3654 (if (eq (org-element-property :type row
) 'rule
) 'rule
3655 (org-export-table-row-group row info
))))))))
3657 (ert-deftest test-org-export
/table-row-number
()
3658 "Test `org-export-table-row-number' specifications."
3659 ;; Standard test. Number is 0-indexed.
3662 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3663 (org-element-map tree
'table-row
3664 (lambda (row) (org-export-table-row-number row info
)) info
))))
3665 ;; Number ignores separators.
3668 (org-test-with-parsed-data "
3672 (org-element-map tree
'table-row
3673 (lambda (row) (org-export-table-row-number row info
)) info
))))
3674 ;; Number ignores special rows.
3677 (org-test-with-parsed-data "
3683 (org-element-map tree
'table-row
3684 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3686 (ert-deftest test-org-export
/table-cell-width
()
3687 "Test `org-export-table-cell-width' specifications."
3688 ;; 1. Width is primarily determined by width cookies. If no cookie
3689 ;; is found, cell's width is nil.
3690 (org-test-with-parsed-data "
3691 | / | <l> | <6> | <l7> |
3696 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3697 (org-element-map tree
'table-cell
'identity info
)))))
3698 ;; 2. The last width cookie has precedence.
3699 (org-test-with-parsed-data "
3706 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3707 (org-element-map tree
'table-cell
'identity info
)))))
3708 ;; 3. Valid width cookies must have a specific row.
3709 (org-test-with-parsed-data "| <6> | cell |"
3713 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3714 (org-element-map tree
'table-cell
'identity
))))))
3716 (ert-deftest test-org-export
/table-cell-alignment
()
3717 "Test `org-export-table-cell-alignment' specifications."
3718 ;; 1. Alignment is primarily determined by alignment cookies.
3720 (equal '(left center right
)
3721 (let ((org-table-number-fraction 0.5)
3722 (org-table-number-regexp "^[0-9]+$"))
3723 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3724 (mapcar (lambda (cell)
3725 (org-export-table-cell-alignment cell info
))
3726 (org-element-map tree
'table-cell
'identity
))))))
3727 ;; 2. The last alignment cookie has precedence.
3729 (equal '(right right right
)
3730 (org-test-with-parsed-data "
3734 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3735 (org-element-map tree
'table-cell
'identity
)))))
3736 ;; 3. If there's no cookie, cell's contents determine alignment.
3737 ;; A column mostly made of cells containing numbers will align
3738 ;; its cells to the right.
3740 (equal '(right right right
)
3741 (let ((org-table-number-fraction 0.5)
3742 (org-table-number-regexp "^[0-9]+$"))
3743 (org-test-with-parsed-data "
3747 (mapcar (lambda (cell)
3748 (org-export-table-cell-alignment cell info
))
3749 (org-element-map tree
'table-cell
'identity
))))))
3750 ;; 4. Otherwise, they will be aligned to the left.
3752 (equal '(left left left
)
3753 (org-test-with-parsed-data "
3757 (mapcar (lambda (cell)
3758 (org-export-table-cell-alignment cell info
))
3759 (org-element-map tree
'table-cell
'identity info
))))))
3761 (ert-deftest test-org-export
/table-cell-borders
()
3762 "Test `org-export-table-cell-borders' specifications."
3763 ;; 1. Recognize various column groups indicators.
3764 (org-test-with-parsed-data "| / | < | > | <> |"
3767 '((right bottom top
) (left bottom top
) (right bottom top
)
3768 (right left bottom top
))
3769 (mapcar (lambda (cell)
3770 (org-export-table-cell-borders cell info
))
3771 (org-element-map tree
'table-cell
'identity
)))))
3772 ;; 2. Accept shortcuts to define column groups.
3773 (org-test-with-parsed-data "| / | < | < |"
3776 '((right bottom top
) (right left bottom top
) (left bottom top
))
3777 (mapcar (lambda (cell)
3778 (org-export-table-cell-borders cell info
))
3779 (org-element-map tree
'table-cell
'identity
)))))
3780 ;; 3. A valid column groups row must start with a "/".
3781 (org-test-with-parsed-data "
3785 (equal '((top) (top) (bottom) (bottom))
3786 (mapcar (lambda (cell)
3787 (org-export-table-cell-borders cell info
))
3788 (org-element-map tree
'table-cell
'identity
)))))
3789 ;; 4. Take table rules into consideration.
3790 (org-test-with-parsed-data "
3795 (equal '((below top
) (bottom above
))
3796 (mapcar (lambda (cell)
3797 (org-export-table-cell-borders cell info
))
3798 (org-element-map tree
'table-cell
'identity
)))))
3799 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3800 ;; (resp. `bottom' and `below') borders. Any special row is
3802 (org-test-with-parsed-data "
3808 (equal '((bottom below top above
))
3810 (mapcar (lambda (cell)
3811 (org-export-table-cell-borders cell info
))
3812 (org-element-map tree
'table-cell
'identity
)))))))
3814 (ert-deftest test-org-export
/table-dimensions
()
3815 "Test `org-export-table-dimensions' specifications."
3816 ;; 1. Standard test.
3817 (org-test-with-parsed-data "
3822 (org-export-table-dimensions
3823 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3824 ;; 2. Ignore horizontal rules and special columns.
3825 (org-test-with-parsed-data "
3832 (org-export-table-dimensions
3833 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3835 (ert-deftest test-org-export
/table-cell-address
()
3836 "Test `org-export-table-cell-address' specifications."
3837 ;; 1. Standard test: index is 0-based.
3838 (org-test-with-parsed-data "| a | b |"
3840 (equal '((0 .
0) (0 .
1))
3841 (org-element-map tree
'table-cell
3842 (lambda (cell) (org-export-table-cell-address cell info
))
3844 ;; 2. Special column isn't counted, nor are special rows.
3845 (org-test-with-parsed-data "
3850 (org-export-table-cell-address
3851 (car (last (org-element-map tree
'table-cell
'identity info
)))
3853 ;; 3. Tables rules do not count either.
3854 (org-test-with-parsed-data "
3862 (org-export-table-cell-address
3863 (car (last (org-element-map tree
'table-cell
'identity info
)))
3865 ;; 4. Return nil for special cells.
3866 (org-test-with-parsed-data "| / | a |"
3868 (org-export-table-cell-address
3869 (org-element-map tree
'table-cell
'identity nil
'first-match
)
3872 (ert-deftest test-org-export
/get-table-cell-at
()
3873 "Test `org-export-get-table-cell-at' specifications."
3874 ;; 1. Address ignores special columns, special rows and rules.
3875 (org-test-with-parsed-data "
3882 (org-element-contents
3883 (org-export-get-table-cell-at
3885 (org-element-map tree
'table
'identity info
'first-match
)
3887 ;; 2. Return value for a non-existent address is nil.
3888 (org-test-with-parsed-data "| a |"
3890 (org-export-get-table-cell-at
3892 (org-element-map tree
'table
'identity info
'first-match
)
3894 (org-test-with-parsed-data "| / |"
3896 (org-export-get-table-cell-at
3898 (org-element-map tree
'table
'identity info
'first-match
)
3901 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
3902 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3903 ;; 1. A cell at a beginning of a row always starts a column group.
3904 (org-test-with-parsed-data "| a |"
3906 (org-export-table-cell-starts-colgroup-p
3907 (org-element-map tree
'table-cell
'identity info
'first-match
)
3909 ;; 2. Special column should be ignored when determining the
3910 ;; beginning of the row.
3911 (org-test-with-parsed-data "
3915 (org-export-table-cell-starts-colgroup-p
3916 (org-element-map tree
'table-cell
'identity info
'first-match
)
3918 ;; 2. Explicit column groups.
3919 (org-test-with-parsed-data "
3925 (org-element-map tree
'table-cell
3927 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3930 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3931 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3932 ;; 1. A cell at the end of a row always ends a column group.
3933 (org-test-with-parsed-data "| a |"
3935 (org-export-table-cell-ends-colgroup-p
3936 (org-element-map tree
'table-cell
'identity info
'first-match
)
3938 ;; 2. Special column should be ignored when determining the
3939 ;; beginning of the row.
3940 (org-test-with-parsed-data "
3944 (org-export-table-cell-ends-colgroup-p
3945 (org-element-map tree
'table-cell
'identity info
'first-match
)
3947 ;; 3. Explicit column groups.
3948 (org-test-with-parsed-data "
3954 (org-element-map tree
'table-cell
3956 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
3959 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
3960 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3961 ;; 1. A row at the beginning of a table always starts a row group.
3962 ;; So does a row following a table rule.
3963 (org-test-with-parsed-data "
3970 (org-element-map tree
'table-row
3972 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3974 ;; 2. Special rows should be ignored when determining the beginning
3976 (org-test-with-parsed-data "
3985 (org-element-map tree
'table-row
3987 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3990 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
3991 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3992 ;; 1. A row at the end of a table always ends a row group. So does
3993 ;; a row preceding a table rule.
3994 (org-test-with-parsed-data "
4001 (org-element-map tree
'table-row
4003 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4005 ;; 2. Special rows should be ignored when determining the beginning
4007 (org-test-with-parsed-data "
4016 (org-element-map tree
'table-row
4018 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4021 (ert-deftest test-org-export
/table-row-in-header-p
()
4022 "Test `org-export-table-row-in-header-p' specifications."
4023 ;; Standard test. Separators are always nil.
4027 (org-test-with-parsed-data "| a |\n|---|\n| b |"
4028 (org-element-map tree
'table-row
4030 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
4031 ;; Nil when there is no header.
4035 (org-test-with-parsed-data "| a |\n| b |"
4036 (org-element-map tree
'table-row
4038 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
4040 (ert-deftest test-org-export
/table-row-starts-header-p
()
4041 "Test `org-export-table-row-starts-header-p' specifications."
4042 ;; 1. Only the row starting the first row group starts the table
4044 (org-test-with-parsed-data "
4052 (org-element-map tree
'table-row
4054 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
4056 ;; 2. A row cannot start an header if there's no header in the
4058 (org-test-with-parsed-data "
4062 (org-export-table-row-starts-header-p
4063 (org-element-map tree
'table-row
'identity info
'first-match
)
4066 (ert-deftest test-org-export
/table-row-ends-header-p
()
4067 "Test `org-export-table-row-ends-header-p' specifications."
4068 ;; 1. Only the row starting the first row group starts the table
4070 (org-test-with-parsed-data "
4078 (org-element-map tree
'table-row
4080 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
4082 ;; 2. A row cannot start an header if there's no header in the
4084 (org-test-with-parsed-data "
4088 (org-export-table-row-ends-header-p
4089 (org-element-map tree
'table-row
'identity info
'first-match
)
4094 ;;; Tables of Contents
4096 (ert-deftest test-org-export
/collect-headlines
()
4097 "Test `org-export-collect-headlines' specifications."
4102 (org-test-with-parsed-data "* H1\n** H2"
4103 (org-export-collect-headlines info
)))))
4104 ;; Do not collect headlines below optional argument.
4108 (org-test-with-parsed-data "* H1\n** H2"
4109 (org-export-collect-headlines info
1)))))
4110 ;; Never collect headlines below maximum headline level.
4114 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4115 (org-export-collect-headlines info
)))))
4119 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4120 (org-export-collect-headlines info
2)))))
4121 ;; Collect headlines locally.
4124 (org-test-with-parsed-data "* H1\n** H2\n** H3"
4125 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4126 (length (org-export-collect-headlines info nil scope
))))))
4127 ;; When collecting locally, optional level is relative.
4130 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
4131 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4132 (length (org-export-collect-headlines info
1 scope
)))))))
4138 (ert-deftest test-org-export
/inner-template
()
4139 "Test `inner-template' translator specifications."
4142 (org-test-with-temp-text "* Headline"
4144 (org-export-create-backend
4146 '((inner-template .
(lambda (contents info
) "Success!"))
4147 (headline .
(lambda (h c i
) "Headline"))))))))
4148 ;; Inner template is applied even in a "body-only" export.
4151 (org-test-with-temp-text "* Headline"
4153 (org-export-create-backend
4154 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
4155 (headline .
(lambda (h c i
) "Headline"))))
4156 nil nil
'body-only
)))))
4158 (ert-deftest test-org-export
/template
()
4159 "Test `template' translator specifications."
4162 (org-test-with-temp-text "* Headline"
4164 (org-export-create-backend
4165 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4166 (headline .
(lambda (h c i
) "Headline"))))))))
4167 ;; Template is not applied in a "body-only" export.
4170 (org-test-with-temp-text "* Headline"
4172 (org-export-create-backend
4173 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4174 (headline .
(lambda (h c i
) "Headline"))))
4175 nil nil
'body-only
)))))
4181 (ert-deftest test-org-export
/get-next-element
()
4182 "Test `org-export-get-next-element' specifications."
4186 (org-test-with-parsed-data "* Headline\n*a* b"
4187 (org-export-get-next-element
4188 (org-element-map tree
'bold
'identity info t
) info
))))
4189 ;; Return nil when no previous element.
4191 (org-test-with-parsed-data "* Headline\na *b*"
4192 (org-export-get-next-element
4193 (org-element-map tree
'bold
'identity info t
) info
)))
4194 ;; Non-exportable elements are ignored.
4196 (let ((org-export-with-timestamps nil
))
4197 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
4198 (org-export-get-next-element
4199 (org-element-map tree
'entity
'identity info t
) info
))))
4200 ;; Find next element in secondary strings.
4203 (org-test-with-parsed-data "* a =verb="
4205 (org-export-get-next-element
4206 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4209 (org-test-with-parsed-data "* /italic/ =verb="
4211 (org-export-get-next-element
4212 (org-element-map tree
'italic
'identity info t
) info
)))))
4213 ;; Find next element in document keywords.
4216 (org-test-with-parsed-data "#+TITLE: a =verb="
4218 (org-export-get-next-element
4220 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4221 ;; Find next element in parsed affiliated keywords.
4224 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
4226 (org-export-get-next-element
4227 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4228 ;; With optional argument N, return a list containing all the
4229 ;; following elements.
4232 '(bold code underline
)
4233 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4235 (org-export-get-next-element
4236 (org-element-map tree
'italic
'identity info t
) info t
)))))
4237 ;; When N is a positive integer, return a list containing up to
4238 ;; N following elements.
4242 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4244 (org-export-get-next-element
4245 (org-element-map tree
'italic
'identity info t
) info
2))))))
4247 (ert-deftest test-org-export
/get-previous-element
()
4248 "Test `org-export-get-previous-element' specifications."
4252 (org-test-with-parsed-data "* Headline\na *b*"
4253 (org-export-get-previous-element
4254 (org-element-map tree
'bold
'identity info t
) info
))))
4255 ;; Return nil when no previous element.
4257 (org-test-with-parsed-data "* Headline\n*a* b"
4258 (org-export-get-previous-element
4259 (org-element-map tree
'bold
'identity info t
) info
)))
4260 ;; Non-exportable elements are ignored.
4262 (let ((org-export-with-timestamps nil
))
4263 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
4264 (org-export-get-previous-element
4265 (org-element-map tree
'entity
'identity info t
) info
))))
4266 ;; Find previous element in secondary strings.
4269 (org-test-with-parsed-data "* =verb= a"
4271 (org-export-get-previous-element
4272 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4275 (org-test-with-parsed-data "* =verb= /italic/"
4277 (org-export-get-previous-element
4278 (org-element-map tree
'italic
'identity info t
) info
)))))
4279 ;; Find previous element in document keywords.
4282 (org-test-with-parsed-data "#+TITLE: =verb= a"
4284 (org-export-get-previous-element
4286 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4287 ;; Find previous element in parsed affiliated keywords.
4290 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
4292 (org-export-get-previous-element
4293 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4294 ;; With optional argument N, return a list containing up to
4295 ;; N previous elements.
4297 (equal '(underline italic bold
)
4298 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4300 (org-export-get-previous-element
4301 (org-element-map tree
'code
'identity info t
) info t
)))))
4302 ;; When N is a positive integer, return a list containing up to
4303 ;; N previous elements.
4305 (equal '(italic bold
)
4306 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4308 (org-export-get-previous-element
4309 (org-element-map tree
'code
'identity info t
) info
2))))))
4313 ;;; test-org-export.el end here