1 ;;; test-ox.el --- Tests for ox.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2016 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
26 (unless (featurep 'ox
)
27 (signal 'missing-test-dependency
"org-export"))
29 (defun org-test-default-backend ()
30 "Return a default export back-end.
31 This back-end simply returns parsed data as Org syntax."
32 (org-export-create-backend
34 (mapcar (lambda (type)
38 (intern (format "org-element-%s-interpreter" type
))
40 (append org-element-all-elements org-element-all-objects
))))
42 (defmacro org-test-with-parsed-data
(data &rest body
)
43 "Execute body with parsed data available.
44 DATA is a string containing the data to be parsed. BODY is the
45 body to execute. Parse tree is available under the `tree'
46 variable, and communication channel under `info'."
47 (declare (debug (form body
)) (indent 1))
48 `(org-test-with-temp-text ,data
49 (org-export--delete-comment-trees)
50 (let* ((tree (org-element-parse-buffer))
51 (info (org-combine-plists
52 (org-export--get-export-attributes)
53 (org-export-get-environment))))
54 (org-export--prune-tree tree info
)
55 (org-export--remove-uninterpreted-data tree info
)
56 (let ((info (org-combine-plists
57 info
(org-export--collect-tree-properties tree info
))))
64 (ert-deftest test-org-export
/bind-keyword
()
65 "Test reading #+BIND: keywords."
66 ;; Test with `org-export-allow-bind-keywords' set to t.
68 (org-test-with-temp-text "#+BIND: test-ox-var value"
69 (let ((org-export-allow-bind-keywords t
))
70 (org-export-get-environment)
71 (eq test-ox-var
'value
))))
72 ;; Test with `org-export-allow-bind-keywords' set to nil.
74 (org-test-with-temp-text "#+BIND: test-ox-var value"
75 (let ((org-export-allow-bind-keywords nil
))
76 (org-export-get-environment)
77 (boundp 'test-ox-var
))))
78 ;; BIND keywords are case-insensitive.
80 (org-test-with-temp-text "#+bind: test-ox-var value"
81 (let ((org-export-allow-bind-keywords t
))
82 (org-export-get-environment)
83 (eq test-ox-var
'value
))))
84 ;; Preserve order of BIND keywords.
86 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
87 (let ((org-export-allow-bind-keywords t
))
88 (org-export-get-environment)
90 ;; Read BIND keywords in setup files.
92 (org-test-with-temp-text
93 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
94 (let ((org-export-allow-bind-keywords t
))
95 (org-export-get-environment)
96 (eq variable
'value
))))
97 ;; Verify that bound variables are seen during export.
100 (org-test-with-temp-text "#+BIND: test-ox-var value"
101 (let ((org-export-allow-bind-keywords t
))
103 (org-export-create-backend
105 '((section .
(lambda (s c i
)
106 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
108 (ert-deftest test-org-export
/parse-option-keyword
()
109 "Test reading all standard #+OPTIONS: items."
112 (org-export--parse-option-keyword
113 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t \
114 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil \
116 (and (eq (plist-get options
:headline-levels
) 1)
117 (eq (plist-get options
:section-numbers
) t
)
118 (eq (plist-get options
:preserve-breaks
) t
)
119 (eq (plist-get options
:time-stamp-file
) t
)
120 (eq (plist-get options
:with-archived-trees
) t
)
121 (eq (plist-get options
:with-author
) t
)
122 (eq (plist-get options
:with-drawers
) t
)
123 (eq (plist-get options
:with-email
) t
)
124 (eq (plist-get options
:with-emphasize
) t
)
125 (eq (plist-get options
:with-entities
) t
)
126 (eq (plist-get options
:with-fixed-width
) t
)
127 (eq (plist-get options
:with-footnotes
) t
)
128 (eq (plist-get options
:with-priority
) t
)
129 (eq (plist-get options
:with-special-strings
) t
)
130 (eq (plist-get options
:with-sub-superscript
) t
)
131 (eq (plist-get options
:with-toc
) t
)
132 (eq (plist-get options
:with-tables
) t
)
133 (eq (plist-get options
:with-tags
) t
)
134 (eq (plist-get options
:with-tasks
) t
)
135 (eq (plist-get options
:with-timestamps
) t
)
136 (eq (plist-get options
:with-todo-keywords
) t
)
137 (eq (plist-get options
:with-inlinetasks
) nil
)
138 (eq (plist-get options
:with-statistics-cookies
) t
)
139 (eq (plist-get options
:with-title
) t
))))
140 ;; Test some special values.
143 (org-export--parse-option-keyword
144 "arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo \
146 (and (eq (plist-get options
:with-archived-trees
) 'headline
)
147 (eq (plist-get options
:with-sub-superscript
) '{})
148 (eq (plist-get options
:with-toc
) 1)
149 (eq (plist-get options
:with-tags
) 'not-in-toc
)
150 (eq (plist-get options
:with-tasks
) 'todo
)
151 (eq (plist-get options
:section-numbers
) 2)
152 (eq (plist-get options
:with-timestamps
) 'active
)
153 (equal (plist-get options
:with-drawers
) '("TEST")))))
154 ;; Test back-end specific values.
157 (org-export--parse-option-keyword
158 "opt:t" (org-export-create-backend :options
'((:option nil
"opt"))))
160 ;; More than one property can refer to the same option item.
162 (equal '(:opt1 t
:opt2 t
)
163 (org-export--parse-option-keyword
165 (org-export-create-backend
166 :options
'((:opt1 nil
"opt") (:opt2 nil
"opt")))))))
168 (ert-deftest test-org-export
/get-inbuffer-options
()
169 "Test reading all standard export keywords."
170 ;; Properties should follow buffer order.
173 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
174 (org-export--get-inbuffer-options))
175 '(:language
"fr" :creator
"Me" :email
"email")))
176 ;; Test `space' behaviour.
179 (let ((back-end (org-export-create-backend
180 :options
'((:keyword
"KEYWORD" nil nil space
)))))
181 (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: spaces"
182 (org-export--get-inbuffer-options back-end
)))
183 '(:keyword
"With spaces")))
184 ;; Test `newline' behaviour.
187 (let ((back-end (org-export-create-backend
188 :options
'((:keyword
"KEYWORD" nil nil newline
)))))
189 (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: two lines"
190 (org-export--get-inbuffer-options back-end
)))
191 '(:keyword
"With\ntwo lines")))
192 ;; Test `split' behaviour.
195 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
196 (org-export--get-inbuffer-options))
197 '(:select-tags
("a" "b"))))
198 ;; Test `parse' behaviour. `parse' implies `space' but preserve
199 ;; line breaks. Multi-line objects are allowed.
202 (org-test-with-temp-text "#+TITLE: *bold*"
203 (plist-get (org-export--get-inbuffer-options) :title
))
204 'bold
#'identity nil t
))
207 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
208 (plist-get (org-export--get-inbuffer-options) :title
))
209 '("Some title with spaces")))
212 (org-test-with-temp-text "#+TITLE: Some title\\\\\n#+TITLE: with spaces"
213 (plist-get (org-export--get-inbuffer-options) :title
))
214 'line-break
#'identity nil t
))
217 (org-test-with-temp-text "#+TITLE: *bold\n#+TITLE: sentence*"
218 (plist-get (org-export--get-inbuffer-options) :title
))
219 'bold
#'identity nil t
))
220 ;; Options set through SETUPFILE.
223 (org-test-with-temp-text
224 (format "#+DESCRIPTION: l1
228 #+SETUPFILE: \"%s/examples/setupfile.org\"
233 (org-export--get-inbuffer-options))
234 '(:language
"fr" :select-tags
("a" "b" "c") :title
("a b c"))))
235 ;; 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
)))))
751 (equal "/simple/ /example/\n"
752 (org-test-with-temp-text "/simple/ /example/"
754 (org-export-create-backend
755 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
756 (paragraph .
(lambda (p c i
) c
))
757 (section .
(lambda (s c i
) c
))))
758 nil nil nil
'(:with-emphasize nil
)))))
759 ;; LaTeX environment.
762 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
764 (org-export-create-backend
765 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
766 (section .
(lambda (s c i
) c
))))
767 nil nil nil
'(:with-latex t
)))))
769 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
770 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
772 (org-export-create-backend
773 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
774 (section .
(lambda (s c i
) c
))))
775 nil nil nil
'(:with-latex verbatim
)))))
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 t
)))))
788 (org-test-with-temp-text "$1$"
790 (org-export-create-backend
791 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
792 (paragraph .
(lambda (p c i
) c
))
793 (section .
(lambda (s c i
) c
))))
794 nil nil nil
'(:with-latex verbatim
)))))
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 t
)))))
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 nil
)))))
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_{b}"
827 (org-export-create-backend
828 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
829 (paragraph .
(lambda (p c i
) c
))
830 (section .
(lambda (s c i
) c
))))
831 nil nil nil
'(:with-sub-superscript
{})))))
834 (org-test-with-temp-text "a_\\alpha"
836 (org-export-create-backend
837 :transcoders
'((entity .
(lambda (e c i
) "entity"))
838 (subscript .
(lambda (s c i
) "dummy"))
839 (paragraph .
(lambda (p c i
) c
))
840 (section .
(lambda (s c i
) c
))))
841 nil nil nil
'(:with-sub-superscript nil
)))))
842 ;; Handle uninterpreted objects in parsed keywords.
845 (org-test-with-temp-text "#+TITLE: a_b"
847 (org-export-create-backend
849 '((subscript .
(lambda (s c i
) "dummy"))
850 (template .
(lambda (c i
)
851 (org-export-data (plist-get i
:title
) i
)))
852 (section .
(lambda (s c i
) c
))))
853 nil nil nil
'(:with-sub-superscript nil
)))))
856 (org-test-with-temp-text "#+FOO: a_b"
858 (org-export-create-backend
860 '((:foo
"FOO" nil nil parse
))
862 '((subscript .
(lambda (s c i
) "dummy"))
863 (template .
(lambda (c i
)
864 (org-export-data (plist-get i
:foo
) i
)))
865 (section .
(lambda (s c i
) c
))))
866 nil nil nil
'(:with-sub-superscript nil
)))))
867 ;; Objects in parsed keywords are "uninterpreted" before filters are
870 (org-test-with-temp-text "#+TITLE: a_b"
872 (org-export-create-backend
876 (org-element-map (plist-get i
:title
) 'subscript
877 (lambda (_) (error "There should be no subscript here")))))))
878 nil nil nil
'(:with-sub-superscript nil
))))
879 ;; Handle uninterpreted objects in captions.
882 (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
884 (org-export-create-backend
886 '((subscript .
(lambda (s c i
) "dummy"))
887 (paragraph .
(lambda (p c i
)
888 (org-export-data (org-export-get-caption p
) i
)))
889 (section .
(lambda (s c i
) c
))))
890 nil nil nil
'(:with-sub-superscript t
)))))
893 (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
895 (org-export-create-backend
897 '((subscript .
(lambda (s c i
) "dummy"))
898 (paragraph .
(lambda (p c i
)
899 (org-export-data (org-export-get-caption p
) i
)))
900 (section .
(lambda (s c i
) c
))))
901 nil nil nil
'(:with-sub-superscript nil
)))))
902 ;; Special case: multiples uninterpreted objects in a row.
905 (org-test-with-temp-text "a_b_c_d"
907 (org-export-create-backend
908 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
909 (paragraph .
(lambda (p c i
) c
))
910 (section .
(lambda (s c i
) c
))))
911 nil nil nil
'(:with-sub-superscript
{}))))))
913 (ert-deftest test-org-export
/export-scope
()
914 "Test all export scopes."
917 (equal "text\n*** H3\n"
918 (org-test-with-temp-text "* H1\n<point>** H2\ntext\n*** H3"
919 (org-export-as (org-test-default-backend) 'subtree
))))
921 (equal "text\n*** H3\n"
922 (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
923 (org-export-as (org-test-default-backend) 'subtree
))))
924 ;; Subtree with a code block calling another block outside.
927 (org-test-with-temp-text "
929 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
934 #+BEGIN_SRC emacs-lisp
937 (let ((org-export-use-babel t
))
938 (org-export-as (org-test-default-backend) 'subtree
)))))
939 ;; Subtree export should ignore leading planning line and property
943 (org-test-with-temp-text "
945 SCHEDULED: <2012-03-29 Thu>
950 (org-export-as (org-test-default-backend)
952 '(:with-planning t
:with-properties t
)))))
956 (org-test-with-temp-text "* H1\n** H2\ntext\n*** H3"
958 (org-export-as (org-test-default-backend) nil
'visible
))))
962 (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
963 (transient-mark-mode 1)
964 (push-mark (point) t t
)
966 (org-export-as (org-test-default-backend)))))
970 (org-test-with-temp-text "Text"
972 (org-export-create-backend
974 '((template .
(lambda (b _i
) (format "BEGIN\n%sEND" b
)))
975 (section .
(lambda (_s c _i
) c
))
976 (paragraph .
(lambda (_p c _i
) c
))))
977 nil nil
'body-only
))))
979 (equal "BEGIN\nText\nEND"
980 (org-test-with-temp-text "Text"
982 (org-export-create-backend
984 '((template .
(lambda (b _i
) (format "BEGIN\n%sEND" b
)))
985 (section .
(lambda (_s c _i
) c
))
986 (paragraph .
(lambda (_p c _i
) c
))))))))
987 ;; Pathological case: Body only on an empty buffer is expected to
988 ;; return an empty string, not nil.
990 (org-test-with-temp-text ""
991 (org-export-as (org-test-default-backend) nil nil t
))))
993 (ert-deftest test-org-export
/output-file-name
()
994 "Test `org-export-output-file-name' specifications."
995 ;; Export from a file: name is built from original file name.
997 (org-test-with-temp-text-in-file "Test"
998 (equal (file-name-base (buffer-file-name))
999 (file-name-base (org-export-output-file-name ".ext")))))
1000 ;; When #+EXPORT_FILE_NAME is defined, use it.
1003 (org-test-with-temp-text-in-file "#+EXPORT_FILE_NAME: test"
1004 (org-export-output-file-name ".ext" t
))))
1005 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
1008 (org-test-with-temp-text-in-file
1009 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
1010 (org-export-output-file-name ".ext" t
))))
1012 (equal "property.ext"
1013 (org-test-with-temp-text
1014 "#+EXPORT_FILE_NAME: keyword
1017 :EXPORT_FILE_NAME: property
1019 (org-export-output-file-name ".ext" t
))))
1020 ;; From a buffer not associated to a file, too.
1023 (org-test-with-temp-text
1024 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
1025 (org-export-output-file-name ".ext" t
))))
1026 ;; When provided name is absolute, preserve it.
1028 (org-test-with-temp-text
1029 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
1030 (expand-file-name "test"))
1031 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
1032 ;; When PUB-DIR argument is provided, use it.
1035 (org-test-with-temp-text-in-file "Test"
1036 (file-name-directory
1037 (org-export-output-file-name ".ext" nil
"dir/")))))
1038 ;; PUB-DIR has precedence over EXPORT_FILE_NAME keyword or property.
1041 (org-test-with-temp-text-in-file
1042 "#+EXPORT_FILE_NAME: /dir/keyword\nTest"
1043 (file-name-directory
1044 (org-export-output-file-name ".ext" nil
"pub-dir/")))))
1045 ;; When returned name would overwrite original file, add EXTENSION
1048 (equal "normal.org.org"
1049 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1050 (org-export-output-file-name ".org")))))
1052 (ert-deftest test-org-export
/expand-include
()
1053 "Test file inclusion in an Org buffer."
1054 ;; Error when file isn't specified.
1056 (org-test-with-temp-text "#+INCLUDE: dummy.org"
1057 (org-export-expand-include-keyword)))
1058 ;; Refuse to expand keywords in commented headings.
1060 (org-test-with-temp-text "* COMMENT H1\n#+INCLUDE: dummy.org"
1061 (org-export-expand-include-keyword)
1063 ;; Full insertion with recursive inclusion.
1068 (expand-file-name "examples/include.org" org-test-dir
))
1069 (replace-regexp-in-string
1070 (regexp-quote "#+INCLUDE: \"include2.org\"")
1071 "Success!" (buffer-string)))
1072 (org-test-with-temp-text
1073 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
1074 (org-export-expand-include-keyword)
1076 ;; Localized insertion.
1077 (org-test-with-temp-text
1078 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
1080 (org-export-expand-include-keyword)
1081 (should (equal (buffer-string)
1082 "Small Org file with an include keyword.\n")))
1083 ;; Insertion with constraints on headlines level.
1086 "* Top heading\n** Heading\nbody\n"
1087 (org-test-with-temp-text
1089 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
1091 (org-export-expand-include-keyword)
1095 "* Top heading\n* Heading\nbody\n"
1096 (org-test-with-temp-text
1098 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
1100 (org-export-expand-include-keyword)
1102 ;; Inclusion within an example block.
1105 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
1106 (org-test-with-temp-text
1107 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
1109 (org-export-expand-include-keyword)
1111 ;; Inclusion within a src-block.
1114 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
1115 (org-test-with-temp-text
1117 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
1119 (org-export-expand-include-keyword)
1121 ;; Inclusion within an html export-block.
1124 "#+BEGIN_EXPORT html\n<p>HTML!</p>\n#+END_EXPORT\n"
1125 (org-test-with-temp-text
1127 "#+INCLUDE: \"%s/examples/include.html\" EXPORT html"
1129 (org-export-expand-include-keyword)
1131 ;; Inclusion within an center paragraph
1134 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
1135 (org-test-with-temp-text
1137 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
1139 (org-export-expand-include-keyword)
1141 ;; Footnotes labels are local to each included file.
1147 Footnotes[fn:1], [fn:test], [fn:test] and [fn:inline:inline footnote].
1149 \[fn:test] Footnote \"test\""))
1150 (org-test-with-temp-text-in-file contents
1151 (let ((file1 (buffer-file-name)))
1152 (org-test-with-temp-text-in-file contents
1153 (let ((file2 (buffer-file-name)))
1154 (org-test-with-temp-text
1155 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
1157 (org-export-expand-include-keyword)
1158 (org-element-map (org-element-parse-buffer)
1160 (lambda (r) (org-element-property :label r
)))))))))))))
1161 ;; Footnotes labels are not local to each include keyword.
1167 Footnotes[fn:1], [fn:test] and [fn:inline:inline footnote].
1169 \[fn:test] Footnote \"test\""))
1170 (org-test-with-temp-text-in-file contents
1171 (let ((file (buffer-file-name)))
1172 (org-test-with-temp-text
1173 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
1174 (org-export-expand-include-keyword)
1175 (org-element-map (org-element-parse-buffer)
1177 (lambda (ref) (org-element-property :label ref
)))))))))))
1178 ;; Footnotes are supported by :lines-like elements and unnecessary
1179 ;; footnotes are dropped.
1188 Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
1193 \[fn:test] Footnote \"test\"
1195 (org-test-with-temp-text-in-file contents
1196 (let ((file (buffer-file-name)))
1197 (org-test-with-temp-text
1198 (format "#+INCLUDE: \"%s::*bar\"\n" file
)
1199 (org-export-expand-include-keyword)
1200 (org-element-map (org-element-parse-buffer)
1201 'footnote-definition
1202 (lambda (ref) (org-element-property :label ref
)))))))))))
1203 ;; If only-contents is non-nil only include contents of element.
1207 (org-test-with-temp-text
1209 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" "
1212 (org-export-expand-include-keyword)
1214 ;; Headings can be included via CUSTOM_ID.
1216 (org-test-with-temp-text
1217 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1218 (org-export-expand-include-keyword)
1219 (goto-char (point-min))
1220 (looking-at "* Another heading")))
1221 ;; Named objects can be included.
1225 (org-test-with-temp-text
1226 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t"
1228 (org-export-expand-include-keyword)
1230 ;; Including non-existing elements should result in an error.
1232 (org-test-with-temp-text
1233 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\""
1235 (org-export-expand-include-keyword)))
1236 ;; Lines work relatively to an included element.
1240 (org-test-with-temp-text
1241 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t \
1244 (org-export-expand-include-keyword)
1246 ;; Properties should be dropped from headlines.
1249 (org-test-with-temp-text
1250 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t"
1252 (org-export-expand-include-keyword)
1254 (org-test-with-temp-text
1255 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1256 (org-export-expand-include-keyword)
1258 ;; Properties should be dropped, drawers should not be.
1261 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1262 (org-test-with-temp-text
1263 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t"
1265 (org-export-expand-include-keyword)
1267 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1269 (cl-every (lambda (level) (zerop (1- level
)))
1270 (org-test-with-temp-text
1272 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n"
1274 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\""
1276 (org-export-expand-include-keyword)
1277 (org-element-map (org-element-parse-buffer) 'headline
1278 (lambda (head) (org-element-property :level head
))))))
1279 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1282 (org-test-with-temp-text
1283 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp"
1285 (org-export-expand-include-keyword)
1287 (org-test-with-temp-text
1289 "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1"
1291 (org-export-expand-include-keyword)
1293 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1295 (org-test-with-temp-text-in-file
1296 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\""
1298 (narrow-to-region (point) (point-max))
1299 (org-export-expand-include-keyword)
1300 (eq 1 (org-current-level))))
1301 ;; If :minlevel is present do not alter it.
1303 (org-test-with-temp-text
1305 "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3"
1307 (narrow-to-region (point) (point-max))
1308 (org-export-expand-include-keyword)
1309 (eq 3 (org-current-level)))))
1311 (ert-deftest test-org-export
/expand-macro
()
1312 "Test macro expansion in an Org buffer."
1314 ;; Standard macro expansion.
1316 (equal "#+MACRO: macro1 value\nvalue\n"
1317 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1318 (org-export-as (org-test-default-backend)))))
1319 ;; Include global macros. However, local macros override them.
1322 (org-test-with-temp-text "{{{M}}}"
1323 (let ((org-export-global-macros '(("M" .
"global"))))
1324 (org-export-as (org-test-default-backend))))))
1326 (equal "global arg\n"
1327 (org-test-with-temp-text "{{{M(arg)}}}"
1328 (let ((org-export-global-macros '(("M" .
"global $1"))))
1329 (org-export-as (org-test-default-backend))))))
1332 (org-test-with-temp-text "{{{M}}}"
1333 (let ((org-export-global-macros '(("M" .
"(eval (+ 1 1))"))))
1334 (org-export-as (org-test-default-backend))))))
1336 (equal "#+MACRO: M local\nlocal\n"
1337 (org-test-with-temp-text "#+macro: M local\n{{{M}}}"
1338 (let ((org-export-global-macros '(("M" .
"global"))))
1339 (org-export-as (org-test-default-backend))))))
1340 ;; Allow macro in parsed keywords and associated properties.
1341 ;; Standard macro expansion.
1345 (let ((backend (org-export-create-backend
1347 :options
'((:k
"K" nil nil parse
)))))
1348 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1349 (org-export-as backend
)))))
1353 (let ((backend (org-export-create-backend
1355 :options
'((:k
"K" nil nil parse
)))))
1356 (org-test-with-temp-text
1357 "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1358 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1359 ;; Expand specific macros.
1361 (equal "me 2012-03-29 me@here Title\n"
1362 (org-test-with-temp-text
1368 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1369 (let ((output (org-export-as (org-test-default-backend))))
1370 (substring output
(string-match ".*\n\\'" output
))))))
1371 ;; Expand specific macros when property contained a regular macro
1375 (org-test-with-temp-text "
1376 #+MACRO: macro1 value
1377 #+TITLE: {{{macro1}}}
1379 (let ((output (org-export-as (org-test-default-backend))))
1380 (substring output
(string-match ".*\n\\'" output
))))))
1381 ;; Expand macros with templates in included files.
1384 (org-test-with-temp-text
1385 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1386 {{{included-macro}}}" org-test-dir
)
1387 (let ((output (org-export-as (org-test-default-backend))))
1388 (substring output
(string-match ".*\n\\'" output
))))))
1389 ;; Date macro takes a optional formatting argument
1392 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1393 (org-export-as (org-test-default-backend)))))
1394 ;; Only single timestamps are formatted
1396 (equal "<2015-02x-09>\n"
1397 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1398 (org-export-as (org-test-default-backend)))))
1399 ;; Throw an error when a macro definition is missing.
1401 (org-test-with-temp-text "{{{missing}}}"
1402 (org-export-as (org-test-default-backend))))
1403 ;; Macros defined in commented subtrees are ignored.
1405 (org-test-with-temp-text
1406 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1407 (org-export-as (org-test-default-backend))))
1409 (org-test-with-temp-text
1410 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1411 (org-export-as (org-test-default-backend)))))
1413 (ert-deftest test-org-export
/before-processing-hook
()
1414 "Test `org-export-before-processing-hook'."
1417 "#+MACRO: mac val\nTest\n"
1418 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1419 (let ((org-export-before-processing-hook
1421 (while (re-search-forward "{{{" nil t
)
1422 (let ((object (org-element-context)))
1423 (when (eq (org-element-type object
) 'macro
)
1425 (org-element-property :begin object
)
1426 (org-element-property :end object
)))))))))
1427 (org-export-as (org-test-default-backend)))))))
1429 (ert-deftest test-org-export
/before-parsing-hook
()
1430 "Test `org-export-before-parsing-hook'."
1432 (equal "Body 1\nBody 2\n"
1433 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1434 (let ((org-export-before-parsing-hook
1436 (goto-char (point-min))
1437 (while (re-search-forward org-outline-regexp-bol nil t
)
1439 (point-at-bol) (progn (forward-line) (point))))))))
1440 (org-export-as (org-test-default-backend)))))))
1444 ;;; Affiliated Keywords
1446 (ert-deftest test-org-export
/read-attribute
()
1447 "Test `org-export-read-attribute' specifications."
1451 (org-export-read-attribute
1453 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1454 (org-element-at-point)))
1456 ;; Return nil on empty attribute.
1458 (org-export-read-attribute
1460 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1461 ;; Return nil on "nil" string.
1463 (equal '(:a nil
:b nil
)
1464 (org-export-read-attribute
1466 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1467 (org-element-at-point)))))
1468 ;; Return nil on empty string.
1470 (equal '(:a nil
:b nil
)
1471 (org-export-read-attribute
1473 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1474 (org-element-at-point)))))
1475 ;; Return empty string when value is "".
1478 (org-export-read-attribute
1480 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1481 (org-element-at-point)))))
1482 ;; Return \"\" when value is """".
1485 (org-export-read-attribute
1487 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1488 (org-element-at-point)))))
1489 ;; Ignore text before first property.
1492 (org-export-read-attribute
1494 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1495 (org-element-at-point))))))
1497 (ert-deftest test-org-export
/get-caption
()
1498 "Test `org-export-get-caption' specifications."
1499 ;; Without optional argument, return long caption
1503 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1504 (org-export-get-caption (org-element-at-point)))))
1505 ;; With optional argument, return short caption.
1509 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1510 (org-export-get-caption (org-element-at-point) t
))))
1511 ;; Multiple lines are separated by white spaces.
1515 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1516 (org-export-get-caption (org-element-at-point))))))
1522 (ert-deftest test-org-export
/define-backend
()
1523 "Test back-end definition and accessors."
1526 (equal '((headline . my-headline-test
))
1527 (let (org-export-registered-backends)
1528 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1529 (org-export-get-all-transcoders 'test
))))
1532 (equal '((:filter-headline . my-filter
))
1533 (let (org-export-registered-backends)
1534 (org-export-define-backend 'test
1535 '((headline . my-headline-test
))
1536 :filters-alist
'((:filter-headline . my-filter
)))
1537 (org-export-backend-filters (org-export-get-backend 'test
)))))
1540 (equal '((:prop value
))
1541 (let (org-export-registered-backends)
1542 (org-export-define-backend 'test
1543 '((headline . my-headline-test
))
1544 :options-alist
'((:prop value
)))
1545 (org-export-backend-options (org-export-get-backend 'test
)))))
1548 (equal '(?k
"Test Export" test
)
1549 (let (org-export-registered-backends)
1550 (org-export-define-backend 'test
1551 '((headline . my-headline-test
))
1552 :menu-entry
'(?k
"Test Export" test
))
1553 (org-export-backend-menu (org-export-get-backend 'test
))))))
1555 (ert-deftest test-org-export
/define-derived-backend
()
1556 "Test `org-export-define-derived-backend' specifications."
1557 ;; Error when parent back-end is not defined.
1559 (let (org-export-registered-backends)
1560 (org-export-define-derived-backend 'test
'parent
)))
1561 ;; Append translation table to parent's.
1563 (equal '((:headline . test
) (:headline . parent
))
1564 (let (org-export-registered-backends)
1565 (org-export-define-backend 'parent
'((:headline . parent
)))
1566 (org-export-define-derived-backend 'test
'parent
1567 :translate-alist
'((:headline . test
)))
1568 (org-export-get-all-transcoders 'test
))))
1569 ;; Options defined in the new back have priority over those defined
1573 (let (org-export-registered-backends)
1574 (org-export-define-backend 'parent
1575 '((:headline . parent
))
1576 :options-alist
'((:a nil nil
'parent
)))
1577 (org-export-define-derived-backend 'test
'parent
1578 :options-alist
'((:a nil nil
'test
)))
1579 (plist-get (org-export--get-global-options
1580 (org-export-get-backend 'test
))
1583 (ert-deftest test-org-export
/derived-backend-p
()
1584 "Test `org-export-derived-backend-p' specifications."
1585 ;; Non-nil with direct match.
1587 (let (org-export-registered-backends)
1588 (org-export-define-backend 'test
'((headline . test
)))
1589 (org-export-derived-backend-p 'test
'test
)))
1591 (let (org-export-registered-backends)
1592 (org-export-define-backend 'test
'((headline . test
)))
1593 (org-export-define-derived-backend 'test2
'test
)
1594 (org-export-derived-backend-p 'test2
'test2
)))
1595 ;; Non-nil with a direct parent.
1597 (let (org-export-registered-backends)
1598 (org-export-define-backend 'test
'((headline . test
)))
1599 (org-export-define-derived-backend 'test2
'test
)
1600 (org-export-derived-backend-p 'test2
'test
)))
1601 ;; Non-nil with an indirect parent.
1603 (let (org-export-registered-backends)
1604 (org-export-define-backend 'test
'((headline . test
)))
1605 (org-export-define-derived-backend 'test2
'test
)
1606 (org-export-define-derived-backend 'test3
'test2
)
1607 (org-export-derived-backend-p 'test3
'test
)))
1610 (let (org-export-registered-backends)
1611 (org-export-define-backend 'test
'((headline . test
)))
1612 (org-export-define-backend 'test2
'((headline . test2
)))
1613 (org-export-derived-backend-p 'test2
'test
)))
1615 (let (org-export-registered-backends)
1616 (org-export-define-backend 'test
'((headline . test
)))
1617 (org-export-define-backend 'test2
'((headline . test2
)))
1618 (org-export-define-derived-backend 'test3
'test2
)
1619 (org-export-derived-backend-p 'test3
'test
))))
1621 (ert-deftest test-org-export
/get-all-transcoders
()
1622 "Test `org-export-get-all-transcoders' specifications."
1623 ;; Return nil when back-end cannot be found.
1624 (should-not (org-export-get-all-transcoders nil
))
1625 ;; Same as `org-export-transcoders' if no parent.
1627 (equal '((headline . ignore
))
1628 (org-export-get-all-transcoders
1629 (org-export-create-backend
1630 :transcoders
'((headline . ignore
))))))
1631 ;; But inherit from all ancestors whenever possible.
1633 (equal '((section . ignore
) (headline . ignore
))
1634 (let (org-export-registered-backends)
1635 (org-export-define-backend 'b1
'((headline . ignore
)))
1636 (org-export-get-all-transcoders
1637 (org-export-create-backend
1638 :parent
'b1
:transcoders
'((section . ignore
)))))))
1640 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1641 (let (org-export-registered-backends)
1642 (org-export-define-backend 'b1
'((headline . ignore
)))
1643 (org-export-define-derived-backend 'b2
'b1
1644 :translate-alist
'((section . ignore
)))
1645 (org-export-get-all-transcoders
1646 (org-export-create-backend
1647 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1648 ;; Back-end transcoders overrule inherited ones.
1651 (let (org-export-registered-backends)
1652 (org-export-define-backend 'b1
'((headline . a
)))
1653 (cdr (assq 'headline
1654 (org-export-get-all-transcoders
1655 (org-export-create-backend
1656 :parent
'b1
:transcoders
'((headline . b
))))))))))
1658 (ert-deftest test-org-export
/get-all-options
()
1659 "Test `org-export-get-all-options' specifications."
1660 ;; Return nil when back-end cannot be found.
1661 (should-not (org-export-get-all-options nil
))
1662 ;; Same as `org-export-options' if no parent.
1664 (equal '((headline . ignore
))
1665 (org-export-get-all-options
1666 (org-export-create-backend
1667 :options
'((headline . ignore
))))))
1668 ;; But inherit from all ancestors whenever possible.
1670 (equal '((:key2 value2
) (:key1 value1
))
1671 (let (org-export-registered-backends)
1672 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1673 (org-export-get-all-options
1674 (org-export-create-backend
1675 :parent
'b1
:options
'((:key2 value2
)))))))
1677 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1678 (let (org-export-registered-backends)
1679 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1680 (org-export-define-derived-backend 'b2
'b1
1681 :options-alist
'((:key2 value2
)))
1682 (org-export-get-all-options
1683 (org-export-create-backend
1684 :parent
'b2
:options
'((:key3 value3
)))))))
1685 ;; Back-end options overrule inherited ones.
1688 (let (org-export-registered-backends)
1689 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1691 (org-export-get-all-options
1692 (org-export-create-backend
1693 :parent
'b1
:options
'((:key1 . b
))))))))))
1695 (ert-deftest test-org-export
/get-all-filters
()
1696 "Test `org-export-get-all-filters' specifications."
1697 ;; Return nil when back-end cannot be found.
1698 (should-not (org-export-get-all-filters nil
))
1699 ;; Same as `org-export-filters' if no parent.
1701 (equal '((:filter-headline . ignore
))
1702 (org-export-get-all-filters
1703 (org-export-create-backend
1704 :filters
'((:filter-headline . ignore
))))))
1705 ;; But inherit from all ancestors whenever possible.
1707 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1708 (let (org-export-registered-backends)
1709 (org-export-define-backend 'b1
1710 nil
:filters-alist
'((:filter-headline . ignore
)))
1711 (org-export-get-all-filters
1712 (org-export-create-backend
1713 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1715 (equal '((:filter-paragraph . ignore
)
1716 (:filter-section . ignore
)
1717 (:filter-headline . ignore
))
1718 (let (org-export-registered-backends)
1719 (org-export-define-backend 'b1
1720 nil
:filters-alist
'((:filter-headline . ignore
)))
1721 (org-export-define-derived-backend 'b2
'b1
1722 :filters-alist
'((:filter-section . ignore
)))
1723 (org-export-get-all-filters
1724 (org-export-create-backend
1725 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1726 ;; Back-end filters overrule inherited ones.
1729 (let (org-export-registered-backends)
1730 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1731 (cdr (assq :filter-headline
1732 (org-export-get-all-filters
1733 (org-export-create-backend
1734 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1736 (ert-deftest test-org-export
/with-backend
()
1737 "Test `org-export-with-backend' definition."
1738 ;; Error when calling an undefined back-end
1739 (should-error (org-export-with-backend nil
"Test"))
1740 ;; Error when called back-end doesn't have an appropriate
1743 (org-export-with-backend
1744 (org-export-create-backend :transcoders
'((headline . ignore
)))
1746 ;; Otherwise, export using correct transcoder
1749 (let (org-export-registered-backends)
1750 (org-export-define-backend 'test
1751 '((plain-text .
(lambda (text contents info
) "Failure"))))
1752 (org-export-define-backend 'test2
1753 '((plain-text .
(lambda (text contents info
) "Success"))))
1754 (org-export-with-backend 'test2
"Test"))))
1755 ;; Provide correct back-end if transcoder needs to use recursive
1759 (let ((test-back-end
1760 (org-export-create-backend
1762 (list (cons 'headline
1763 (lambda (headline contents info
)
1765 (org-element-property :title headline
)
1767 (cons 'plain-text
(lambda (text info
) "Success"))))))
1768 (org-export-string-as
1770 (org-export-create-backend
1772 (list (cons 'headline
1773 (lambda (headline contents info
)
1774 (org-export-with-backend
1775 test-back-end headline contents info
))))))))))
1777 (ert-deftest test-org-export
/data-with-backend
()
1778 "Test `org-export-data-with-backend' specifications."
1779 ;; Error when calling an undefined back-end.
1780 (should-error (org-export-data-with-backend nil
"nil" nil
))
1781 ;; Otherwise, export data recursively, using correct back-end.
1785 (org-export-data-with-backend
1787 (org-export-create-backend
1789 '((plain-text .
(lambda (text info
) "Success"))
1790 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1791 '(:with-emphasize t
)))))
1797 (ert-deftest test-org-export
/comments
()
1798 "Test comments handling during export.
1799 In particular, structure of the document mustn't be altered after
1802 (equal "Para1\n\nPara2\n"
1803 (org-test-with-temp-text "
1809 (org-export-as (org-test-default-backend)))))
1811 (equal "Para1\n\nPara2\n"
1812 (org-test-with-temp-text "
1816 (org-export-as (org-test-default-backend)))))
1818 (equal "[fn:1] Para1\n\n\nPara2\n"
1819 (org-test-with-temp-text "
1824 # Outside definition
1826 (org-export-as (org-test-default-backend)))))
1828 (equal "[fn:1] Para1\n\nPara2\n"
1829 (org-test-with-temp-text "
1837 (org-export-as (org-test-default-backend)))))
1839 (equal "[fn:1] Para1\n\nPara2\n"
1840 (org-test-with-temp-text "
1845 (org-export-as (org-test-default-backend)))))
1847 (equal "[fn:1] Para1\n\nPara2\n"
1848 (org-test-with-temp-text "
1853 (org-export-as (org-test-default-backend)))))
1855 (equal "- item 1\n\n- item 2\n"
1856 (org-test-with-temp-text "
1862 (org-export-as (org-test-default-backend))))))
1868 (ert-deftest test-org-export
/export-block
()
1869 "Test export blocks transcoding."
1872 (org-test-with-temp-text
1873 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1875 (org-export-create-backend
1876 :transcoders
'((export-block .
(lambda (b _c _i
)
1877 (org-element-property :value b
)))
1878 (section .
(lambda (_s c _i
) c
))))))))
1881 (org-test-with-temp-text
1882 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1884 (org-export-create-backend
1889 (and (equal (org-element-property :type b
) "BACKEND")
1890 (org-element-property :value b
))))
1891 (cons 'section
(lambda (_s c _i
) c
)))))))))
1896 (ert-deftest test-org-export
/export-snippet
()
1897 "Test export snippets transcoding."
1899 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1900 (let ((backend (org-test-default-backend)))
1901 (setf (org-export-backend-name backend
) 'test
)
1902 (setf (org-export-backend-transcoders backend
)
1903 (cons (cons 'export-snippet
1904 (lambda (snippet contents info
)
1905 (when (eq (org-export-snippet-backend snippet
) 'test
)
1906 (org-element-property :value snippet
))))
1907 (org-export-backend-transcoders backend
)))
1908 (let ((org-export-snippet-translation-alist nil
))
1909 (should (equal (org-export-as backend
) "A\n")))
1910 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1911 (should (equal (org-export-as backend
) "AB\n")))))
1912 ;; Ignored export snippets do not remove any blank.
1914 (equal "begin end\n"
1915 (org-test-with-parsed-data "begin @@test:A@@ end"
1916 (org-export-data-with-backend
1918 (org-export-create-backend
1920 '((paragraph .
(lambda (paragraph contents info
) contents
))
1921 (section .
(lambda (section contents info
) contents
))))
1927 (ert-deftest test-org-export
/filter-apply-functions
()
1928 "Test `org-export-filter-apply-functions' specifications."
1929 ;; Functions are applied in order and return values are reduced.
1932 (org-export-filter-apply-functions
1933 (list (lambda (value &rest _
) (concat "1" value
))
1934 (lambda (value &rest _
) (concat "2" value
)))
1936 ;; Functions returning nil are skipped.
1939 (org-export-filter-apply-functions
1940 (list #'ignore
(lambda (value &rest _
) (concat "2" value
)))
1942 ;; If all functions are skipped, return the initial value.
1945 (org-export-filter-apply-functions (list #'ignore
) "0" nil
)))
1946 ;; If any function returns the empty string, final value is the
1950 (org-export-filter-apply-functions
1951 (list (lambda (value &rest _
) "")
1952 (lambda (value &rest _
) (concat "2" value
)))
1954 ;; Any function returning the empty string short-circuits the
1957 (org-export-filter-apply-functions
1958 (list (lambda (value &rest _
) "")
1959 (lambda (value &rest _
) (error "This shouldn't happen")))
1965 (ert-deftest test-org-export
/footnote-first-reference-p
()
1966 "Test `org-export-footnote-first-reference-p' specifications."
1970 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1973 (org-export-create-backend
1975 `(,(cons 'footnote-reference
1977 (push (org-export-footnote-first-reference-p f i
)
1980 (section .
(lambda (s c i
) c
))
1981 (paragraph .
(lambda (p c i
) c
))))
1982 nil nil nil
'(:with-footnotes t
))
1983 (nreverse result
)))))
1984 ;; Limit check to DATA, when non-nil.
1988 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1990 (org-element-map tree
'footnote-reference
1993 (org-export-footnote-first-reference-p
1994 ref info
(org-element-map tree
'headline
#'identity info t
))
1997 (nreverse result
)))))
2001 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
2003 (org-element-map tree
'footnote-reference
2005 (push (org-export-footnote-first-reference-p ref info
) result
))
2007 (nreverse result
)))))
2008 ;; If optional argument BODY-FIRST is non-nil, first find footnote
2009 ;; in the main body of the document. Otherwise, enter footnote
2010 ;; definitions when they are encountered.
2014 (org-test-with-temp-text
2015 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
2018 (org-export-create-backend
2020 `(,(cons 'footnote-reference
2022 (when (org-element-lineage f
'(drawer))
2023 (push (org-export-footnote-first-reference-p f i nil
)
2026 (drawer .
(lambda (d c i
) c
))
2027 (footnote-definition .
(lambda (d c i
) c
))
2028 (section .
(lambda (s c i
) c
))
2029 (paragraph .
(lambda (p c i
) c
))))
2030 nil nil nil
'(:with-footnotes t
))
2031 (nreverse result
)))))
2035 (org-test-with-temp-text
2036 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
2039 (org-export-create-backend
2041 `(,(cons 'footnote-reference
2043 (when (org-element-lineage f
'(drawer))
2044 (push (org-export-footnote-first-reference-p f i nil t
)
2047 (drawer .
(lambda (d c i
) c
))
2048 (footnote-definition .
(lambda (d c i
) c
))
2049 (section .
(lambda (s c i
) c
))
2050 (paragraph .
(lambda (p c i
) c
))))
2051 nil nil nil
'(:with-footnotes t
))
2052 (nreverse result
))))))
2054 (ert-deftest test-org-export
/get-footnote-number
()
2055 "Test `org-export-get-footnote-number' specifications."
2058 (org-test-with-parsed-data
2059 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
2060 (org-element-map tree
'footnote-reference
2061 (lambda (ref) (org-export-get-footnote-number ref info
))
2063 ;; Anonymous footnotes all get a new number.
2066 (org-test-with-parsed-data
2067 "Text[fn::anon1][fn::anon2]"
2068 (org-element-map tree
'footnote-reference
2069 (lambda (ref) (org-export-get-footnote-number ref info
))
2071 ;; Test nested footnotes order.
2074 '((1 .
"1") (2 .
"2") (3 .
"3") (3 .
"3") (4))
2075 (org-test-with-parsed-data
2076 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
2077 (org-element-map tree
'footnote-reference
2079 (cons (org-export-get-footnote-number ref info
)
2080 (org-element-property :label ref
)))
2082 ;; Limit number to provided DATA, when non-nil.
2086 (org-test-with-parsed-data
2087 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2088 (org-element-map tree
'footnote-reference
2090 (org-export-get-footnote-number
2091 ref info
(org-element-map tree
'headline
#'identity info t
)))
2096 (org-test-with-parsed-data
2097 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
2098 (org-element-map tree
'footnote-reference
2099 (lambda (ref) (org-export-get-footnote-number ref info
))
2101 ;; With a non-nil BODY-FIRST optional argument, first check body,
2102 ;; then footnote definitions.
2105 '(("1" .
1) ("2" .
2) ("3" .
3) ("3" .
3))
2106 (org-test-with-parsed-data
2107 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2108 (org-element-map tree
'footnote-reference
2110 (cons (org-element-property :label ref
)
2111 (org-export-get-footnote-number ref info nil t
)))
2115 '(("1" .
1) ("2" .
3) ("3" .
2) ("3" .
2))
2116 (org-test-with-parsed-data
2117 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2118 (org-element-map tree
'footnote-reference
2120 (cons (org-element-property :label ref
)
2121 (org-export-get-footnote-number ref info nil
)))
2124 (ert-deftest test-org-export
/get-footnote-definition
()
2125 "Test `org-export-get-footnote-definition' specifications."
2129 (org-element-interpret-data
2130 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1] A"
2131 (org-export-get-footnote-definition
2132 (org-element-map tree
'footnote-reference
#'identity nil t
)
2134 ;; Raise an error if no definition is found.
2136 (org-test-with-parsed-data "Text[fn:1]"
2137 (org-export-get-footnote-definition
2138 (org-element-map tree
'footnote-reference
#'identity nil t
)
2140 ;; Find inline definitions.
2143 (org-element-interpret-data
2144 (org-test-with-parsed-data "Text[fn:1:A]"
2145 (org-export-get-footnote-definition
2146 (org-element-map tree
'footnote-reference
#'identity nil t
)
2148 ;; Find anonymous definitions.
2151 (org-element-interpret-data
2152 (org-test-with-parsed-data "Text[fn::A]"
2153 (org-export-get-footnote-definition
2154 (org-element-map tree
'footnote-reference
#'identity nil t
)
2156 ;; Find empty definitions.
2159 (org-element-interpret-data
2160 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1]"
2161 (org-export-get-footnote-definition
2162 (org-element-map tree
'footnote-reference
#'identity nil t
)
2166 (org-element-interpret-data
2167 (org-test-with-parsed-data "Text[fn:1:]"
2168 (org-export-get-footnote-definition
2169 (org-element-map tree
'footnote-reference
#'identity nil t
)
2173 (org-element-interpret-data
2174 (org-test-with-parsed-data "Text[fn::]"
2175 (org-export-get-footnote-definition
2176 (org-element-map tree
'footnote-reference
#'identity nil t
)
2179 (ert-deftest test-org-export
/collect-footnote-definitions
()
2180 "Test `org-export-collect-footnote-definitions' specifications."
2183 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2185 \[fn:2] B [fn:3] [fn::D].
2188 (length (org-export-collect-footnote-definitions info
)))))
2189 ;; Limit number to provided DATA, when non-nil.
2193 (org-test-with-parsed-data
2194 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2196 (org-export-collect-footnote-definitions
2197 info
(org-element-map tree
'headline
#'identity info t
))))))
2201 (org-test-with-parsed-data
2202 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2203 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
2204 ;; With optional argument BODY-FIRST, first check body, then
2205 ;; footnote definitions.
2207 (equal '("1" "3" "2" nil
)
2208 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2210 \[fn:2] B [fn:3] [fn::D].
2213 (mapcar (lambda (e) (nth 1 e
))
2214 (org-export-collect-footnote-definitions info nil t
)))))
2216 (equal '("1" "3" "2" nil
)
2217 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2219 \[fn:2] B [fn:3] [fn::D].
2222 (mapcar (lambda (e) (nth 1 e
))
2223 (org-export-collect-footnote-definitions info
))))))
2225 (ert-deftest test-org-export
/footnotes
()
2226 "Miscellaneous tests on footnotes."
2227 (let ((org-footnote-section nil
)
2228 (org-export-with-footnotes t
))
2229 ;; Read every type of footnote.
2232 '((1 .
"A\n") (2 .
"C") (3 .
"D"))
2233 (org-test-with-parsed-data
2234 "Text[fn:1] [fn:label:C] [fn::D]\n\n[fn:1] A\n"
2235 (org-element-map tree
'footnote-reference
2237 (let ((def (org-export-get-footnote-definition ref info
)))
2238 (cons (org-export-get-footnote-number ref info
)
2239 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
2240 (car (org-element-contents
2241 (car (org-element-contents def
))))))))
2243 ;; Export nested footnote in invisible definitions.
2246 (org-test-with-temp-text "Text[fn:1]\n\n[fn:1] B [fn:2]\n\n[fn:2] C."
2247 (narrow-to-region (point) (line-end-position))
2250 (org-export-create-backend
2255 (throw 'exit
(length
2256 (org-export-collect-footnote-definitions
2258 ;; Export footnotes defined outside parsing scope.
2262 (org-test-with-temp-text "[fn:1] Out of scope
2264 <point>Paragraph[fn:1]"
2265 (org-export-as (org-test-default-backend) 'subtree
))))
2269 (org-test-with-temp-text "[fn:1] Out of scope
2271 <point>Paragraph[fn:1]"
2272 (narrow-to-region (point) (point-max))
2273 (org-export-as (org-test-default-backend)))))
2274 ;; Export nested footnotes defined outside parsing scope.
2278 (org-test-with-temp-text "
2279 \[fn:1] Out of scope[fn:2]
2281 \[fn:2] Very out of scope
2283 <point>Paragraph[fn:1]"
2284 (org-export-as (org-test-default-backend) 'subtree
))))
2288 (org-test-with-temp-text "
2289 \[fn:1] Out of scope[fn:2]
2291 \[fn:2] Very out of scope
2293 <point>Paragraph[fn:1]"
2294 (narrow-to-region (point) (point-max))
2295 (org-export-as (org-test-default-backend)))))
2299 (org-test-with-temp-text "
2300 \[fn:1] Out of scope[fn:2:D2]
2302 <point>Paragraph[fn:1]"
2303 (narrow-to-region (point) (point-max))
2304 (org-export-as (org-test-default-backend)))))
2305 ;; Export footnotes in pruned parts of tree.
2309 (let ((org-export-exclude-tags '("noexport")))
2310 (org-test-with-temp-text
2311 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] Definition"
2312 (org-export-as (org-test-default-backend))))))
2316 (let ((org-export-select-tags '("export")))
2317 (org-test-with-temp-text
2318 "* H :export:\nText[fn:1]\n* H2\n[fn:1] Definition"
2319 (org-export-as (org-test-default-backend))))))
2320 ;; Export nested footnotes in pruned parts of tree.
2324 (let ((org-export-exclude-tags '("noexport")))
2325 (org-test-with-temp-text
2326 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2327 (org-export-as (org-test-default-backend))))))
2331 (let ((org-export-select-tags '("export")))
2332 (org-test-with-temp-text
2333 "* H :export:\nText[fn:1]\n* H2\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2334 (org-export-as (org-test-default-backend))))))
2335 ;; Handle uninterpreted data in pruned footnote definitions.
2339 (let ((org-export-with-tables nil
))
2340 (org-test-with-temp-text
2341 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1]\n| a |"
2342 (org-export-as (org-test-default-backend))))))
2343 ;; Footnotes without a definition should throw an error.
2345 (org-test-with-parsed-data "Text[fn:1]"
2346 (org-export-get-footnote-definition
2347 (org-element-map tree
'footnote-reference
#'identity info t
) info
)))
2348 ;; Footnote section should be ignored in TOC and in headlines
2351 (= 1 (let ((org-footnote-section "Footnotes"))
2352 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
2353 (org-export-collect-headlines info
))))))
2356 (let ((org-footnote-section "Footnotes"))
2357 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
2358 (org-element-map tree
'headline
2360 (when (equal (org-element-property :raw-value hl
) "H2")
2361 (org-export-get-headline-number hl info
)))
2366 ;;; Headlines and Inlinetasks
2368 (ert-deftest test-org-export
/get-relative-level
()
2369 "Test `org-export-get-relative-level' specifications."
2373 (let ((org-odd-levels-only nil
))
2374 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2375 (org-element-map tree
'headline
2376 (lambda (h) (org-export-get-relative-level h info
))
2381 (let ((org-odd-levels-only nil
))
2382 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
2383 (org-element-map tree
'headline
2384 (lambda (h) (org-export-get-relative-level h info
))
2387 (ert-deftest test-org-export
/low-level-p
()
2388 "Test `org-export-low-level-p' specifications."
2392 (let ((org-odd-levels-only nil
))
2393 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2394 (org-element-map tree
'headline
2395 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
2396 (plist-put info
:headline-levels
1)))))))
2398 (ert-deftest test-org-export
/get-headline-number
()
2399 "Test `org-export-get-headline-number' specifications."
2404 (let ((org-odd-levels-only nil
))
2405 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2406 (org-element-map tree
'headline
2407 (lambda (h) (org-export-get-headline-number h info
))
2409 ;; Missing levels are replaced with 0.
2413 (let ((org-odd-levels-only nil
))
2414 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
2415 (org-element-map tree
'headline
2416 (lambda (h) (org-export-get-headline-number h info
))
2419 (ert-deftest test-org-export
/numbered-headline-p
()
2420 "Test `org-export-numbered-headline-p' specifications."
2421 ;; If `:section-numbers' is nil, never number headlines.
2423 (org-test-with-parsed-data "* Headline"
2424 (org-element-map tree
'headline
2425 (lambda (h) (org-export-numbered-headline-p h info
))
2426 (plist-put info
:section-numbers nil
))))
2427 ;; If `:section-numbers' is a number, only number headlines with
2428 ;; a level greater that it.
2432 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2433 (org-element-map tree
'headline
2434 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
2435 (plist-put info
:section-numbers
1)))))
2436 ;; Otherwise, headlines are always numbered.
2438 (org-test-with-parsed-data "* Headline"
2439 (org-element-map tree
'headline
2440 (lambda (h) (org-export-numbered-headline-p h info
))
2441 (plist-put info
:section-numbers t
))))
2442 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
2444 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
2445 (org-export-numbered-headline-p
2446 (org-element-map tree
'headline
'identity info t
)
2448 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
2450 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
2451 (org-export-numbered-headline-p
2452 (org-element-map tree
'headline
#'identity info t
)
2454 ;; UNNUMBERED ignores inheritance. Any non-nil value among
2455 ;; ancestors disables numbering.
2457 (org-test-with-parsed-data
2468 (lambda (h) (not (org-export-numbered-headline-p h info
)))
2469 (org-element-map tree
'headline
#'identity info
)))))
2471 (ert-deftest test-org-export
/number-to-roman
()
2472 "Test `org-export-number-to-roman' specifications."
2473 ;; If number is negative, return it as a string.
2474 (should (equal (org-export-number-to-roman -
1) "-1"))
2475 ;; Otherwise, return it as a roman number.
2476 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
2478 (ert-deftest test-org-export
/get-optional-title
()
2479 "Test `org-export-get-alt-title' specifications."
2480 ;; If ALT_TITLE property is defined, use it.
2483 (org-test-with-parsed-data
2484 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
2485 (org-export-get-alt-title
2486 (org-element-map tree
'headline
'identity info t
)
2488 ;; Otherwise, fall-back to regular title.
2490 (equal '("Headline")
2491 (org-test-with-parsed-data "* Headline"
2492 (org-export-get-alt-title
2493 (org-element-map tree
'headline
'identity info t
)
2496 (ert-deftest test-org-export
/get-tags
()
2497 "Test `org-export-get-tags' specifications."
2498 ;; Standard test: tags which are not a select tag, an exclude tag,
2499 ;; or specified as optional argument shouldn't be ignored.
2501 (org-test-with-parsed-data "* Headline :tag:"
2502 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2504 ;; Tags provided in the optional argument are ignored.
2506 (org-test-with-parsed-data "* Headline :ignore:"
2507 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2509 ;; Allow tag inheritance.
2513 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2514 (org-element-map tree
'headline
2515 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2516 ;; Tag inheritance checks FILETAGS keywords.
2520 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2521 (org-element-map tree
'headline
2522 (lambda (hl) (org-export-get-tags hl info nil t
)) info
)))))
2524 (ert-deftest test-org-export
/get-node-property
()
2525 "Test`org-export-get-node-property' specifications."
2529 (org-test-with-parsed-data "* Headline
2533 (org-export-get-node-property
2534 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2535 ;; Test inheritance.
2538 (org-test-with-parsed-data "* Parent
2544 (org-export-get-node-property
2545 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2546 ;; Cannot return a value before the first headline.
2548 (org-test-with-parsed-data "Paragraph
2553 (org-export-get-node-property
2554 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2556 (ert-deftest test-org-export
/get-category
()
2557 "Test `org-export-get-category' specifications."
2561 (org-test-with-parsed-data "* Headline
2565 (org-export-get-category
2566 (org-element-map tree
'headline
'identity nil t
) info
))))
2567 ;; Test inheritance from a parent headline.
2569 (equal '("value" "value")
2570 (org-test-with-parsed-data "* Headline1
2575 (org-element-map tree
'headline
2576 (lambda (hl) (org-export-get-category hl info
)) info
))))
2577 ;; Test inheritance from #+CATEGORY keyword
2580 (org-test-with-parsed-data "#+CATEGORY: value
2582 (org-export-get-category
2583 (org-element-map tree
'headline
'identity nil t
) info
))))
2584 ;; Test inheritance from file name.
2587 (org-test-with-parsed-data "* Headline"
2588 (let ((info (plist-put info
:input-file
"~/test.org")))
2589 (org-export-get-category
2590 (org-element-map tree
'headline
'identity nil t
) info
)))))
2594 (org-test-with-parsed-data "* Headline"
2595 (org-export-get-category
2596 (org-element-map tree
'headline
'identity nil t
) info
)))))
2598 (ert-deftest test-org-export
/first-sibling-p
()
2599 "Test `org-export-first-sibling-p' specifications."
2604 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2605 (org-element-map tree
'headline
2606 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2610 (org-test-with-parsed-data "- item\n\n para"
2611 (org-element-map tree
'paragraph
2612 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2614 ;; Ignore sections for headlines.
2617 (org-test-with-parsed-data "* H\nSection\n** H 2"
2618 (org-element-map tree
'headline
2619 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2621 ;; Ignore headlines not exported.
2625 (let ((org-export-exclude-tags '("ignore")))
2626 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2627 (org-element-map tree
'headline
2628 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2631 (ert-deftest test-org-export
/last-sibling-p
()
2632 "Test `org-export-last-sibling-p' specifications."
2637 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2638 (org-element-map tree
'headline
2639 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2643 (org-test-with-parsed-data "- item\n\n para"
2644 (org-element-map tree
'paragraph
2645 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2647 ;; Ignore headlines not exported.
2651 (let ((org-export-exclude-tags '("ignore")))
2652 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2653 (org-element-map tree
'headline
2654 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2657 (ert-deftest test-org-export
/handle-inlinetasks
()
2658 "Test inlinetask export."
2659 ;; Inlinetask with an exclude tag.
2660 (when (featurep 'org-inlinetask
)
2664 (let ((org-inlinetask-min-level 3)
2665 org-export-filter-body-functions
2666 org-export-filter-final-output-functions
)
2667 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2668 (org-export-as (org-test-default-backend)
2669 nil nil nil
'(:exclude-tags
("noexp")))))))
2670 ;; Inlinetask with an include tag.
2673 "* H2\n*** Inline :exp:\n"
2674 (let ((org-inlinetask-min-level 3)
2675 (org-tags-column 0))
2676 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2677 (org-export-as (org-test-default-backend)
2678 nil nil nil
'(:select-tags
("exp")))))))
2679 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2682 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2683 (org-inlinetask-min-level 3)
2684 org-export-filter-body-functions
2685 org-export-filter-final-output-functions
)
2686 (org-test-with-temp-text "*** TODO Inline"
2687 (org-export-as (org-test-default-backend)
2688 nil nil nil
'(:with-tasks nil
))))))))
2694 (ert-deftest test-org-export
/get-date
()
2695 "Test `org-export-get-date' specifications."
2696 ;; Return a properly formatted string when
2697 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2698 ;; consists in a single timestamp.
2701 (let ((org-export-date-timestamp-format "%d %m %Y"))
2702 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2703 (org-export-get-date info
)))))
2704 ;; Return a secondary string otherwise.
2707 (let ((org-export-date-timestamp-format nil
))
2708 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2709 (org-export-get-date info
)))))
2712 (org-test-with-parsed-data "#+DATE: Date"
2713 (org-export-get-date info
))))
2714 ;; Optional argument has precedence over
2715 ;; `org-export-date-timestamp-format'.
2718 (let ((org-export-date-timestamp-format "%d %m %Y"))
2719 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2720 (org-export-get-date info
"%d %m"))))))
2726 (ert-deftest test-org-export
/custom-protocol-maybe
()
2727 "Test `org-export-custom-protocol-maybe' specifications."
2732 (org-link-set-parameters "foo" :export
(lambda (p d f
) "success"))
2733 (org-export-string-as
2735 (org-export-create-backend
2738 '((section .
(lambda (s c i
) c
))
2739 (paragraph .
(lambda (p c i
) c
))
2740 (link .
(lambda (l c i
)
2741 (or (org-export-custom-protocol-maybe l c
'test
)
2747 (org-link-set-parameters
2748 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2749 (org-export-string-as
2751 (org-export-create-backend
2754 '((section .
(lambda (s c i
) c
))
2755 (paragraph .
(lambda (p c i
) c
))
2756 (link .
(lambda (l c i
)
2757 (or (org-export-custom-protocol-maybe l c
'no-test
)
2759 ;; Ignore anonymous back-ends.
2764 (org-link-set-parameters
2765 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2766 (org-export-string-as
2768 (org-export-create-backend
2770 '((section .
(lambda (s c i
) c
))
2771 (paragraph .
(lambda (p c i
) c
))
2772 (link .
(lambda (l c i
)
2773 (or (org-export-custom-protocol-maybe l c nil
)
2776 (ert-deftest test-org-export
/get-coderef-format
()
2777 "Test `org-export-get-coderef-format' specifications."
2778 ;; A link without description returns "%s"
2779 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2781 ;; Return "%s" when path is matched within description.
2782 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2784 ;; Otherwise return description.
2785 (should (equal (org-export-get-coderef-format "path" "desc")
2788 (ert-deftest test-org-export
/inline-image-p
()
2789 "Test `org-export-inline-image-p' specifications."
2791 (org-export-inline-image-p
2792 (org-test-with-temp-text "[[#id]]"
2793 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2794 '(("custom-id" .
"id")))))
2796 (ert-deftest test-org-export
/insert-image-links
()
2797 "Test `org-export-insert-image-links' specifications."
2800 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2801 (org-element-map tree
'link
2802 (lambda (l) (org-element-property :type l
))))))
2805 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2806 (org-element-map (org-export-insert-image-links tree info
) 'link
2807 (lambda (l) (org-element-property :type l
))))))
2808 ;; Properly set `:parent' property when replace contents with image
2812 (org-test-with-parsed-data "[[http://orgmode.org][file:image.png]]"
2813 (org-element-map (org-export-insert-image-links tree info
) 'link
2815 (org-element-type (org-element-property :parent l
)))))))
2816 ;; With optional argument RULES, recognize different links as
2820 (org-test-with-parsed-data "[[http://orgmode.org][file:image.xxx]]"
2821 (org-element-map (org-export-insert-image-links tree info
) 'link
2822 (lambda (l) (org-element-property :type l
))))))
2825 (org-test-with-parsed-data "[[http://orgmode.org][file:image.xxx]]"
2827 (org-export-insert-image-links tree info
'(("file" .
"xxx")))
2829 (lambda (l) (org-element-property :type l
)))))))
2831 (ert-deftest test-org-export
/fuzzy-link
()
2832 "Test fuzzy links specifications."
2833 ;; Link to an headline should return headline's number.
2835 ;; Note: Headline's number is in fact a list of numbers.
2837 (org-test-with-parsed-data
2838 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2839 (org-element-map tree
'link
2841 (org-export-get-ordinal
2842 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2843 ;; Link to a target in an item should return item's number.
2845 ;; Note: Item's number is in fact a list of numbers.
2847 (org-test-with-parsed-data
2848 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2849 (org-element-map tree
'link
2851 (org-export-get-ordinal
2852 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2853 ;; Link to a target in a footnote should return footnote's number.
2856 (org-test-with-parsed-data "
2857 Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
2861 (org-element-map tree
'link
2863 (org-export-get-ordinal
2864 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2865 ;; Link to a named element should return sequence number of that
2869 (org-test-with-parsed-data
2870 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2871 (org-element-map tree
'link
2873 (org-export-get-ordinal
2874 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2875 ;; Link to a target not within an item, a table, a footnote
2876 ;; reference or definition should return section number.
2879 (org-test-with-parsed-data
2880 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2881 (org-element-map tree
'link
2883 (org-export-get-ordinal
2884 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2885 ;; Space are not significant when matching a fuzzy link.
2887 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2888 (org-element-map tree
'link
2889 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2891 ;; Statistics cookies are ignored for headline match.
2893 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2894 (org-element-map tree
'link
2895 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2898 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2899 (org-element-map tree
'link
2900 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2903 (defun test-org-gen-loc-list(text type
)
2904 (org-test-with-parsed-data text
2905 (org-element-map tree type
2906 (lambda (el) (or (org-export-get-loc el info
) 'no-loc
)))))
2908 (ert-deftest test-org-export
/get-loc
()
2909 "Test `org-export-get-loc' specifications."
2911 ;; "-n" resets line number.
2913 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n\n Text\n#+END_EXAMPLE"
2915 ;; The first "+n" has 0 lines before it
2918 (test-org-gen-loc-list "#+BEGIN_EXAMPLE +n\n Text\n#+END_EXAMPLE"
2920 ;; "-n 10" resets line number but has "9 lines" before it.
2923 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n Text\n#+END_EXAMPLE"
2925 ;; -n10 with two lines then +n 15
2928 (test-org-gen-loc-list "
2929 #+BEGIN_EXAMPLE -n 10
2933 #+BEGIN_EXAMPLE +n 15
2939 (test-org-gen-loc-list "
2940 #+BEGIN_EXAMPLE -n 10
2943 #+BEGIN_EXAMPLE +n 10
2951 ;; an Example Block without -n does not add to the line count.
2953 (equal '(9 no-loc
19)
2954 (test-org-gen-loc-list "
2955 #+BEGIN_EXAMPLE -n 10
2961 #+BEGIN_EXAMPLE +n 10
2965 ;; "-n" resets line number.
2969 (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n \n (- 1 1) \n#+END_SRC"
2971 ;; The first "+n" has 0 lines before it.
2974 (test-org-gen-loc-list
2975 "#+BEGIN_SRC emacs-lisp +n \n (+ 0 (- 1 1))\n#+END_SRC"
2977 ;; "-n 10" resets line number but has "9 lines" before it.
2980 (test-org-gen-loc-list
2981 "#+BEGIN_SRC emacs-lisp -n 10\n (- 10 1)\n#+END_SRC"
2985 (test-org-gen-loc-list "
2986 #+BEGIN_SRC emacs-lisp -n 10
2990 #+BEGIN_SRC emacs-lisp +n 15
2991 (+ (- 10 1) 2 (- 15 1))
2996 (test-org-gen-loc-list "
2997 #+BEGIN_SRC emacs-lisp -n 10
3000 #+BEGIN_SRC emacs-lisp +n 10
3001 (+ (- 10 1) 1 (- 10 1))
3003 #+BEGIN_SRC emacs-lisp -n
3007 ;; A SRC Block without -n does not add to the line count.
3009 (equal '(9 no-loc
19)
3010 (test-org-gen-loc-list
3011 "#+BEGIN_SRC emacs-lisp -n 10
3014 #+BEGIN_SRC emacs-lisp
3017 #+BEGIN_SRC emacs-lisp +n 10
3018 (+ (- 10 1) 1 (- 10 1))
3022 (ert-deftest test-org-export
/resolve-coderef
()
3023 "Test `org-export-resolve-coderef' specifications."
3024 (let ((org-coderef-label-format "(ref:%s)"))
3025 ;; A link to a "-n -k -r" block returns line number.
3028 (org-test-with-parsed-data
3029 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3030 (org-export-resolve-coderef "coderef" info
))))
3033 (org-test-with-parsed-data
3034 "#+BEGIN_EXAMPLE -n 10 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3035 (org-export-resolve-coderef "coderef" info
))))
3038 (org-test-with-parsed-data
3039 "#+BEGIN_EXAMPLE -n 10 -k -r\nText \n#+END_EXAMPLE\n
3040 #+BEGIN_EXAMPLE +n 125 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
3041 (org-export-resolve-coderef "coderef" info
))))
3044 (org-test-with-parsed-data
3045 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3046 (org-export-resolve-coderef "coderef" info
))))
3049 (org-test-with-parsed-data
3050 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3051 (org-export-resolve-coderef "coderef" info
))))
3054 (org-test-with-parsed-data
3055 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) \n#+END_SRC\n
3056 #+BEGIN_SRC emacs-lisp +n 125 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3057 (org-export-resolve-coderef "coderef" info
))))
3058 ;; A link to a "-n -r" block returns line number.
3061 (org-test-with-parsed-data
3062 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
3063 (org-export-resolve-coderef "coderef" info
))))
3066 (org-test-with-parsed-data
3067 "#+BEGIN_EXAMPLE -n 10 -r\nText (ref:coderef)\n#+END_EXAMPLE"
3068 (org-export-resolve-coderef "coderef" info
))))
3071 (org-test-with-parsed-data
3072 "#+BEGIN_EXAMPLE +n 10 -r\nText \n#+END_EXAMPLE
3073 #+BEGIN_EXAMPLE +n 125 -r\nText (ref:coderef)\n#+END_EXAMPLE"
3074 (org-export-resolve-coderef "coderef" info
))))
3078 (org-test-with-parsed-data
3079 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3080 (org-export-resolve-coderef "coderef" info
))))
3083 (org-test-with-parsed-data
3084 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3085 (org-export-resolve-coderef "coderef" info
))))
3088 (org-test-with-parsed-data
3089 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) \n#+END_SRC
3090 #+BEGIN_SRC emacs-lisp +n125 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3091 (org-export-resolve-coderef "coderef" info
))))
3092 ;; A link to a "-n" block returns coderef.
3095 (org-test-with-parsed-data
3096 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3097 (org-export-resolve-coderef "coderef" info
))))
3100 (org-test-with-parsed-data
3101 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
3102 (org-export-resolve-coderef "coderef" info
))))
3103 ;; A link to a "-r" block returns line number.
3106 (org-test-with-parsed-data
3107 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3108 (org-export-resolve-coderef "coderef" info
))))
3111 (org-test-with-parsed-data
3112 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
3113 (org-export-resolve-coderef "coderef" info
))))
3114 ;; A link to a block without a switch returns coderef.
3117 (org-test-with-parsed-data
3118 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3119 (org-export-resolve-coderef "coderef" info
))))
3120 (org-test-with-parsed-data
3121 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
3122 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
3123 ;; Correctly handle continued line numbers. A "+n" switch should
3124 ;; resume numbering from previous block with numbered lines,
3125 ;; ignoring blocks not numbering lines in the process. A "-n"
3126 ;; switch resets count.
3129 (org-test-with-parsed-data "
3134 #+BEGIN_SRC emacs-lisp
3138 #+BEGIN_SRC emacs-lisp +n -r
3139 \(+ 1 1) (ref:addition)
3142 #+BEGIN_EXAMPLE -n -r
3143 Another text. (ref:text)
3145 (list (org-export-resolve-coderef "addition" info
)
3146 (org-export-resolve-coderef "text" info
)))))
3147 ;; Recognize coderef with user-specified syntax.
3151 (org-test-with-parsed-data
3152 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
3153 (org-export-resolve-coderef "text" info
))))
3154 ;; Unresolved coderefs raise a `org-link-broken' signal.
3157 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3158 (org-export-resolve-coderef "unknown" info
))
3159 (org-link-broken t
)))))
3161 (ert-deftest test-org-export
/resolve-fuzzy-link
()
3162 "Test `org-export-resolve-fuzzy-link' specifications."
3163 ;; Match target objects.
3165 (org-test-with-parsed-data "<<target>> [[target]]"
3166 (org-export-resolve-fuzzy-link
3167 (org-element-map tree
'link
'identity info t
) info
)))
3168 ;; Match named elements.
3170 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
3171 (org-export-resolve-fuzzy-link
3172 (org-element-map tree
'link
'identity info t
) info
)))
3173 ;; Match exact headline's name.
3175 (org-test-with-parsed-data "* My headline\n[[My headline]]"
3176 (org-export-resolve-fuzzy-link
3177 (org-element-map tree
'link
'identity info t
) info
)))
3178 ;; Targets objects have priority over headline titles.
3181 (org-test-with-parsed-data "* target\n<<target>>[[target]]"
3183 (org-export-resolve-fuzzy-link
3184 (org-element-map tree
'link
'identity info t
) info
)))))
3185 ;; Named elements have priority over headline titles.
3188 (org-test-with-parsed-data
3189 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
3191 (org-export-resolve-fuzzy-link
3192 (org-element-map tree
'link
'identity info t
) info
)))))
3193 ;; If link's path starts with a "*", only match headline titles,
3197 (org-test-with-parsed-data
3198 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
3200 (org-export-resolve-fuzzy-link
3201 (org-element-map tree
'link
'identity info t
) info
)))))
3202 ;; Raise a `org-link-broken' signal if no match.
3204 (org-test-with-parsed-data "[[target]]"
3206 (org-export-resolve-fuzzy-link
3207 (org-element-map tree
'link
#'identity info t
) info
)
3208 (org-link-broken t
))))
3209 ;; Match fuzzy link even when before first headline.
3212 (org-test-with-parsed-data "[[hl]]\n* hl"
3214 (org-export-resolve-fuzzy-link
3215 (org-element-map tree
'link
'identity info t
) info
)))))
3216 ;; Handle url-encoded fuzzy links.
3218 (org-test-with-parsed-data "* A B\n[[A%20B]]"
3219 (org-export-resolve-fuzzy-link
3220 (org-element-map tree
'link
#'identity info t
) info
))))
3222 (ert-deftest test-org-export
/resolve-id-link
()
3223 "Test `org-export-resolve-id-link' specifications."
3224 ;; Regular test for custom-id link.
3226 (equal '("Headline1")
3227 (org-test-with-parsed-data "* Headline1
3233 (org-element-property
3235 (org-export-resolve-id-link
3236 (org-element-map tree
'link
'identity info t
) info
)))))
3237 ;; Raise a `org-link-broken' signal on failing searches.
3239 (org-test-with-parsed-data "* Headline1
3246 (org-export-resolve-id-link
3247 (org-element-map tree
'link
#'identity info t
) info
)
3248 (org-link-broken t
))))
3249 ;; Test for internal id target.
3251 (equal '("Headline1")
3252 (org-test-with-parsed-data "* Headline1
3258 (org-element-property
3260 (org-export-resolve-id-link
3261 (org-element-map tree
'link
'identity info t
) info
)))))
3262 ;; Test for external id target.
3266 (org-test-with-parsed-data "[[id:aaaa]]"
3267 (org-export-resolve-id-link
3268 (org-element-map tree
'link
'identity info t
)
3269 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
3271 (ert-deftest test-org-export
/resolve-radio-link
()
3272 "Test `org-export-resolve-radio-link' specifications."
3275 (org-test-with-temp-text "<<<radio>>> radio"
3276 (org-update-radio-target-regexp)
3277 (let* ((tree (org-element-parse-buffer))
3278 (info `(:parse-tree
,tree
)))
3279 (org-export-resolve-radio-link
3280 (org-element-map tree
'link
'identity info t
)
3282 ;; Radio targets are case-insensitive.
3284 (org-test-with-temp-text "<<<RADIO>>> radio"
3285 (org-update-radio-target-regexp)
3286 (let* ((tree (org-element-parse-buffer))
3287 (info `(:parse-tree
,tree
)))
3288 (org-export-resolve-radio-link
3289 (org-element-map tree
'link
'identity info t
)
3291 ;; Radio target with objects.
3293 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
3294 (org-update-radio-target-regexp)
3295 (let* ((tree (org-element-parse-buffer))
3296 (info `(:parse-tree
,tree
)))
3297 (org-export-resolve-radio-link
3298 (org-element-map tree
'link
'identity info t
)
3300 ;; Radio target with objects at its beginning.
3302 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
3303 (org-update-radio-target-regexp)
3304 (let* ((tree (org-element-parse-buffer))
3305 (info `(:parse-tree
,tree
)))
3306 (org-export-resolve-radio-link
3307 (org-element-map tree
'link
'identity info t
)
3309 ;; Radio link next to an apostrophe.
3311 (org-test-with-temp-text "<<<radio>>> radio's"
3312 (org-update-radio-target-regexp)
3313 (let* ((tree (org-element-parse-buffer))
3314 (info `(:parse-tree
,tree
)))
3315 (org-export-resolve-radio-link
3316 (org-element-map tree
'link
'identity info t
)
3318 ;; Multiple radio targets.
3320 (equal '("radio1" "radio2")
3321 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
3322 (org-update-radio-target-regexp)
3323 (let* ((tree (org-element-parse-buffer))
3324 (info `(:parse-tree
,tree
)))
3325 (org-element-map tree
'link
3327 (org-element-property
3328 :value
(org-export-resolve-radio-link link info
)))
3330 ;; Radio target is whitespace insensitive.
3332 (org-test-with-temp-text "<<<a radio>>> a\n radio"
3333 (org-update-radio-target-regexp)
3334 (let* ((tree (org-element-parse-buffer))
3335 (info `(:parse-tree
,tree
)))
3336 (org-element-map tree
'link
3337 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
3339 (ert-deftest test-org-export
/file-uri
()
3340 "Test `org-export-file-uri' specifications."
3341 ;; Preserve relative filenames.
3342 (should (equal "relative.org" (org-export-file-uri "relative.org")))
3343 ;; Local files start with "file://"
3344 (should (equal (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "/local.org"))
3345 (org-export-file-uri "/local.org")))
3346 ;; Remote files start with "file://"
3347 (should (equal "file://myself@some.where:papers/last.pdf"
3348 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
3349 (should (equal "file://localhost/etc/fstab"
3350 (org-export-file-uri "//localhost/etc/fstab")))
3351 ;; Expand filename starting with "~".
3352 (should (equal (org-export-file-uri "~/file.org")
3353 (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "~/file.org")))))
3355 (ert-deftest test-org-export
/get-reference
()
3356 "Test `org-export-get-reference' specifications."
3358 (org-test-with-parsed-data "* Headline"
3359 (org-export-get-reference (org-element-map tree
'headline
#'identity nil t
)
3361 ;; For a given element always return the same reference.
3363 (org-test-with-parsed-data "* Headline"
3364 (let ((headline (org-element-map tree
'headline
#'identity nil t
)))
3365 (equal (org-export-get-reference headline info
)
3366 (org-export-get-reference headline info
)))))
3367 ;; References get through local export back-ends.
3369 (org-test-with-parsed-data "* Headline"
3370 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3372 (org-export-create-backend
3374 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3375 (equal (org-trim (org-export-data-with-backend headline backend info
))
3376 (org-export-get-reference headline info
)))))
3378 (org-test-with-parsed-data "* Headline"
3379 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3381 (org-export-create-backend
3383 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3384 (equal (org-export-with-backend backend headline nil info
)
3385 (org-export-get-reference headline info
)))))
3386 ;; Use search cells defined in `:crossrefs'. However, handle
3387 ;; duplicate search cells.
3390 (org-test-with-parsed-data "* Headline"
3391 (let* ((headline (org-element-map tree
'headline
#'identity nil t
))
3392 (search-cell (car (org-export-search-cells headline
))))
3394 (plist-put info
:crossrefs
(list (cons search-cell
1))))
3395 (org-export-get-reference headline info
)))))
3397 (equal '("org0000001" "org0000001")
3398 (org-test-with-parsed-data "* H\n** H"
3399 (org-element-map tree
'headline
3401 (let* ((search-cell (car (org-export-search-cells h
)))
3402 (info (plist-put info
:crossrefs
3403 (list (cons search-cell
1)))))
3404 (org-export-get-reference h info
))))))))
3407 ;;; Pseudo objects and pseudo elements
3409 (ert-deftest test-org-export
/pseudo-elements
()
3410 "Test exporting pseudo-elements."
3411 ;; Handle blank lines after pseudo-elements. In particular, do not
3412 ;; replace them with white spaces.
3414 (equal "contents\n\nparagraph\n"
3415 (let ((backend (org-export-create-backend
3417 '((pseudo-element .
(lambda (_p c _i
) c
))
3418 (paragraph .
(lambda (_p c _i
) c
))
3419 (plain-text .
(lambda (c _i
) c
)))))
3420 (element '(pseudo-element (:post-blank
1) "contents"))
3421 (paragraph '(paragraph nil
"paragraph"))
3422 (data '(org-data nil
)))
3423 (org-element-adopt-elements data element paragraph
)
3424 (org-export-data-with-backend data backend nil
)))))
3426 (ert-deftest test-org-export
/pseudo-objects
()
3427 "Test exporting pseudo-objects."
3428 ;; Handle blank spaces after pseudo-objects. In particular, do not
3429 ;; replace them with newlines.
3431 (equal "begin x end\n"
3432 (let ((backend (org-export-create-backend
3434 '((pseudo-object .
(lambda (_p c _i
) c
))
3435 (paragraph .
(lambda (_p c _i
) c
))
3436 (plain-text .
(lambda (c _i
) c
)))))
3437 (object '(pseudo-object (:post-blank
1) "x"))
3438 (paragraph '(paragraph nil
)))
3439 (org-element-adopt-elements paragraph
"begin " object
"end")
3440 (org-export-data-with-backend paragraph backend nil
)))))
3443 ;;; Src-block and example-block
3445 (ert-deftest test-org-export
/unravel-code
()
3446 "Test `org-export-unravel-code' function."
3447 ;; Code without reference.
3449 (equal '("(+ 1 1)\n")
3450 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3451 (org-export-unravel-code (org-element-at-point)))))
3452 ;; Code with reference.
3454 (equal '("(+ 1 1)\n" (1 .
"test"))
3455 (org-test-with-temp-text
3456 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
3457 (let ((org-coderef-label-format "(ref:%s)"))
3458 (org-export-unravel-code (org-element-at-point))))))
3459 ;; Code with user-defined reference.
3462 '("(+ 1 1)\n" (1 .
"test"))
3463 (org-test-with-temp-text
3464 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
3465 (let ((org-coderef-label-format "(ref:%s)"))
3466 (org-export-unravel-code (org-element-at-point))))))
3467 ;; Code references keys are relative to the current block.
3469 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
3470 (org-test-with-temp-text "
3479 (let ((org-coderef-label-format "(ref:%s)"))
3480 (org-export-unravel-code (org-element-at-point)))))))
3482 (ert-deftest test-org-export
/format-code-default
()
3483 "Test `org-export-format-code-default' specifications."
3484 ;; Return the empty string when code is empty.
3487 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
3488 (org-export-format-code-default
3489 (org-element-map tree
'src-block
'identity info t
) info
))))
3490 ;; Number lines, two whitespace characters before the actual loc.
3493 (org-test-with-parsed-data
3494 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
3495 (org-export-format-code-default
3496 (org-element-map tree
'src-block
'identity info t
) info
))))
3497 ;; Put references 6 whitespace characters after the widest line,
3498 ;; wrapped within parenthesis.
3500 (equal "123 (a)\n1 (b)\n"
3501 (let ((org-coderef-label-format "(ref:%s)"))
3502 (org-test-with-parsed-data
3503 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
3504 (org-export-format-code-default
3505 (org-element-map tree
'src-block
'identity info t
) info
))))))
3511 (ert-deftest test-org-export
/activate-smart-quotes
()
3512 "Test `org-export-activate-smart-quotes' specifications."
3513 ;; Double quotes: standard test.
3516 '("some “quoted” text")
3517 (let ((org-export-default-language "en"))
3518 (org-test-with-parsed-data "some \"quoted\" text"
3519 (org-element-map tree
'plain-text
3520 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3522 ;; Opening quotes: at the beginning of a paragraph.
3526 (let ((org-export-default-language "en"))
3527 (org-test-with-parsed-data "\"begin"
3528 (org-element-map tree
'plain-text
3529 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3531 ;; Opening quotes: after an object.
3534 '("“quoted” text")
3535 (let ((org-export-default-language "en"))
3536 (org-test-with-parsed-data "=verb= \"quoted\" text"
3537 (org-element-map tree
'plain-text
3538 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3540 ;; Closing quotes: at the end of a paragraph.
3543 '("Quoted “text”")
3544 (let ((org-export-default-language "en"))
3545 (org-test-with-parsed-data "Quoted \"text\""
3546 (org-element-map tree
'plain-text
3547 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3549 ;; Inner quotes: standard test.
3551 (equal '("« outer « inner » outer »")
3552 (let ((org-export-default-language "fr"))
3553 (org-test-with-parsed-data "\"outer 'inner' outer\""
3554 (org-element-map tree
'plain-text
3555 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3557 ;; Inner quotes: close to special symbols.
3559 (equal '("« outer (« inner ») outer »")
3560 (let ((org-export-default-language "fr"))
3561 (org-test-with-parsed-data "\"outer ('inner') outer\""
3562 (org-element-map tree
'plain-text
3563 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3566 (equal '("« « inner » »")
3567 (let ((org-export-default-language "fr"))
3568 (org-test-with-parsed-data "\"'inner'\""
3569 (org-element-map tree
'plain-text
3570 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3572 ;; Apostrophe: standard test.
3574 (equal '("It « shouldn’t » fail")
3575 (let ((org-export-default-language "fr"))
3576 (org-test-with-parsed-data "It \"shouldn't\" fail"
3577 (org-element-map tree
'plain-text
3578 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3581 (equal '("It shouldn’t fail")
3582 (let ((org-export-default-language "fr"))
3583 (org-test-with-parsed-data "It shouldn't fail"
3584 (org-element-map tree
'plain-text
3585 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3587 ;; Apostrophe: before an object.
3590 '("« a’" " »")
3591 (let ((org-export-default-language "fr"))
3592 (org-test-with-parsed-data "\"a'=b=\""
3593 (org-element-map tree
'plain-text
3594 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3596 ;; Apostrophe: after an object.
3598 (equal '("« " "’s »")
3599 (let ((org-export-default-language "fr"))
3600 (org-test-with-parsed-data "\"=code='s\""
3601 (org-element-map tree
'plain-text
3602 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3604 ;; Special case: isolated quotes.
3606 (equal '("“" "”")
3607 (let ((org-export-default-language "en"))
3608 (org-test-with-parsed-data "\"$x$\""
3609 (org-element-map tree
'plain-text
3610 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3612 ;; Smart quotes in secondary strings.
3614 (equal '("“" "”")
3615 (let ((org-export-default-language "en"))
3616 (org-test-with-parsed-data "* \"$x$\""
3617 (org-element-map tree
'plain-text
3618 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3620 ;; Smart quotes in document keywords.
3622 (equal '("“" "”")
3623 (let ((org-export-default-language "en"))
3624 (org-test-with-parsed-data "#+TITLE: \"$x$\""
3625 (org-element-map (plist-get info
:title
) 'plain-text
3626 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3628 ;; Smart quotes in parsed affiliated keywords.
3630 (equal '("“" "”" "Paragraph")
3631 (let ((org-export-default-language "en"))
3632 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
3633 (org-element-map tree
'plain-text
3634 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3636 ;; Smart quotes within objects.
3638 (equal '("“foo”")
3639 (let ((org-export-default-language "en"))
3640 (org-test-with-parsed-data "| \"foo\" |"
3641 (org-element-map tree
'plain-text
3642 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3644 ;; FIXME: Test failing non-interactively.
3647 ;; (equal '("“foo”")
3648 ;; (let ((org-export-default-language "en"))
3649 ;; (org-test-with-parsed-data "*\"foo\"*"
3650 ;; (org-element-map tree 'plain-text
3651 ;; (lambda (s) (org-export-activate-smart-quotes s :html info))
3652 ;; info nil nil t)))))
3659 (ert-deftest test-org-export
/special-column
()
3660 "Test if the table's special column is properly recognized."
3661 ;; 1. First column is special if it contains only a special marking
3662 ;; characters or empty cells.
3663 (org-test-with-temp-text "
3667 (org-export-table-has-special-column-p
3669 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3670 ;; 2. If the column contains anything else, it isn't special.
3671 (org-test-with-temp-text "
3675 (org-export-table-has-special-column-p
3677 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3678 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
3680 (org-test-with-temp-text "
3689 (org-export-table-has-special-column-p
3691 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3692 ;; 4. A first column with only empty cells isn't considered as
3694 (org-test-with-temp-text "
3698 (org-export-table-has-special-column-p
3700 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
3702 (ert-deftest test-org-export
/table-row-is-special-p
()
3703 "Test `org-export-table-row-is-special-p' specifications."
3704 ;; 1. A row is special if it has a special marking character in the
3706 (org-test-with-parsed-data "| ! | 1 |"
3708 (org-export-table-row-is-special-p
3709 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3710 ;; 2. A row is special when its first field is "/"
3711 (org-test-with-parsed-data "
3715 (org-export-table-row-is-special-p
3716 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3717 ;; 3. A row only containing alignment cookies is also considered as
3719 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
3721 (org-export-table-row-is-special-p
3722 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3723 ;; 4. Everything else isn't considered as special.
3724 (org-test-with-parsed-data "| \alpha | | c |"
3726 (org-export-table-row-is-special-p
3727 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3728 ;; 5. Table's rules are never considered as special rows.
3729 (org-test-with-parsed-data "|---+---|"
3731 (org-export-table-row-is-special-p
3732 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
3734 (ert-deftest test-org-export
/has-header-p
()
3735 "Test `org-export-table-has-header-p' specifications."
3738 (org-test-with-parsed-data "
3742 (org-export-table-has-header-p
3743 (org-element-map tree
'table
'identity info
'first-match
)
3745 ;; Without an header.
3747 (org-test-with-parsed-data "
3750 (org-export-table-has-header-p
3751 (org-element-map tree
'table
'identity info
'first-match
)
3753 ;; Don't get fooled with starting and ending rules.
3755 (org-test-with-parsed-data "
3760 (org-export-table-has-header-p
3761 (org-element-map tree
'table
'identity info
'first-match
)
3764 (ert-deftest test-org-export
/table-row-group
()
3765 "Test `org-export-table-row-group' specifications."
3766 ;; A rule creates a new group.
3769 (org-test-with-parsed-data "
3773 (org-element-map tree
'table-row
3775 (if (eq (org-element-property :type row
) 'rule
) 'rule
3776 (org-export-table-row-group row info
)))))))
3777 ;; Special rows are ignored in count.
3781 (org-test-with-parsed-data "
3785 (org-element-map tree
'table-row
3787 (if (eq (org-element-property :type row
) 'rule
) 'rule
3788 (org-export-table-row-group row info
)))
3790 ;; Double rules also are ignored in count.
3792 (equal '(1 rule rule
2)
3793 (org-test-with-parsed-data "
3798 (org-element-map tree
'table-row
3800 (if (eq (org-element-property :type row
) 'rule
) 'rule
3801 (org-export-table-row-group row info
))))))))
3803 (ert-deftest test-org-export
/table-row-number
()
3804 "Test `org-export-table-row-number' specifications."
3805 ;; Standard test. Number is 0-indexed.
3808 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3809 (org-element-map tree
'table-row
3810 (lambda (row) (org-export-table-row-number row info
)) info
))))
3811 ;; Number ignores separators.
3814 (org-test-with-parsed-data "
3818 (org-element-map tree
'table-row
3819 (lambda (row) (org-export-table-row-number row info
)) info
))))
3820 ;; Number ignores special rows.
3823 (org-test-with-parsed-data "
3829 (org-element-map tree
'table-row
3830 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3832 (ert-deftest test-org-export
/table-cell-width
()
3833 "Test `org-export-table-cell-width' specifications."
3834 ;; 1. Width is primarily determined by width cookies. If no cookie
3835 ;; is found, cell's width is nil.
3836 (org-test-with-parsed-data "
3837 | / | <l> | <6> | <l7> |
3842 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3843 (org-element-map tree
'table-cell
'identity info
)))))
3844 ;; 2. The last width cookie has precedence.
3845 (org-test-with-parsed-data "
3852 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3853 (org-element-map tree
'table-cell
'identity info
)))))
3854 ;; 3. Valid width cookies must have a specific row.
3855 (org-test-with-parsed-data "| <6> | cell |"
3859 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3860 (org-element-map tree
'table-cell
'identity
))))))
3862 (ert-deftest test-org-export
/table-cell-alignment
()
3863 "Test `org-export-table-cell-alignment' specifications."
3864 ;; 1. Alignment is primarily determined by alignment cookies.
3866 (equal '(left center right
)
3867 (let ((org-table-number-fraction 0.5)
3868 (org-table-number-regexp "^[0-9]+$"))
3869 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3870 (mapcar (lambda (cell)
3871 (org-export-table-cell-alignment cell info
))
3872 (org-element-map tree
'table-cell
'identity
))))))
3873 ;; 2. The last alignment cookie has precedence.
3875 (equal '(right right right
)
3876 (org-test-with-parsed-data "
3880 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3881 (org-element-map tree
'table-cell
'identity
)))))
3882 ;; 3. If there's no cookie, cell's contents determine alignment.
3883 ;; A column mostly made of cells containing numbers will align
3884 ;; its cells to the right.
3886 (equal '(right right right
)
3887 (let ((org-table-number-fraction 0.5)
3888 (org-table-number-regexp "^[0-9]+$"))
3889 (org-test-with-parsed-data "
3893 (mapcar (lambda (cell)
3894 (org-export-table-cell-alignment cell info
))
3895 (org-element-map tree
'table-cell
'identity
))))))
3896 ;; 4. Otherwise, they will be aligned to the left.
3898 (equal '(left left left
)
3899 (org-test-with-parsed-data "
3903 (mapcar (lambda (cell)
3904 (org-export-table-cell-alignment cell info
))
3905 (org-element-map tree
'table-cell
'identity info
))))))
3907 (ert-deftest test-org-export
/table-cell-borders
()
3908 "Test `org-export-table-cell-borders' specifications."
3909 ;; 1. Recognize various column groups indicators.
3910 (org-test-with-parsed-data "| / | < | > | <> |"
3913 '((right bottom top
) (left bottom top
) (right bottom top
)
3914 (right left bottom top
))
3915 (mapcar (lambda (cell)
3916 (org-export-table-cell-borders cell info
))
3917 (org-element-map tree
'table-cell
'identity
)))))
3918 ;; 2. Accept shortcuts to define column groups.
3919 (org-test-with-parsed-data "| / | < | < |"
3922 '((right bottom top
) (right left bottom top
) (left bottom top
))
3923 (mapcar (lambda (cell)
3924 (org-export-table-cell-borders cell info
))
3925 (org-element-map tree
'table-cell
'identity
)))))
3926 ;; 3. A valid column groups row must start with a "/".
3927 (org-test-with-parsed-data "
3931 (equal '((top) (top) (bottom) (bottom))
3932 (mapcar (lambda (cell)
3933 (org-export-table-cell-borders cell info
))
3934 (org-element-map tree
'table-cell
'identity
)))))
3935 ;; 4. Take table rules into consideration.
3936 (org-test-with-parsed-data "
3941 (equal '((below top
) (bottom above
))
3942 (mapcar (lambda (cell)
3943 (org-export-table-cell-borders cell info
))
3944 (org-element-map tree
'table-cell
'identity
)))))
3945 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3946 ;; (resp. `bottom' and `below') borders. Any special row is
3948 (org-test-with-parsed-data "
3954 (equal '((bottom below top above
))
3956 (mapcar (lambda (cell)
3957 (org-export-table-cell-borders cell info
))
3958 (org-element-map tree
'table-cell
'identity
)))))))
3960 (ert-deftest test-org-export
/table-dimensions
()
3961 "Test `org-export-table-dimensions' specifications."
3962 ;; 1. Standard test.
3963 (org-test-with-parsed-data "
3968 (org-export-table-dimensions
3969 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3970 ;; 2. Ignore horizontal rules and special columns.
3971 (org-test-with-parsed-data "
3978 (org-export-table-dimensions
3979 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3981 (ert-deftest test-org-export
/table-cell-address
()
3982 "Test `org-export-table-cell-address' specifications."
3983 ;; 1. Standard test: index is 0-based.
3984 (org-test-with-parsed-data "| a | b |"
3986 (equal '((0 .
0) (0 .
1))
3987 (org-element-map tree
'table-cell
3988 (lambda (cell) (org-export-table-cell-address cell info
))
3990 ;; 2. Special column isn't counted, nor are special rows.
3991 (org-test-with-parsed-data "
3996 (org-export-table-cell-address
3997 (car (last (org-element-map tree
'table-cell
'identity info
)))
3999 ;; 3. Tables rules do not count either.
4000 (org-test-with-parsed-data "
4008 (org-export-table-cell-address
4009 (car (last (org-element-map tree
'table-cell
'identity info
)))
4011 ;; 4. Return nil for special cells.
4012 (org-test-with-parsed-data "| / | a |"
4014 (org-export-table-cell-address
4015 (org-element-map tree
'table-cell
'identity nil
'first-match
)
4018 (ert-deftest test-org-export
/get-table-cell-at
()
4019 "Test `org-export-get-table-cell-at' specifications."
4020 ;; 1. Address ignores special columns, special rows and rules.
4021 (org-test-with-parsed-data "
4028 (org-element-contents
4029 (org-export-get-table-cell-at
4031 (org-element-map tree
'table
'identity info
'first-match
)
4033 ;; 2. Return value for a non-existent address is nil.
4034 (org-test-with-parsed-data "| a |"
4036 (org-export-get-table-cell-at
4038 (org-element-map tree
'table
'identity info
'first-match
)
4040 (org-test-with-parsed-data "| / |"
4042 (org-export-get-table-cell-at
4044 (org-element-map tree
'table
'identity info
'first-match
)
4047 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
4048 "Test `org-export-table-cell-starts-colgroup-p' specifications."
4049 ;; 1. A cell at a beginning of a row always starts a column group.
4050 (org-test-with-parsed-data "| a |"
4052 (org-export-table-cell-starts-colgroup-p
4053 (org-element-map tree
'table-cell
'identity info
'first-match
)
4055 ;; 2. Special column should be ignored when determining the
4056 ;; beginning of the row.
4057 (org-test-with-parsed-data "
4061 (org-export-table-cell-starts-colgroup-p
4062 (org-element-map tree
'table-cell
'identity info
'first-match
)
4064 ;; 2. Explicit column groups.
4065 (org-test-with-parsed-data "
4071 (org-element-map tree
'table-cell
4073 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
4076 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
4077 "Test `org-export-table-cell-ends-colgroup-p' specifications."
4078 ;; 1. A cell at the end of a row always ends a column group.
4079 (org-test-with-parsed-data "| a |"
4081 (org-export-table-cell-ends-colgroup-p
4082 (org-element-map tree
'table-cell
'identity info
'first-match
)
4084 ;; 2. Special column should be ignored when determining the
4085 ;; beginning of the row.
4086 (org-test-with-parsed-data "
4090 (org-export-table-cell-ends-colgroup-p
4091 (org-element-map tree
'table-cell
'identity info
'first-match
)
4093 ;; 3. Explicit column groups.
4094 (org-test-with-parsed-data "
4100 (org-element-map tree
'table-cell
4102 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
4105 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
4106 "Test `org-export-table-row-starts-rowgroup-p' specifications."
4107 ;; 1. A row at the beginning of a table always starts a row group.
4108 ;; So does a row following a table rule.
4109 (org-test-with-parsed-data "
4116 (org-element-map tree
'table-row
4118 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4120 ;; 2. Special rows should be ignored when determining the beginning
4122 (org-test-with-parsed-data "
4131 (org-element-map tree
'table-row
4133 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4136 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
4137 "Test `org-export-table-row-ends-rowgroup-p' specifications."
4138 ;; 1. A row at the end of a table always ends a row group. So does
4139 ;; a row preceding a table rule.
4140 (org-test-with-parsed-data "
4147 (org-element-map tree
'table-row
4149 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4151 ;; 2. Special rows should be ignored when determining the beginning
4153 (org-test-with-parsed-data "
4162 (org-element-map tree
'table-row
4164 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4167 (ert-deftest test-org-export
/table-row-in-header-p
()
4168 "Test `org-export-table-row-in-header-p' specifications."
4169 ;; Standard test. Separators are always nil.
4173 (org-test-with-parsed-data "| a |\n|---|\n| b |"
4174 (org-element-map tree
'table-row
4176 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
4177 ;; Nil when there is no header.
4181 (org-test-with-parsed-data "| a |\n| b |"
4182 (org-element-map tree
'table-row
4184 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
4186 (ert-deftest test-org-export
/table-row-starts-header-p
()
4187 "Test `org-export-table-row-starts-header-p' specifications."
4188 ;; 1. Only the row starting the first row group starts the table
4190 (org-test-with-parsed-data "
4198 (org-element-map tree
'table-row
4200 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
4202 ;; 2. A row cannot start an header if there's no header in the
4204 (org-test-with-parsed-data "
4208 (org-export-table-row-starts-header-p
4209 (org-element-map tree
'table-row
'identity info
'first-match
)
4212 (ert-deftest test-org-export
/table-row-ends-header-p
()
4213 "Test `org-export-table-row-ends-header-p' specifications."
4214 ;; 1. Only the row starting the first row group starts the table
4216 (org-test-with-parsed-data "
4224 (org-element-map tree
'table-row
4226 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
4228 ;; 2. A row cannot start an header if there's no header in the
4230 (org-test-with-parsed-data "
4234 (org-export-table-row-ends-header-p
4235 (org-element-map tree
'table-row
'identity info
'first-match
)
4240 ;;; Tables of Contents
4242 (ert-deftest test-org-export
/collect-headlines
()
4243 "Test `org-export-collect-headlines' specifications."
4248 (org-test-with-parsed-data "* H1\n** H2"
4249 (org-export-collect-headlines info
)))))
4250 ;; Do not collect headlines below optional argument.
4254 (org-test-with-parsed-data "* H1\n** H2"
4255 (org-export-collect-headlines info
1)))))
4256 ;; Never collect headlines below maximum headline level.
4260 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4261 (org-export-collect-headlines info
)))))
4265 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4266 (org-export-collect-headlines info
2)))))
4267 ;; Collect headlines locally.
4270 (org-test-with-parsed-data "* H1\n** H2\n** H3"
4271 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4272 (length (org-export-collect-headlines info nil scope
))))))
4273 ;; When collecting locally, optional level is relative.
4276 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
4277 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4278 (length (org-export-collect-headlines info
1 scope
)))))))
4284 (ert-deftest test-org-export
/inner-template
()
4285 "Test `inner-template' translator specifications."
4288 (org-test-with-temp-text "* Headline"
4290 (org-export-create-backend
4292 '((inner-template .
(lambda (contents info
) "Success!"))
4293 (headline .
(lambda (h c i
) "Headline"))))))))
4294 ;; Inner template is applied even in a "body-only" export.
4297 (org-test-with-temp-text "* Headline"
4299 (org-export-create-backend
4300 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
4301 (headline .
(lambda (h c i
) "Headline"))))
4302 nil nil
'body-only
)))))
4304 (ert-deftest test-org-export
/template
()
4305 "Test `template' translator specifications."
4308 (org-test-with-temp-text "* Headline"
4310 (org-export-create-backend
4311 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4312 (headline .
(lambda (h c i
) "Headline"))))))))
4313 ;; Template is not applied in a "body-only" export.
4316 (org-test-with-temp-text "* Headline"
4318 (org-export-create-backend
4319 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4320 (headline .
(lambda (h c i
) "Headline"))))
4321 nil nil
'body-only
)))))
4327 (ert-deftest test-org-export
/get-next-element
()
4328 "Test `org-export-get-next-element' specifications."
4332 (org-test-with-parsed-data "* Headline\n*a* b"
4333 (org-export-get-next-element
4334 (org-element-map tree
'bold
'identity info t
) info
))))
4335 ;; Return nil when no previous element.
4337 (org-test-with-parsed-data "* Headline\na *b*"
4338 (org-export-get-next-element
4339 (org-element-map tree
'bold
'identity info t
) info
)))
4340 ;; Non-exportable elements are ignored.
4342 (let ((org-export-with-timestamps nil
))
4343 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
4344 (org-export-get-next-element
4345 (org-element-map tree
'entity
'identity info t
) info
))))
4346 ;; Find next element in secondary strings.
4349 (org-test-with-parsed-data "* a =verb="
4351 (org-export-get-next-element
4352 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4355 (org-test-with-parsed-data "* /italic/ =verb="
4357 (org-export-get-next-element
4358 (org-element-map tree
'italic
'identity info t
) info
)))))
4359 ;; Find next element in document keywords.
4362 (org-test-with-parsed-data "#+TITLE: a =verb="
4364 (org-export-get-next-element
4366 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4367 ;; Find next element in parsed affiliated keywords.
4370 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
4372 (org-export-get-next-element
4373 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4374 ;; With optional argument N, return a list containing all the
4375 ;; following elements.
4378 '(bold code underline
)
4379 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4381 (org-export-get-next-element
4382 (org-element-map tree
'italic
'identity info t
) info t
)))))
4383 ;; When N is a positive integer, return a list containing up to
4384 ;; N following elements.
4388 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4390 (org-export-get-next-element
4391 (org-element-map tree
'italic
'identity info t
) info
2))))))
4393 (ert-deftest test-org-export
/get-previous-element
()
4394 "Test `org-export-get-previous-element' specifications."
4398 (org-test-with-parsed-data "* Headline\na *b*"
4399 (org-export-get-previous-element
4400 (org-element-map tree
'bold
'identity info t
) info
))))
4401 ;; Return nil when no previous element.
4403 (org-test-with-parsed-data "* Headline\n*a* b"
4404 (org-export-get-previous-element
4405 (org-element-map tree
'bold
'identity info t
) info
)))
4406 ;; Non-exportable elements are ignored.
4408 (let ((org-export-with-timestamps nil
))
4409 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
4410 (org-export-get-previous-element
4411 (org-element-map tree
'entity
'identity info t
) info
))))
4412 ;; Find previous element in secondary strings.
4415 (org-test-with-parsed-data "* =verb= a"
4417 (org-export-get-previous-element
4418 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4421 (org-test-with-parsed-data "* =verb= /italic/"
4423 (org-export-get-previous-element
4424 (org-element-map tree
'italic
'identity info t
) info
)))))
4425 ;; Find previous element in document keywords.
4428 (org-test-with-parsed-data "#+TITLE: =verb= a"
4430 (org-export-get-previous-element
4432 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4433 ;; Find previous element in parsed affiliated keywords.
4436 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
4438 (org-export-get-previous-element
4439 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4440 ;; With optional argument N, return a list containing up to
4441 ;; N previous elements.
4443 (equal '(underline italic bold
)
4444 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4446 (org-export-get-previous-element
4447 (org-element-map tree
'code
'identity info t
) info t
)))))
4448 ;; When N is a positive integer, return a list containing up to
4449 ;; N previous elements.
4451 (equal '(italic bold
)
4452 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4454 (org-export-get-previous-element
4455 (org-element-map tree
'code
'identity info t
) info
2))))))
4459 ;;; test-org-export.el end here