Fix c9a52787c14c3a7429bcd3c8975350525e0baa04
[org-mode.git] / testing / lisp / test-ox.el
blob0e1895c51be9760778932e9a7fa9ba30838027b8
1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012-2015 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Code:
24 (unless (featurep 'ox)
25 (signal 'missing-test-dependency "org-export"))
27 (defun org-test-default-backend ()
28 "Return a default export back-end.
29 This back-end simply returns parsed data as Org syntax."
30 (org-export-create-backend
31 :transcoders (let (transcode-table)
32 (dolist (type (append org-element-all-elements
33 org-element-all-objects)
34 transcode-table)
35 (push
36 (cons type
37 (lambda (obj contents info)
38 (funcall
39 (intern (format "org-element-%s-interpreter"
40 type))
41 obj contents)))
42 transcode-table)))))
44 (defmacro org-test-with-parsed-data (data &rest body)
45 "Execute body with parsed data available.
46 DATA is a string containing the data to be parsed. BODY is the
47 body to execute. Parse tree is available under the `tree'
48 variable, and communication channel under `info'."
49 (declare (debug (form body)) (indent 1))
50 `(org-test-with-temp-text ,data
51 (let* ((tree (org-element-parse-buffer))
52 (info (org-export-get-environment)))
53 (org-export--prune-tree tree info)
54 (org-export--remove-uninterpreted-data tree info)
55 (let ((info (org-combine-plists
56 info (org-export-collect-tree-properties tree info))))
57 ,@body))))
61 ;;; Internal Tests
63 (ert-deftest test-org-export/bind-keyword ()
64 "Test reading #+BIND: keywords."
65 ;; Test with `org-export-allow-bind-keywords' set to t.
66 (should
67 (org-test-with-temp-text "#+BIND: test-ox-var value"
68 (let ((org-export-allow-bind-keywords t))
69 (org-export-get-environment)
70 (eq test-ox-var 'value))))
71 ;; Test with `org-export-allow-bind-keywords' set to nil.
72 (should-not
73 (org-test-with-temp-text "#+BIND: test-ox-var value"
74 (let ((org-export-allow-bind-keywords nil))
75 (org-export-get-environment)
76 (boundp 'test-ox-var))))
77 ;; BIND keywords are case-insensitive.
78 (should
79 (org-test-with-temp-text "#+bind: test-ox-var value"
80 (let ((org-export-allow-bind-keywords t))
81 (org-export-get-environment)
82 (eq test-ox-var 'value))))
83 ;; Preserve order of BIND keywords.
84 (should
85 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
86 (let ((org-export-allow-bind-keywords t))
87 (org-export-get-environment)
88 (eq test-ox-var 2))))
89 ;; Read BIND keywords in setup files.
90 (should
91 (org-test-with-temp-text
92 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
93 (let ((org-export-allow-bind-keywords t))
94 (org-export-get-environment)
95 (eq variable 'value))))
96 ;; Verify that bound variables are seen during export.
97 (should
98 (equal "Yes\n"
99 (org-test-with-temp-text "#+BIND: test-ox-var value"
100 (let ((org-export-allow-bind-keywords t))
101 (org-export-as
102 (org-export-create-backend
103 :transcoders
104 '((section . (lambda (s c i)
105 (if (eq test-ox-var 'value) "Yes" "No")))))))))))
107 (ert-deftest test-org-export/parse-option-keyword ()
108 "Test reading all standard #+OPTIONS: items."
109 (should
110 (equal
111 (org-export--parse-option-keyword
112 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
113 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
114 stat:t title:t")
115 '(:headline-levels
116 1 :preserve-breaks t :section-numbers t :time-stamp-file t
117 :with-archived-trees t :with-author t :with-creator t :with-drawers t
118 :with-email t :with-emphasize t :with-entities t :with-fixed-width t
119 :with-footnotes t :with-inlinetasks nil :with-priority t
120 :with-special-strings t :with-statistics-cookies t :with-sub-superscript t
121 :with-toc t :with-tables t :with-tags t :with-tasks t :with-timestamps t
122 :with-title t :with-todo-keywords t)))
123 ;; Test some special values.
124 (should
125 (equal
126 (org-export--parse-option-keyword
127 "arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
128 '( :section-numbers
130 :with-archived-trees headline :with-drawers ("TEST")
131 :with-sub-superscript {} :with-toc 1 :with-tags not-in-toc
132 :with-tasks todo :with-timestamps active))))
134 (ert-deftest test-org-export/get-inbuffer-options ()
135 "Test reading all standard export keywords."
136 ;; Properties should follow buffer order.
137 (should
138 (equal
139 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
140 (org-export--get-inbuffer-options))
141 '(:language "fr" :creator "Me" :email "email")))
142 ;; Parse document keywords.
143 (should
144 (equal
145 (org-test-with-temp-text "#+AUTHOR: Me"
146 (org-export--get-inbuffer-options))
147 '(:author ("Me"))))
148 ;; Test `space' behaviour.
149 (should
150 (equal
151 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
152 (org-export--get-inbuffer-options))
153 '(:title ("Some title with spaces"))))
154 ;; Test `newline' behaviour.
155 (should
156 (equal
157 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
158 (org-export--get-inbuffer-options))
159 '(:description "With\ntwo lines")))
160 ;; Test `split' behaviour.
161 (should
162 (equal
163 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
164 (org-export--get-inbuffer-options))
165 '(:select-tags ("a" "b"))))
166 ;; Options set through SETUPFILE.
167 (should
168 (equal
169 (org-test-with-temp-text
170 (format "#+DESCRIPTION: l1
171 #+LANGUAGE: es
172 #+SELECT_TAGS: a
173 #+TITLE: a
174 #+SETUPFILE: \"%s/examples/setupfile.org\"
175 #+DESCRIPTION: l3
176 #+LANGUAGE: fr
177 #+SELECT_TAGS: c
178 #+TITLE: c"
179 org-test-dir)
180 (org-export--get-inbuffer-options))
181 '(:description "l1\nl2\nl3":language "fr" :select-tags ("a" "b" "c")
182 :title ("a b c"))))
183 ;; More than one property can refer to the same buffer keyword.
184 (should
185 (equal '(:k2 "value" :k1 "value")
186 (let ((backend (org-export-create-backend
187 :options '((:k1 "KEYWORD")
188 (:k2 "KEYWORD")))))
189 (org-test-with-temp-text "#+KEYWORD: value"
190 (org-export--get-inbuffer-options backend)))))
191 ;; Keywords in commented subtrees are ignored.
192 (should-not
193 (equal "Me"
194 (org-test-with-parsed-data "* COMMENT H1\n#+AUTHOR: Me"
195 (plist-get info :author))))
196 (should-not
197 (equal "Mine"
198 (org-test-with-parsed-data "* COMMENT H1\n** H2\n#+EMAIL: Mine"
199 (plist-get info :email)))))
201 (ert-deftest test-org-export/get-subtree-options ()
202 "Test setting options from headline's properties."
203 ;; EXPORT_TITLE.
204 (org-test-with-temp-text "#+TITLE: Title
205 * Headline
206 :PROPERTIES:
207 :EXPORT_TITLE: Subtree Title
208 :END:
209 Paragraph"
210 (forward-line)
211 (should (equal (plist-get (org-export-get-environment nil t) :title)
212 '("Subtree Title"))))
213 :title
214 '("subtree-title")
215 ;; EXPORT_OPTIONS.
216 (org-test-with-temp-text "#+OPTIONS: H:1
217 * Headline
218 :PROPERTIES:
219 :EXPORT_OPTIONS: H:2
220 :END:
221 Paragraph"
222 (forward-line)
223 (should
224 (= 2 (plist-get (org-export-get-environment nil t) :headline-levels))))
225 ;; EXPORT_DATE.
226 (org-test-with-temp-text "#+DATE: today
227 * Headline
228 :PROPERTIES:
229 :EXPORT_DATE: 29-03-2012
230 :END:
231 Paragraph"
232 (forward-line)
233 (should (equal (plist-get (org-export-get-environment nil t) :date)
234 '("29-03-2012"))))
235 ;; Properties with `split' behaviour are stored as a list of
236 ;; strings.
237 (should
238 (equal '("a" "b")
239 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
240 * Headline
241 :PROPERTIES:
242 :EXPORT_EXCLUDE_TAGS: a b
243 :END:
244 Paragraph"
245 (progn
246 (forward-line)
247 (plist-get (org-export-get-environment nil t) :exclude-tags)))))
248 ;; Handle :PROPERTY+: syntax.
249 (should
250 (equal '("a" "b")
251 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
252 * Headline
253 :PROPERTIES:
254 :EXPORT_EXCLUDE_TAGS: a
255 :EXPORT_EXCLUDE_TAGS+: b
256 :END:
257 Paragraph"
258 (progn
259 (forward-line)
260 (plist-get (org-export-get-environment nil t) :exclude-tags)))))
261 ;; Export properties are case-insensitive.
262 (org-test-with-temp-text "* Headline
263 :PROPERTIES:
264 :EXPORT_Date: 29-03-2012
265 :END:
266 Paragraph"
267 (should (equal (plist-get (org-export-get-environment nil t) :date)
268 '("29-03-2012"))))
269 ;; Still grab correct options when section above is empty.
270 (should
271 (equal '("H1")
272 (org-test-with-temp-text "* H1\n** H11\n** H12"
273 (progn (forward-line 2)
274 (plist-get (org-export-get-environment nil t) :title))))))
276 (ert-deftest test-org-export/set-title ()
277 "Test title setting."
278 ;; Without TITLE keyword.
279 (should
280 (equal
282 (let (org-export-filter-body-functions
283 org-export-filter-final-output-functions)
284 (org-test-with-temp-text "Test"
285 (org-export-as
286 (org-export-create-backend
287 :transcoders
288 '((template . (lambda (text info)
289 (org-element-interpret-data
290 (plist-get info :title)))))))))))
291 ;; With a blank TITLE keyword.
292 (should
293 (equal
295 (let (org-export-filter-body-functions
296 org-export-filter-final-output-functions)
297 (org-test-with-temp-text "#+TITLE:\nTest"
298 (org-export-as
299 (org-export-create-backend
300 :transcoders
301 '((template . (lambda (text info)
302 (org-element-interpret-data
303 (plist-get info :title)))))))))))
304 ;; With a non-empty TITLE keyword.
305 (should
306 (equal
307 "Title"
308 (org-test-with-temp-text "#+TITLE: Title\nTest"
309 (org-export-as
310 (org-export-create-backend
311 :transcoders
312 '((template . (lambda (text info)
313 (org-element-interpret-data
314 (plist-get info :title))))))))))
315 ;; When exporting a subtree, its heading becomes the headline of the
316 ;; document...
317 (should
318 (equal
319 "Headline"
320 (org-test-with-temp-text "* Headline\nBody"
321 (org-export-as
322 (org-export-create-backend
323 :transcoders
324 '((template . (lambda (text info)
325 (org-element-interpret-data
326 (plist-get info :title))))))
327 'subtree))))
328 ;; ... unless there is an EXPORT_TITLE property at the root of the
329 ;; subtree.
330 (should
331 (equal
333 (org-test-with-temp-text
334 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
335 (org-export-as
336 (org-export-create-backend
337 :transcoders
338 '((template . (lambda (text info)
339 (org-element-interpret-data
340 (plist-get info :title))))))
341 'subtree)))))
343 (ert-deftest test-org-export/handle-options ()
344 "Test if export options have an impact on output."
345 ;; Test exclude tags for headlines and inlinetasks.
346 (should
347 (equal ""
348 (let (org-export-filter-body-functions
349 org-export-filter-final-output-functions)
350 (org-test-with-temp-text "* Head1 :noexp:"
351 (org-export-as (org-test-default-backend)
352 nil nil nil '(:exclude-tags ("noexp")))))))
353 ;; Test include tags for headlines and inlinetasks.
354 (should
355 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
356 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
357 (let ((org-tags-column 0))
358 (org-export-as (org-test-default-backend)
359 nil nil nil '(:select-tags ("exp")))))))
360 ;; If there is an include tag, ignore the section before the first
361 ;; headline, if any.
362 (should
363 (equal "* H1 :exp:\nBody\n"
364 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
365 (let ((org-tags-column 0))
366 (org-export-as (org-test-default-backend)
367 nil nil nil '(:select-tags ("exp")))))))
368 (should-not
369 (equal "* H1 :exp:\n"
370 (org-test-with-temp-text "* H1 :exp:\nBody"
371 (let ((org-tags-column 0))
372 (org-export-as (org-test-default-backend)
373 nil nil nil '(:select-tags ("exp")))))))
374 ;; Test mixing include tags and exclude tags.
375 (should
376 (string-match
377 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
378 (org-test-with-temp-text "
379 * Head1 :export:
380 ** Sub-Head1 :noexport:
381 ** Sub-Head2
382 * Head2 :noexport:
383 ** Sub-Head1 :export:"
384 (org-export-as (org-test-default-backend) nil nil nil
385 '(:select-tags ("export") :exclude-tags ("noexport"))))))
386 ;; Ignore tasks.
387 (should
388 (equal ""
389 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
390 org-export-filter-body-functions
391 org-export-filter-final-output-functions)
392 (org-test-with-temp-text "* TODO Head1"
393 (org-export-as (org-test-default-backend)
394 nil nil nil '(:with-tasks nil))))))
395 (should
396 (equal "* TODO Head1\n"
397 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
398 (org-test-with-temp-text "* TODO Head1"
399 (org-export-as (org-test-default-backend)
400 nil nil nil '(:with-tasks t))))))
401 ;; Archived tree.
402 (should
403 (equal ""
404 (let (org-export-filter-body-functions
405 org-export-filter-final-output-functions)
406 (org-test-with-temp-text "* Head1 :archive:"
407 (let ((org-archive-tag "archive"))
408 (org-export-as (org-test-default-backend)
409 nil nil nil '(:with-archived-trees nil)))))))
410 (should
411 (string-match
412 "\\* Head1[ \t]+:archive:"
413 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
414 (let ((org-archive-tag "archive"))
415 (org-export-as (org-test-default-backend) nil nil nil
416 '(:with-archived-trees headline))))))
417 (should
418 (string-match
419 "\\`\\* Head1[ \t]+:archive:\n\\'"
420 (org-test-with-temp-text "* Head1 :archive:"
421 (let ((org-archive-tag "archive"))
422 (org-export-as (org-test-default-backend)
423 nil nil nil '(:with-archived-trees t))))))
424 ;; Clocks.
425 (should
426 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
427 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
428 (org-export-as (org-test-default-backend)
429 nil nil nil '(:with-clocks t)))))
430 (should
431 (equal ""
432 (let (org-export-filter-body-functions
433 org-export-filter-final-output-functions)
434 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
435 (org-export-as (org-test-default-backend)
436 nil nil nil '(:with-clocks nil))))))
437 ;; Drawers.
438 (should
439 (equal ""
440 (let (org-export-filter-body-functions
441 org-export-filter-final-output-functions)
442 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
443 (org-export-as (org-test-default-backend)
444 nil nil nil '(:with-drawers nil))))))
445 (should
446 (equal ":TEST:\ncontents\n:END:\n"
447 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
448 (org-export-as (org-test-default-backend)
449 nil nil nil '(:with-drawers t)))))
450 (should
451 (equal ":FOO:\nkeep\n:END:\n"
452 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
453 (org-export-as (org-test-default-backend)
454 nil nil nil '(:with-drawers ("FOO"))))))
455 (should
456 (equal ":FOO:\nkeep\n:END:\n"
457 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
458 (org-export-as (org-test-default-backend)
459 nil nil nil '(:with-drawers (not "BAR"))))))
460 ;; Fixed-width.
461 (should
462 (equal ": A\n"
463 (org-test-with-temp-text ": A"
464 (org-export-as (org-test-default-backend) nil nil nil
465 '(:with-fixed-width t)))))
466 (should
467 (equal ""
468 (let (org-export-filter-body-functions
469 org-export-filter-final-output-functions)
470 (org-test-with-temp-text ": A"
471 (org-export-as (org-test-default-backend) nil nil nil
472 '(:with-fixed-width nil))))))
473 ;; Footnotes.
474 (should
475 (equal "Footnote?"
476 (let ((org-footnote-section nil))
477 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
478 (org-trim (org-export-as (org-test-default-backend)
479 nil nil nil '(:with-footnotes nil)))))))
480 (should
481 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
482 (let ((org-footnote-section nil))
483 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
484 (org-trim (org-export-as (org-test-default-backend)
485 nil nil nil '(:with-footnotes t)))))))
486 ;; Inlinetasks.
487 (when (featurep 'org-inlinetask)
488 (should
489 (equal
491 (let ((org-inlinetask-min-level 15)
492 org-export-filter-body-functions
493 org-export-filter-final-output-functions)
494 (org-test-with-temp-text "*************** Task"
495 (org-export-as (org-test-default-backend)
496 nil nil nil '(:with-inlinetasks nil))))))
497 (should
498 (equal
500 (let ((org-inlinetask-min-level 15)
501 org-export-filter-body-functions
502 org-export-filter-final-output-functions)
503 (org-test-with-temp-text
504 "*************** Task\nContents\n*************** END"
505 (org-export-as (org-test-default-backend)
506 nil nil nil '(:with-inlinetasks nil)))))))
507 ;; Plannings.
508 (should
509 (string-match
510 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
511 (let ((org-closed-string "CLOSED:"))
512 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
513 (org-export-as (org-test-default-backend)
514 nil nil nil '(:with-planning t))))))
515 (should
516 (equal "* H\n"
517 (let ((org-closed-string "CLOSED:"))
518 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
519 (org-export-as (org-test-default-backend)
520 nil nil nil '(:with-planning nil))))))
521 ;; Property Drawers.
522 (should
523 (equal "* H1\n"
524 (org-test-with-temp-text
525 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
526 (org-export-as (org-test-default-backend)
527 nil nil nil '(:with-properties nil)))))
528 (should
529 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
530 (org-test-with-temp-text
531 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
532 (org-export-as (org-test-default-backend)
533 nil nil nil '(:with-properties t)))))
534 (should
535 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
536 (org-test-with-temp-text
537 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
538 (org-export-as (org-test-default-backend)
539 nil nil nil '(:with-properties ("B"))))))
540 ;; Statistics cookies.
541 (should
542 (equal ""
543 (let (org-export-filter-body-functions
544 org-export-filter-final-output-functions)
545 (org-trim
546 (org-test-with-temp-text "[0/0]"
547 (org-export-as (org-test-default-backend)
548 nil nil nil '(:with-statistics-cookies nil)))))))
549 ;; Tables.
550 (should
551 (equal "| A |\n"
552 (org-test-with-temp-text "| A |"
553 (org-export-as (org-test-default-backend) nil nil nil
554 '(:with-tables t)))))
555 (should
556 (equal ""
557 (let (org-export-filter-body-functions
558 org-export-filter-final-output-functions)
559 (org-test-with-temp-text "| A |"
560 (org-export-as (org-test-default-backend) nil nil nil
561 '(:with-tables nil)))))))
563 (ert-deftest test-org-export/with-timestamps ()
564 "Test `org-export-with-timestamps' specifications."
565 ;; t value.
566 (should
567 (string-match
568 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
569 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
570 (org-export-as (org-test-default-backend)
571 nil nil nil '(:with-timestamps t)))))
572 ;; nil value.
573 (should
574 (equal
576 (let (org-export-filter-body-functions
577 org-export-filter-final-output-functions)
578 (org-trim
579 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
580 (org-export-as (org-test-default-backend)
581 nil nil nil '(:with-timestamps nil)))))))
582 ;; `active' value.
583 (should
584 (string-match
585 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
586 (org-test-with-temp-text
587 "<2012-03-29 Thu>[2012-03-29 Thu]
589 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
590 (org-export-as (org-test-default-backend)
591 nil nil nil '(:with-timestamps active)))))
592 ;; `inactive' value.
593 (should
594 (string-match
595 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
596 (org-test-with-temp-text
597 "<2012-03-29 Thu>[2012-03-29 Thu]
599 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
600 (org-export-as (org-test-default-backend)
601 nil nil nil '(:with-timestamps inactive))))))
603 (ert-deftest test-org-export/comment-tree ()
604 "Test if export process ignores commented trees."
605 (should
606 (equal ""
607 (let (org-export-filter-body-functions
608 org-export-filter-final-output-functions)
609 (org-test-with-temp-text "* COMMENT Head1"
610 (org-export-as (org-test-default-backend)))))))
612 (ert-deftest test-org-export/uninterpreted ()
613 "Test handling of uninterpreted elements."
614 ;; Entities.
615 (should
616 (equal "dummy\n"
617 (org-test-with-temp-text "\\alpha"
618 (org-export-as
619 (org-export-create-backend
620 :transcoders '((entity . (lambda (e c i) "dummy"))
621 (paragraph . (lambda (p c i) c))
622 (section . (lambda (s c i) c))))
623 nil nil nil '(:with-entities t)))))
624 (should
625 (equal "\\alpha\n"
626 (org-test-with-temp-text "\\alpha"
627 (org-export-as
628 (org-export-create-backend
629 :transcoders '((entity . (lambda (e c i) "dummy"))
630 (paragraph . (lambda (p c i) c))
631 (section . (lambda (s c i) c))))
632 nil nil nil '(:with-entities nil)))))
633 ;; Emphasis.
634 (should
635 (equal "dummy\n"
636 (org-test-with-temp-text "*bold*"
637 (org-export-as
638 (org-export-create-backend
639 :transcoders '((bold . (lambda (b c i) "dummy"))
640 (paragraph . (lambda (p c i) c))
641 (section . (lambda (s c i) c))))
642 nil nil nil '(:with-emphasize t)))))
643 (should
644 (equal "*bold*\n"
645 (org-test-with-temp-text "*bold*"
646 (org-export-as
647 (org-export-create-backend
648 :transcoders '((bold . (lambda (b c i) "dummy"))
649 (paragraph . (lambda (p c i) c))
650 (section . (lambda (s c i) c))))
651 nil nil nil '(:with-emphasize nil)))))
652 ;; LaTeX environment.
653 (should
654 (equal "dummy\n"
655 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
656 (org-export-as
657 (org-export-create-backend
658 :transcoders '((latex-environment . (lambda (l c i) "dummy"))
659 (section . (lambda (s c i) c))))
660 nil nil nil '(:with-latex t)))))
661 (should
662 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
663 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
664 (org-export-as
665 (org-export-create-backend
666 :transcoders '((latex-environment . (lambda (l c i) "dummy"))
667 (section . (lambda (s c i) c))))
668 nil nil nil '(:with-latex verbatim)))))
669 ;; LaTeX fragment.
670 (should
671 (equal "dummy\n"
672 (org-test-with-temp-text "$1$"
673 (org-export-as
674 (org-export-create-backend
675 :transcoders '((latex-fragment . (lambda (l c i) "dummy"))
676 (paragraph . (lambda (p c i) c))
677 (section . (lambda (s c i) c))))
678 nil nil nil '(:with-latex t)))))
679 (should
680 (equal "$1$\n"
681 (org-test-with-temp-text "$1$"
682 (org-export-as
683 (org-export-create-backend
684 :transcoders '((latex-fragment . (lambda (l c i) "dummy"))
685 (paragraph . (lambda (p c i) c))
686 (section . (lambda (s c i) c))))
687 nil nil nil '(:with-latex verbatim)))))
688 ;; Sub/superscript.
689 (should
690 (equal "adummy\n"
691 (org-test-with-temp-text "a_b"
692 (org-export-as
693 (org-export-create-backend
694 :transcoders '((subscript . (lambda (s c i) "dummy"))
695 (paragraph . (lambda (p c i) c))
696 (section . (lambda (s c i) c))))
697 nil nil nil '(:with-sub-superscript t)))))
698 (should
699 (equal "a_b\n"
700 (org-test-with-temp-text "a_b"
701 (org-export-as
702 (org-export-create-backend
703 :transcoders '((subscript . (lambda (s c i) "dummy"))
704 (paragraph . (lambda (p c i) c))
705 (section . (lambda (s c i) c))))
706 nil nil nil '(:with-sub-superscript nil)))))
707 (should
708 (equal "a_b\n"
709 (org-test-with-temp-text "a_b"
710 (org-export-as
711 (org-export-create-backend
712 :transcoders '((subscript . (lambda (s c i) "dummy"))
713 (paragraph . (lambda (p c i) c))
714 (section . (lambda (s c i) c))))
715 nil nil nil '(:with-sub-superscript {})))))
716 (should
717 (equal "adummy\n"
718 (org-test-with-temp-text "a_{b}"
719 (org-export-as
720 (org-export-create-backend
721 :transcoders '((subscript . (lambda (s c i) "dummy"))
722 (paragraph . (lambda (p c i) c))
723 (section . (lambda (s c i) c))))
724 nil nil nil '(:with-sub-superscript {})))))
725 ;; Also handle uninterpreted objects in title.
726 (should
727 (equal "a_b"
728 (org-test-with-temp-text "#+TITLE: a_b"
729 (org-export-as
730 (org-export-create-backend
731 :transcoders
732 '((subscript . (lambda (s c i) "dummy"))
733 (template . (lambda (c i) (org-export-data
734 (plist-get i :title) i)))
735 (section . (lambda (s c i) c))))
736 nil nil nil '(:with-sub-superscript nil)))))
737 ;; Special case: multiples uninterpreted objects in a row.
738 (should
739 (equal "a_b_c_d\n"
740 (org-test-with-temp-text "a_b_c_d"
741 (org-export-as
742 (org-export-create-backend
743 :transcoders '((subscript . (lambda (s c i) "dummy"))
744 (paragraph . (lambda (p c i) c))
745 (section . (lambda (s c i) c))))
746 nil nil nil '(:with-sub-superscript {}))))))
748 (ert-deftest test-org-export/export-scope ()
749 "Test all export scopes."
750 (org-test-with-temp-text "
751 * Head1
752 ** Head2
753 text
754 *** Head3"
755 ;; Subtree.
756 (forward-line 3)
757 (should (equal (org-export-as (org-test-default-backend) 'subtree)
758 "text\n*** Head3\n"))
759 ;; Visible.
760 (goto-char (point-min))
761 (forward-line)
762 (org-cycle)
763 (should (equal (org-export-as (org-test-default-backend) nil 'visible)
764 "* Head1\n"))
765 ;; Region.
766 (goto-char (point-min))
767 (forward-line 3)
768 (transient-mark-mode 1)
769 (push-mark (point) t t)
770 (goto-char (point-at-eol))
771 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
772 ;; Subtree with a code block calling another block outside.
773 (let ((org-export-babel-evaluate t))
774 (should
775 (equal ": 3\n"
776 (org-test-with-temp-text "
777 * Head1
778 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
779 <<test>>
780 #+END_SRC
781 * Head2
782 #+NAME: test
783 #+BEGIN_SRC emacs-lisp
784 \(+ 1 2)
785 #+END_SRC"
786 (forward-line 1)
787 (org-export-as (org-test-default-backend) 'subtree)))))
788 ;; Body only.
789 (let ((backend (org-test-default-backend)))
790 (setf (org-export-backend-transcoders backend)
791 (cons '(template . (lambda (body i)
792 (format "BEGIN\n%sEND" body)))
793 (org-export-backend-transcoders backend)))
794 (org-test-with-temp-text "Text"
795 (should (equal (org-export-as backend nil nil 'body-only)
796 "Text\n"))
797 (should (equal (org-export-as backend) "BEGIN\nText\nEND")))))
799 (ert-deftest test-org-export/output-file-name ()
800 "Test `org-export-output-file-name' specifications."
801 ;; Export from a file: name is built from original file name.
802 (should
803 (org-test-with-temp-text-in-file "Test"
804 (equal (concat (file-name-as-directory ".")
805 (file-name-nondirectory
806 (file-name-sans-extension (buffer-file-name))))
807 (file-name-sans-extension (org-export-output-file-name ".ext")))))
808 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
809 (should
810 (org-test-with-temp-text-in-file
811 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
812 (equal (org-export-output-file-name ".ext" t) "./test.ext")))
813 ;; From a buffer not associated to a file, too.
814 (should
815 (org-test-with-temp-text
816 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
817 (equal (org-export-output-file-name ".ext" t) "./test.ext")))
818 ;; When provided name is absolute, preserve it.
819 (should
820 (org-test-with-temp-text
821 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
822 (expand-file-name "test"))
823 (file-name-absolute-p (org-export-output-file-name ".ext" t))))
824 ;; When PUB-DIR argument is provided, use it.
825 (should
826 (org-test-with-temp-text-in-file "Test"
827 (equal (file-name-directory
828 (org-export-output-file-name ".ext" nil "dir/"))
829 "dir/")))
830 ;; When returned name would overwrite original file, add EXTENSION
831 ;; another time.
832 (should
833 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
834 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
836 (ert-deftest test-org-export/expand-include ()
837 "Test file inclusion in an Org buffer."
838 ;; Error when file isn't specified.
839 (should-error
840 (org-test-with-temp-text "#+INCLUDE: dummy.org"
841 (org-export-expand-include-keyword)))
842 ;; Full insertion with recursive inclusion.
843 (should
844 (equal
845 (with-temp-buffer
846 (insert-file
847 (expand-file-name "examples/include.org" org-test-dir))
848 (replace-regexp-in-string
849 (regexp-quote "#+INCLUDE: \"include2.org\"")
850 "Success!" (buffer-string)))
851 (org-test-with-temp-text
852 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
853 (org-export-expand-include-keyword)
854 (buffer-string))))
855 ;; Localized insertion.
856 (org-test-with-temp-text
857 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
858 org-test-dir)
859 (org-export-expand-include-keyword)
860 (should (equal (buffer-string)
861 "Small Org file with an include keyword.\n")))
862 ;; Insertion with constraints on headlines level.
863 (should
864 (equal
865 "* Top heading\n** Heading\nbody\n"
866 (org-test-with-temp-text
867 (format
868 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
869 org-test-dir)
870 (org-export-expand-include-keyword)
871 (buffer-string))))
872 (should
873 (equal
874 "* Top heading\n* Heading\nbody\n"
875 (org-test-with-temp-text
876 (format
877 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
878 org-test-dir)
879 (org-export-expand-include-keyword)
880 (buffer-string))))
881 ;; Inclusion within an example block.
882 (should
883 (equal
884 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
885 (org-test-with-temp-text
886 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
887 org-test-dir)
888 (org-export-expand-include-keyword)
889 (buffer-string))))
890 ;; Inclusion within a src-block.
891 (should
892 (equal
893 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
894 (org-test-with-temp-text
895 (format
896 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
897 org-test-dir)
898 (org-export-expand-include-keyword)
899 (buffer-string))))
900 ;; Inclusion within an html export-block.
901 (should
902 (equal
903 "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
904 (org-test-with-temp-text
905 (format
906 "#+INCLUDE: \"%s/examples/include.html\" HTML"
907 org-test-dir)
908 (org-export-expand-include-keyword)
909 (buffer-string))))
910 ;; Inclusion within an center paragraph
911 (should
912 (equal
913 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
914 (org-test-with-temp-text
915 (format
916 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
917 org-test-dir)
918 (org-export-expand-include-keyword)
919 (buffer-string))))
920 ;; Footnotes labels are local to each included file.
921 (should
922 (= 6
923 (length
924 (delete-dups
925 (let ((contents "
926 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
927 \[fn:1] Footnote 1
928 \[fn:test] Footnote \"test\""))
929 (org-test-with-temp-text-in-file contents
930 (let ((file1 (buffer-file-name)))
931 (org-test-with-temp-text-in-file contents
932 (let ((file2 (buffer-file-name)))
933 (org-test-with-temp-text
934 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
935 file1 file2)
936 (org-export-expand-include-keyword)
937 (org-element-map (org-element-parse-buffer)
938 'footnote-reference
939 (lambda (ref)
940 (org-element-property :label ref)))))))))))))
941 ;; Footnotes labels are not local to each include keyword.
942 (should
943 (= 4
944 (length
945 (delete-dups
946 (let ((contents "
947 Footnotes[fn:1], [fn:test], [2] and [fn:inline:anonymous footnote].
948 \[fn:1] Footnote 1
949 \[2] Footnote 2
950 \[fn:test] Footnote \"test\""))
951 (org-test-with-temp-text-in-file contents
952 (let ((file (buffer-file-name)))
953 (org-test-with-temp-text
954 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file)
955 (org-export-expand-include-keyword)
956 (org-element-map (org-element-parse-buffer)
957 'footnote-reference
958 (lambda (ref) (org-element-property :label ref)))))))))))
959 ;; Footnotes are supported by :lines-like elements and unnecessary
960 ;; footnotes are dropped.
961 (should
962 (= 4
963 (length
964 (delete-dups
965 (let ((contents "
966 * foo
967 Footnotes[fn:1]
968 * bar
969 Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote]
971 \[fn:1] Footnote 1
972 \[fn:2] Footnote 1
973 * Footnotes
974 \[fn:test] Footnote \"test\"
975 \[3] Footnote 3
977 (org-test-with-temp-text-in-file contents
978 (let ((file (buffer-file-name)))
979 (org-test-with-temp-text
980 (format "#+INCLUDE: \"%s::*bar\"
981 " file)
982 (org-export-expand-include-keyword)
983 (org-element-map (org-element-parse-buffer)
984 'footnote-definition
985 (lambda (ref) (org-element-property :label ref)))))))))))
986 ;; If only-contents is non-nil only include contents of element.
987 (should
988 (equal
989 "body\n"
990 (org-test-with-temp-text
991 (concat
992 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" " org-test-dir)
993 ":only-contents t")
994 (org-export-expand-include-keyword)
995 (buffer-string))))
996 ;; Headings can be included via CUSTOM_ID.
997 (should
998 (org-test-with-temp-text
999 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir)
1000 (org-export-expand-include-keyword)
1001 (goto-char (point-min))
1002 (looking-at "* Another heading")))
1003 ;; Named objects can be included.
1004 (should
1005 (equal
1006 "| 1 |\n"
1007 (org-test-with-temp-text
1008 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t" org-test-dir)
1009 (org-export-expand-include-keyword)
1010 (buffer-string))))
1011 ;; Including non-existing elements should result in an error.
1012 (should-error
1013 (org-test-with-temp-text
1014 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\"" org-test-dir)
1015 (org-export-expand-include-keyword)))
1016 ;; Lines work relatively to an included element.
1017 (should
1018 (equal
1019 "2\n3\n"
1020 (org-test-with-temp-text
1021 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t :lines \"2-3\"" org-test-dir)
1022 (org-export-expand-include-keyword)
1023 (buffer-string))))
1024 ;; Properties should be dropped from headlines.
1025 (should
1026 (equal
1027 (org-test-with-temp-text
1028 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t" org-test-dir)
1029 (org-export-expand-include-keyword)
1030 (buffer-string))
1031 (org-test-with-temp-text
1032 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir)
1033 (org-export-expand-include-keyword)
1034 (buffer-string))))
1035 ;; Properties should be dropped, drawers should not be.
1036 (should
1037 (equal
1038 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1039 (org-test-with-temp-text
1040 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir)
1041 (org-export-expand-include-keyword)
1042 (buffer-string))))
1043 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1044 (should
1045 (org-every (lambda (level) (zerop (1- level)))
1046 (org-test-with-temp-text
1047 (concat
1048 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n" org-test-dir)
1049 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\"" org-test-dir))
1050 (org-export-expand-include-keyword)
1051 (org-element-map (org-element-parse-buffer) 'headline
1052 (lambda (head) (org-element-property :level head))))))
1053 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1054 (should-not
1055 (equal
1056 (org-test-with-temp-text
1057 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp" org-test-dir)
1058 (org-export-expand-include-keyword)
1059 (buffer-string))
1060 (org-test-with-temp-text
1061 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1" org-test-dir)
1062 (org-export-expand-include-keyword)
1063 (buffer-string))))
1064 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1065 (should
1066 (org-test-with-temp-text-in-file
1067 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir)
1068 (narrow-to-region (point) (point-max))
1069 (org-export-expand-include-keyword)
1070 (eq 1 (org-current-level))))
1071 ;; If :minlevel is present do not alter it.
1072 (should
1073 (org-test-with-temp-text
1074 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3" org-test-dir)
1075 (narrow-to-region (point) (point-max))
1076 (org-export-expand-include-keyword)
1077 (eq 3 (org-current-level)))))
1079 (ert-deftest test-org-export/expand-macro ()
1080 "Test macro expansion in an Org buffer."
1081 ;; Standard macro expansion.
1082 (should
1083 (equal "#+MACRO: macro1 value\nvalue\n"
1084 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1085 (org-export-as (org-test-default-backend)))))
1086 ;; Expand specific macros.
1087 (should
1088 (equal "me 2012-03-29 me@here Title\n"
1089 (org-test-with-temp-text
1091 #+TITLE: Title
1092 #+DATE: 2012-03-29
1093 #+AUTHOR: me
1094 #+EMAIL: me@here
1095 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1096 (let ((output (org-export-as (org-test-default-backend))))
1097 (substring output (string-match ".*\n\\'" output))))))
1098 ;; Expand specific macros when property contained a regular macro
1099 ;; already.
1100 (should
1101 (equal "value\n"
1102 (org-test-with-temp-text "
1103 #+MACRO: macro1 value
1104 #+TITLE: {{{macro1}}}
1105 {{{title}}}"
1106 (let ((output (org-export-as (org-test-default-backend))))
1107 (substring output (string-match ".*\n\\'" output))))))
1108 ;; Expand macros with templates in included files.
1109 (should
1110 (equal "success\n"
1111 (org-test-with-temp-text
1112 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1113 {{{included-macro}}}" org-test-dir)
1114 (let ((output (org-export-as (org-test-default-backend))))
1115 (substring output (string-match ".*\n\\'" output))))))
1116 ;; Date macro takes a optional formatting argument
1117 (should
1118 (equal "09-02-15\n"
1119 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1120 (org-export-as (org-test-default-backend)))))
1121 ;; Only single timestamps are formatted
1122 (should
1123 (equal "<2015-02x-09>\n"
1124 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1125 (org-export-as (org-test-default-backend)))))
1126 ;; Throw an error when a macro definition is missing.
1127 (should-error
1128 (org-test-with-temp-text "{{{missing}}}"
1129 (org-export-as (org-test-default-backend))))
1130 ;; Macros defined in commented subtrees are ignored.
1131 (should-error
1132 (org-test-with-temp-text
1133 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1134 (org-export-as (org-test-default-backend))))
1135 (should-error
1136 (org-test-with-temp-text
1137 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1138 (org-export-as (org-test-default-backend)))))
1140 (ert-deftest test-org-export/before-processing-hook ()
1141 "Test `org-export-before-processing-hook'."
1142 (should
1143 (equal
1144 "#+MACRO: mac val\nTest\n"
1145 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1146 (let ((org-export-before-processing-hook
1147 '((lambda (backend)
1148 (while (re-search-forward "{{{" nil t)
1149 (let ((object (org-element-context)))
1150 (when (eq (org-element-type object) 'macro)
1151 (delete-region
1152 (org-element-property :begin object)
1153 (org-element-property :end object)))))))))
1154 (org-export-as (org-test-default-backend)))))))
1156 (ert-deftest test-org-export/before-parsing-hook ()
1157 "Test `org-export-before-parsing-hook'."
1158 (should
1159 (equal "Body 1\nBody 2\n"
1160 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1161 (let ((org-export-before-parsing-hook
1162 '((lambda (backend)
1163 (goto-char (point-min))
1164 (while (re-search-forward org-outline-regexp-bol nil t)
1165 (delete-region
1166 (point-at-bol) (progn (forward-line) (point))))))))
1167 (org-export-as (org-test-default-backend)))))))
1171 ;;; Affiliated Keywords
1173 (ert-deftest test-org-export/read-attribute ()
1174 "Test `org-export-read-attribute' specifications."
1175 ;; Standard test.
1176 (should
1177 (equal
1178 (org-export-read-attribute
1179 :attr_html
1180 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1181 (org-element-at-point)))
1182 '(:a "1" :b "2")))
1183 ;; Return nil on empty attribute.
1184 (should-not
1185 (org-export-read-attribute
1186 :attr_html
1187 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1188 ;; Return nil on "nil" string.
1189 (should
1190 (equal '(:a nil :b nil)
1191 (org-export-read-attribute
1192 :attr_html
1193 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1194 (org-element-at-point)))))
1195 ;; Return nil on empty string.
1196 (should
1197 (equal '(:a nil :b nil)
1198 (org-export-read-attribute
1199 :attr_html
1200 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1201 (org-element-at-point)))))
1202 ;; Return empty string when value is "".
1203 (should
1204 (equal '(:a "")
1205 (org-export-read-attribute
1206 :attr_html
1207 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1208 (org-element-at-point)))))
1209 ;; Return \"\" when value is """".
1210 (should
1211 (equal '(:a "\"\"")
1212 (org-export-read-attribute
1213 :attr_html
1214 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1215 (org-element-at-point)))))
1216 ;; Ignore text before first property.
1217 (should-not
1218 (member "ignore"
1219 (org-export-read-attribute
1220 :attr_html
1221 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1222 (org-element-at-point))))))
1224 (ert-deftest test-org-export/get-caption ()
1225 "Test `org-export-get-caption' specifications."
1226 ;; Without optional argument, return long caption
1227 (should
1228 (equal
1229 '("l")
1230 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1231 (org-export-get-caption (org-element-at-point)))))
1232 ;; With optional argument, return short caption.
1233 (should
1234 (equal
1235 '("s")
1236 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1237 (org-export-get-caption (org-element-at-point) t))))
1238 ;; Multiple lines are separated by white spaces.
1239 (should
1240 (equal
1241 '("a" " " "b")
1242 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1243 (org-export-get-caption (org-element-at-point))))))
1247 ;;; Back-End Tools
1249 (ert-deftest test-org-export/define-backend ()
1250 "Test back-end definition and accessors."
1251 ;; Translate table.
1252 (should
1253 (equal '((headline . my-headline-test))
1254 (let (org-export--registered-backends)
1255 (org-export-define-backend 'test '((headline . my-headline-test)))
1256 (org-export-get-all-transcoders 'test))))
1257 ;; Filters.
1258 (should
1259 (equal '((:filter-headline . my-filter))
1260 (let (org-export--registered-backends)
1261 (org-export-define-backend 'test
1262 '((headline . my-headline-test))
1263 :filters-alist '((:filter-headline . my-filter)))
1264 (org-export-backend-filters (org-export-get-backend 'test)))))
1265 ;; Options.
1266 (should
1267 (equal '((:prop value))
1268 (let (org-export--registered-backends)
1269 (org-export-define-backend 'test
1270 '((headline . my-headline-test))
1271 :options-alist '((:prop value)))
1272 (org-export-backend-options (org-export-get-backend 'test)))))
1273 ;; Menu.
1274 (should
1275 (equal '(?k "Test Export" test)
1276 (let (org-export--registered-backends)
1277 (org-export-define-backend 'test
1278 '((headline . my-headline-test))
1279 :menu-entry '(?k "Test Export" test))
1280 (org-export-backend-menu (org-export-get-backend 'test)))))
1281 ;; Export Blocks.
1282 (should
1283 (equal '(("TEST" . org-element-export-block-parser))
1284 (let (org-export--registered-backends org-element-block-name-alist)
1285 (org-export-define-backend 'test
1286 '((headline . my-headline-test))
1287 :export-block '("test"))
1288 org-element-block-name-alist))))
1290 (ert-deftest test-org-export/define-derived-backend ()
1291 "Test `org-export-define-derived-backend' specifications."
1292 ;; Error when parent back-end is not defined.
1293 (should-error
1294 (let (org-export--registered-backends)
1295 (org-export-define-derived-backend 'test 'parent)))
1296 ;; Append translation table to parent's.
1297 (should
1298 (equal '((:headline . test) (:headline . parent))
1299 (let (org-export--registered-backends)
1300 (org-export-define-backend 'parent '((:headline . parent)))
1301 (org-export-define-derived-backend 'test 'parent
1302 :translate-alist '((:headline . test)))
1303 (org-export-get-all-transcoders 'test))))
1304 ;; Options defined in the new back have priority over those defined
1305 ;; in parent.
1306 (should
1307 (eq 'test
1308 (let (org-export--registered-backends)
1309 (org-export-define-backend 'parent
1310 '((:headline . parent))
1311 :options-alist '((:a nil nil 'parent)))
1312 (org-export-define-derived-backend 'test 'parent
1313 :options-alist '((:a nil nil 'test)))
1314 (plist-get (org-export--get-global-options
1315 (org-export-get-backend 'test))
1316 :a)))))
1318 (ert-deftest test-org-export/derived-backend-p ()
1319 "Test `org-export-derived-backend-p' specifications."
1320 ;; Non-nil with direct match.
1321 (should
1322 (let (org-export--registered-backends)
1323 (org-export-define-backend 'test '((headline . test)))
1324 (org-export-derived-backend-p 'test 'test)))
1325 (should
1326 (let (org-export--registered-backends)
1327 (org-export-define-backend 'test '((headline . test)))
1328 (org-export-define-derived-backend 'test2 'test)
1329 (org-export-derived-backend-p 'test2 'test2)))
1330 ;; Non-nil with a direct parent.
1331 (should
1332 (let (org-export--registered-backends)
1333 (org-export-define-backend 'test '((headline . test)))
1334 (org-export-define-derived-backend 'test2 'test)
1335 (org-export-derived-backend-p 'test2 'test)))
1336 ;; Non-nil with an indirect parent.
1337 (should
1338 (let (org-export--registered-backends)
1339 (org-export-define-backend 'test '((headline . test)))
1340 (org-export-define-derived-backend 'test2 'test)
1341 (org-export-define-derived-backend 'test3 'test2)
1342 (org-export-derived-backend-p 'test3 'test)))
1343 ;; Nil otherwise.
1344 (should-not
1345 (let (org-export--registered-backends)
1346 (org-export-define-backend 'test '((headline . test)))
1347 (org-export-define-backend 'test2 '((headline . test2)))
1348 (org-export-derived-backend-p 'test2 'test)))
1349 (should-not
1350 (let (org-export--registered-backends)
1351 (org-export-define-backend 'test '((headline . test)))
1352 (org-export-define-backend 'test2 '((headline . test2)))
1353 (org-export-define-derived-backend 'test3 'test2)
1354 (org-export-derived-backend-p 'test3 'test))))
1356 (ert-deftest test-org-export/get-all-transcoders ()
1357 "Test `org-export-get-all-transcoders' specifications."
1358 ;; Return nil when back-end cannot be found.
1359 (should-not (org-export-get-all-transcoders nil))
1360 ;; Same as `org-export-transcoders' if no parent.
1361 (should
1362 (equal '((headline . ignore))
1363 (org-export-get-all-transcoders
1364 (org-export-create-backend
1365 :transcoders '((headline . ignore))))))
1366 ;; But inherit from all ancestors whenever possible.
1367 (should
1368 (equal '((section . ignore) (headline . ignore))
1369 (let (org-export--registered-backends)
1370 (org-export-define-backend 'b1 '((headline . ignore)))
1371 (org-export-get-all-transcoders
1372 (org-export-create-backend
1373 :parent 'b1 :transcoders '((section . ignore)))))))
1374 (should
1375 (equal '((paragraph . ignore) (section . ignore) (headline . ignore))
1376 (let (org-export--registered-backends)
1377 (org-export-define-backend 'b1 '((headline . ignore)))
1378 (org-export-define-derived-backend 'b2 'b1
1379 :translate-alist '((section . ignore)))
1380 (org-export-get-all-transcoders
1381 (org-export-create-backend
1382 :parent 'b2 :transcoders '((paragraph . ignore)))))))
1383 ;; Back-end transcoders overrule inherited ones.
1384 (should
1385 (eq 'b
1386 (let (org-export--registered-backends)
1387 (org-export-define-backend 'b1 '((headline . a)))
1388 (cdr (assq 'headline
1389 (org-export-get-all-transcoders
1390 (org-export-create-backend
1391 :parent 'b1 :transcoders '((headline . b))))))))))
1393 (ert-deftest test-org-export/get-all-options ()
1394 "Test `org-export-get-all-options' specifications."
1395 ;; Return nil when back-end cannot be found.
1396 (should-not (org-export-get-all-options nil))
1397 ;; Same as `org-export-options' if no parent.
1398 (should
1399 (equal '((headline . ignore))
1400 (org-export-get-all-options
1401 (org-export-create-backend
1402 :options '((headline . ignore))))))
1403 ;; But inherit from all ancestors whenever possible.
1404 (should
1405 (equal '((:key2 value2) (:key1 value1))
1406 (let (org-export--registered-backends)
1407 (org-export-define-backend 'b1 nil :options-alist '((:key1 value1)))
1408 (org-export-get-all-options
1409 (org-export-create-backend
1410 :parent 'b1 :options '((:key2 value2)))))))
1411 (should
1412 (equal '((:key3 value3) (:key2 value2) (:key1 value1))
1413 (let (org-export--registered-backends)
1414 (org-export-define-backend 'b1 nil :options-alist '((:key1 value1)))
1415 (org-export-define-derived-backend 'b2 'b1
1416 :options-alist '((:key2 value2)))
1417 (org-export-get-all-options
1418 (org-export-create-backend
1419 :parent 'b2 :options '((:key3 value3)))))))
1420 ;; Back-end options overrule inherited ones.
1421 (should
1422 (eq 'b
1423 (let (org-export--registered-backends)
1424 (org-export-define-backend 'b1 nil :options-alist '((:key1 . a)))
1425 (cdr (assq :key1
1426 (org-export-get-all-options
1427 (org-export-create-backend
1428 :parent 'b1 :options '((:key1 . b))))))))))
1430 (ert-deftest test-org-export/get-all-filters ()
1431 "Test `org-export-get-all-filters' specifications."
1432 ;; Return nil when back-end cannot be found.
1433 (should-not (org-export-get-all-filters nil))
1434 ;; Same as `org-export-filters' if no parent.
1435 (should
1436 (equal '((:filter-headline . ignore))
1437 (org-export-get-all-filters
1438 (org-export-create-backend
1439 :filters '((:filter-headline . ignore))))))
1440 ;; But inherit from all ancestors whenever possible.
1441 (should
1442 (equal '((:filter-section . ignore) (:filter-headline . ignore))
1443 (let (org-export--registered-backends)
1444 (org-export-define-backend 'b1
1445 nil :filters-alist '((:filter-headline . ignore)))
1446 (org-export-get-all-filters
1447 (org-export-create-backend
1448 :parent 'b1 :filters '((:filter-section . ignore)))))))
1449 (should
1450 (equal '((:filter-paragraph . ignore)
1451 (:filter-section . ignore)
1452 (:filter-headline . ignore))
1453 (let (org-export--registered-backends)
1454 (org-export-define-backend 'b1
1455 nil :filters-alist '((:filter-headline . ignore)))
1456 (org-export-define-derived-backend 'b2 'b1
1457 :filters-alist '((:filter-section . ignore)))
1458 (org-export-get-all-filters
1459 (org-export-create-backend
1460 :parent 'b2 :filters '((:filter-paragraph . ignore)))))))
1461 ;; Back-end filters overrule inherited ones.
1462 (should
1463 (eq 'b
1464 (let (org-export--registered-backends)
1465 (org-export-define-backend 'b1 '((:filter-headline . a)))
1466 (cdr (assq :filter-headline
1467 (org-export-get-all-filters
1468 (org-export-create-backend
1469 :parent 'b1 :filters '((:filter-headline . b))))))))))
1471 (ert-deftest test-org-export/with-backend ()
1472 "Test `org-export-with-backend' definition."
1473 ;; Error when calling an undefined back-end
1474 (should-error (org-export-with-backend nil "Test"))
1475 ;; Error when called back-end doesn't have an appropriate
1476 ;; transcoder.
1477 (should-error
1478 (org-export-with-backend
1479 (org-export-create-backend :transcoders '((headline . ignore)))
1480 "Test"))
1481 ;; Otherwise, export using correct transcoder
1482 (should
1483 (equal "Success"
1484 (let (org-export--registered-backends)
1485 (org-export-define-backend 'test
1486 '((plain-text . (lambda (text contents info) "Failure"))))
1487 (org-export-define-backend 'test2
1488 '((plain-text . (lambda (text contents info) "Success"))))
1489 (org-export-with-backend 'test2 "Test"))))
1490 ;; Provide correct back-end if transcoder needs to use recursive
1491 ;; calls anyway.
1492 (should
1493 (equal "Success\n"
1494 (let ((test-back-end
1495 (org-export-create-backend
1496 :transcoders
1497 '((headline . (lambda (headline contents info)
1498 (org-export-data
1499 (org-element-property :title headline)
1500 info)))
1501 (plain-text . (lambda (text info) "Success"))))))
1502 (org-export-string-as
1503 "* Test"
1504 (org-export-create-backend
1505 :transcoders
1506 '((headline . (lambda (headline contents info)
1507 (org-export-with-backend
1508 test-back-end headline contents info))))))))))
1510 (ert-deftest test-org-export/data-with-backend ()
1511 "Test `org-export-data-with-backend' specifications."
1512 ;; Error when calling an undefined back-end.
1513 (should-error (org-export-data-with-backend nil "nil" nil))
1514 ;; Otherwise, export data recursively, using correct back-end.
1515 (should
1516 (equal
1517 "Success!"
1518 (org-export-data-with-backend
1519 '(bold nil "Test")
1520 (org-export-create-backend
1521 :transcoders
1522 '((plain-text . (lambda (text info) "Success"))
1523 (bold . (lambda (bold contents info) (concat contents "!")))))
1524 '(:with-emphasize t)))))
1528 ;;; Export Snippets
1530 (ert-deftest test-org-export/export-snippet ()
1531 "Test export snippets transcoding."
1532 ;; Standard test.
1533 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1534 (let ((backend (org-test-default-backend)))
1535 (setf (org-export-backend-name backend) 'test)
1536 (setf (org-export-backend-transcoders backend)
1537 (cons (cons 'export-snippet
1538 (lambda (snippet contents info)
1539 (when (eq (org-export-snippet-backend snippet) 'test)
1540 (org-element-property :value snippet))))
1541 (org-export-backend-transcoders backend)))
1542 (let ((org-export-snippet-translation-alist nil))
1543 (should (equal (org-export-as backend) "A\n")))
1544 (let ((org-export-snippet-translation-alist '(("t" . "test"))))
1545 (should (equal (org-export-as backend) "AB\n")))))
1546 ;; Ignored export snippets do not remove any blank.
1547 (should
1548 (equal "begin end\n"
1549 (org-test-with-parsed-data "begin @@test:A@@ end"
1550 (org-export-data-with-backend
1551 tree
1552 (org-export-create-backend
1553 :transcoders
1554 '((paragraph . (lambda (paragraph contents info) contents))
1555 (section . (lambda (section contents info) contents))))
1556 info)))))
1560 ;;; Footnotes
1562 (ert-deftest test-org-export/footnote-first-reference-p ()
1563 "Test `org-export-footnote-first-reference-p' specifications."
1564 (should
1565 (equal
1566 '(t nil)
1567 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1568 (let (result)
1569 (org-export-as
1570 (org-export-create-backend
1571 :transcoders
1572 `(,(cons 'footnote-reference
1573 (lambda (f c i)
1574 (push (org-export-footnote-first-reference-p f info)
1575 result)
1576 ""))
1577 (section . (lambda (s c i) c))
1578 (paragraph . (lambda (p c i) c))))
1579 nil nil nil '(:with-footnotes t))
1580 (nreverse result)))))
1581 ;; Limit check to DATA, when non-nil.
1582 (should
1583 (equal
1584 '(nil t)
1585 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1586 (let (result)
1587 (org-element-map tree 'footnote-reference
1588 (lambda (ref)
1589 (push
1590 (org-export-footnote-first-reference-p
1591 ref info (org-element-map tree 'headline #'identity info t))
1592 result))
1593 info)
1594 (nreverse result)))))
1595 (should
1596 (equal
1597 '(t nil)
1598 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1599 (let (result)
1600 (org-element-map tree 'footnote-reference
1601 (lambda (ref)
1602 (push (org-export-footnote-first-reference-p ref info) result))
1603 info)
1604 (nreverse result)))))
1605 ;; If optional argument BODY-FIRST is non-nil, first find footnote
1606 ;; in the main body of the document. Otherwise, enter footnote
1607 ;; definitions when they are encountered.
1608 (should
1609 (equal
1610 '(t nil)
1611 (org-test-with-temp-text
1612 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1613 (let (result)
1614 (org-export-as
1615 (org-export-create-backend
1616 :transcoders
1617 `(,(cons 'footnote-reference
1618 (lambda (f c i)
1619 (when (org-element-lineage f '(drawer))
1620 (push (org-export-footnote-first-reference-p f info nil)
1621 result))
1622 ""))
1623 (drawer . (lambda (d c i) c))
1624 (footnote-definition . (lambda (d c i) c))
1625 (section . (lambda (s c i) c))
1626 (paragraph . (lambda (p c i) c))))
1627 nil nil nil '(:with-footnotes t))
1628 (nreverse result)))))
1629 (should
1630 (equal
1631 '(t t)
1632 (org-test-with-temp-text
1633 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1634 (let (result)
1635 (org-export-as
1636 (org-export-create-backend
1637 :transcoders
1638 `(,(cons 'footnote-reference
1639 (lambda (f c i)
1640 (when (org-element-lineage f '(drawer))
1641 (push (org-export-footnote-first-reference-p f info nil t)
1642 result))
1643 ""))
1644 (drawer . (lambda (d c i) c))
1645 (footnote-definition . (lambda (d c i) c))
1646 (section . (lambda (s c i) c))
1647 (paragraph . (lambda (p c i) c))))
1648 nil nil nil '(:with-footnotes t))
1649 (nreverse result))))))
1651 (ert-deftest test-org-export/get-footnote-number ()
1652 "Test `org-export-get-footnote-number' specifications."
1653 (should
1654 (equal '(1 2 1)
1655 (org-test-with-parsed-data
1656 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
1657 (org-element-map tree 'footnote-reference
1658 (lambda (ref) (org-export-get-footnote-number ref info))
1659 info))))
1660 ;; Anonymous footnotes all get a new number.
1661 (should
1662 (equal '(1 2)
1663 (org-test-with-parsed-data
1664 "Text[fn::anon1][fn::anon2]"
1665 (org-element-map tree 'footnote-reference
1666 (lambda (ref) (org-export-get-footnote-number ref info))
1667 info))))
1668 ;; Test nested footnotes order.
1669 (should
1670 (equal
1671 '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (3 . "fn:3") (4))
1672 (org-test-with-parsed-data
1673 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1674 (org-element-map tree 'footnote-reference
1675 (lambda (ref)
1676 (cons (org-export-get-footnote-number ref info)
1677 (org-element-property :label ref)))
1678 info))))
1679 ;; Limit number to provided DATA, when non-nil.
1680 (should
1681 (equal
1682 '(1)
1683 (org-test-with-parsed-data
1684 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1685 (org-element-map tree 'footnote-reference
1686 (lambda (ref)
1687 (org-export-get-footnote-number
1688 ref info (org-element-map tree 'headline #'identity info t)))
1689 info))))
1690 (should
1691 (equal
1692 '(1 2)
1693 (org-test-with-parsed-data
1694 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
1695 (org-element-map tree 'footnote-reference
1696 (lambda (ref) (org-export-get-footnote-number ref info))
1697 info))))
1698 ;; With a non-nil BODY-FIRST optional argument, first check body,
1699 ;; then footnote definitions.
1700 (should
1701 (equal
1702 '(("fn:1" . 1) ("fn:2" . 2) ("fn:3" . 3) ("fn:3" . 3))
1703 (org-test-with-parsed-data
1704 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1705 (org-element-map tree 'footnote-reference
1706 (lambda (ref)
1707 (cons (org-element-property :label ref)
1708 (org-export-get-footnote-number ref info nil t)))
1709 info))))
1710 (should
1711 (equal
1712 '(("fn:1" . 1) ("fn:2" . 3) ("fn:3" . 2) ("fn:3" . 2))
1713 (org-test-with-parsed-data
1714 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1715 (org-element-map tree 'footnote-reference
1716 (lambda (ref)
1717 (cons (org-element-property :label ref)
1718 (org-export-get-footnote-number ref info nil)))
1719 info)))))
1721 (ert-deftest test-org-export/collect-footnote-definitions ()
1722 "Test `org-export-collect-footnote-definitions' specifications."
1723 (should
1724 (= 4
1725 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1727 \[fn:2] B [fn:3] [fn::D].
1729 \[fn:3] C."
1730 (length (org-export-collect-footnote-definitions info)))))
1731 ;; Limit number to provided DATA, when non-nil.
1732 (should
1733 (equal
1734 '((1 "fn:2"))
1735 (org-test-with-parsed-data
1736 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1737 (mapcar #'butlast
1738 (org-export-collect-footnote-definitions
1739 info (org-element-map tree 'headline #'identity info t))))))
1740 (should
1741 (equal
1742 '((1 "fn:1") (2 "fn:2"))
1743 (org-test-with-parsed-data
1744 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1745 (mapcar #'butlast (org-export-collect-footnote-definitions info)))))
1746 ;; With optional argument BODY-FIRST, first check body, then
1747 ;; footnote definitions.
1748 (should
1749 (equal '("fn:1" "fn:3" "fn:2" nil)
1750 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1752 \[fn:2] B [fn:3] [fn::D].
1754 \[fn:3] C."
1755 (mapcar (lambda (e) (nth 1 e))
1756 (org-export-collect-footnote-definitions info nil t)))))
1757 (should-not
1758 (equal '("fn:1" "fn:3" "fn:2" nil)
1759 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1761 \[fn:2] B [fn:3] [fn::D].
1763 \[fn:3] C."
1764 (mapcar (lambda (e) (nth 1 e))
1765 (org-export-collect-footnote-definitions info))))))
1767 (ert-deftest test-org-export/footnotes ()
1768 "Miscellaneous tests on footnotes."
1769 (let ((org-footnote-section nil)
1770 (org-export-with-footnotes t))
1771 ;; Read every type of footnote.
1772 (should
1773 (equal
1774 '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
1775 (org-test-with-parsed-data
1776 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1777 (org-element-map tree 'footnote-reference
1778 (lambda (ref)
1779 (let ((def (org-export-get-footnote-definition ref info)))
1780 (cons (org-export-get-footnote-number ref info)
1781 (if (eq (org-element-property :type ref) 'inline) (car def)
1782 (car (org-element-contents
1783 (car (org-element-contents def))))))))
1784 info))))
1785 ;; Test nested footnote in invisible definitions.
1786 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1787 ;; Hide definitions.
1788 (narrow-to-region (point) (point-at-eol))
1789 (let* ((tree (org-element-parse-buffer))
1790 (info (org-combine-plists
1791 `(:parse-tree ,tree)
1792 (org-export-collect-tree-properties
1793 tree (org-export-get-environment)))))
1794 ;; Both footnotes should be seen.
1795 (should
1796 (= (length (org-export-collect-footnote-definitions info)) 2))))
1797 ;; Test export of footnotes defined outside parsing scope.
1798 (should
1799 (equal
1800 "ParagraphOut of scope\n"
1801 (org-test-with-temp-text "[fn:1] Out of scope
1802 * Title
1803 Paragraph[fn:1]"
1804 (let ((backend (org-test-default-backend)))
1805 (setf (org-export-backend-transcoders backend)
1806 (cons (cons 'footnote-reference
1807 (lambda (fn contents info)
1808 (org-element-interpret-data
1809 (org-export-get-footnote-definition fn info))))
1810 (org-export-backend-transcoders backend)))
1811 (forward-line)
1812 (org-export-as backend 'subtree)))))
1813 ;; Footnotes without a definition should throw an error.
1814 (should-error
1815 (org-test-with-parsed-data "Text[fn:1]"
1816 (org-export-get-footnote-definition
1817 (org-element-map tree 'footnote-reference 'identity info t) info)))
1818 ;; Footnote section should be ignored in TOC and in headlines
1819 ;; numbering.
1820 (should
1821 (= 1 (let ((org-footnote-section "Footnotes"))
1822 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1823 (org-export-collect-headlines info))))))
1824 (should
1825 (equal '(2)
1826 (let ((org-footnote-section "Footnotes"))
1827 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1828 (org-element-map tree 'headline
1829 (lambda (hl)
1830 (when (equal (org-element-property :raw-value hl) "H2")
1831 (org-export-get-headline-number hl info)))
1832 info t)))))))
1836 ;;; Headlines and Inlinetasks
1838 (ert-deftest test-org-export/get-relative-level ()
1839 "Test `org-export-get-relative-level' specifications."
1840 ;; Standard test.
1841 (should
1842 (equal '(1 2)
1843 (let ((org-odd-levels-only nil))
1844 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1845 (org-element-map tree 'headline
1846 (lambda (h) (org-export-get-relative-level h info))
1847 info)))))
1848 ;; Missing levels
1849 (should
1850 (equal '(1 3)
1851 (let ((org-odd-levels-only nil))
1852 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1853 (org-element-map tree 'headline
1854 (lambda (h) (org-export-get-relative-level h info))
1855 info))))))
1857 (ert-deftest test-org-export/low-level-p ()
1858 "Test `org-export-low-level-p' specifications."
1859 (should
1860 (equal
1861 '(no yes)
1862 (let ((org-odd-levels-only nil))
1863 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1864 (org-element-map tree 'headline
1865 (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
1866 (plist-put info :headline-levels 1)))))))
1868 (ert-deftest test-org-export/get-headline-number ()
1869 "Test `org-export-get-headline-number' specifications."
1870 ;; Standard test.
1871 (should
1872 (equal
1873 '((1) (1 1))
1874 (let ((org-odd-levels-only nil))
1875 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1876 (org-element-map tree 'headline
1877 (lambda (h) (org-export-get-headline-number h info))
1878 info)))))
1879 ;; Missing levels are replaced with 0.
1880 (should
1881 (equal
1882 '((1) (1 0 1))
1883 (let ((org-odd-levels-only nil))
1884 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1885 (org-element-map tree 'headline
1886 (lambda (h) (org-export-get-headline-number h info))
1887 info))))))
1889 (ert-deftest test-org-export/numbered-headline-p ()
1890 "Test `org-export-numbered-headline-p' specifications."
1891 ;; If `:section-numbers' is nil, never number headlines.
1892 (should-not
1893 (org-test-with-parsed-data "* Headline"
1894 (org-element-map tree 'headline
1895 (lambda (h) (org-export-numbered-headline-p h info))
1896 (plist-put info :section-numbers nil))))
1897 ;; If `:section-numbers' is a number, only number headlines with
1898 ;; a level greater that it.
1899 (should
1900 (equal
1901 '(yes no)
1902 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1903 (org-element-map tree 'headline
1904 (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
1905 (plist-put info :section-numbers 1)))))
1906 ;; Otherwise, headlines are always numbered.
1907 (should
1908 (org-test-with-parsed-data "* Headline"
1909 (org-element-map tree 'headline
1910 (lambda (h) (org-export-numbered-headline-p h info))
1911 (plist-put info :section-numbers t)))))
1913 (ert-deftest test-org-export/org-export-get-headline-id ()
1914 "Test `org-export-get-headline-id' specifications."
1915 ;; Numbered headlines have IDs akin to "sec-N".
1916 (should
1917 (equal "sec-1"
1918 (org-test-with-parsed-data "* H"
1919 (org-export-get-headline-id
1920 (org-element-map tree 'headline #'identity info t)
1921 info))))
1922 ;; The ID of numbered headlines reflect the hierarchy.
1923 (should
1924 (equal "sec-1-1"
1925 (org-test-with-parsed-data "* H1\n** H2"
1926 (org-export-get-headline-id
1927 (org-element-map tree 'headline
1928 (lambda (h)
1929 (and (equal "H2" (org-element-property :raw-value h)) h))
1930 info t)
1931 info))))
1932 ;; Unnumbered headlines have IDs akin to "unnumbered-N".
1933 (should
1934 (equal "unnumbered-1"
1935 (org-test-with-parsed-data
1936 "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
1937 (org-export-get-headline-id
1938 (org-element-map tree 'headline #'identity info t)
1939 info))))
1940 ;; The ID of Unnumbered headlines do not reflect the hierarchy.
1941 (should
1942 (equal "unnumbered-2"
1943 (org-test-with-parsed-data
1944 "* H1\n:PROPERTIES:\n:UNNUMBERED: t\n:END:\n** H2"
1945 (org-export-get-headline-id
1946 (org-element-map tree 'headline
1947 (lambda (h)
1948 (and (equal "H2" (org-element-property :raw-value h)) h))
1949 info t)
1950 info))))
1951 ;; When #+OPTIONS: num:nil all headlines are unnumbered.
1952 (should
1953 (equal "unnumbered-1"
1954 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
1955 (org-export-get-headline-id
1956 (org-element-map tree 'headline 'identity info t)
1957 info))))
1958 ;; UNNUMBERED ignores inheritance. Any non-nil value among
1959 ;; ancestors disables numbering.
1960 (should
1961 (org-test-with-parsed-data
1962 "* H
1963 :PROPERTIES:
1964 :UNNUMBERED: t
1965 :END:
1966 ** H2
1967 :PROPERTIES:
1968 :UNNUMBERED: nil
1969 :END:
1970 *** H3"
1971 (org-every
1972 (lambda (h) (not (org-export-numbered-headline-p h info)))
1973 (org-element-map tree 'headline #'identity info)))))
1975 (ert-deftest test-org-export/number-to-roman ()
1976 "Test `org-export-number-to-roman' specifications."
1977 ;; If number is negative, return it as a string.
1978 (should (equal (org-export-number-to-roman -1) "-1"))
1979 ;; Otherwise, return it as a roman number.
1980 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1982 (ert-deftest test-org-export/get-optional-title ()
1983 "Test `org-export-get-alt-title' specifications."
1984 ;; If ALT_TITLE property is defined, use it.
1985 (should
1986 (equal '("opt")
1987 (org-test-with-parsed-data
1988 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1989 (org-export-get-alt-title
1990 (org-element-map tree 'headline 'identity info t)
1991 info))))
1992 ;; Otherwise, fall-back to regular title.
1993 (should
1994 (equal '("Headline")
1995 (org-test-with-parsed-data "* Headline"
1996 (org-export-get-alt-title
1997 (org-element-map tree 'headline 'identity info t)
1998 info)))))
2000 (ert-deftest test-org-export/get-tags ()
2001 "Test `org-export-get-tags' specifications."
2002 (let ((org-export-exclude-tags '("noexport"))
2003 (org-export-select-tags '("export")))
2004 ;; Standard test: tags which are not a select tag, an exclude tag,
2005 ;; or specified as optional argument shouldn't be ignored.
2006 (should
2007 (org-test-with-parsed-data "* Headline :tag:"
2008 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
2009 info)))
2010 ;; Exclude tags are removed.
2011 (should-not
2012 (org-test-with-parsed-data "* Headline :noexport:"
2013 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
2014 info)))
2015 ;; Select tags are removed.
2016 (should-not
2017 (org-test-with-parsed-data "* Headline :export:"
2018 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
2019 info)))
2020 (should
2021 (equal
2022 '("tag")
2023 (org-test-with-parsed-data "* Headline :tag:export:"
2024 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
2025 info))))
2026 ;; Tags provided in the optional argument are also ignored.
2027 (should-not
2028 (org-test-with-parsed-data "* Headline :ignore:"
2029 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
2030 info '("ignore"))))
2031 ;; Allow tag inheritance.
2032 (should
2033 (equal
2034 '(("tag") ("tag"))
2035 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2036 (org-element-map tree 'headline
2037 (lambda (hl) (org-export-get-tags hl info nil t)) info))))
2038 ;; Tag inheritance checks FILETAGS keywords.
2039 (should
2040 (equal
2041 '(("a" "b" "tag"))
2042 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2043 (org-element-map tree 'headline
2044 (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
2046 (ert-deftest test-org-export/get-node-property ()
2047 "Test`org-export-get-node-property' specifications."
2048 ;; Standard test.
2049 (should
2050 (equal "value"
2051 (org-test-with-parsed-data "* Headline
2052 :PROPERTIES:
2053 :prop: value
2054 :END:"
2055 (org-export-get-node-property
2056 :PROP (org-element-map tree 'headline 'identity nil t)))))
2057 ;; Test inheritance.
2058 (should
2059 (equal "value"
2060 (org-test-with-parsed-data "* Parent
2061 :PROPERTIES:
2062 :prop: value
2063 :END:
2064 ** Headline
2065 Paragraph"
2066 (org-export-get-node-property
2067 :PROP (org-element-map tree 'paragraph 'identity nil t) t))))
2068 ;; Cannot return a value before the first headline.
2069 (should-not
2070 (org-test-with-parsed-data "Paragraph
2071 * Headline
2072 :PROPERTIES:
2073 :prop: value
2074 :END:"
2075 (org-export-get-node-property
2076 :PROP (org-element-map tree 'paragraph 'identity nil t)))))
2078 (ert-deftest test-org-export/get-category ()
2079 "Test `org-export-get-category' specifications."
2080 ;; Standard test.
2081 (should
2082 (equal "value"
2083 (org-test-with-parsed-data "* Headline
2084 :PROPERTIES:
2085 :CATEGORY: value
2086 :END:"
2087 (org-export-get-category
2088 (org-element-map tree 'headline 'identity nil t) info))))
2089 ;; Test inheritance from a parent headline.
2090 (should
2091 (equal '("value" "value")
2092 (org-test-with-parsed-data "* Headline1
2093 :PROPERTIES:
2094 :CATEGORY: value
2095 :END:
2096 ** Headline2"
2097 (org-element-map tree 'headline
2098 (lambda (hl) (org-export-get-category hl info)) info))))
2099 ;; Test inheritance from #+CATEGORY keyword
2100 (should
2101 (equal "value"
2102 (org-test-with-parsed-data "#+CATEGORY: value
2103 * Headline"
2104 (org-export-get-category
2105 (org-element-map tree 'headline 'identity nil t) info))))
2106 ;; Test inheritance from file name.
2107 (should
2108 (equal "test"
2109 (org-test-with-parsed-data "* Headline"
2110 (let ((info (plist-put info :input-file "~/test.org")))
2111 (org-export-get-category
2112 (org-element-map tree 'headline 'identity nil t) info)))))
2113 ;; Fall-back value.
2114 (should
2115 (equal "???"
2116 (org-test-with-parsed-data "* Headline"
2117 (org-export-get-category
2118 (org-element-map tree 'headline 'identity nil t) info)))))
2120 (ert-deftest test-org-export/first-sibling-p ()
2121 "Test `org-export-first-sibling-p' specifications."
2122 ;; Standard test.
2123 (should
2124 (equal
2125 '(yes yes no)
2126 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2127 (org-element-map tree 'headline
2128 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
2129 info))))
2130 (should
2131 (equal '(yes no)
2132 (org-test-with-parsed-data "- item\n\n para"
2133 (org-element-map tree 'paragraph
2134 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
2135 info))))
2136 ;; Ignore sections for headlines.
2137 (should
2138 (equal '(yes yes)
2139 (org-test-with-parsed-data "* H\nSection\n** H 2"
2140 (org-element-map tree 'headline
2141 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
2142 info))))
2143 ;; Ignore headlines not exported.
2144 (should
2145 (equal
2146 '(yes)
2147 (let ((org-export-exclude-tags '("ignore")))
2148 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2149 (org-element-map tree 'headline
2150 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
2151 info))))))
2153 (ert-deftest test-org-export/last-sibling-p ()
2154 "Test `org-export-last-sibling-p' specifications."
2155 ;; Standard test.
2156 (should
2157 (equal
2158 '(yes no yes)
2159 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2160 (org-element-map tree 'headline
2161 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
2162 info))))
2163 (should
2164 (equal '(no yes)
2165 (org-test-with-parsed-data "- item\n\n para"
2166 (org-element-map tree 'paragraph
2167 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
2168 info))))
2169 ;; Ignore headlines not exported.
2170 (should
2171 (equal
2172 '(yes)
2173 (let ((org-export-exclude-tags '("ignore")))
2174 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2175 (org-element-map tree 'headline
2176 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
2177 info))))))
2179 (ert-deftest test-org-export/handle-inlinetasks ()
2180 "Test inlinetask export."
2181 ;; Inlinetask with an exclude tag.
2182 (when (featurep 'org-inlinetask)
2183 (should
2184 (equal
2186 (let ((org-inlinetask-min-level 3)
2187 org-export-filter-body-functions
2188 org-export-filter-final-output-functions)
2189 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2190 (org-export-as (org-test-default-backend)
2191 nil nil nil '(:exclude-tags ("noexp")))))))
2192 ;; Inlinetask with an include tag.
2193 (should
2194 (equal
2195 "* H2\n*** Inline :exp:\n"
2196 (let ((org-inlinetask-min-level 3)
2197 (org-tags-column 0))
2198 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2199 (org-export-as (org-test-default-backend)
2200 nil nil nil '(:select-tags ("exp")))))))
2201 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2202 (should
2203 (equal ""
2204 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2205 (org-inlinetask-min-level 3)
2206 org-export-filter-body-functions
2207 org-export-filter-final-output-functions)
2208 (org-test-with-temp-text "*** TODO Inline"
2209 (org-export-as (org-test-default-backend)
2210 nil nil nil '(:with-tasks nil))))))))
2214 ;;; Keywords
2216 (ert-deftest test-org-export/get-date ()
2217 "Test `org-export-get-date' specifications."
2218 ;; Return a properly formatted string when
2219 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2220 ;; consists in a single timestamp.
2221 (should
2222 (equal "29 03 2012"
2223 (let ((org-export-date-timestamp-format "%d %m %Y"))
2224 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2225 (org-export-get-date info)))))
2226 ;; Return a secondary string otherwise.
2227 (should-not
2228 (stringp
2229 (let ((org-export-date-timestamp-format nil))
2230 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2231 (org-export-get-date info)))))
2232 (should
2233 (equal '("Date")
2234 (org-test-with-parsed-data "#+DATE: Date"
2235 (org-export-get-date info))))
2236 ;; Optional argument has precedence over
2237 ;; `org-export-date-timestamp-format'.
2238 (should
2239 (equal "29 03"
2240 (let ((org-export-date-timestamp-format "%d %m %Y"))
2241 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2242 (org-export-get-date info "%d %m"))))))
2246 ;;; Links
2248 (ert-deftest test-org-export/custom-protocol-maybe ()
2249 "Test `org-export-custom-protocol-maybe' specifications."
2250 (should
2251 (string-match
2252 "success"
2253 (let ((org-link-types (copy-sequence org-link-types)))
2254 (org-add-link-type "foo" nil (lambda (p d f) "success"))
2255 (org-export-string-as
2256 "[[foo:path]]"
2257 (org-export-create-backend
2258 :name 'test
2259 :transcoders
2260 '((section . (lambda (s c i) c))
2261 (paragraph . (lambda (p c i) c))
2262 (link . (lambda (l c i)
2263 (or (org-export-custom-protocol-maybe l c 'test)
2264 "failure")))))))))
2265 (should-not
2266 (string-match
2267 "success"
2268 (let ((org-link-types (copy-sequence org-link-types)))
2269 (org-add-link-type
2270 "foo" nil (lambda (p d f) (and (eq f 'test) "success")))
2271 (org-export-string-as
2272 "[[foo:path]]"
2273 (org-export-create-backend
2274 :name 'no-test
2275 :transcoders
2276 '((section . (lambda (s c i) c))
2277 (paragraph . (lambda (p c i) c))
2278 (link . (lambda (l c i)
2279 (or (org-export-custom-protocol-maybe l c 'no-test)
2280 "failure")))))))))
2281 ;; Ignore anonymous back-ends.
2282 (should-not
2283 (string-match
2284 "success"
2285 (let ((org-link-types (copy-sequence org-link-types)))
2286 (org-add-link-type
2287 "foo" nil (lambda (p d f) (and (eq f 'test) "success")))
2288 (org-export-string-as
2289 "[[foo:path]]"
2290 (org-export-create-backend
2291 :transcoders
2292 '((section . (lambda (s c i) c))
2293 (paragraph . (lambda (p c i) c))
2294 (link . (lambda (l c i)
2295 (or (org-export-custom-protocol-maybe l c nil)
2296 "failure"))))))))))
2298 (ert-deftest test-org-export/get-coderef-format ()
2299 "Test `org-export-get-coderef-format' specifications."
2300 ;; A link without description returns "%s"
2301 (should (equal (org-export-get-coderef-format "(ref:line)" nil)
2302 "%s"))
2303 ;; Return "%s" when path is matched within description.
2304 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2305 "desc %s"))
2306 ;; Otherwise return description.
2307 (should (equal (org-export-get-coderef-format "path" "desc")
2308 "desc")))
2310 (ert-deftest test-org-export/inline-image-p ()
2311 "Test `org-export-inline-image-p' specifications."
2312 (should
2313 (org-export-inline-image-p
2314 (org-test-with-temp-text "[[#id]]"
2315 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
2316 '(("custom-id" . "id")))))
2318 (ert-deftest test-org-export/fuzzy-link ()
2319 "Test fuzzy links specifications."
2320 ;; Link to an headline should return headline's number.
2321 (org-test-with-parsed-data
2322 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2323 (should
2324 ;; Note: Headline's number is in fact a list of numbers.
2325 (equal '(2)
2326 (org-element-map tree 'link
2327 (lambda (link)
2328 (org-export-get-ordinal
2329 (org-export-resolve-fuzzy-link link info) info)) info t))))
2330 ;; Link to a target in an item should return item's number.
2331 (org-test-with-parsed-data
2332 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2333 (should
2334 ;; Note: Item's number is in fact a list of numbers.
2335 (equal '(1 2)
2336 (org-element-map tree 'link
2337 (lambda (link)
2338 (org-export-get-ordinal
2339 (org-export-resolve-fuzzy-link link info) info)) info t))))
2340 ;; Link to a target in a footnote should return footnote's number.
2341 (org-test-with-parsed-data "
2342 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
2343 (should
2344 (equal '(2 3)
2345 (org-element-map tree 'link
2346 (lambda (link)
2347 (org-export-get-ordinal
2348 (org-export-resolve-fuzzy-link link info) info)) info))))
2349 ;; Link to a named element should return sequence number of that
2350 ;; element.
2351 (org-test-with-parsed-data
2352 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2353 (should
2354 (= 2
2355 (org-element-map tree 'link
2356 (lambda (link)
2357 (org-export-get-ordinal
2358 (org-export-resolve-fuzzy-link link info) info)) info t))))
2359 ;; Link to a target not within an item, a table, a footnote
2360 ;; reference or definition should return section number.
2361 (org-test-with-parsed-data
2362 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2363 (should
2364 (equal '(2)
2365 (org-element-map tree 'link
2366 (lambda (link)
2367 (org-export-get-ordinal
2368 (org-export-resolve-fuzzy-link link info) info)) info t))))
2369 ;; Space are not significant when matching a fuzzy link.
2370 (should
2371 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2372 (org-element-map tree 'link
2373 (lambda (link) (org-export-resolve-fuzzy-link link info))
2374 info t)))
2375 ;; Statistics cookies are ignored for headline match.
2376 (should
2377 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2378 (org-element-map tree 'link
2379 (lambda (link) (org-export-resolve-fuzzy-link link info))
2380 info t)))
2381 (should
2382 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2383 (org-element-map tree 'link
2384 (lambda (link) (org-export-resolve-fuzzy-link link info))
2385 info t)))
2386 ;; Headline match is position dependent.
2387 (should-not
2388 (apply
2390 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
2391 (org-element-map tree 'link
2392 (lambda (link) (org-export-resolve-fuzzy-link link info)) info)))))
2394 (ert-deftest test-org-export/resolve-coderef ()
2395 "Test `org-export-resolve-coderef' specifications."
2396 (let ((org-coderef-label-format "(ref:%s)"))
2397 ;; A link to a "-n -k -r" block returns line number.
2398 (should
2399 (= 1
2400 (org-test-with-parsed-data
2401 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2402 (org-export-resolve-coderef "coderef" info))))
2403 (should
2404 (= 1
2405 (org-test-with-parsed-data
2406 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2407 (org-export-resolve-coderef "coderef" info))))
2408 ;; A link to a "-n -r" block returns line number.
2409 (should
2410 (= 1
2411 (org-test-with-parsed-data
2412 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2413 (org-export-resolve-coderef "coderef" info))))
2414 (should
2415 (= 1
2416 (org-test-with-parsed-data
2417 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2418 (org-export-resolve-coderef "coderef" info))))
2419 ;; A link to a "-n" block returns coderef.
2420 (should
2421 (equal "coderef"
2422 (org-test-with-parsed-data
2423 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2424 (org-export-resolve-coderef "coderef" info))))
2425 (should
2426 (equal "coderef"
2427 (org-test-with-parsed-data
2428 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2429 (org-export-resolve-coderef "coderef" info))))
2430 ;; A link to a "-r" block returns line number.
2431 (should
2432 (= 1
2433 (org-test-with-parsed-data
2434 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2435 (org-export-resolve-coderef "coderef" info))))
2436 (should
2437 (= 1
2438 (org-test-with-parsed-data
2439 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2440 (org-export-resolve-coderef "coderef" info))))
2441 ;; A link to a block without a switch returns coderef.
2442 (should
2443 (equal "coderef"
2444 (org-test-with-parsed-data
2445 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2446 (org-export-resolve-coderef "coderef" info))))
2447 (org-test-with-parsed-data
2448 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2449 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
2450 ;; Correctly handle continued line numbers. A "+n" switch should
2451 ;; resume numbering from previous block with numbered lines,
2452 ;; ignoring blocks not numbering lines in the process. A "-n"
2453 ;; switch resets count.
2454 (should
2455 (equal '(2 1)
2456 (org-test-with-parsed-data "
2457 #+BEGIN_EXAMPLE -n
2458 Text.
2459 #+END_EXAMPLE
2461 #+BEGIN_SRC emacs-lisp
2462 \(- 1 1)
2463 #+END_SRC
2465 #+BEGIN_SRC emacs-lisp +n -r
2466 \(+ 1 1) (ref:addition)
2467 #+END_SRC
2469 #+BEGIN_EXAMPLE -n -r
2470 Another text. (ref:text)
2471 #+END_EXAMPLE"
2472 (list (org-export-resolve-coderef "addition" info)
2473 (org-export-resolve-coderef "text" info)))))
2474 ;; Recognize coderef with user-specified syntax.
2475 (should
2476 (equal "text"
2477 (org-test-with-parsed-data
2478 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2479 (org-export-resolve-coderef "text" info))))
2480 ;; Unresolved coderefs throw an error.
2481 (should-error
2482 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2483 (org-export-resolve-coderef "unknown" info)))))
2485 (ert-deftest test-org-export/resolve-fuzzy-link ()
2486 "Test `org-export-resolve-fuzzy-link' specifications."
2487 ;; Match target objects.
2488 (should
2489 (org-test-with-parsed-data "<<target>> [[target]]"
2490 (org-export-resolve-fuzzy-link
2491 (org-element-map tree 'link 'identity info t) info)))
2492 ;; Match named elements.
2493 (should
2494 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2495 (org-export-resolve-fuzzy-link
2496 (org-element-map tree 'link 'identity info t) info)))
2497 ;; Match exact headline's name.
2498 (should
2499 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2500 (org-export-resolve-fuzzy-link
2501 (org-element-map tree 'link 'identity info t) info)))
2502 ;; Targets objects have priority over named elements and headline
2503 ;; titles.
2504 (should
2505 (eq 'target
2506 (org-test-with-parsed-data
2507 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2508 (org-element-type
2509 (org-export-resolve-fuzzy-link
2510 (org-element-map tree 'link 'identity info t) info)))))
2511 ;; Named elements have priority over headline titles.
2512 (should
2513 (eq 'paragraph
2514 (org-test-with-parsed-data
2515 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2516 (org-element-type
2517 (org-export-resolve-fuzzy-link
2518 (org-element-map tree 'link 'identity info t) info)))))
2519 ;; If link's path starts with a "*", only match headline titles,
2520 ;; though.
2521 (should
2522 (eq 'headline
2523 (org-test-with-parsed-data
2524 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2525 (org-element-type
2526 (org-export-resolve-fuzzy-link
2527 (org-element-map tree 'link 'identity info t) info)))))
2528 ;; Error if no match.
2529 (should-error
2530 (org-test-with-parsed-data "[[target]]"
2531 (org-export-resolve-fuzzy-link
2532 (org-element-map tree 'link 'identity info t) info)))
2533 ;; Match fuzzy link even when before first headline.
2534 (should
2535 (eq 'headline
2536 (org-test-with-parsed-data "[[hl]]\n* hl"
2537 (org-element-type
2538 (org-export-resolve-fuzzy-link
2539 (org-element-map tree 'link 'identity info t) info))))))
2541 (ert-deftest test-org-export/resolve-id-link ()
2542 "Test `org-export-resolve-id-link' specifications."
2543 ;; Regular test for custom-id link.
2544 (should
2545 (equal '("Headline1")
2546 (org-test-with-parsed-data "* Headline1
2547 :PROPERTIES:
2548 :CUSTOM_ID: test
2549 :END:
2550 * Headline 2
2551 \[[#test]]"
2552 (org-element-property
2553 :title
2554 (org-export-resolve-id-link
2555 (org-element-map tree 'link 'identity info t) info)))))
2556 ;; Throw an error on failing searches.
2557 (should-error
2558 (org-test-with-parsed-data "* Headline1
2559 :PROPERTIES:
2560 :CUSTOM_ID: test
2561 :END:
2562 * Headline 2
2563 \[[#no-match]]"
2564 (org-export-resolve-id-link
2565 (org-element-map tree 'link 'identity info t) info)))
2566 ;; Test for internal id target.
2567 (should
2568 (equal '("Headline1")
2569 (org-test-with-parsed-data "* Headline1
2570 :PROPERTIES:
2571 :ID: aaaa
2572 :END:
2573 * Headline 2
2574 \[[id:aaaa]]"
2575 (org-element-property
2576 :title
2577 (org-export-resolve-id-link
2578 (org-element-map tree 'link 'identity info t) info)))))
2579 ;; Test for external id target.
2580 (should
2581 (equal
2582 "external-file"
2583 (org-test-with-parsed-data "[[id:aaaa]]"
2584 (org-export-resolve-id-link
2585 (org-element-map tree 'link 'identity info t)
2586 (org-combine-plists info '(:id-alist (("aaaa" . "external-file")))))))))
2588 (ert-deftest test-org-export/resolve-radio-link ()
2589 "Test `org-export-resolve-radio-link' specifications."
2590 ;; Standard test.
2591 (should
2592 (org-test-with-temp-text "<<<radio>>> radio"
2593 (org-update-radio-target-regexp)
2594 (let* ((tree (org-element-parse-buffer))
2595 (info `(:parse-tree ,tree)))
2596 (org-export-resolve-radio-link
2597 (org-element-map tree 'link 'identity info t)
2598 info))))
2599 ;; Radio targets are case-insensitive.
2600 (should
2601 (org-test-with-temp-text "<<<RADIO>>> radio"
2602 (org-update-radio-target-regexp)
2603 (let* ((tree (org-element-parse-buffer))
2604 (info `(:parse-tree ,tree)))
2605 (org-export-resolve-radio-link
2606 (org-element-map tree 'link 'identity info t)
2607 info))))
2608 ;; Radio target with objects.
2609 (should
2610 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2611 (org-update-radio-target-regexp)
2612 (let* ((tree (org-element-parse-buffer))
2613 (info `(:parse-tree ,tree)))
2614 (org-export-resolve-radio-link
2615 (org-element-map tree 'link 'identity info t)
2616 info))))
2617 ;; Radio target with objects at its beginning.
2618 (should
2619 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2620 (org-update-radio-target-regexp)
2621 (let* ((tree (org-element-parse-buffer))
2622 (info `(:parse-tree ,tree)))
2623 (org-export-resolve-radio-link
2624 (org-element-map tree 'link 'identity info t)
2625 info))))
2626 ;; Radio link next to an apostrophe.
2627 (should
2628 (org-test-with-temp-text "<<<radio>>> radio's"
2629 (org-update-radio-target-regexp)
2630 (let* ((tree (org-element-parse-buffer))
2631 (info `(:parse-tree ,tree)))
2632 (org-export-resolve-radio-link
2633 (org-element-map tree 'link 'identity info t)
2634 info))))
2635 ;; Multiple radio targets.
2636 (should
2637 (equal '("radio1" "radio2")
2638 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2639 (org-update-radio-target-regexp)
2640 (let* ((tree (org-element-parse-buffer))
2641 (info `(:parse-tree ,tree)))
2642 (org-element-map tree 'link
2643 (lambda (link)
2644 (org-element-property
2645 :value (org-export-resolve-radio-link link info)))
2646 info)))))
2647 ;; Radio target is whitespace insensitive.
2648 (should
2649 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2650 (org-update-radio-target-regexp)
2651 (let* ((tree (org-element-parse-buffer))
2652 (info `(:parse-tree ,tree)))
2653 (org-element-map tree 'link
2654 (lambda (link) (org-export-resolve-radio-link link info)) info t)))))
2658 ;;; Src-block and example-block
2660 (ert-deftest test-org-export/unravel-code ()
2661 "Test `org-export-unravel-code' function."
2662 ;; Code without reference.
2663 (should
2664 (equal '("(+ 1 1)\n")
2665 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2666 (org-export-unravel-code (org-element-at-point)))))
2667 ;; Code with reference.
2668 (should
2669 (equal '("(+ 1 1)\n" (1 . "test"))
2670 (org-test-with-temp-text
2671 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2672 (let ((org-coderef-label-format "(ref:%s)"))
2673 (org-export-unravel-code (org-element-at-point))))))
2674 ;; Code with user-defined reference.
2675 (should
2676 (equal
2677 '("(+ 1 1)\n" (1 . "test"))
2678 (org-test-with-temp-text
2679 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2680 (let ((org-coderef-label-format "(ref:%s)"))
2681 (org-export-unravel-code (org-element-at-point))))))
2682 ;; Code references keys are relative to the current block.
2683 (should
2684 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 . "one"))
2685 (org-test-with-temp-text "
2686 #+BEGIN_EXAMPLE -n
2687 \(+ 1 1)
2688 #+END_EXAMPLE
2689 #+BEGIN_EXAMPLE +n
2690 \(+ 2 2)
2691 \(+ 3 3) (ref:one)
2692 #+END_EXAMPLE"
2693 (goto-line 5)
2694 (let ((org-coderef-label-format "(ref:%s)"))
2695 (org-export-unravel-code (org-element-at-point)))))))
2697 (ert-deftest test-org-export/format-code-default ()
2698 "Test `org-export-format-code-default' specifications."
2699 ;; Return the empty string when code is empty.
2700 (should
2701 (equal ""
2702 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2703 (org-export-format-code-default
2704 (org-element-map tree 'src-block 'identity info t) info))))
2705 ;; Number lines, two whitespace characters before the actual loc.
2706 (should
2707 (equal "1 a\n2 b\n"
2708 (org-test-with-parsed-data
2709 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2710 (org-export-format-code-default
2711 (org-element-map tree 'src-block 'identity info t) info))))
2712 ;; Put references 6 whitespace characters after the widest line,
2713 ;; wrapped within parenthesis.
2714 (should
2715 (equal "123 (a)\n1 (b)\n"
2716 (let ((org-coderef-label-format "(ref:%s)"))
2717 (org-test-with-parsed-data
2718 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2719 (org-export-format-code-default
2720 (org-element-map tree 'src-block 'identity info t) info))))))
2724 ;;; Smart Quotes
2726 (ert-deftest test-org-export/activate-smart-quotes ()
2727 "Test `org-export-activate-smart-quotes' specifications."
2728 ;; Opening double quotes: standard test.
2729 (should
2730 (equal
2731 '("some &ldquo;paragraph")
2732 (let ((org-export-default-language "en"))
2733 (org-test-with-parsed-data "some \"paragraph"
2734 (org-element-map tree 'plain-text
2735 (lambda (s) (org-export-activate-smart-quotes s :html info))
2736 info)))))
2737 ;; Opening quotes: at the beginning of a paragraph.
2738 (should
2739 (equal
2740 '("&ldquo;begin")
2741 (let ((org-export-default-language "en"))
2742 (org-test-with-parsed-data "\"begin"
2743 (org-element-map tree 'plain-text
2744 (lambda (s) (org-export-activate-smart-quotes s :html info))
2745 info)))))
2746 ;; Opening quotes: after an object.
2747 (should
2748 (equal
2749 '("&ldquo;begin")
2750 (let ((org-export-default-language "en"))
2751 (org-test-with-parsed-data "=verb= \"begin"
2752 (org-element-map tree 'plain-text
2753 (lambda (s) (org-export-activate-smart-quotes s :html info))
2754 info)))))
2755 ;; Closing quotes: standard test.
2756 (should
2757 (equal
2758 '("some&rdquo; paragraph")
2759 (let ((org-export-default-language "en"))
2760 (org-test-with-parsed-data "some\" paragraph"
2761 (org-element-map tree 'plain-text
2762 (lambda (s) (org-export-activate-smart-quotes s :html info))
2763 info)))))
2764 ;; Closing quotes: at the end of a paragraph.
2765 (should
2766 (equal
2767 '("end&rdquo;")
2768 (let ((org-export-default-language "en"))
2769 (org-test-with-parsed-data "end\""
2770 (org-element-map tree 'plain-text
2771 (lambda (s) (org-export-activate-smart-quotes s :html info))
2772 info)))))
2773 ;; Apostrophe: standard test.
2774 (should
2775 (equal
2776 '("It shouldn&rsquo;t fail")
2777 (let ((org-export-default-language "en"))
2778 (org-test-with-parsed-data "It shouldn't fail"
2779 (org-element-map tree 'plain-text
2780 (lambda (s) (org-export-activate-smart-quotes s :html info))
2781 info)))))
2782 ;; Apostrophe: before an object.
2783 (should
2784 (equal
2785 '("a&rsquo;")
2786 (let ((org-export-default-language "en"))
2787 (org-test-with-parsed-data "a'=b="
2788 (org-element-map tree 'plain-text
2789 (lambda (s) (org-export-activate-smart-quotes s :html info))
2790 info)))))
2791 ;; Apostrophe: after an object.
2792 (should
2793 (equal
2794 '("&rsquo;s")
2795 (let ((org-export-default-language "en"))
2796 (org-test-with-parsed-data "=code='s"
2797 (org-element-map tree 'plain-text
2798 (lambda (s) (org-export-activate-smart-quotes s :html info))
2799 info)))))
2800 ;; Special case: isolated quotes.
2801 (should
2802 (equal '("&ldquo;" "&rdquo;")
2803 (let ((org-export-default-language "en"))
2804 (org-test-with-parsed-data "\"$x$\""
2805 (org-element-map tree 'plain-text
2806 (lambda (s) (org-export-activate-smart-quotes s :html info))
2807 info)))))
2808 ;; Smart quotes in secondary strings.
2809 (should
2810 (equal '("&ldquo;" "&rdquo;")
2811 (let ((org-export-default-language "en"))
2812 (org-test-with-parsed-data "* \"$x$\""
2813 (org-element-map tree 'plain-text
2814 (lambda (s) (org-export-activate-smart-quotes s :html info))
2815 info)))))
2816 ;; Smart quotes in document keywords.
2817 (should
2818 (equal '("&ldquo;" "&rdquo;")
2819 (let ((org-export-default-language "en"))
2820 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2821 (org-element-map (plist-get info :title) 'plain-text
2822 (lambda (s) (org-export-activate-smart-quotes s :html info))
2823 info)))))
2824 ;; Smart quotes in parsed affiliated keywords.
2825 (should
2826 (equal '("&ldquo;" "&rdquo;" "Paragraph")
2827 (let ((org-export-default-language "en"))
2828 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2829 (org-element-map tree 'plain-text
2830 (lambda (s) (org-export-activate-smart-quotes s :html info))
2831 info nil nil t))))))
2835 ;;; Tables
2837 (ert-deftest test-org-export/special-column ()
2838 "Test if the table's special column is properly recognized."
2839 ;; 1. First column is special if it contains only a special marking
2840 ;; characters or empty cells.
2841 (org-test-with-temp-text "
2842 | ! | 1 |
2843 | | 2 |"
2844 (should
2845 (org-export-table-has-special-column-p
2846 (org-element-map
2847 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
2848 ;; 2. If the column contains anything else, it isn't special.
2849 (org-test-with-temp-text "
2850 | ! | 1 |
2851 | b | 2 |"
2852 (should-not
2853 (org-export-table-has-special-column-p
2854 (org-element-map
2855 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
2856 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2857 ;; and "!".
2858 (org-test-with-temp-text "
2859 | # | 1 |
2860 | ^ | 2 |
2861 | * | 3 |
2862 | _ | 4 |
2863 | / | 5 |
2864 | $ | 6 |
2865 | ! | 7 |"
2866 (should
2867 (org-export-table-has-special-column-p
2868 (org-element-map
2869 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
2870 ;; 4. A first column with only empty cells isn't considered as
2871 ;; special.
2872 (org-test-with-temp-text "
2873 | | 1 |
2874 | | 2 |"
2875 (should-not
2876 (org-export-table-has-special-column-p
2877 (org-element-map
2878 (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
2880 (ert-deftest test-org-export/table-row-is-special-p ()
2881 "Test `org-export-table-row-is-special-p' specifications."
2882 ;; 1. A row is special if it has a special marking character in the
2883 ;; special column.
2884 (org-test-with-parsed-data "| ! | 1 |"
2885 (should
2886 (org-export-table-row-is-special-p
2887 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
2888 ;; 2. A row is special when its first field is "/"
2889 (org-test-with-parsed-data "
2890 | / | 1 |
2891 | a | b |"
2892 (should
2893 (org-export-table-row-is-special-p
2894 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
2895 ;; 3. A row only containing alignment cookies is also considered as
2896 ;; special.
2897 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2898 (should
2899 (org-export-table-row-is-special-p
2900 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
2901 ;; 4. Everything else isn't considered as special.
2902 (org-test-with-parsed-data "| \alpha | | c |"
2903 (should-not
2904 (org-export-table-row-is-special-p
2905 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
2906 ;; 5. Table's rules are never considered as special rows.
2907 (org-test-with-parsed-data "|---+---|"
2908 (should-not
2909 (org-export-table-row-is-special-p
2910 (org-element-map tree 'table-row 'identity nil 'first-match) info))))
2912 (ert-deftest test-org-export/has-header-p ()
2913 "Test `org-export-table-has-header-p' specifications."
2914 ;; 1. With an header.
2915 (org-test-with-parsed-data "
2916 | a | b |
2917 |---+---|
2918 | c | d |"
2919 (should
2920 (org-export-table-has-header-p
2921 (org-element-map tree 'table 'identity info 'first-match)
2922 info)))
2923 ;; 2. Without an header.
2924 (org-test-with-parsed-data "
2925 | a | b |
2926 | c | d |"
2927 (should-not
2928 (org-export-table-has-header-p
2929 (org-element-map tree 'table 'identity info 'first-match)
2930 info)))
2931 ;; 3. Don't get fooled with starting and ending rules.
2932 (org-test-with-parsed-data "
2933 |---+---|
2934 | a | b |
2935 | c | d |
2936 |---+---|"
2937 (should-not
2938 (org-export-table-has-header-p
2939 (org-element-map tree 'table 'identity info 'first-match)
2940 info))))
2942 (ert-deftest test-org-export/table-row-group ()
2943 "Test `org-export-table-row-group' specifications."
2944 ;; 1. A rule creates a new group.
2945 (should
2946 (equal '(1 rule 2)
2947 (org-test-with-parsed-data "
2948 | a | b |
2949 |---+---|
2950 | 1 | 2 |"
2951 (org-element-map tree 'table-row
2952 (lambda (row)
2953 (if (eq (org-element-property :type row) 'rule) 'rule
2954 (org-export-table-row-group row info)))))))
2955 ;; 2. Special rows are ignored in count.
2956 (should
2957 (equal
2958 '(rule 1)
2959 (org-test-with-parsed-data "
2960 | / | < | > |
2961 |---|---+---|
2962 | | 1 | 2 |"
2963 (org-element-map tree 'table-row
2964 (lambda (row)
2965 (if (eq (org-element-property :type row) 'rule) 'rule
2966 (org-export-table-row-group row info)))
2967 info))))
2968 ;; 3. Double rules also are ignored in count.
2969 (should
2970 (equal '(1 rule rule 2)
2971 (org-test-with-parsed-data "
2972 | a | b |
2973 |---+---|
2974 |---+---|
2975 | 1 | 2 |"
2976 (org-element-map tree 'table-row
2977 (lambda (row)
2978 (if (eq (org-element-property :type row) 'rule) 'rule
2979 (org-export-table-row-group row info))))))))
2981 (ert-deftest test-org-export/table-row-number ()
2982 "Test `org-export-table-row-number' specifications."
2983 ;; Standard test. Number is 0-indexed.
2984 (should
2985 (equal '(0 1)
2986 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2987 (org-element-map tree 'table-row
2988 (lambda (row) (org-export-table-row-number row info)) info))))
2989 ;; Number ignores separators.
2990 (should
2991 (equal '(0 1)
2992 (org-test-with-parsed-data "
2993 | a | b | c |
2994 |---+---+---|
2995 | d | e | f |"
2996 (org-element-map tree 'table-row
2997 (lambda (row) (org-export-table-row-number row info)) info))))
2998 ;; Number ignores special rows.
2999 (should
3000 (equal '(0 1)
3001 (org-test-with-parsed-data "
3002 | / | < | > |
3003 | | b | c |
3004 |---+-----+-----|
3005 | | <c> | <c> |
3006 | | e | f |"
3007 (org-element-map tree 'table-row
3008 (lambda (row) (org-export-table-row-number row info)) info)))))
3010 (ert-deftest test-org-export/table-cell-width ()
3011 "Test `org-export-table-cell-width' specifications."
3012 ;; 1. Width is primarily determined by width cookies. If no cookie
3013 ;; is found, cell's width is nil.
3014 (org-test-with-parsed-data "
3015 | / | <l> | <6> | <l7> |
3016 | | a | b | c |"
3017 (should
3018 (equal
3019 '(nil 6 7)
3020 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
3021 (org-element-map tree 'table-cell 'identity info)))))
3022 ;; 2. The last width cookie has precedence.
3023 (org-test-with-parsed-data "
3024 | <6> |
3025 | <7> |
3026 | a |"
3027 (should
3028 (equal
3029 '(7)
3030 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
3031 (org-element-map tree 'table-cell 'identity info)))))
3032 ;; 3. Valid width cookies must have a specific row.
3033 (org-test-with-parsed-data "| <6> | cell |"
3034 (should
3035 (equal
3036 '(nil nil)
3037 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
3038 (org-element-map tree 'table-cell 'identity))))))
3040 (ert-deftest test-org-export/table-cell-alignment ()
3041 "Test `org-export-table-cell-alignment' specifications."
3042 ;; 1. Alignment is primarily determined by alignment cookies.
3043 (should
3044 (equal '(left center right)
3045 (let ((org-table-number-fraction 0.5)
3046 (org-table-number-regexp "^[0-9]+$"))
3047 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3048 (mapcar (lambda (cell)
3049 (org-export-table-cell-alignment cell info))
3050 (org-element-map tree 'table-cell 'identity))))))
3051 ;; 2. The last alignment cookie has precedence.
3052 (should
3053 (equal '(right right right)
3054 (org-test-with-parsed-data "
3055 | <l8> |
3056 | cell |
3057 | <r9> |"
3058 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
3059 (org-element-map tree 'table-cell 'identity)))))
3060 ;; 3. If there's no cookie, cell's contents determine alignment.
3061 ;; A column mostly made of cells containing numbers will align
3062 ;; its cells to the right.
3063 (should
3064 (equal '(right right right)
3065 (let ((org-table-number-fraction 0.5)
3066 (org-table-number-regexp "^[0-9]+$"))
3067 (org-test-with-parsed-data "
3068 | 123 |
3069 | some text |
3070 | 12345 |"
3071 (mapcar (lambda (cell)
3072 (org-export-table-cell-alignment cell info))
3073 (org-element-map tree 'table-cell 'identity))))))
3074 ;; 4. Otherwise, they will be aligned to the left.
3075 (should
3076 (equal '(left left left)
3077 (org-test-with-parsed-data "
3078 | text |
3079 | some text |
3080 | \alpha |"
3081 (mapcar (lambda (cell)
3082 (org-export-table-cell-alignment cell info))
3083 (org-element-map tree 'table-cell 'identity info))))))
3085 (ert-deftest test-org-export/table-cell-borders ()
3086 "Test `org-export-table-cell-borders' specifications."
3087 ;; 1. Recognize various column groups indicators.
3088 (org-test-with-parsed-data "| / | < | > | <> |"
3089 (should
3090 (equal
3091 '((right bottom top) (left bottom top) (right bottom top)
3092 (right left bottom top))
3093 (mapcar (lambda (cell)
3094 (org-export-table-cell-borders cell info))
3095 (org-element-map tree 'table-cell 'identity)))))
3096 ;; 2. Accept shortcuts to define column groups.
3097 (org-test-with-parsed-data "| / | < | < |"
3098 (should
3099 (equal
3100 '((right bottom top) (right left bottom top) (left bottom top))
3101 (mapcar (lambda (cell)
3102 (org-export-table-cell-borders cell info))
3103 (org-element-map tree 'table-cell 'identity)))))
3104 ;; 3. A valid column groups row must start with a "/".
3105 (org-test-with-parsed-data "
3106 | | < |
3107 | a | b |"
3108 (should
3109 (equal '((top) (top) (bottom) (bottom))
3110 (mapcar (lambda (cell)
3111 (org-export-table-cell-borders cell info))
3112 (org-element-map tree 'table-cell 'identity)))))
3113 ;; 4. Take table rules into consideration.
3114 (org-test-with-parsed-data "
3115 | 1 |
3116 |---|
3117 | 2 |"
3118 (should
3119 (equal '((below top) (bottom above))
3120 (mapcar (lambda (cell)
3121 (org-export-table-cell-borders cell info))
3122 (org-element-map tree 'table-cell 'identity)))))
3123 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3124 ;; (resp. `bottom' and `below') borders. Any special row is
3125 ;; ignored.
3126 (org-test-with-parsed-data "
3127 |---+----|
3128 | / | |
3129 | | 1 |
3130 |---+----|"
3131 (should
3132 (equal '((bottom below top above))
3133 (last
3134 (mapcar (lambda (cell)
3135 (org-export-table-cell-borders cell info))
3136 (org-element-map tree 'table-cell 'identity)))))))
3138 (ert-deftest test-org-export/table-dimensions ()
3139 "Test `org-export-table-dimensions' specifications."
3140 ;; 1. Standard test.
3141 (org-test-with-parsed-data "
3142 | 1 | 2 | 3 |
3143 | 4 | 5 | 6 |"
3144 (should
3145 (equal '(2 . 3)
3146 (org-export-table-dimensions
3147 (org-element-map tree 'table 'identity info 'first-match) info))))
3148 ;; 2. Ignore horizontal rules and special columns.
3149 (org-test-with-parsed-data "
3150 | / | < | > |
3151 | 1 | 2 | 3 |
3152 |---+---+---|
3153 | 4 | 5 | 6 |"
3154 (should
3155 (equal '(2 . 3)
3156 (org-export-table-dimensions
3157 (org-element-map tree 'table 'identity info 'first-match) info)))))
3159 (ert-deftest test-org-export/table-cell-address ()
3160 "Test `org-export-table-cell-address' specifications."
3161 ;; 1. Standard test: index is 0-based.
3162 (org-test-with-parsed-data "| a | b |"
3163 (should
3164 (equal '((0 . 0) (0 . 1))
3165 (org-element-map tree 'table-cell
3166 (lambda (cell) (org-export-table-cell-address cell info))
3167 info))))
3168 ;; 2. Special column isn't counted, nor are special rows.
3169 (org-test-with-parsed-data "
3170 | / | <> |
3171 | | c |"
3172 (should
3173 (equal '(0 . 0)
3174 (org-export-table-cell-address
3175 (car (last (org-element-map tree 'table-cell 'identity info)))
3176 info))))
3177 ;; 3. Tables rules do not count either.
3178 (org-test-with-parsed-data "
3179 | a |
3180 |---|
3181 | b |
3182 |---|
3183 | c |"
3184 (should
3185 (equal '(2 . 0)
3186 (org-export-table-cell-address
3187 (car (last (org-element-map tree 'table-cell 'identity info)))
3188 info))))
3189 ;; 4. Return nil for special cells.
3190 (org-test-with-parsed-data "| / | a |"
3191 (should-not
3192 (org-export-table-cell-address
3193 (org-element-map tree 'table-cell 'identity nil 'first-match)
3194 info))))
3196 (ert-deftest test-org-export/get-table-cell-at ()
3197 "Test `org-export-get-table-cell-at' specifications."
3198 ;; 1. Address ignores special columns, special rows and rules.
3199 (org-test-with-parsed-data "
3200 | / | <> |
3201 | | a |
3202 |---+----|
3203 | | b |"
3204 (should
3205 (equal '("b")
3206 (org-element-contents
3207 (org-export-get-table-cell-at
3208 '(1 . 0)
3209 (org-element-map tree 'table 'identity info 'first-match)
3210 info)))))
3211 ;; 2. Return value for a non-existent address is nil.
3212 (org-test-with-parsed-data "| a |"
3213 (should-not
3214 (org-export-get-table-cell-at
3215 '(2 . 2)
3216 (org-element-map tree 'table 'identity info 'first-match)
3217 info)))
3218 (org-test-with-parsed-data "| / |"
3219 (should-not
3220 (org-export-get-table-cell-at
3221 '(0 . 0)
3222 (org-element-map tree 'table 'identity info 'first-match)
3223 info))))
3225 (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
3226 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3227 ;; 1. A cell at a beginning of a row always starts a column group.
3228 (org-test-with-parsed-data "| a |"
3229 (should
3230 (org-export-table-cell-starts-colgroup-p
3231 (org-element-map tree 'table-cell 'identity info 'first-match)
3232 info)))
3233 ;; 2. Special column should be ignored when determining the
3234 ;; beginning of the row.
3235 (org-test-with-parsed-data "
3236 | / | |
3237 | | a |"
3238 (should
3239 (org-export-table-cell-starts-colgroup-p
3240 (org-element-map tree 'table-cell 'identity info 'first-match)
3241 info)))
3242 ;; 2. Explicit column groups.
3243 (org-test-with-parsed-data "
3244 | / | | < |
3245 | a | b | c |"
3246 (should
3247 (equal
3248 '(yes no yes)
3249 (org-element-map tree 'table-cell
3250 (lambda (cell)
3251 (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
3252 info)))))
3254 (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
3255 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3256 ;; 1. A cell at the end of a row always ends a column group.
3257 (org-test-with-parsed-data "| a |"
3258 (should
3259 (org-export-table-cell-ends-colgroup-p
3260 (org-element-map tree 'table-cell 'identity info 'first-match)
3261 info)))
3262 ;; 2. Special column should be ignored when determining the
3263 ;; beginning of the row.
3264 (org-test-with-parsed-data "
3265 | / | |
3266 | | a |"
3267 (should
3268 (org-export-table-cell-ends-colgroup-p
3269 (org-element-map tree 'table-cell 'identity info 'first-match)
3270 info)))
3271 ;; 3. Explicit column groups.
3272 (org-test-with-parsed-data "
3273 | / | < | |
3274 | a | b | c |"
3275 (should
3276 (equal
3277 '(yes no yes)
3278 (org-element-map tree 'table-cell
3279 (lambda (cell)
3280 (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
3281 info)))))
3283 (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
3284 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3285 ;; 1. A row at the beginning of a table always starts a row group.
3286 ;; So does a row following a table rule.
3287 (org-test-with-parsed-data "
3288 | a |
3289 |---|
3290 | b |"
3291 (should
3292 (equal
3293 '(yes no yes)
3294 (org-element-map tree 'table-row
3295 (lambda (row)
3296 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
3297 info))))
3298 ;; 2. Special rows should be ignored when determining the beginning
3299 ;; of the row.
3300 (org-test-with-parsed-data "
3301 | / | < |
3302 | | a |
3303 |---+---|
3304 | / | < |
3305 | | b |"
3306 (should
3307 (equal
3308 '(yes no yes)
3309 (org-element-map tree 'table-row
3310 (lambda (row)
3311 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
3312 info)))))
3314 (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
3315 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3316 ;; 1. A row at the end of a table always ends a row group. So does
3317 ;; a row preceding a table rule.
3318 (org-test-with-parsed-data "
3319 | a |
3320 |---|
3321 | b |"
3322 (should
3323 (equal
3324 '(yes no yes)
3325 (org-element-map tree 'table-row
3326 (lambda (row)
3327 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
3328 info))))
3329 ;; 2. Special rows should be ignored when determining the beginning
3330 ;; of the row.
3331 (org-test-with-parsed-data "
3332 | | a |
3333 | / | < |
3334 |---+---|
3335 | | b |
3336 | / | < |"
3337 (should
3338 (equal
3339 '(yes no yes)
3340 (org-element-map tree 'table-row
3341 (lambda (row)
3342 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
3343 info)))))
3345 (ert-deftest test-org-export/table-row-in-header-p ()
3346 "Test `org-export-table-row-in-header-p' specifications."
3347 ;; Standard test. Separators are always nil.
3348 (should
3349 (equal
3350 '(yes no no)
3351 (org-test-with-parsed-data "| a |\n|---|\n| b |"
3352 (org-element-map tree 'table-row
3353 (lambda (row)
3354 (if (org-export-table-row-in-header-p row info) 'yes 'no)) info))))
3355 ;; Nil when there is no header.
3356 (should
3357 (equal
3358 '(no no)
3359 (org-test-with-parsed-data "| a |\n| b |"
3360 (org-element-map tree 'table-row
3361 (lambda (row)
3362 (if (org-export-table-row-in-header-p row info) 'yes 'no)) info)))))
3364 (ert-deftest test-org-export/table-row-starts-header-p ()
3365 "Test `org-export-table-row-starts-header-p' specifications."
3366 ;; 1. Only the row starting the first row group starts the table
3367 ;; header.
3368 (org-test-with-parsed-data "
3369 | a |
3370 | b |
3371 |---|
3372 | c |"
3373 (should
3374 (equal
3375 '(yes no no no)
3376 (org-element-map tree 'table-row
3377 (lambda (row)
3378 (if (org-export-table-row-starts-header-p row info) 'yes 'no))
3379 info))))
3380 ;; 2. A row cannot start an header if there's no header in the
3381 ;; table.
3382 (org-test-with-parsed-data "
3383 | a |
3384 |---|"
3385 (should-not
3386 (org-export-table-row-starts-header-p
3387 (org-element-map tree 'table-row 'identity info 'first-match)
3388 info))))
3390 (ert-deftest test-org-export/table-row-ends-header-p ()
3391 "Test `org-export-table-row-ends-header-p' specifications."
3392 ;; 1. Only the row starting the first row group starts the table
3393 ;; header.
3394 (org-test-with-parsed-data "
3395 | a |
3396 | b |
3397 |---|
3398 | c |"
3399 (should
3400 (equal
3401 '(no yes no no)
3402 (org-element-map tree 'table-row
3403 (lambda (row)
3404 (if (org-export-table-row-ends-header-p row info) 'yes 'no))
3405 info))))
3406 ;; 2. A row cannot start an header if there's no header in the
3407 ;; table.
3408 (org-test-with-parsed-data "
3409 | a |
3410 |---|"
3411 (should-not
3412 (org-export-table-row-ends-header-p
3413 (org-element-map tree 'table-row 'identity info 'first-match)
3414 info))))
3418 ;;; Tables of Contents
3420 (ert-deftest test-org-export/collect-headlines ()
3421 "Test `org-export-collect-headlines' specifications."
3422 ;; Standard test.
3423 (should
3424 (= 2
3425 (length
3426 (org-test-with-parsed-data "* H1\n** H2"
3427 (org-export-collect-headlines info)))))
3428 ;; Do not collect headlines below optional argument.
3429 (should
3430 (= 1
3431 (length
3432 (org-test-with-parsed-data "* H1\n** H2"
3433 (org-export-collect-headlines info 1)))))
3434 ;; Never collect headlines below maximum headline level.
3435 (should
3436 (= 1
3437 (length
3438 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3439 (org-export-collect-headlines info)))))
3440 (should
3441 (= 1
3442 (length
3443 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3444 (org-export-collect-headlines info 2)))))
3445 ;; Collect headlines locally.
3446 (should
3447 (= 2
3448 (org-test-with-parsed-data "* H1\n** H2\n** H3"
3449 (let ((scope (org-element-map tree 'headline #'identity info t)))
3450 (length (org-export-collect-headlines info nil scope))))))
3451 ;; When collecting locally, optional level is relative.
3452 (should
3453 (= 1
3454 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
3455 (let ((scope (org-element-map tree 'headline #'identity info t)))
3456 (length (org-export-collect-headlines info 1 scope)))))))
3460 ;;; Templates
3462 (ert-deftest test-org-export/inner-template ()
3463 "Test `inner-template' translator specifications."
3464 (should
3465 (equal "Success!"
3466 (org-test-with-temp-text "* Headline"
3467 (org-export-as
3468 (org-export-create-backend
3469 :transcoders
3470 '((inner-template . (lambda (contents info) "Success!"))
3471 (headline . (lambda (h c i) "Headline"))))))))
3472 ;; Inner template is applied even in a "body-only" export.
3473 (should
3474 (equal "Success!"
3475 (org-test-with-temp-text "* Headline"
3476 (org-export-as
3477 (org-export-create-backend
3478 :transcoders '((inner-template . (lambda (c i) "Success!"))
3479 (headline . (lambda (h c i) "Headline"))))
3480 nil nil 'body-only)))))
3482 (ert-deftest test-org-export/template ()
3483 "Test `template' translator specifications."
3484 (should
3485 (equal "Success!"
3486 (org-test-with-temp-text "* Headline"
3487 (org-export-as
3488 (org-export-create-backend
3489 :transcoders '((template . (lambda (contents info) "Success!"))
3490 (headline . (lambda (h c i) "Headline"))))))))
3491 ;; Template is not applied in a "body-only" export.
3492 (should-not
3493 (equal "Success!"
3494 (org-test-with-temp-text "* Headline"
3495 (org-export-as
3496 (org-export-create-backend
3497 :transcoders '((template . (lambda (contents info) "Success!"))
3498 (headline . (lambda (h c i) "Headline"))))
3499 nil nil 'body-only)))))
3503 ;;; Topology
3505 (ert-deftest test-org-export/get-next-element ()
3506 "Test `org-export-get-next-element' specifications."
3507 ;; Standard test.
3508 (should
3509 (equal "b"
3510 (org-test-with-parsed-data "* Headline\n*a* b"
3511 (org-export-get-next-element
3512 (org-element-map tree 'bold 'identity info t) info))))
3513 ;; Return nil when no previous element.
3514 (should-not
3515 (org-test-with-parsed-data "* Headline\na *b*"
3516 (org-export-get-next-element
3517 (org-element-map tree 'bold 'identity info t) info)))
3518 ;; Non-exportable elements are ignored.
3519 (should-not
3520 (let ((org-export-with-timestamps nil))
3521 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3522 (org-export-get-next-element
3523 (org-element-map tree 'entity 'identity info t) info))))
3524 ;; Find next element in secondary strings.
3525 (should
3526 (eq 'verbatim
3527 (org-test-with-parsed-data "* a =verb="
3528 (org-element-type
3529 (org-export-get-next-element
3530 (org-element-map tree 'plain-text 'identity info t) info)))))
3531 (should
3532 (eq 'verbatim
3533 (org-test-with-parsed-data "* /italic/ =verb="
3534 (org-element-type
3535 (org-export-get-next-element
3536 (org-element-map tree 'italic 'identity info t) info)))))
3537 ;; Find next element in document keywords.
3538 (should
3539 (eq 'verbatim
3540 (org-test-with-parsed-data "#+TITLE: a =verb="
3541 (org-element-type
3542 (org-export-get-next-element
3543 (org-element-map
3544 (plist-get info :title) 'plain-text 'identity info t) info)))))
3545 ;; Find next element in parsed affiliated keywords.
3546 (should
3547 (eq 'verbatim
3548 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3549 (org-element-type
3550 (org-export-get-next-element
3551 (org-element-map tree 'plain-text 'identity info t nil t) info)))))
3552 ;; With optional argument N, return a list containing all the
3553 ;; following elements.
3554 (should
3555 (equal
3556 '(bold code underline)
3557 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3558 (mapcar 'car
3559 (org-export-get-next-element
3560 (org-element-map tree 'italic 'identity info t) info t)))))
3561 ;; When N is a positive integer, return a list containing up to
3562 ;; N following elements.
3563 (should
3564 (equal
3565 '(bold code)
3566 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3567 (mapcar 'car
3568 (org-export-get-next-element
3569 (org-element-map tree 'italic 'identity info t) info 2))))))
3571 (ert-deftest test-org-export/get-previous-element ()
3572 "Test `org-export-get-previous-element' specifications."
3573 ;; Standard test.
3574 (should
3575 (equal "a "
3576 (org-test-with-parsed-data "* Headline\na *b*"
3577 (org-export-get-previous-element
3578 (org-element-map tree 'bold 'identity info t) info))))
3579 ;; Return nil when no previous element.
3580 (should-not
3581 (org-test-with-parsed-data "* Headline\n*a* b"
3582 (org-export-get-previous-element
3583 (org-element-map tree 'bold 'identity info t) info)))
3584 ;; Non-exportable elements are ignored.
3585 (should-not
3586 (let ((org-export-with-timestamps nil))
3587 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3588 (org-export-get-previous-element
3589 (org-element-map tree 'entity 'identity info t) info))))
3590 ;; Find previous element in secondary strings.
3591 (should
3592 (eq 'verbatim
3593 (org-test-with-parsed-data "* =verb= a"
3594 (org-element-type
3595 (org-export-get-previous-element
3596 (org-element-map tree 'plain-text 'identity info t) info)))))
3597 (should
3598 (eq 'verbatim
3599 (org-test-with-parsed-data "* =verb= /italic/"
3600 (org-element-type
3601 (org-export-get-previous-element
3602 (org-element-map tree 'italic 'identity info t) info)))))
3603 ;; Find previous element in document keywords.
3604 (should
3605 (eq 'verbatim
3606 (org-test-with-parsed-data "#+TITLE: =verb= a"
3607 (org-element-type
3608 (org-export-get-previous-element
3609 (org-element-map
3610 (plist-get info :title) 'plain-text 'identity info t) info)))))
3611 ;; Find previous element in parsed affiliated keywords.
3612 (should
3613 (eq 'verbatim
3614 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3615 (org-element-type
3616 (org-export-get-previous-element
3617 (org-element-map tree 'plain-text 'identity info t nil t) info)))))
3618 ;; With optional argument N, return a list containing up to
3619 ;; N previous elements.
3620 (should
3621 (equal '(underline italic bold)
3622 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3623 (mapcar 'car
3624 (org-export-get-previous-element
3625 (org-element-map tree 'code 'identity info t) info t)))))
3626 ;; When N is a positive integer, return a list containing up to
3627 ;; N previous elements.
3628 (should
3629 (equal '(italic bold)
3630 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3631 (mapcar 'car
3632 (org-export-get-previous-element
3633 (org-element-map tree 'code 'identity info t) info 2))))))
3636 (provide 'test-ox)
3637 ;;; test-org-export.el end here