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-babel-evaluate 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 (concat (file-name-as-directory ".")
999 (file-name-nondirectory
1000 (file-name-sans-extension (buffer-file-name))))
1001 (file-name-sans-extension (org-export-output-file-name ".ext")))))
1002 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
1004 (org-test-with-temp-text-in-file
1005 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
1006 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
1007 ;; From a buffer not associated to a file, too.
1009 (org-test-with-temp-text
1010 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
1011 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
1012 ;; When provided name is absolute, preserve it.
1014 (org-test-with-temp-text
1015 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
1016 (expand-file-name "test"))
1017 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
1018 ;; When PUB-DIR argument is provided, use it.
1020 (org-test-with-temp-text-in-file "Test"
1021 (equal (file-name-directory
1022 (org-export-output-file-name ".ext" nil
"dir/"))
1024 ;; When returned name would overwrite original file, add EXTENSION
1027 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1028 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
1030 (ert-deftest test-org-export
/expand-include
()
1031 "Test file inclusion in an Org buffer."
1032 ;; Error when file isn't specified.
1034 (org-test-with-temp-text "#+INCLUDE: dummy.org"
1035 (org-export-expand-include-keyword)))
1036 ;; Full insertion with recursive inclusion.
1041 (expand-file-name "examples/include.org" org-test-dir
))
1042 (replace-regexp-in-string
1043 (regexp-quote "#+INCLUDE: \"include2.org\"")
1044 "Success!" (buffer-string)))
1045 (org-test-with-temp-text
1046 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
1047 (org-export-expand-include-keyword)
1049 ;; Localized insertion.
1050 (org-test-with-temp-text
1051 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
1053 (org-export-expand-include-keyword)
1054 (should (equal (buffer-string)
1055 "Small Org file with an include keyword.\n")))
1056 ;; Insertion with constraints on headlines level.
1059 "* Top heading\n** Heading\nbody\n"
1060 (org-test-with-temp-text
1062 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
1064 (org-export-expand-include-keyword)
1068 "* Top heading\n* Heading\nbody\n"
1069 (org-test-with-temp-text
1071 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
1073 (org-export-expand-include-keyword)
1075 ;; Inclusion within an example block.
1078 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
1079 (org-test-with-temp-text
1080 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
1082 (org-export-expand-include-keyword)
1084 ;; Inclusion within a src-block.
1087 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
1088 (org-test-with-temp-text
1090 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
1092 (org-export-expand-include-keyword)
1094 ;; Inclusion within an html export-block.
1097 "#+BEGIN_EXPORT html\n<p>HTML!</p>\n#+END_EXPORT\n"
1098 (org-test-with-temp-text
1100 "#+INCLUDE: \"%s/examples/include.html\" EXPORT html"
1102 (org-export-expand-include-keyword)
1104 ;; Inclusion within an center paragraph
1107 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
1108 (org-test-with-temp-text
1110 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
1112 (org-export-expand-include-keyword)
1114 ;; Footnotes labels are local to each included file.
1120 Footnotes[fn:1], [fn:test], [fn:test] and [fn:inline:inline footnote].
1122 \[fn:test] Footnote \"test\""))
1123 (org-test-with-temp-text-in-file contents
1124 (let ((file1 (buffer-file-name)))
1125 (org-test-with-temp-text-in-file contents
1126 (let ((file2 (buffer-file-name)))
1127 (org-test-with-temp-text
1128 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
1130 (org-export-expand-include-keyword)
1131 (org-element-map (org-element-parse-buffer)
1133 (lambda (r) (org-element-property :label r
)))))))))))))
1134 ;; Footnotes labels are not local to each include keyword.
1140 Footnotes[fn:1], [fn:test] and [fn:inline:inline footnote].
1142 \[fn:test] Footnote \"test\""))
1143 (org-test-with-temp-text-in-file contents
1144 (let ((file (buffer-file-name)))
1145 (org-test-with-temp-text
1146 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
1147 (org-export-expand-include-keyword)
1148 (org-element-map (org-element-parse-buffer)
1150 (lambda (ref) (org-element-property :label ref
)))))))))))
1151 ;; Footnotes are supported by :lines-like elements and unnecessary
1152 ;; footnotes are dropped.
1161 Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
1166 \[fn:test] Footnote \"test\"
1168 (org-test-with-temp-text-in-file contents
1169 (let ((file (buffer-file-name)))
1170 (org-test-with-temp-text
1171 (format "#+INCLUDE: \"%s::*bar\"\n" file
)
1172 (org-export-expand-include-keyword)
1173 (org-element-map (org-element-parse-buffer)
1174 'footnote-definition
1175 (lambda (ref) (org-element-property :label ref
)))))))))))
1176 ;; If only-contents is non-nil only include contents of element.
1180 (org-test-with-temp-text
1182 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" "
1185 (org-export-expand-include-keyword)
1187 ;; Headings can be included via CUSTOM_ID.
1189 (org-test-with-temp-text
1190 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1191 (org-export-expand-include-keyword)
1192 (goto-char (point-min))
1193 (looking-at "* Another heading")))
1194 ;; Named objects can be included.
1198 (org-test-with-temp-text
1199 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t"
1201 (org-export-expand-include-keyword)
1203 ;; Including non-existing elements should result in an error.
1205 (org-test-with-temp-text
1206 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\""
1208 (org-export-expand-include-keyword)))
1209 ;; Lines work relatively to an included element.
1213 (org-test-with-temp-text
1214 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t \
1217 (org-export-expand-include-keyword)
1219 ;; Properties should be dropped from headlines.
1222 (org-test-with-temp-text
1223 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t"
1225 (org-export-expand-include-keyword)
1227 (org-test-with-temp-text
1228 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1229 (org-export-expand-include-keyword)
1231 ;; Properties should be dropped, drawers should not be.
1234 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1235 (org-test-with-temp-text
1236 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t"
1238 (org-export-expand-include-keyword)
1240 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1242 (cl-every (lambda (level) (zerop (1- level
)))
1243 (org-test-with-temp-text
1245 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n"
1247 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\""
1249 (org-export-expand-include-keyword)
1250 (org-element-map (org-element-parse-buffer) 'headline
1251 (lambda (head) (org-element-property :level head
))))))
1252 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1255 (org-test-with-temp-text
1256 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp"
1258 (org-export-expand-include-keyword)
1260 (org-test-with-temp-text
1262 "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1"
1264 (org-export-expand-include-keyword)
1266 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1268 (org-test-with-temp-text-in-file
1269 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\""
1271 (narrow-to-region (point) (point-max))
1272 (org-export-expand-include-keyword)
1273 (eq 1 (org-current-level))))
1274 ;; If :minlevel is present do not alter it.
1276 (org-test-with-temp-text
1278 "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3"
1280 (narrow-to-region (point) (point-max))
1281 (org-export-expand-include-keyword)
1282 (eq 3 (org-current-level)))))
1284 (ert-deftest test-org-export
/expand-macro
()
1285 "Test macro expansion in an Org buffer."
1287 ;; Standard macro expansion.
1289 (equal "#+MACRO: macro1 value\nvalue\n"
1290 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1291 (org-export-as (org-test-default-backend)))))
1292 ;; Allow macro in parsed keywords and associated properties.
1293 ;; Standard macro expansion.
1297 (let ((backend (org-export-create-backend
1299 :options
'((:k
"K" nil nil parse
)))))
1300 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1301 (org-export-as backend
)))))
1305 (let ((backend (org-export-create-backend
1307 :options
'((:k
"K" nil nil parse
)))))
1308 (org-test-with-temp-text
1309 "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1310 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1311 ;; Expand specific macros.
1313 (equal "me 2012-03-29 me@here Title\n"
1314 (org-test-with-temp-text
1320 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1321 (let ((output (org-export-as (org-test-default-backend))))
1322 (substring output
(string-match ".*\n\\'" output
))))))
1323 ;; Expand specific macros when property contained a regular macro
1327 (org-test-with-temp-text "
1328 #+MACRO: macro1 value
1329 #+TITLE: {{{macro1}}}
1331 (let ((output (org-export-as (org-test-default-backend))))
1332 (substring output
(string-match ".*\n\\'" output
))))))
1333 ;; Expand macros with templates in included files.
1336 (org-test-with-temp-text
1337 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1338 {{{included-macro}}}" org-test-dir
)
1339 (let ((output (org-export-as (org-test-default-backend))))
1340 (substring output
(string-match ".*\n\\'" output
))))))
1341 ;; Date macro takes a optional formatting argument
1344 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1345 (org-export-as (org-test-default-backend)))))
1346 ;; Only single timestamps are formatted
1348 (equal "<2015-02x-09>\n"
1349 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1350 (org-export-as (org-test-default-backend)))))
1351 ;; Throw an error when a macro definition is missing.
1353 (org-test-with-temp-text "{{{missing}}}"
1354 (org-export-as (org-test-default-backend))))
1355 ;; Macros defined in commented subtrees are ignored.
1357 (org-test-with-temp-text
1358 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1359 (org-export-as (org-test-default-backend))))
1361 (org-test-with-temp-text
1362 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1363 (org-export-as (org-test-default-backend)))))
1365 (ert-deftest test-org-export
/before-processing-hook
()
1366 "Test `org-export-before-processing-hook'."
1369 "#+MACRO: mac val\nTest\n"
1370 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1371 (let ((org-export-before-processing-hook
1373 (while (re-search-forward "{{{" nil t
)
1374 (let ((object (org-element-context)))
1375 (when (eq (org-element-type object
) 'macro
)
1377 (org-element-property :begin object
)
1378 (org-element-property :end object
)))))))))
1379 (org-export-as (org-test-default-backend)))))))
1381 (ert-deftest test-org-export
/before-parsing-hook
()
1382 "Test `org-export-before-parsing-hook'."
1384 (equal "Body 1\nBody 2\n"
1385 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1386 (let ((org-export-before-parsing-hook
1388 (goto-char (point-min))
1389 (while (re-search-forward org-outline-regexp-bol nil t
)
1391 (point-at-bol) (progn (forward-line) (point))))))))
1392 (org-export-as (org-test-default-backend)))))))
1396 ;;; Affiliated Keywords
1398 (ert-deftest test-org-export
/read-attribute
()
1399 "Test `org-export-read-attribute' specifications."
1403 (org-export-read-attribute
1405 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1406 (org-element-at-point)))
1408 ;; Return nil on empty attribute.
1410 (org-export-read-attribute
1412 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1413 ;; Return nil on "nil" string.
1415 (equal '(:a nil
:b nil
)
1416 (org-export-read-attribute
1418 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1419 (org-element-at-point)))))
1420 ;; Return nil on empty string.
1422 (equal '(:a nil
:b nil
)
1423 (org-export-read-attribute
1425 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1426 (org-element-at-point)))))
1427 ;; Return empty string when value is "".
1430 (org-export-read-attribute
1432 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1433 (org-element-at-point)))))
1434 ;; Return \"\" when value is """".
1437 (org-export-read-attribute
1439 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1440 (org-element-at-point)))))
1441 ;; Ignore text before first property.
1444 (org-export-read-attribute
1446 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1447 (org-element-at-point))))))
1449 (ert-deftest test-org-export
/get-caption
()
1450 "Test `org-export-get-caption' specifications."
1451 ;; Without optional argument, return long caption
1455 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1456 (org-export-get-caption (org-element-at-point)))))
1457 ;; With optional argument, return short caption.
1461 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1462 (org-export-get-caption (org-element-at-point) t
))))
1463 ;; Multiple lines are separated by white spaces.
1467 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1468 (org-export-get-caption (org-element-at-point))))))
1474 (ert-deftest test-org-export
/define-backend
()
1475 "Test back-end definition and accessors."
1478 (equal '((headline . my-headline-test
))
1479 (let (org-export-registered-backends)
1480 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1481 (org-export-get-all-transcoders 'test
))))
1484 (equal '((:filter-headline . my-filter
))
1485 (let (org-export-registered-backends)
1486 (org-export-define-backend 'test
1487 '((headline . my-headline-test
))
1488 :filters-alist
'((:filter-headline . my-filter
)))
1489 (org-export-backend-filters (org-export-get-backend 'test
)))))
1492 (equal '((:prop value
))
1493 (let (org-export-registered-backends)
1494 (org-export-define-backend 'test
1495 '((headline . my-headline-test
))
1496 :options-alist
'((:prop value
)))
1497 (org-export-backend-options (org-export-get-backend 'test
)))))
1500 (equal '(?k
"Test Export" test
)
1501 (let (org-export-registered-backends)
1502 (org-export-define-backend 'test
1503 '((headline . my-headline-test
))
1504 :menu-entry
'(?k
"Test Export" test
))
1505 (org-export-backend-menu (org-export-get-backend 'test
))))))
1507 (ert-deftest test-org-export
/define-derived-backend
()
1508 "Test `org-export-define-derived-backend' specifications."
1509 ;; Error when parent back-end is not defined.
1511 (let (org-export-registered-backends)
1512 (org-export-define-derived-backend 'test
'parent
)))
1513 ;; Append translation table to parent's.
1515 (equal '((:headline . test
) (:headline . parent
))
1516 (let (org-export-registered-backends)
1517 (org-export-define-backend 'parent
'((:headline . parent
)))
1518 (org-export-define-derived-backend 'test
'parent
1519 :translate-alist
'((:headline . test
)))
1520 (org-export-get-all-transcoders 'test
))))
1521 ;; Options defined in the new back have priority over those defined
1525 (let (org-export-registered-backends)
1526 (org-export-define-backend 'parent
1527 '((:headline . parent
))
1528 :options-alist
'((:a nil nil
'parent
)))
1529 (org-export-define-derived-backend 'test
'parent
1530 :options-alist
'((:a nil nil
'test
)))
1531 (plist-get (org-export--get-global-options
1532 (org-export-get-backend 'test
))
1535 (ert-deftest test-org-export
/derived-backend-p
()
1536 "Test `org-export-derived-backend-p' specifications."
1537 ;; Non-nil with direct match.
1539 (let (org-export-registered-backends)
1540 (org-export-define-backend 'test
'((headline . test
)))
1541 (org-export-derived-backend-p 'test
'test
)))
1543 (let (org-export-registered-backends)
1544 (org-export-define-backend 'test
'((headline . test
)))
1545 (org-export-define-derived-backend 'test2
'test
)
1546 (org-export-derived-backend-p 'test2
'test2
)))
1547 ;; Non-nil with a direct parent.
1549 (let (org-export-registered-backends)
1550 (org-export-define-backend 'test
'((headline . test
)))
1551 (org-export-define-derived-backend 'test2
'test
)
1552 (org-export-derived-backend-p 'test2
'test
)))
1553 ;; Non-nil with an indirect parent.
1555 (let (org-export-registered-backends)
1556 (org-export-define-backend 'test
'((headline . test
)))
1557 (org-export-define-derived-backend 'test2
'test
)
1558 (org-export-define-derived-backend 'test3
'test2
)
1559 (org-export-derived-backend-p 'test3
'test
)))
1562 (let (org-export-registered-backends)
1563 (org-export-define-backend 'test
'((headline . test
)))
1564 (org-export-define-backend 'test2
'((headline . test2
)))
1565 (org-export-derived-backend-p 'test2
'test
)))
1567 (let (org-export-registered-backends)
1568 (org-export-define-backend 'test
'((headline . test
)))
1569 (org-export-define-backend 'test2
'((headline . test2
)))
1570 (org-export-define-derived-backend 'test3
'test2
)
1571 (org-export-derived-backend-p 'test3
'test
))))
1573 (ert-deftest test-org-export
/get-all-transcoders
()
1574 "Test `org-export-get-all-transcoders' specifications."
1575 ;; Return nil when back-end cannot be found.
1576 (should-not (org-export-get-all-transcoders nil
))
1577 ;; Same as `org-export-transcoders' if no parent.
1579 (equal '((headline . ignore
))
1580 (org-export-get-all-transcoders
1581 (org-export-create-backend
1582 :transcoders
'((headline . ignore
))))))
1583 ;; But inherit from all ancestors whenever possible.
1585 (equal '((section . ignore
) (headline . ignore
))
1586 (let (org-export-registered-backends)
1587 (org-export-define-backend 'b1
'((headline . ignore
)))
1588 (org-export-get-all-transcoders
1589 (org-export-create-backend
1590 :parent
'b1
:transcoders
'((section . ignore
)))))))
1592 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1593 (let (org-export-registered-backends)
1594 (org-export-define-backend 'b1
'((headline . ignore
)))
1595 (org-export-define-derived-backend 'b2
'b1
1596 :translate-alist
'((section . ignore
)))
1597 (org-export-get-all-transcoders
1598 (org-export-create-backend
1599 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1600 ;; Back-end transcoders overrule inherited ones.
1603 (let (org-export-registered-backends)
1604 (org-export-define-backend 'b1
'((headline . a
)))
1605 (cdr (assq 'headline
1606 (org-export-get-all-transcoders
1607 (org-export-create-backend
1608 :parent
'b1
:transcoders
'((headline . b
))))))))))
1610 (ert-deftest test-org-export
/get-all-options
()
1611 "Test `org-export-get-all-options' specifications."
1612 ;; Return nil when back-end cannot be found.
1613 (should-not (org-export-get-all-options nil
))
1614 ;; Same as `org-export-options' if no parent.
1616 (equal '((headline . ignore
))
1617 (org-export-get-all-options
1618 (org-export-create-backend
1619 :options
'((headline . ignore
))))))
1620 ;; But inherit from all ancestors whenever possible.
1622 (equal '((:key2 value2
) (:key1 value1
))
1623 (let (org-export-registered-backends)
1624 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1625 (org-export-get-all-options
1626 (org-export-create-backend
1627 :parent
'b1
:options
'((:key2 value2
)))))))
1629 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1630 (let (org-export-registered-backends)
1631 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1632 (org-export-define-derived-backend 'b2
'b1
1633 :options-alist
'((:key2 value2
)))
1634 (org-export-get-all-options
1635 (org-export-create-backend
1636 :parent
'b2
:options
'((:key3 value3
)))))))
1637 ;; Back-end options overrule inherited ones.
1640 (let (org-export-registered-backends)
1641 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1643 (org-export-get-all-options
1644 (org-export-create-backend
1645 :parent
'b1
:options
'((:key1 . b
))))))))))
1647 (ert-deftest test-org-export
/get-all-filters
()
1648 "Test `org-export-get-all-filters' specifications."
1649 ;; Return nil when back-end cannot be found.
1650 (should-not (org-export-get-all-filters nil
))
1651 ;; Same as `org-export-filters' if no parent.
1653 (equal '((:filter-headline . ignore
))
1654 (org-export-get-all-filters
1655 (org-export-create-backend
1656 :filters
'((:filter-headline . ignore
))))))
1657 ;; But inherit from all ancestors whenever possible.
1659 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1660 (let (org-export-registered-backends)
1661 (org-export-define-backend 'b1
1662 nil
:filters-alist
'((:filter-headline . ignore
)))
1663 (org-export-get-all-filters
1664 (org-export-create-backend
1665 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1667 (equal '((:filter-paragraph . ignore
)
1668 (:filter-section . ignore
)
1669 (:filter-headline . ignore
))
1670 (let (org-export-registered-backends)
1671 (org-export-define-backend 'b1
1672 nil
:filters-alist
'((:filter-headline . ignore
)))
1673 (org-export-define-derived-backend 'b2
'b1
1674 :filters-alist
'((:filter-section . ignore
)))
1675 (org-export-get-all-filters
1676 (org-export-create-backend
1677 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1678 ;; Back-end filters overrule inherited ones.
1681 (let (org-export-registered-backends)
1682 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1683 (cdr (assq :filter-headline
1684 (org-export-get-all-filters
1685 (org-export-create-backend
1686 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1688 (ert-deftest test-org-export
/with-backend
()
1689 "Test `org-export-with-backend' definition."
1690 ;; Error when calling an undefined back-end
1691 (should-error (org-export-with-backend nil
"Test"))
1692 ;; Error when called back-end doesn't have an appropriate
1695 (org-export-with-backend
1696 (org-export-create-backend :transcoders
'((headline . ignore
)))
1698 ;; Otherwise, export using correct transcoder
1701 (let (org-export-registered-backends)
1702 (org-export-define-backend 'test
1703 '((plain-text .
(lambda (text contents info
) "Failure"))))
1704 (org-export-define-backend 'test2
1705 '((plain-text .
(lambda (text contents info
) "Success"))))
1706 (org-export-with-backend 'test2
"Test"))))
1707 ;; Provide correct back-end if transcoder needs to use recursive
1711 (let ((test-back-end
1712 (org-export-create-backend
1714 (list (cons 'headline
1715 (lambda (headline contents info
)
1717 (org-element-property :title headline
)
1719 (cons 'plain-text
(lambda (text info
) "Success"))))))
1720 (org-export-string-as
1722 (org-export-create-backend
1724 (list (cons 'headline
1725 (lambda (headline contents info
)
1726 (org-export-with-backend
1727 test-back-end headline contents info
))))))))))
1729 (ert-deftest test-org-export
/data-with-backend
()
1730 "Test `org-export-data-with-backend' specifications."
1731 ;; Error when calling an undefined back-end.
1732 (should-error (org-export-data-with-backend nil
"nil" nil
))
1733 ;; Otherwise, export data recursively, using correct back-end.
1737 (org-export-data-with-backend
1739 (org-export-create-backend
1741 '((plain-text .
(lambda (text info
) "Success"))
1742 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1743 '(:with-emphasize t
)))))
1749 (ert-deftest test-org-export
/comments
()
1750 "Test comments handling during export.
1751 In particular, structure of the document mustn't be altered after
1754 (equal "Para1\n\nPara2\n"
1755 (org-test-with-temp-text "
1761 (org-export-as (org-test-default-backend)))))
1763 (equal "Para1\n\nPara2\n"
1764 (org-test-with-temp-text "
1768 (org-export-as (org-test-default-backend)))))
1770 (equal "[fn:1] Para1\n\n\nPara2\n"
1771 (org-test-with-temp-text "
1776 # Outside definition
1778 (org-export-as (org-test-default-backend)))))
1780 (equal "[fn:1] Para1\n\nPara2\n"
1781 (org-test-with-temp-text "
1789 (org-export-as (org-test-default-backend)))))
1791 (equal "[fn:1] Para1\n\nPara2\n"
1792 (org-test-with-temp-text "
1797 (org-export-as (org-test-default-backend)))))
1799 (equal "[fn:1] Para1\n\nPara2\n"
1800 (org-test-with-temp-text "
1805 (org-export-as (org-test-default-backend)))))
1807 (equal "- item 1\n\n- item 2\n"
1808 (org-test-with-temp-text "
1814 (org-export-as (org-test-default-backend))))))
1820 (ert-deftest test-org-export
/export-block
()
1821 "Test export blocks transcoding."
1824 (org-test-with-temp-text
1825 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1827 (org-export-create-backend
1828 :transcoders
'((export-block .
(lambda (b _c _i
)
1829 (org-element-property :value b
)))
1830 (section .
(lambda (_s c _i
) c
))))))))
1833 (org-test-with-temp-text
1834 "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
1836 (org-export-create-backend
1841 (and (equal (org-element-property :type b
) "BACKEND")
1842 (org-element-property :value b
))))
1843 (cons 'section
(lambda (_s c _i
) c
)))))))))
1848 (ert-deftest test-org-export
/export-snippet
()
1849 "Test export snippets transcoding."
1851 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1852 (let ((backend (org-test-default-backend)))
1853 (setf (org-export-backend-name backend
) 'test
)
1854 (setf (org-export-backend-transcoders backend
)
1855 (cons (cons 'export-snippet
1856 (lambda (snippet contents info
)
1857 (when (eq (org-export-snippet-backend snippet
) 'test
)
1858 (org-element-property :value snippet
))))
1859 (org-export-backend-transcoders backend
)))
1860 (let ((org-export-snippet-translation-alist nil
))
1861 (should (equal (org-export-as backend
) "A\n")))
1862 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1863 (should (equal (org-export-as backend
) "AB\n")))))
1864 ;; Ignored export snippets do not remove any blank.
1866 (equal "begin end\n"
1867 (org-test-with-parsed-data "begin @@test:A@@ end"
1868 (org-export-data-with-backend
1870 (org-export-create-backend
1872 '((paragraph .
(lambda (paragraph contents info
) contents
))
1873 (section .
(lambda (section contents info
) contents
))))
1879 (ert-deftest test-org-export
/filter-apply-functions
()
1880 "Test `org-export-filter-apply-functions' specifications."
1881 ;; Functions are applied in order and return values are reduced.
1884 (org-export-filter-apply-functions
1885 (list (lambda (value &rest _
) (concat "1" value
))
1886 (lambda (value &rest _
) (concat "2" value
)))
1888 ;; Functions returning nil are skipped.
1891 (org-export-filter-apply-functions
1892 (list #'ignore
(lambda (value &rest _
) (concat "2" value
)))
1894 ;; If all functions are skipped, return the initial value.
1897 (org-export-filter-apply-functions (list #'ignore
) "0" nil
)))
1898 ;; If any function returns the empty string, final value is the
1902 (org-export-filter-apply-functions
1903 (list (lambda (value &rest _
) "")
1904 (lambda (value &rest _
) (concat "2" value
)))
1906 ;; Any function returning the empty string short-circuits the
1909 (org-export-filter-apply-functions
1910 (list (lambda (value &rest _
) "")
1911 (lambda (value &rest _
) (error "This shouldn't happen")))
1917 (ert-deftest test-org-export
/footnote-first-reference-p
()
1918 "Test `org-export-footnote-first-reference-p' specifications."
1922 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1925 (org-export-create-backend
1927 `(,(cons 'footnote-reference
1929 (push (org-export-footnote-first-reference-p f i
)
1932 (section .
(lambda (s c i
) c
))
1933 (paragraph .
(lambda (p c i
) c
))))
1934 nil nil nil
'(:with-footnotes t
))
1935 (nreverse result
)))))
1936 ;; Limit check to DATA, when non-nil.
1940 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1942 (org-element-map tree
'footnote-reference
1945 (org-export-footnote-first-reference-p
1946 ref info
(org-element-map tree
'headline
#'identity info t
))
1949 (nreverse result
)))))
1953 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1955 (org-element-map tree
'footnote-reference
1957 (push (org-export-footnote-first-reference-p ref info
) result
))
1959 (nreverse result
)))))
1960 ;; If optional argument BODY-FIRST is non-nil, first find footnote
1961 ;; in the main body of the document. Otherwise, enter footnote
1962 ;; definitions when they are encountered.
1966 (org-test-with-temp-text
1967 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1970 (org-export-create-backend
1972 `(,(cons 'footnote-reference
1974 (when (org-element-lineage f
'(drawer))
1975 (push (org-export-footnote-first-reference-p f i nil
)
1978 (drawer .
(lambda (d c i
) c
))
1979 (footnote-definition .
(lambda (d c i
) c
))
1980 (section .
(lambda (s c i
) c
))
1981 (paragraph .
(lambda (p c i
) c
))))
1982 nil nil nil
'(:with-footnotes t
))
1983 (nreverse result
)))))
1987 (org-test-with-temp-text
1988 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1991 (org-export-create-backend
1993 `(,(cons 'footnote-reference
1995 (when (org-element-lineage f
'(drawer))
1996 (push (org-export-footnote-first-reference-p f i nil t
)
1999 (drawer .
(lambda (d c i
) c
))
2000 (footnote-definition .
(lambda (d c i
) c
))
2001 (section .
(lambda (s c i
) c
))
2002 (paragraph .
(lambda (p c i
) c
))))
2003 nil nil nil
'(:with-footnotes t
))
2004 (nreverse result
))))))
2006 (ert-deftest test-org-export
/get-footnote-number
()
2007 "Test `org-export-get-footnote-number' specifications."
2010 (org-test-with-parsed-data
2011 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
2012 (org-element-map tree
'footnote-reference
2013 (lambda (ref) (org-export-get-footnote-number ref info
))
2015 ;; Anonymous footnotes all get a new number.
2018 (org-test-with-parsed-data
2019 "Text[fn::anon1][fn::anon2]"
2020 (org-element-map tree
'footnote-reference
2021 (lambda (ref) (org-export-get-footnote-number ref info
))
2023 ;; Test nested footnotes order.
2026 '((1 .
"1") (2 .
"2") (3 .
"3") (3 .
"3") (4))
2027 (org-test-with-parsed-data
2028 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
2029 (org-element-map tree
'footnote-reference
2031 (cons (org-export-get-footnote-number ref info
)
2032 (org-element-property :label ref
)))
2034 ;; Limit number to provided DATA, when non-nil.
2038 (org-test-with-parsed-data
2039 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2040 (org-element-map tree
'footnote-reference
2042 (org-export-get-footnote-number
2043 ref info
(org-element-map tree
'headline
#'identity info t
)))
2048 (org-test-with-parsed-data
2049 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
2050 (org-element-map tree
'footnote-reference
2051 (lambda (ref) (org-export-get-footnote-number ref info
))
2053 ;; With a non-nil BODY-FIRST optional argument, first check body,
2054 ;; then footnote definitions.
2057 '(("1" .
1) ("2" .
2) ("3" .
3) ("3" .
3))
2058 (org-test-with-parsed-data
2059 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2060 (org-element-map tree
'footnote-reference
2062 (cons (org-element-property :label ref
)
2063 (org-export-get-footnote-number ref info nil t
)))
2067 '(("1" .
1) ("2" .
3) ("3" .
2) ("3" .
2))
2068 (org-test-with-parsed-data
2069 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
2070 (org-element-map tree
'footnote-reference
2072 (cons (org-element-property :label ref
)
2073 (org-export-get-footnote-number ref info nil
)))
2076 (ert-deftest test-org-export
/get-footnote-definition
()
2077 "Test `org-export-get-footnote-definition' specifications."
2081 (org-element-interpret-data
2082 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1] A"
2083 (org-export-get-footnote-definition
2084 (org-element-map tree
'footnote-reference
#'identity nil t
)
2086 ;; Raise an error if no definition is found.
2088 (org-test-with-parsed-data "Text[fn:1]"
2089 (org-export-get-footnote-definition
2090 (org-element-map tree
'footnote-reference
#'identity nil t
)
2092 ;; Find inline definitions.
2095 (org-element-interpret-data
2096 (org-test-with-parsed-data "Text[fn:1:A]"
2097 (org-export-get-footnote-definition
2098 (org-element-map tree
'footnote-reference
#'identity nil t
)
2100 ;; Find anonymous definitions.
2103 (org-element-interpret-data
2104 (org-test-with-parsed-data "Text[fn::A]"
2105 (org-export-get-footnote-definition
2106 (org-element-map tree
'footnote-reference
#'identity nil t
)
2108 ;; Find empty definitions.
2111 (org-element-interpret-data
2112 (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1]"
2113 (org-export-get-footnote-definition
2114 (org-element-map tree
'footnote-reference
#'identity nil t
)
2118 (org-element-interpret-data
2119 (org-test-with-parsed-data "Text[fn:1:]"
2120 (org-export-get-footnote-definition
2121 (org-element-map tree
'footnote-reference
#'identity nil t
)
2125 (org-element-interpret-data
2126 (org-test-with-parsed-data "Text[fn::]"
2127 (org-export-get-footnote-definition
2128 (org-element-map tree
'footnote-reference
#'identity nil t
)
2131 (ert-deftest test-org-export
/collect-footnote-definitions
()
2132 "Test `org-export-collect-footnote-definitions' specifications."
2135 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2137 \[fn:2] B [fn:3] [fn::D].
2140 (length (org-export-collect-footnote-definitions info
)))))
2141 ;; Limit number to provided DATA, when non-nil.
2145 (org-test-with-parsed-data
2146 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2148 (org-export-collect-footnote-definitions
2149 info
(org-element-map tree
'headline
#'identity info t
))))))
2153 (org-test-with-parsed-data
2154 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
2155 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
2156 ;; With optional argument BODY-FIRST, first check body, then
2157 ;; footnote definitions.
2159 (equal '("1" "3" "2" nil
)
2160 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2162 \[fn:2] B [fn:3] [fn::D].
2165 (mapcar (lambda (e) (nth 1 e
))
2166 (org-export-collect-footnote-definitions info nil t
)))))
2168 (equal '("1" "3" "2" nil
)
2169 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
2171 \[fn:2] B [fn:3] [fn::D].
2174 (mapcar (lambda (e) (nth 1 e
))
2175 (org-export-collect-footnote-definitions info
))))))
2177 (ert-deftest test-org-export
/footnotes
()
2178 "Miscellaneous tests on footnotes."
2179 (let ((org-footnote-section nil
)
2180 (org-export-with-footnotes t
))
2181 ;; Read every type of footnote.
2184 '((1 .
"A\n") (2 .
"C") (3 .
"D"))
2185 (org-test-with-parsed-data
2186 "Text[fn:1] [fn:label:C] [fn::D]\n\n[fn:1] A\n"
2187 (org-element-map tree
'footnote-reference
2189 (let ((def (org-export-get-footnote-definition ref info
)))
2190 (cons (org-export-get-footnote-number ref info
)
2191 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
2192 (car (org-element-contents
2193 (car (org-element-contents def
))))))))
2195 ;; Export nested footnote in invisible definitions.
2198 (org-test-with-temp-text "Text[fn:1]\n\n[fn:1] B [fn:2]\n\n[fn:2] C."
2199 (narrow-to-region (point) (line-end-position))
2202 (org-export-create-backend
2207 (throw 'exit
(length
2208 (org-export-collect-footnote-definitions
2210 ;; Export footnotes defined outside parsing scope.
2214 (org-test-with-temp-text "[fn:1] Out of scope
2216 <point>Paragraph[fn:1]"
2217 (org-export-as (org-test-default-backend) 'subtree
))))
2221 (org-test-with-temp-text "[fn:1] Out of scope
2223 <point>Paragraph[fn:1]"
2224 (narrow-to-region (point) (point-max))
2225 (org-export-as (org-test-default-backend)))))
2226 ;; Export nested footnotes defined outside parsing scope.
2230 (org-test-with-temp-text "
2231 \[fn:1] Out of scope[fn:2]
2233 \[fn:2] Very out of scope
2235 <point>Paragraph[fn:1]"
2236 (org-export-as (org-test-default-backend) 'subtree
))))
2240 (org-test-with-temp-text "
2241 \[fn:1] Out of scope[fn:2]
2243 \[fn:2] Very out of scope
2245 <point>Paragraph[fn:1]"
2246 (narrow-to-region (point) (point-max))
2247 (org-export-as (org-test-default-backend)))))
2251 (org-test-with-temp-text "
2252 \[fn:1] Out of scope[fn:2:D2]
2254 <point>Paragraph[fn:1]"
2255 (narrow-to-region (point) (point-max))
2256 (org-export-as (org-test-default-backend)))))
2257 ;; Export footnotes in pruned parts of tree.
2261 (let ((org-export-exclude-tags '("noexport")))
2262 (org-test-with-temp-text
2263 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] Definition"
2264 (org-export-as (org-test-default-backend))))))
2268 (let ((org-export-select-tags '("export")))
2269 (org-test-with-temp-text
2270 "* H :export:\nText[fn:1]\n* H2\n[fn:1] Definition"
2271 (org-export-as (org-test-default-backend))))))
2272 ;; Export nested footnotes in pruned parts of tree.
2276 (let ((org-export-exclude-tags '("noexport")))
2277 (org-test-with-temp-text
2278 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2279 (org-export-as (org-test-default-backend))))))
2283 (let ((org-export-select-tags '("export")))
2284 (org-test-with-temp-text
2285 "* H :export:\nText[fn:1]\n* H2\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
2286 (org-export-as (org-test-default-backend))))))
2287 ;; Handle uninterpreted data in pruned footnote definitions.
2291 (let ((org-export-with-tables nil
))
2292 (org-test-with-temp-text
2293 "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1]\n| a |"
2294 (org-export-as (org-test-default-backend))))))
2295 ;; Footnotes without a definition should throw an error.
2297 (org-test-with-parsed-data "Text[fn:1]"
2298 (org-export-get-footnote-definition
2299 (org-element-map tree
'footnote-reference
#'identity info t
) info
)))
2300 ;; Footnote section should be ignored in TOC and in headlines
2303 (= 1 (let ((org-footnote-section "Footnotes"))
2304 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
2305 (org-export-collect-headlines info
))))))
2308 (let ((org-footnote-section "Footnotes"))
2309 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
2310 (org-element-map tree
'headline
2312 (when (equal (org-element-property :raw-value hl
) "H2")
2313 (org-export-get-headline-number hl info
)))
2318 ;;; Headlines and Inlinetasks
2320 (ert-deftest test-org-export
/get-relative-level
()
2321 "Test `org-export-get-relative-level' specifications."
2325 (let ((org-odd-levels-only nil
))
2326 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2327 (org-element-map tree
'headline
2328 (lambda (h) (org-export-get-relative-level h info
))
2333 (let ((org-odd-levels-only nil
))
2334 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
2335 (org-element-map tree
'headline
2336 (lambda (h) (org-export-get-relative-level h info
))
2339 (ert-deftest test-org-export
/low-level-p
()
2340 "Test `org-export-low-level-p' specifications."
2344 (let ((org-odd-levels-only nil
))
2345 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2346 (org-element-map tree
'headline
2347 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
2348 (plist-put info
:headline-levels
1)))))))
2350 (ert-deftest test-org-export
/get-headline-number
()
2351 "Test `org-export-get-headline-number' specifications."
2356 (let ((org-odd-levels-only nil
))
2357 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2358 (org-element-map tree
'headline
2359 (lambda (h) (org-export-get-headline-number h info
))
2361 ;; Missing levels are replaced with 0.
2365 (let ((org-odd-levels-only nil
))
2366 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
2367 (org-element-map tree
'headline
2368 (lambda (h) (org-export-get-headline-number h info
))
2371 (ert-deftest test-org-export
/numbered-headline-p
()
2372 "Test `org-export-numbered-headline-p' specifications."
2373 ;; If `:section-numbers' is nil, never number headlines.
2375 (org-test-with-parsed-data "* Headline"
2376 (org-element-map tree
'headline
2377 (lambda (h) (org-export-numbered-headline-p h info
))
2378 (plist-put info
:section-numbers nil
))))
2379 ;; If `:section-numbers' is a number, only number headlines with
2380 ;; a level greater that it.
2384 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
2385 (org-element-map tree
'headline
2386 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
2387 (plist-put info
:section-numbers
1)))))
2388 ;; Otherwise, headlines are always numbered.
2390 (org-test-with-parsed-data "* Headline"
2391 (org-element-map tree
'headline
2392 (lambda (h) (org-export-numbered-headline-p h info
))
2393 (plist-put info
:section-numbers t
))))
2394 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
2396 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
2397 (org-export-numbered-headline-p
2398 (org-element-map tree
'headline
'identity info t
)
2400 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
2402 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
2403 (org-export-numbered-headline-p
2404 (org-element-map tree
'headline
#'identity info t
)
2406 ;; UNNUMBERED ignores inheritance. Any non-nil value among
2407 ;; ancestors disables numbering.
2409 (org-test-with-parsed-data
2420 (lambda (h) (not (org-export-numbered-headline-p h info
)))
2421 (org-element-map tree
'headline
#'identity info
)))))
2423 (ert-deftest test-org-export
/number-to-roman
()
2424 "Test `org-export-number-to-roman' specifications."
2425 ;; If number is negative, return it as a string.
2426 (should (equal (org-export-number-to-roman -
1) "-1"))
2427 ;; Otherwise, return it as a roman number.
2428 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
2430 (ert-deftest test-org-export
/get-optional-title
()
2431 "Test `org-export-get-alt-title' specifications."
2432 ;; If ALT_TITLE property is defined, use it.
2435 (org-test-with-parsed-data
2436 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
2437 (org-export-get-alt-title
2438 (org-element-map tree
'headline
'identity info t
)
2440 ;; Otherwise, fall-back to regular title.
2442 (equal '("Headline")
2443 (org-test-with-parsed-data "* Headline"
2444 (org-export-get-alt-title
2445 (org-element-map tree
'headline
'identity info t
)
2448 (ert-deftest test-org-export
/get-tags
()
2449 "Test `org-export-get-tags' specifications."
2450 ;; Standard test: tags which are not a select tag, an exclude tag,
2451 ;; or specified as optional argument shouldn't be ignored.
2453 (org-test-with-parsed-data "* Headline :tag:"
2454 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2456 ;; Tags provided in the optional argument are ignored.
2458 (org-test-with-parsed-data "* Headline :ignore:"
2459 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2461 ;; Allow tag inheritance.
2465 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2466 (org-element-map tree
'headline
2467 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2468 ;; Tag inheritance checks FILETAGS keywords.
2472 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2473 (org-element-map tree
'headline
2474 (lambda (hl) (org-export-get-tags hl info nil t
)) info
)))))
2476 (ert-deftest test-org-export
/get-node-property
()
2477 "Test`org-export-get-node-property' specifications."
2481 (org-test-with-parsed-data "* Headline
2485 (org-export-get-node-property
2486 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2487 ;; Test inheritance.
2490 (org-test-with-parsed-data "* Parent
2496 (org-export-get-node-property
2497 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2498 ;; Cannot return a value before the first headline.
2500 (org-test-with-parsed-data "Paragraph
2505 (org-export-get-node-property
2506 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2508 (ert-deftest test-org-export
/get-category
()
2509 "Test `org-export-get-category' specifications."
2513 (org-test-with-parsed-data "* Headline
2517 (org-export-get-category
2518 (org-element-map tree
'headline
'identity nil t
) info
))))
2519 ;; Test inheritance from a parent headline.
2521 (equal '("value" "value")
2522 (org-test-with-parsed-data "* Headline1
2527 (org-element-map tree
'headline
2528 (lambda (hl) (org-export-get-category hl info
)) info
))))
2529 ;; Test inheritance from #+CATEGORY keyword
2532 (org-test-with-parsed-data "#+CATEGORY: value
2534 (org-export-get-category
2535 (org-element-map tree
'headline
'identity nil t
) info
))))
2536 ;; Test inheritance from file name.
2539 (org-test-with-parsed-data "* Headline"
2540 (let ((info (plist-put info
:input-file
"~/test.org")))
2541 (org-export-get-category
2542 (org-element-map tree
'headline
'identity nil t
) info
)))))
2546 (org-test-with-parsed-data "* Headline"
2547 (org-export-get-category
2548 (org-element-map tree
'headline
'identity nil t
) info
)))))
2550 (ert-deftest test-org-export
/first-sibling-p
()
2551 "Test `org-export-first-sibling-p' specifications."
2556 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2557 (org-element-map tree
'headline
2558 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2562 (org-test-with-parsed-data "- item\n\n para"
2563 (org-element-map tree
'paragraph
2564 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2566 ;; Ignore sections for headlines.
2569 (org-test-with-parsed-data "* H\nSection\n** H 2"
2570 (org-element-map tree
'headline
2571 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2573 ;; Ignore headlines not exported.
2577 (let ((org-export-exclude-tags '("ignore")))
2578 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2579 (org-element-map tree
'headline
2580 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2583 (ert-deftest test-org-export
/last-sibling-p
()
2584 "Test `org-export-last-sibling-p' specifications."
2589 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2590 (org-element-map tree
'headline
2591 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2595 (org-test-with-parsed-data "- item\n\n para"
2596 (org-element-map tree
'paragraph
2597 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2599 ;; Ignore headlines not exported.
2603 (let ((org-export-exclude-tags '("ignore")))
2604 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2605 (org-element-map tree
'headline
2606 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2609 (ert-deftest test-org-export
/handle-inlinetasks
()
2610 "Test inlinetask export."
2611 ;; Inlinetask with an exclude tag.
2612 (when (featurep 'org-inlinetask
)
2616 (let ((org-inlinetask-min-level 3)
2617 org-export-filter-body-functions
2618 org-export-filter-final-output-functions
)
2619 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2620 (org-export-as (org-test-default-backend)
2621 nil nil nil
'(:exclude-tags
("noexp")))))))
2622 ;; Inlinetask with an include tag.
2625 "* H2\n*** Inline :exp:\n"
2626 (let ((org-inlinetask-min-level 3)
2627 (org-tags-column 0))
2628 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2629 (org-export-as (org-test-default-backend)
2630 nil nil nil
'(:select-tags
("exp")))))))
2631 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2634 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2635 (org-inlinetask-min-level 3)
2636 org-export-filter-body-functions
2637 org-export-filter-final-output-functions
)
2638 (org-test-with-temp-text "*** TODO Inline"
2639 (org-export-as (org-test-default-backend)
2640 nil nil nil
'(:with-tasks nil
))))))))
2646 (ert-deftest test-org-export
/get-date
()
2647 "Test `org-export-get-date' specifications."
2648 ;; Return a properly formatted string when
2649 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2650 ;; consists in a single timestamp.
2653 (let ((org-export-date-timestamp-format "%d %m %Y"))
2654 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2655 (org-export-get-date info
)))))
2656 ;; Return a secondary string otherwise.
2659 (let ((org-export-date-timestamp-format nil
))
2660 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2661 (org-export-get-date info
)))))
2664 (org-test-with-parsed-data "#+DATE: Date"
2665 (org-export-get-date info
))))
2666 ;; Optional argument has precedence over
2667 ;; `org-export-date-timestamp-format'.
2670 (let ((org-export-date-timestamp-format "%d %m %Y"))
2671 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2672 (org-export-get-date info
"%d %m"))))))
2678 (ert-deftest test-org-export
/custom-protocol-maybe
()
2679 "Test `org-export-custom-protocol-maybe' specifications."
2684 (org-link-set-parameters "foo" :export
(lambda (p d f
) "success"))
2685 (org-export-string-as
2687 (org-export-create-backend
2690 '((section .
(lambda (s c i
) c
))
2691 (paragraph .
(lambda (p c i
) c
))
2692 (link .
(lambda (l c i
)
2693 (or (org-export-custom-protocol-maybe l c
'test
)
2699 (org-link-set-parameters
2700 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2701 (org-export-string-as
2703 (org-export-create-backend
2706 '((section .
(lambda (s c i
) c
))
2707 (paragraph .
(lambda (p c i
) c
))
2708 (link .
(lambda (l c i
)
2709 (or (org-export-custom-protocol-maybe l c
'no-test
)
2711 ;; Ignore anonymous back-ends.
2716 (org-link-set-parameters
2717 "foo" :export
(lambda (p d f
) (and (eq f
'test
) "success")))
2718 (org-export-string-as
2720 (org-export-create-backend
2722 '((section .
(lambda (s c i
) c
))
2723 (paragraph .
(lambda (p c i
) c
))
2724 (link .
(lambda (l c i
)
2725 (or (org-export-custom-protocol-maybe l c nil
)
2728 (ert-deftest test-org-export
/get-coderef-format
()
2729 "Test `org-export-get-coderef-format' specifications."
2730 ;; A link without description returns "%s"
2731 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2733 ;; Return "%s" when path is matched within description.
2734 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2736 ;; Otherwise return description.
2737 (should (equal (org-export-get-coderef-format "path" "desc")
2740 (ert-deftest test-org-export
/inline-image-p
()
2741 "Test `org-export-inline-image-p' specifications."
2743 (org-export-inline-image-p
2744 (org-test-with-temp-text "[[#id]]"
2745 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2746 '(("custom-id" .
"id")))))
2748 (ert-deftest test-org-export
/fuzzy-link
()
2749 "Test fuzzy links specifications."
2750 ;; Link to an headline should return headline's number.
2752 ;; Note: Headline's number is in fact a list of numbers.
2754 (org-test-with-parsed-data
2755 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2756 (org-element-map tree
'link
2758 (org-export-get-ordinal
2759 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2760 ;; Link to a target in an item should return item's number.
2762 ;; Note: Item's number is in fact a list of numbers.
2764 (org-test-with-parsed-data
2765 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2766 (org-element-map tree
'link
2768 (org-export-get-ordinal
2769 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2770 ;; Link to a target in a footnote should return footnote's number.
2773 (org-test-with-parsed-data "
2774 Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
2778 (org-element-map tree
'link
2780 (org-export-get-ordinal
2781 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2782 ;; Link to a named element should return sequence number of that
2786 (org-test-with-parsed-data
2787 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2788 (org-element-map tree
'link
2790 (org-export-get-ordinal
2791 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2792 ;; Link to a target not within an item, a table, a footnote
2793 ;; reference or definition should return section number.
2796 (org-test-with-parsed-data
2797 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2798 (org-element-map tree
'link
2800 (org-export-get-ordinal
2801 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2802 ;; Space are not significant when matching a fuzzy link.
2804 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2805 (org-element-map tree
'link
2806 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2808 ;; Statistics cookies are ignored for headline match.
2810 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2811 (org-element-map tree
'link
2812 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2815 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2816 (org-element-map tree
'link
2817 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2820 (defun test-org-gen-loc-list(text type
)
2821 (org-test-with-parsed-data text
2822 (org-element-map tree type
2823 (lambda (el) (or (org-export-get-loc el info
) 'no-loc
)))))
2825 (ert-deftest test-org-export
/get-loc
()
2826 "Test `org-export-get-loc' specifications."
2828 ;; "-n" resets line number.
2830 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n\n Text\n#+END_EXAMPLE"
2832 ;; The first "+n" has 0 lines before it
2835 (test-org-gen-loc-list "#+BEGIN_EXAMPLE +n\n Text\n#+END_EXAMPLE"
2837 ;; "-n 10" resets line number but has "9 lines" before it.
2840 (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n Text\n#+END_EXAMPLE"
2842 ;; -n10 with two lines then +n 15
2845 (test-org-gen-loc-list "
2846 #+BEGIN_EXAMPLE -n 10
2850 #+BEGIN_EXAMPLE +n 15
2856 (test-org-gen-loc-list "
2857 #+BEGIN_EXAMPLE -n 10
2860 #+BEGIN_EXAMPLE +n 10
2868 ;; an Example Block without -n does not add to the line count.
2870 (equal '(9 no-loc
19)
2871 (test-org-gen-loc-list "
2872 #+BEGIN_EXAMPLE -n 10
2878 #+BEGIN_EXAMPLE +n 10
2882 ;; "-n" resets line number.
2886 (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n \n (- 1 1) \n#+END_SRC"
2888 ;; The first "+n" has 0 lines before it.
2891 (test-org-gen-loc-list
2892 "#+BEGIN_SRC emacs-lisp +n \n (+ 0 (- 1 1))\n#+END_SRC"
2894 ;; "-n 10" resets line number but has "9 lines" before it.
2897 (test-org-gen-loc-list
2898 "#+BEGIN_SRC emacs-lisp -n 10\n (- 10 1)\n#+END_SRC"
2902 (test-org-gen-loc-list "
2903 #+BEGIN_SRC emacs-lisp -n 10
2907 #+BEGIN_SRC emacs-lisp +n 15
2908 (+ (- 10 1) 2 (- 15 1))
2913 (test-org-gen-loc-list "
2914 #+BEGIN_SRC emacs-lisp -n 10
2917 #+BEGIN_SRC emacs-lisp +n 10
2918 (+ (- 10 1) 1 (- 10 1))
2920 #+BEGIN_SRC emacs-lisp -n
2924 ;; A SRC Block without -n does not add to the line count.
2926 (equal '(9 no-loc
19)
2927 (test-org-gen-loc-list
2928 "#+BEGIN_SRC emacs-lisp -n 10
2931 #+BEGIN_SRC emacs-lisp
2934 #+BEGIN_SRC emacs-lisp +n 10
2935 (+ (- 10 1) 1 (- 10 1))
2939 (ert-deftest test-org-export
/resolve-coderef
()
2940 "Test `org-export-resolve-coderef' specifications."
2941 (let ((org-coderef-label-format "(ref:%s)"))
2942 ;; A link to a "-n -k -r" block returns line number.
2945 (org-test-with-parsed-data
2946 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2947 (org-export-resolve-coderef "coderef" info
))))
2950 (org-test-with-parsed-data
2951 "#+BEGIN_EXAMPLE -n 10 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2952 (org-export-resolve-coderef "coderef" info
))))
2955 (org-test-with-parsed-data
2956 "#+BEGIN_EXAMPLE -n 10 -k -r\nText \n#+END_EXAMPLE\n
2957 #+BEGIN_EXAMPLE +n 125 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2958 (org-export-resolve-coderef "coderef" info
))))
2961 (org-test-with-parsed-data
2962 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2963 (org-export-resolve-coderef "coderef" info
))))
2966 (org-test-with-parsed-data
2967 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2968 (org-export-resolve-coderef "coderef" info
))))
2971 (org-test-with-parsed-data
2972 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) \n#+END_SRC\n
2973 #+BEGIN_SRC emacs-lisp +n 125 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2974 (org-export-resolve-coderef "coderef" info
))))
2975 ;; A link to a "-n -r" block returns line number.
2978 (org-test-with-parsed-data
2979 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2980 (org-export-resolve-coderef "coderef" info
))))
2983 (org-test-with-parsed-data
2984 "#+BEGIN_EXAMPLE -n 10 -r\nText (ref:coderef)\n#+END_EXAMPLE"
2985 (org-export-resolve-coderef "coderef" info
))))
2988 (org-test-with-parsed-data
2989 "#+BEGIN_EXAMPLE +n 10 -r\nText \n#+END_EXAMPLE
2990 #+BEGIN_EXAMPLE +n 125 -r\nText (ref:coderef)\n#+END_EXAMPLE"
2991 (org-export-resolve-coderef "coderef" info
))))
2995 (org-test-with-parsed-data
2996 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2997 (org-export-resolve-coderef "coderef" info
))))
3000 (org-test-with-parsed-data
3001 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3002 (org-export-resolve-coderef "coderef" info
))))
3005 (org-test-with-parsed-data
3006 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) \n#+END_SRC
3007 #+BEGIN_SRC emacs-lisp +n125 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3008 (org-export-resolve-coderef "coderef" info
))))
3009 ;; A link to a "-n" block returns coderef.
3012 (org-test-with-parsed-data
3013 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3014 (org-export-resolve-coderef "coderef" info
))))
3017 (org-test-with-parsed-data
3018 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
3019 (org-export-resolve-coderef "coderef" info
))))
3020 ;; A link to a "-r" block returns line number.
3023 (org-test-with-parsed-data
3024 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3025 (org-export-resolve-coderef "coderef" info
))))
3028 (org-test-with-parsed-data
3029 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
3030 (org-export-resolve-coderef "coderef" info
))))
3031 ;; A link to a block without a switch returns coderef.
3034 (org-test-with-parsed-data
3035 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
3036 (org-export-resolve-coderef "coderef" info
))))
3037 (org-test-with-parsed-data
3038 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
3039 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
3040 ;; Correctly handle continued line numbers. A "+n" switch should
3041 ;; resume numbering from previous block with numbered lines,
3042 ;; ignoring blocks not numbering lines in the process. A "-n"
3043 ;; switch resets count.
3046 (org-test-with-parsed-data "
3051 #+BEGIN_SRC emacs-lisp
3055 #+BEGIN_SRC emacs-lisp +n -r
3056 \(+ 1 1) (ref:addition)
3059 #+BEGIN_EXAMPLE -n -r
3060 Another text. (ref:text)
3062 (list (org-export-resolve-coderef "addition" info
)
3063 (org-export-resolve-coderef "text" info
)))))
3064 ;; Recognize coderef with user-specified syntax.
3068 (org-test-with-parsed-data
3069 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
3070 (org-export-resolve-coderef "text" info
))))
3071 ;; Unresolved coderefs raise a `org-link-broken' signal.
3074 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3075 (org-export-resolve-coderef "unknown" info
))
3076 (org-link-broken t
)))))
3078 (ert-deftest test-org-export
/resolve-fuzzy-link
()
3079 "Test `org-export-resolve-fuzzy-link' specifications."
3080 ;; Match target objects.
3082 (org-test-with-parsed-data "<<target>> [[target]]"
3083 (org-export-resolve-fuzzy-link
3084 (org-element-map tree
'link
'identity info t
) info
)))
3085 ;; Match named elements.
3087 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
3088 (org-export-resolve-fuzzy-link
3089 (org-element-map tree
'link
'identity info t
) info
)))
3090 ;; Match exact headline's name.
3092 (org-test-with-parsed-data "* My headline\n[[My headline]]"
3093 (org-export-resolve-fuzzy-link
3094 (org-element-map tree
'link
'identity info t
) info
)))
3095 ;; Targets objects have priority over headline titles.
3098 (org-test-with-parsed-data "* target\n<<target>>[[target]]"
3100 (org-export-resolve-fuzzy-link
3101 (org-element-map tree
'link
'identity info t
) info
)))))
3102 ;; Named elements have priority over headline titles.
3105 (org-test-with-parsed-data
3106 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
3108 (org-export-resolve-fuzzy-link
3109 (org-element-map tree
'link
'identity info t
) info
)))))
3110 ;; If link's path starts with a "*", only match headline titles,
3114 (org-test-with-parsed-data
3115 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
3117 (org-export-resolve-fuzzy-link
3118 (org-element-map tree
'link
'identity info t
) info
)))))
3119 ;; Raise a `org-link-broken' signal if no match.
3121 (org-test-with-parsed-data "[[target]]"
3123 (org-export-resolve-fuzzy-link
3124 (org-element-map tree
'link
#'identity info t
) info
)
3125 (org-link-broken t
))))
3126 ;; Match fuzzy link even when before first headline.
3129 (org-test-with-parsed-data "[[hl]]\n* hl"
3131 (org-export-resolve-fuzzy-link
3132 (org-element-map tree
'link
'identity info t
) info
)))))
3133 ;; Handle url-encoded fuzzy links.
3135 (org-test-with-parsed-data "* A B\n[[A%20B]]"
3136 (org-export-resolve-fuzzy-link
3137 (org-element-map tree
'link
#'identity info t
) info
))))
3139 (ert-deftest test-org-export
/resolve-id-link
()
3140 "Test `org-export-resolve-id-link' specifications."
3141 ;; Regular test for custom-id link.
3143 (equal '("Headline1")
3144 (org-test-with-parsed-data "* Headline1
3150 (org-element-property
3152 (org-export-resolve-id-link
3153 (org-element-map tree
'link
'identity info t
) info
)))))
3154 ;; Raise a `org-link-broken' signal on failing searches.
3156 (org-test-with-parsed-data "* Headline1
3163 (org-export-resolve-id-link
3164 (org-element-map tree
'link
#'identity info t
) info
)
3165 (org-link-broken t
))))
3166 ;; Test for internal id target.
3168 (equal '("Headline1")
3169 (org-test-with-parsed-data "* Headline1
3175 (org-element-property
3177 (org-export-resolve-id-link
3178 (org-element-map tree
'link
'identity info t
) info
)))))
3179 ;; Test for external id target.
3183 (org-test-with-parsed-data "[[id:aaaa]]"
3184 (org-export-resolve-id-link
3185 (org-element-map tree
'link
'identity info t
)
3186 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
3188 (ert-deftest test-org-export
/resolve-radio-link
()
3189 "Test `org-export-resolve-radio-link' specifications."
3192 (org-test-with-temp-text "<<<radio>>> radio"
3193 (org-update-radio-target-regexp)
3194 (let* ((tree (org-element-parse-buffer))
3195 (info `(:parse-tree
,tree
)))
3196 (org-export-resolve-radio-link
3197 (org-element-map tree
'link
'identity info t
)
3199 ;; Radio targets are case-insensitive.
3201 (org-test-with-temp-text "<<<RADIO>>> radio"
3202 (org-update-radio-target-regexp)
3203 (let* ((tree (org-element-parse-buffer))
3204 (info `(:parse-tree
,tree
)))
3205 (org-export-resolve-radio-link
3206 (org-element-map tree
'link
'identity info t
)
3208 ;; Radio target with objects.
3210 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
3211 (org-update-radio-target-regexp)
3212 (let* ((tree (org-element-parse-buffer))
3213 (info `(:parse-tree
,tree
)))
3214 (org-export-resolve-radio-link
3215 (org-element-map tree
'link
'identity info t
)
3217 ;; Radio target with objects at its beginning.
3219 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
3220 (org-update-radio-target-regexp)
3221 (let* ((tree (org-element-parse-buffer))
3222 (info `(:parse-tree
,tree
)))
3223 (org-export-resolve-radio-link
3224 (org-element-map tree
'link
'identity info t
)
3226 ;; Radio link next to an apostrophe.
3228 (org-test-with-temp-text "<<<radio>>> radio's"
3229 (org-update-radio-target-regexp)
3230 (let* ((tree (org-element-parse-buffer))
3231 (info `(:parse-tree
,tree
)))
3232 (org-export-resolve-radio-link
3233 (org-element-map tree
'link
'identity info t
)
3235 ;; Multiple radio targets.
3237 (equal '("radio1" "radio2")
3238 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
3239 (org-update-radio-target-regexp)
3240 (let* ((tree (org-element-parse-buffer))
3241 (info `(:parse-tree
,tree
)))
3242 (org-element-map tree
'link
3244 (org-element-property
3245 :value
(org-export-resolve-radio-link link info
)))
3247 ;; Radio target is whitespace insensitive.
3249 (org-test-with-temp-text "<<<a radio>>> a\n radio"
3250 (org-update-radio-target-regexp)
3251 (let* ((tree (org-element-parse-buffer))
3252 (info `(:parse-tree
,tree
)))
3253 (org-element-map tree
'link
3254 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
3256 (ert-deftest test-org-export
/file-uri
()
3257 "Test `org-export-file-uri' specifications."
3258 ;; Preserve relative filenames.
3259 (should (equal "relative.org" (org-export-file-uri "relative.org")))
3260 ;; Local files start with "file://"
3261 (should (equal (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "/local.org"))
3262 (org-export-file-uri "/local.org")))
3263 ;; Remote files start with "file://"
3264 (should (equal "file://myself@some.where:papers/last.pdf"
3265 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
3266 (should (equal "file://localhost/etc/fstab"
3267 (org-export-file-uri "//localhost/etc/fstab")))
3268 ;; Expand filename starting with "~".
3269 (should (equal (org-export-file-uri "~/file.org")
3270 (concat (if (memq system-type
'(windows-nt cygwin
)) "file:///" "file://") (expand-file-name "~/file.org")))))
3272 (ert-deftest test-org-export
/get-reference
()
3273 "Test `org-export-get-reference' specifications."
3275 (org-test-with-parsed-data "* Headline"
3276 (org-export-get-reference (org-element-map tree
'headline
#'identity nil t
)
3278 ;; For a given element always return the same reference.
3280 (org-test-with-parsed-data "* Headline"
3281 (let ((headline (org-element-map tree
'headline
#'identity nil t
)))
3282 (equal (org-export-get-reference headline info
)
3283 (org-export-get-reference headline info
)))))
3284 ;; References get through local export back-ends.
3286 (org-test-with-parsed-data "* Headline"
3287 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3289 (org-export-create-backend
3291 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3292 (equal (org-trim (org-export-data-with-backend headline backend info
))
3293 (org-export-get-reference headline info
)))))
3295 (org-test-with-parsed-data "* Headline"
3296 (let ((headline (org-element-map tree
'headline
#'identity nil t
))
3298 (org-export-create-backend
3300 '((headline .
(lambda (h _c i
) (org-export-get-reference h i
)))))))
3301 (equal (org-export-with-backend backend headline nil info
)
3302 (org-export-get-reference headline info
)))))
3303 ;; Use search cells defined in `:crossrefs'. However, handle
3304 ;; duplicate search cells.
3307 (org-test-with-parsed-data "* Headline"
3308 (let* ((headline (org-element-map tree
'headline
#'identity nil t
))
3309 (search-cell (car (org-export-search-cells headline
))))
3311 (plist-put info
:crossrefs
(list (cons search-cell
1))))
3312 (org-export-get-reference headline info
)))))
3314 (equal '("org0000001" "org0000001")
3315 (org-test-with-parsed-data "* H\n** H"
3316 (org-element-map tree
'headline
3318 (let* ((search-cell (car (org-export-search-cells h
)))
3319 (info (plist-put info
:crossrefs
3320 (list (cons search-cell
1)))))
3321 (org-export-get-reference h info
))))))))
3324 ;;; Pseudo objects and pseudo elements
3326 (ert-deftest test-org-export
/pseudo-elements
()
3327 "Test exporting pseudo-elements."
3328 ;; Handle blank lines after pseudo-elements. In particular, do not
3329 ;; replace them with white spaces.
3331 (equal "contents\n\nparagraph\n"
3332 (let ((backend (org-export-create-backend
3334 '((pseudo-element .
(lambda (_p c _i
) c
))
3335 (paragraph .
(lambda (_p c _i
) c
))
3336 (plain-text .
(lambda (c _i
) c
)))))
3337 (element '(pseudo-element (:post-blank
1) "contents"))
3338 (paragraph '(paragraph nil
"paragraph"))
3339 (data '(org-data nil
)))
3340 (org-element-adopt-elements data element paragraph
)
3341 (org-export-data-with-backend data backend nil
)))))
3343 (ert-deftest test-org-export
/pseudo-objects
()
3344 "Test exporting pseudo-objects."
3345 ;; Handle blank spaces after pseudo-objects. In particular, do not
3346 ;; replace them with newlines.
3348 (equal "begin x end\n"
3349 (let ((backend (org-export-create-backend
3351 '((pseudo-object .
(lambda (_p c _i
) c
))
3352 (paragraph .
(lambda (_p c _i
) c
))
3353 (plain-text .
(lambda (c _i
) c
)))))
3354 (object '(pseudo-object (:post-blank
1) "x"))
3355 (paragraph '(paragraph nil
)))
3356 (org-element-adopt-elements paragraph
"begin " object
"end")
3357 (org-export-data-with-backend paragraph backend nil
)))))
3360 ;;; Src-block and example-block
3362 (ert-deftest test-org-export
/unravel-code
()
3363 "Test `org-export-unravel-code' function."
3364 ;; Code without reference.
3366 (equal '("(+ 1 1)\n")
3367 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3368 (org-export-unravel-code (org-element-at-point)))))
3369 ;; Code with reference.
3371 (equal '("(+ 1 1)\n" (1 .
"test"))
3372 (org-test-with-temp-text
3373 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
3374 (let ((org-coderef-label-format "(ref:%s)"))
3375 (org-export-unravel-code (org-element-at-point))))))
3376 ;; Code with user-defined reference.
3379 '("(+ 1 1)\n" (1 .
"test"))
3380 (org-test-with-temp-text
3381 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
3382 (let ((org-coderef-label-format "(ref:%s)"))
3383 (org-export-unravel-code (org-element-at-point))))))
3384 ;; Code references keys are relative to the current block.
3386 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
3387 (org-test-with-temp-text "
3396 (let ((org-coderef-label-format "(ref:%s)"))
3397 (org-export-unravel-code (org-element-at-point)))))))
3399 (ert-deftest test-org-export
/format-code-default
()
3400 "Test `org-export-format-code-default' specifications."
3401 ;; Return the empty string when code is empty.
3404 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
3405 (org-export-format-code-default
3406 (org-element-map tree
'src-block
'identity info t
) info
))))
3407 ;; Number lines, two whitespace characters before the actual loc.
3410 (org-test-with-parsed-data
3411 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
3412 (org-export-format-code-default
3413 (org-element-map tree
'src-block
'identity info t
) info
))))
3414 ;; Put references 6 whitespace characters after the widest line,
3415 ;; wrapped within parenthesis.
3417 (equal "123 (a)\n1 (b)\n"
3418 (let ((org-coderef-label-format "(ref:%s)"))
3419 (org-test-with-parsed-data
3420 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
3421 (org-export-format-code-default
3422 (org-element-map tree
'src-block
'identity info t
) info
))))))
3428 (ert-deftest test-org-export
/activate-smart-quotes
()
3429 "Test `org-export-activate-smart-quotes' specifications."
3430 ;; Double quotes: standard test.
3433 '("some “quoted” text")
3434 (let ((org-export-default-language "en"))
3435 (org-test-with-parsed-data "some \"quoted\" text"
3436 (org-element-map tree
'plain-text
3437 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3439 ;; Opening quotes: at the beginning of a paragraph.
3443 (let ((org-export-default-language "en"))
3444 (org-test-with-parsed-data "\"begin"
3445 (org-element-map tree
'plain-text
3446 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3448 ;; Opening quotes: after an object.
3451 '("“quoted” text")
3452 (let ((org-export-default-language "en"))
3453 (org-test-with-parsed-data "=verb= \"quoted\" text"
3454 (org-element-map tree
'plain-text
3455 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3457 ;; Closing quotes: at the end of a paragraph.
3460 '("Quoted “text”")
3461 (let ((org-export-default-language "en"))
3462 (org-test-with-parsed-data "Quoted \"text\""
3463 (org-element-map tree
'plain-text
3464 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3466 ;; Inner quotes: standard test.
3468 (equal '("« outer « inner » outer »")
3469 (let ((org-export-default-language "fr"))
3470 (org-test-with-parsed-data "\"outer 'inner' outer\""
3471 (org-element-map tree
'plain-text
3472 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3474 ;; Inner quotes: close to special symbols.
3476 (equal '("« outer (« inner ») outer »")
3477 (let ((org-export-default-language "fr"))
3478 (org-test-with-parsed-data "\"outer ('inner') outer\""
3479 (org-element-map tree
'plain-text
3480 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3483 (equal '("« « inner » »")
3484 (let ((org-export-default-language "fr"))
3485 (org-test-with-parsed-data "\"'inner'\""
3486 (org-element-map tree
'plain-text
3487 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3489 ;; Apostrophe: standard test.
3491 (equal '("It « shouldn’t » fail")
3492 (let ((org-export-default-language "fr"))
3493 (org-test-with-parsed-data "It \"shouldn't\" fail"
3494 (org-element-map tree
'plain-text
3495 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3498 (equal '("It shouldn’t fail")
3499 (let ((org-export-default-language "fr"))
3500 (org-test-with-parsed-data "It shouldn't fail"
3501 (org-element-map tree
'plain-text
3502 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3504 ;; Apostrophe: before an object.
3507 '("« a’" " »")
3508 (let ((org-export-default-language "fr"))
3509 (org-test-with-parsed-data "\"a'=b=\""
3510 (org-element-map tree
'plain-text
3511 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3513 ;; Apostrophe: after an object.
3515 (equal '("« " "’s »")
3516 (let ((org-export-default-language "fr"))
3517 (org-test-with-parsed-data "\"=code='s\""
3518 (org-element-map tree
'plain-text
3519 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
3521 ;; Special case: isolated quotes.
3523 (equal '("“" "”")
3524 (let ((org-export-default-language "en"))
3525 (org-test-with-parsed-data "\"$x$\""
3526 (org-element-map tree
'plain-text
3527 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3529 ;; Smart quotes in secondary strings.
3531 (equal '("“" "”")
3532 (let ((org-export-default-language "en"))
3533 (org-test-with-parsed-data "* \"$x$\""
3534 (org-element-map tree
'plain-text
3535 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3537 ;; Smart quotes in document keywords.
3539 (equal '("“" "”")
3540 (let ((org-export-default-language "en"))
3541 (org-test-with-parsed-data "#+TITLE: \"$x$\""
3542 (org-element-map (plist-get info
:title
) 'plain-text
3543 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3545 ;; Smart quotes in parsed affiliated keywords.
3547 (equal '("“" "”" "Paragraph")
3548 (let ((org-export-default-language "en"))
3549 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
3550 (org-element-map tree
'plain-text
3551 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3553 ;; Smart quotes within objects.
3555 (equal '("“foo”")
3556 (let ((org-export-default-language "en"))
3557 (org-test-with-parsed-data "| \"foo\" |"
3558 (org-element-map tree
'plain-text
3559 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
3561 ;; FIXME: Test failing non-interactively.
3564 ;; (equal '("“foo”")
3565 ;; (let ((org-export-default-language "en"))
3566 ;; (org-test-with-parsed-data "*\"foo\"*"
3567 ;; (org-element-map tree 'plain-text
3568 ;; (lambda (s) (org-export-activate-smart-quotes s :html info))
3569 ;; info nil nil t)))))
3576 (ert-deftest test-org-export
/special-column
()
3577 "Test if the table's special column is properly recognized."
3578 ;; 1. First column is special if it contains only a special marking
3579 ;; characters or empty cells.
3580 (org-test-with-temp-text "
3584 (org-export-table-has-special-column-p
3586 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3587 ;; 2. If the column contains anything else, it isn't special.
3588 (org-test-with-temp-text "
3592 (org-export-table-has-special-column-p
3594 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3595 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
3597 (org-test-with-temp-text "
3606 (org-export-table-has-special-column-p
3608 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
3609 ;; 4. A first column with only empty cells isn't considered as
3611 (org-test-with-temp-text "
3615 (org-export-table-has-special-column-p
3617 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
3619 (ert-deftest test-org-export
/table-row-is-special-p
()
3620 "Test `org-export-table-row-is-special-p' specifications."
3621 ;; 1. A row is special if it has a special marking character in the
3623 (org-test-with-parsed-data "| ! | 1 |"
3625 (org-export-table-row-is-special-p
3626 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3627 ;; 2. A row is special when its first field is "/"
3628 (org-test-with-parsed-data "
3632 (org-export-table-row-is-special-p
3633 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3634 ;; 3. A row only containing alignment cookies is also considered as
3636 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
3638 (org-export-table-row-is-special-p
3639 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3640 ;; 4. Everything else isn't considered as special.
3641 (org-test-with-parsed-data "| \alpha | | c |"
3643 (org-export-table-row-is-special-p
3644 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
3645 ;; 5. Table's rules are never considered as special rows.
3646 (org-test-with-parsed-data "|---+---|"
3648 (org-export-table-row-is-special-p
3649 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
3651 (ert-deftest test-org-export
/has-header-p
()
3652 "Test `org-export-table-has-header-p' specifications."
3653 ;; 1. With an header.
3654 (org-test-with-parsed-data "
3659 (org-export-table-has-header-p
3660 (org-element-map tree
'table
'identity info
'first-match
)
3662 ;; 2. Without an header.
3663 (org-test-with-parsed-data "
3667 (org-export-table-has-header-p
3668 (org-element-map tree
'table
'identity info
'first-match
)
3670 ;; 3. Don't get fooled with starting and ending rules.
3671 (org-test-with-parsed-data "
3677 (org-export-table-has-header-p
3678 (org-element-map tree
'table
'identity info
'first-match
)
3681 (ert-deftest test-org-export
/table-row-group
()
3682 "Test `org-export-table-row-group' specifications."
3683 ;; 1. A rule creates a new group.
3686 (org-test-with-parsed-data "
3690 (org-element-map tree
'table-row
3692 (if (eq (org-element-property :type row
) 'rule
) 'rule
3693 (org-export-table-row-group row info
)))))))
3694 ;; 2. Special rows are ignored in count.
3698 (org-test-with-parsed-data "
3702 (org-element-map tree
'table-row
3704 (if (eq (org-element-property :type row
) 'rule
) 'rule
3705 (org-export-table-row-group row info
)))
3707 ;; 3. Double rules also are ignored in count.
3709 (equal '(1 rule rule
2)
3710 (org-test-with-parsed-data "
3715 (org-element-map tree
'table-row
3717 (if (eq (org-element-property :type row
) 'rule
) 'rule
3718 (org-export-table-row-group row info
))))))))
3720 (ert-deftest test-org-export
/table-row-number
()
3721 "Test `org-export-table-row-number' specifications."
3722 ;; Standard test. Number is 0-indexed.
3725 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3726 (org-element-map tree
'table-row
3727 (lambda (row) (org-export-table-row-number row info
)) info
))))
3728 ;; Number ignores separators.
3731 (org-test-with-parsed-data "
3735 (org-element-map tree
'table-row
3736 (lambda (row) (org-export-table-row-number row info
)) info
))))
3737 ;; Number ignores special rows.
3740 (org-test-with-parsed-data "
3746 (org-element-map tree
'table-row
3747 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3749 (ert-deftest test-org-export
/table-cell-width
()
3750 "Test `org-export-table-cell-width' specifications."
3751 ;; 1. Width is primarily determined by width cookies. If no cookie
3752 ;; is found, cell's width is nil.
3753 (org-test-with-parsed-data "
3754 | / | <l> | <6> | <l7> |
3759 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3760 (org-element-map tree
'table-cell
'identity info
)))))
3761 ;; 2. The last width cookie has precedence.
3762 (org-test-with-parsed-data "
3769 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3770 (org-element-map tree
'table-cell
'identity info
)))))
3771 ;; 3. Valid width cookies must have a specific row.
3772 (org-test-with-parsed-data "| <6> | cell |"
3776 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3777 (org-element-map tree
'table-cell
'identity
))))))
3779 (ert-deftest test-org-export
/table-cell-alignment
()
3780 "Test `org-export-table-cell-alignment' specifications."
3781 ;; 1. Alignment is primarily determined by alignment cookies.
3783 (equal '(left center right
)
3784 (let ((org-table-number-fraction 0.5)
3785 (org-table-number-regexp "^[0-9]+$"))
3786 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3787 (mapcar (lambda (cell)
3788 (org-export-table-cell-alignment cell info
))
3789 (org-element-map tree
'table-cell
'identity
))))))
3790 ;; 2. The last alignment cookie has precedence.
3792 (equal '(right right right
)
3793 (org-test-with-parsed-data "
3797 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3798 (org-element-map tree
'table-cell
'identity
)))))
3799 ;; 3. If there's no cookie, cell's contents determine alignment.
3800 ;; A column mostly made of cells containing numbers will align
3801 ;; its cells to the right.
3803 (equal '(right right right
)
3804 (let ((org-table-number-fraction 0.5)
3805 (org-table-number-regexp "^[0-9]+$"))
3806 (org-test-with-parsed-data "
3810 (mapcar (lambda (cell)
3811 (org-export-table-cell-alignment cell info
))
3812 (org-element-map tree
'table-cell
'identity
))))))
3813 ;; 4. Otherwise, they will be aligned to the left.
3815 (equal '(left left left
)
3816 (org-test-with-parsed-data "
3820 (mapcar (lambda (cell)
3821 (org-export-table-cell-alignment cell info
))
3822 (org-element-map tree
'table-cell
'identity info
))))))
3824 (ert-deftest test-org-export
/table-cell-borders
()
3825 "Test `org-export-table-cell-borders' specifications."
3826 ;; 1. Recognize various column groups indicators.
3827 (org-test-with-parsed-data "| / | < | > | <> |"
3830 '((right bottom top
) (left bottom top
) (right bottom top
)
3831 (right left bottom top
))
3832 (mapcar (lambda (cell)
3833 (org-export-table-cell-borders cell info
))
3834 (org-element-map tree
'table-cell
'identity
)))))
3835 ;; 2. Accept shortcuts to define column groups.
3836 (org-test-with-parsed-data "| / | < | < |"
3839 '((right bottom top
) (right left bottom top
) (left bottom top
))
3840 (mapcar (lambda (cell)
3841 (org-export-table-cell-borders cell info
))
3842 (org-element-map tree
'table-cell
'identity
)))))
3843 ;; 3. A valid column groups row must start with a "/".
3844 (org-test-with-parsed-data "
3848 (equal '((top) (top) (bottom) (bottom))
3849 (mapcar (lambda (cell)
3850 (org-export-table-cell-borders cell info
))
3851 (org-element-map tree
'table-cell
'identity
)))))
3852 ;; 4. Take table rules into consideration.
3853 (org-test-with-parsed-data "
3858 (equal '((below top
) (bottom above
))
3859 (mapcar (lambda (cell)
3860 (org-export-table-cell-borders cell info
))
3861 (org-element-map tree
'table-cell
'identity
)))))
3862 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3863 ;; (resp. `bottom' and `below') borders. Any special row is
3865 (org-test-with-parsed-data "
3871 (equal '((bottom below top above
))
3873 (mapcar (lambda (cell)
3874 (org-export-table-cell-borders cell info
))
3875 (org-element-map tree
'table-cell
'identity
)))))))
3877 (ert-deftest test-org-export
/table-dimensions
()
3878 "Test `org-export-table-dimensions' specifications."
3879 ;; 1. Standard test.
3880 (org-test-with-parsed-data "
3885 (org-export-table-dimensions
3886 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3887 ;; 2. Ignore horizontal rules and special columns.
3888 (org-test-with-parsed-data "
3895 (org-export-table-dimensions
3896 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3898 (ert-deftest test-org-export
/table-cell-address
()
3899 "Test `org-export-table-cell-address' specifications."
3900 ;; 1. Standard test: index is 0-based.
3901 (org-test-with-parsed-data "| a | b |"
3903 (equal '((0 .
0) (0 .
1))
3904 (org-element-map tree
'table-cell
3905 (lambda (cell) (org-export-table-cell-address cell info
))
3907 ;; 2. Special column isn't counted, nor are special rows.
3908 (org-test-with-parsed-data "
3913 (org-export-table-cell-address
3914 (car (last (org-element-map tree
'table-cell
'identity info
)))
3916 ;; 3. Tables rules do not count either.
3917 (org-test-with-parsed-data "
3925 (org-export-table-cell-address
3926 (car (last (org-element-map tree
'table-cell
'identity info
)))
3928 ;; 4. Return nil for special cells.
3929 (org-test-with-parsed-data "| / | a |"
3931 (org-export-table-cell-address
3932 (org-element-map tree
'table-cell
'identity nil
'first-match
)
3935 (ert-deftest test-org-export
/get-table-cell-at
()
3936 "Test `org-export-get-table-cell-at' specifications."
3937 ;; 1. Address ignores special columns, special rows and rules.
3938 (org-test-with-parsed-data "
3945 (org-element-contents
3946 (org-export-get-table-cell-at
3948 (org-element-map tree
'table
'identity info
'first-match
)
3950 ;; 2. Return value for a non-existent address is nil.
3951 (org-test-with-parsed-data "| a |"
3953 (org-export-get-table-cell-at
3955 (org-element-map tree
'table
'identity info
'first-match
)
3957 (org-test-with-parsed-data "| / |"
3959 (org-export-get-table-cell-at
3961 (org-element-map tree
'table
'identity info
'first-match
)
3964 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
3965 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3966 ;; 1. A cell at a beginning of a row always starts a column group.
3967 (org-test-with-parsed-data "| a |"
3969 (org-export-table-cell-starts-colgroup-p
3970 (org-element-map tree
'table-cell
'identity info
'first-match
)
3972 ;; 2. Special column should be ignored when determining the
3973 ;; beginning of the row.
3974 (org-test-with-parsed-data "
3978 (org-export-table-cell-starts-colgroup-p
3979 (org-element-map tree
'table-cell
'identity info
'first-match
)
3981 ;; 2. Explicit column groups.
3982 (org-test-with-parsed-data "
3988 (org-element-map tree
'table-cell
3990 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3993 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3994 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3995 ;; 1. A cell at the end of a row always ends a column group.
3996 (org-test-with-parsed-data "| a |"
3998 (org-export-table-cell-ends-colgroup-p
3999 (org-element-map tree
'table-cell
'identity info
'first-match
)
4001 ;; 2. Special column should be ignored when determining the
4002 ;; beginning of the row.
4003 (org-test-with-parsed-data "
4007 (org-export-table-cell-ends-colgroup-p
4008 (org-element-map tree
'table-cell
'identity info
'first-match
)
4010 ;; 3. Explicit column groups.
4011 (org-test-with-parsed-data "
4017 (org-element-map tree
'table-cell
4019 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
4022 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
4023 "Test `org-export-table-row-starts-rowgroup-p' specifications."
4024 ;; 1. A row at the beginning of a table always starts a row group.
4025 ;; So does a row following a table rule.
4026 (org-test-with-parsed-data "
4033 (org-element-map tree
'table-row
4035 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4037 ;; 2. Special rows should be ignored when determining the beginning
4039 (org-test-with-parsed-data "
4048 (org-element-map tree
'table-row
4050 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
4053 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
4054 "Test `org-export-table-row-ends-rowgroup-p' specifications."
4055 ;; 1. A row at the end of a table always ends a row group. So does
4056 ;; a row preceding a table rule.
4057 (org-test-with-parsed-data "
4064 (org-element-map tree
'table-row
4066 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4068 ;; 2. Special rows should be ignored when determining the beginning
4070 (org-test-with-parsed-data "
4079 (org-element-map tree
'table-row
4081 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
4084 (ert-deftest test-org-export
/table-row-in-header-p
()
4085 "Test `org-export-table-row-in-header-p' specifications."
4086 ;; Standard test. Separators are always nil.
4090 (org-test-with-parsed-data "| a |\n|---|\n| b |"
4091 (org-element-map tree
'table-row
4093 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
4094 ;; Nil when there is no header.
4098 (org-test-with-parsed-data "| a |\n| b |"
4099 (org-element-map tree
'table-row
4101 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
4103 (ert-deftest test-org-export
/table-row-starts-header-p
()
4104 "Test `org-export-table-row-starts-header-p' specifications."
4105 ;; 1. Only the row starting the first row group starts the table
4107 (org-test-with-parsed-data "
4115 (org-element-map tree
'table-row
4117 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
4119 ;; 2. A row cannot start an header if there's no header in the
4121 (org-test-with-parsed-data "
4125 (org-export-table-row-starts-header-p
4126 (org-element-map tree
'table-row
'identity info
'first-match
)
4129 (ert-deftest test-org-export
/table-row-ends-header-p
()
4130 "Test `org-export-table-row-ends-header-p' specifications."
4131 ;; 1. Only the row starting the first row group starts the table
4133 (org-test-with-parsed-data "
4141 (org-element-map tree
'table-row
4143 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
4145 ;; 2. A row cannot start an header if there's no header in the
4147 (org-test-with-parsed-data "
4151 (org-export-table-row-ends-header-p
4152 (org-element-map tree
'table-row
'identity info
'first-match
)
4157 ;;; Tables of Contents
4159 (ert-deftest test-org-export
/collect-headlines
()
4160 "Test `org-export-collect-headlines' specifications."
4165 (org-test-with-parsed-data "* H1\n** H2"
4166 (org-export-collect-headlines info
)))))
4167 ;; Do not collect headlines below optional argument.
4171 (org-test-with-parsed-data "* H1\n** H2"
4172 (org-export-collect-headlines info
1)))))
4173 ;; Never collect headlines below maximum headline level.
4177 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4178 (org-export-collect-headlines info
)))))
4182 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
4183 (org-export-collect-headlines info
2)))))
4184 ;; Collect headlines locally.
4187 (org-test-with-parsed-data "* H1\n** H2\n** H3"
4188 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4189 (length (org-export-collect-headlines info nil scope
))))))
4190 ;; When collecting locally, optional level is relative.
4193 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
4194 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
4195 (length (org-export-collect-headlines info
1 scope
)))))))
4201 (ert-deftest test-org-export
/inner-template
()
4202 "Test `inner-template' translator specifications."
4205 (org-test-with-temp-text "* Headline"
4207 (org-export-create-backend
4209 '((inner-template .
(lambda (contents info
) "Success!"))
4210 (headline .
(lambda (h c i
) "Headline"))))))))
4211 ;; Inner template is applied even in a "body-only" export.
4214 (org-test-with-temp-text "* Headline"
4216 (org-export-create-backend
4217 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
4218 (headline .
(lambda (h c i
) "Headline"))))
4219 nil nil
'body-only
)))))
4221 (ert-deftest test-org-export
/template
()
4222 "Test `template' translator specifications."
4225 (org-test-with-temp-text "* Headline"
4227 (org-export-create-backend
4228 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4229 (headline .
(lambda (h c i
) "Headline"))))))))
4230 ;; Template is not applied in a "body-only" export.
4233 (org-test-with-temp-text "* Headline"
4235 (org-export-create-backend
4236 :transcoders
'((template .
(lambda (contents info
) "Success!"))
4237 (headline .
(lambda (h c i
) "Headline"))))
4238 nil nil
'body-only
)))))
4244 (ert-deftest test-org-export
/get-next-element
()
4245 "Test `org-export-get-next-element' specifications."
4249 (org-test-with-parsed-data "* Headline\n*a* b"
4250 (org-export-get-next-element
4251 (org-element-map tree
'bold
'identity info t
) info
))))
4252 ;; Return nil when no previous element.
4254 (org-test-with-parsed-data "* Headline\na *b*"
4255 (org-export-get-next-element
4256 (org-element-map tree
'bold
'identity info t
) info
)))
4257 ;; Non-exportable elements are ignored.
4259 (let ((org-export-with-timestamps nil
))
4260 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
4261 (org-export-get-next-element
4262 (org-element-map tree
'entity
'identity info t
) info
))))
4263 ;; Find next element in secondary strings.
4266 (org-test-with-parsed-data "* a =verb="
4268 (org-export-get-next-element
4269 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4272 (org-test-with-parsed-data "* /italic/ =verb="
4274 (org-export-get-next-element
4275 (org-element-map tree
'italic
'identity info t
) info
)))))
4276 ;; Find next element in document keywords.
4279 (org-test-with-parsed-data "#+TITLE: a =verb="
4281 (org-export-get-next-element
4283 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4284 ;; Find next element in parsed affiliated keywords.
4287 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
4289 (org-export-get-next-element
4290 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4291 ;; With optional argument N, return a list containing all the
4292 ;; following elements.
4295 '(bold code underline
)
4296 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4298 (org-export-get-next-element
4299 (org-element-map tree
'italic
'identity info t
) info t
)))))
4300 ;; When N is a positive integer, return a list containing up to
4301 ;; N following elements.
4305 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
4307 (org-export-get-next-element
4308 (org-element-map tree
'italic
'identity info t
) info
2))))))
4310 (ert-deftest test-org-export
/get-previous-element
()
4311 "Test `org-export-get-previous-element' specifications."
4315 (org-test-with-parsed-data "* Headline\na *b*"
4316 (org-export-get-previous-element
4317 (org-element-map tree
'bold
'identity info t
) info
))))
4318 ;; Return nil when no previous element.
4320 (org-test-with-parsed-data "* Headline\n*a* b"
4321 (org-export-get-previous-element
4322 (org-element-map tree
'bold
'identity info t
) info
)))
4323 ;; Non-exportable elements are ignored.
4325 (let ((org-export-with-timestamps nil
))
4326 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
4327 (org-export-get-previous-element
4328 (org-element-map tree
'entity
'identity info t
) info
))))
4329 ;; Find previous element in secondary strings.
4332 (org-test-with-parsed-data "* =verb= a"
4334 (org-export-get-previous-element
4335 (org-element-map tree
'plain-text
'identity info t
) info
)))))
4338 (org-test-with-parsed-data "* =verb= /italic/"
4340 (org-export-get-previous-element
4341 (org-element-map tree
'italic
'identity info t
) info
)))))
4342 ;; Find previous element in document keywords.
4345 (org-test-with-parsed-data "#+TITLE: =verb= a"
4347 (org-export-get-previous-element
4349 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
4350 ;; Find previous element in parsed affiliated keywords.
4353 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
4355 (org-export-get-previous-element
4356 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
4357 ;; With optional argument N, return a list containing up to
4358 ;; N previous elements.
4360 (equal '(underline italic bold
)
4361 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4363 (org-export-get-previous-element
4364 (org-element-map tree
'code
'identity info t
) info t
)))))
4365 ;; When N is a positive integer, return a list containing up to
4366 ;; N previous elements.
4368 (equal '(italic bold
)
4369 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
4371 (org-export-get-previous-element
4372 (org-element-map tree
'code
'identity info t
) info
2))))))
4376 ;;; test-org-export.el end here