Allow radio links after an apostrophe and mid-word
[org-mode.git] / testing / lisp / test-ox.el
blobfe20496a1055c60a976acbbd9797d4c8c496dede
1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012, 2013, 2014 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.
47 DATA is a string containing the data to be parsed. BODY is the
48 body to execute. Parse tree is available under the `tree'
49 variable, and communication channel under `info'.
51 This function calls `org-export-collect-tree-properties'. As
52 such, `:ignore-list' (for `org-element-map') and
53 `:parse-tree' (for `org-export-get-genealogy') properties are
54 already filled in `info'."
55 (declare (debug (form body)) (indent 1))
56 `(org-test-with-temp-text ,data
57 (let* ((tree (org-element-parse-buffer))
58 (info (org-export-collect-tree-properties
59 tree (org-export-get-environment))))
60 ,@body)))
64 ;;; Internal Tests
66 (ert-deftest test-org-export/bind-keyword ()
67 "Test reading #+BIND: keywords."
68 ;; Test with `org-export-allow-bind-keywords' set to t.
69 (should
70 (org-test-with-temp-text "#+BIND: test-ox-var value"
71 (let ((org-export-allow-bind-keywords t))
72 (org-export-get-environment)
73 (eq test-ox-var 'value))))
74 ;; Test with `org-export-allow-bind-keywords' set to nil.
75 (should-not
76 (org-test-with-temp-text "#+BIND: test-ox-var value"
77 (let ((org-export-allow-bind-keywords nil))
78 (org-export-get-environment)
79 (boundp 'test-ox-var))))
80 ;; BIND keywords are case-insensitive.
81 (should
82 (org-test-with-temp-text "#+bind: test-ox-var value"
83 (let ((org-export-allow-bind-keywords t))
84 (org-export-get-environment)
85 (eq test-ox-var 'value))))
86 ;; Preserve order of BIND keywords.
87 (should
88 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
89 (let ((org-export-allow-bind-keywords t))
90 (org-export-get-environment)
91 (eq test-ox-var 2))))
92 ;; Read BIND keywords in setup files.
93 (should
94 (org-test-with-temp-text
95 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
96 (let ((org-export-allow-bind-keywords t))
97 (org-export-get-environment)
98 (eq variable 'value))))
99 ;; Verify that bound variables are seen during export.
100 (should
101 (equal "Yes\n"
102 (org-test-with-temp-text "#+BIND: test-ox-var value"
103 (let ((org-export-allow-bind-keywords t))
104 (org-export-as
105 (org-export-create-backend
106 :transcoders
107 '((section . (lambda (s c i)
108 (if (eq test-ox-var 'value) "Yes" "No")))))))))))
110 (ert-deftest test-org-export/parse-option-keyword ()
111 "Test reading all standard #+OPTIONS: items."
112 (should
113 (equal
114 (org-export--parse-option-keyword
115 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
116 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
117 stat:t")
118 '(:headline-levels
119 1 :preserve-breaks t :section-numbers t :time-stamp-file t
120 :with-archived-trees t :with-author t :with-creator t :with-drawers t
121 :with-email t :with-emphasize t :with-entities t :with-fixed-width t
122 :with-footnotes t :with-inlinetasks nil :with-priority t
123 :with-special-strings t :with-statistics-cookies t :with-sub-superscript t
124 :with-toc t :with-tables t :with-tags t :with-tasks t :with-timestamps t
125 :with-todo-keywords t)))
126 ;; Test some special values.
127 (should
128 (equal
129 (org-export--parse-option-keyword
130 "arch:headline creator:comment d:(\"TEST\")
131 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
132 '( :section-numbers
134 :with-archived-trees headline :with-creator comment
135 :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
136 :with-tags not-in-toc :with-tasks todo :with-timestamps active))))
138 (ert-deftest test-org-export/get-inbuffer-options ()
139 "Test reading all standard export keywords."
140 ;; Properties should follow buffer order.
141 (should
142 (equal
143 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
144 (org-export--get-inbuffer-options))
145 '(:language "fr" :creator "Me" :email "email")))
146 ;; Parse document keywords.
147 (should
148 (equal
149 (org-test-with-temp-text "#+AUTHOR: Me"
150 (org-export--get-inbuffer-options))
151 '(:author ("Me"))))
152 ;; Test `space' behaviour.
153 (should
154 (equal
155 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
156 (org-export--get-inbuffer-options))
157 '(:title ("Some title with spaces"))))
158 ;; Test `newline' behaviour.
159 (should
160 (equal
161 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
162 (org-export--get-inbuffer-options))
163 '(:description "With\ntwo lines")))
164 ;; Test `split' behaviour.
165 (should
166 (equal
167 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
168 (org-export--get-inbuffer-options))
169 '(:select-tags ("a" "b"))))
170 ;; Options set through SETUPFILE.
171 (should
172 (equal
173 (org-test-with-temp-text
174 (format "#+DESCRIPTION: l1
175 #+LANGUAGE: es
176 #+SELECT_TAGS: a
177 #+TITLE: a
178 #+SETUPFILE: \"%s/examples/setupfile.org\"
179 #+DESCRIPTION: l3
180 #+LANGUAGE: fr
181 #+SELECT_TAGS: c
182 #+TITLE: c"
183 org-test-dir)
184 (org-export--get-inbuffer-options))
185 '(:description "l1\nl2\nl3":language "fr" :select-tags ("a" "b" "c")
186 :title ("a b c"))))
187 ;; More than one property can refer to the same buffer keyword.
188 (should
189 (equal '(:k2 "value" :k1 "value")
190 (let ((backend (org-export-create-backend
191 :options '((:k1 "KEYWORD")
192 (:k2 "KEYWORD")))))
193 (org-test-with-temp-text "#+KEYWORD: value"
194 (org-export--get-inbuffer-options backend))))))
196 (ert-deftest test-org-export/get-subtree-options ()
197 "Test setting options from headline's properties."
198 ;; EXPORT_TITLE.
199 (org-test-with-temp-text "#+TITLE: Title
200 * Headline
201 :PROPERTIES:
202 :EXPORT_TITLE: Subtree Title
203 :END:
204 Paragraph"
205 (forward-line)
206 (should (equal (plist-get (org-export-get-environment nil t) :title)
207 '("Subtree Title"))))
208 :title
209 '("subtree-title")
210 ;; EXPORT_OPTIONS.
211 (org-test-with-temp-text "#+OPTIONS: H:1
212 * Headline
213 :PROPERTIES:
214 :EXPORT_OPTIONS: H:2
215 :END:
216 Paragraph"
217 (forward-line)
218 (should
219 (= 2 (plist-get (org-export-get-environment nil t) :headline-levels))))
220 ;; EXPORT_DATE.
221 (org-test-with-temp-text "#+DATE: today
222 * Headline
223 :PROPERTIES:
224 :EXPORT_DATE: 29-03-2012
225 :END:
226 Paragraph"
227 (forward-line)
228 (should (equal (plist-get (org-export-get-environment nil t) :date)
229 '("29-03-2012"))))
230 ;; Properties with `split' behaviour are stored as a list of
231 ;; strings.
232 (should
233 (equal '("a" "b")
234 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
235 * Headline
236 :PROPERTIES:
237 :EXPORT_EXCLUDE_TAGS: a b
238 :END:
239 Paragraph"
240 (progn
241 (forward-line)
242 (plist-get (org-export-get-environment nil t) :exclude-tags)))))
243 ;; Handle :PROPERTY+: syntax.
244 (should
245 (equal '("a" "b")
246 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
247 * Headline
248 :PROPERTIES:
249 :EXPORT_EXCLUDE_TAGS: a
250 :EXPORT_EXCLUDE_TAGS+: b
251 :END:
252 Paragraph"
253 (progn
254 (forward-line)
255 (plist-get (org-export-get-environment nil t) :exclude-tags)))))
256 ;; Export properties are case-insensitive.
257 (org-test-with-temp-text "* Headline
258 :PROPERTIES:
259 :EXPORT_Date: 29-03-2012
260 :END:
261 Paragraph"
262 (should (equal (plist-get (org-export-get-environment nil t) :date)
263 '("29-03-2012"))))
264 ;; Still grab correct options when section above is empty.
265 (should
266 (equal '("H1")
267 (org-test-with-temp-text "* H1\n** H11\n** H12"
268 (progn (forward-line 2)
269 (plist-get (org-export-get-environment nil t) :title))))))
271 (ert-deftest test-org-export/set-title ()
272 "Test title setting."
273 ;; If no title if specified, use file name.
274 (should
275 (apply
276 'equal
277 (org-test-with-temp-text-in-file "Test"
278 (org-mode)
279 (list (org-export-as
280 (org-export-create-backend
281 :transcoders
282 '((template . (lambda (text info)
283 (org-element-interpret-data
284 (plist-get info :title)))))))
285 (file-name-nondirectory
286 (file-name-sans-extension (buffer-file-name)))))))
287 ;; If no title is specified, and no file is associated to the
288 ;; buffer, use buffer's name.
289 (should
290 (apply
291 'equal
292 (org-test-with-temp-text "Test"
293 (org-mode)
294 (list (org-export-as
295 (org-export-create-backend
296 :transcoders
297 '((template . (lambda (text info)
298 (org-element-interpret-data
299 (plist-get info :title)))))))
300 (buffer-name)))))
301 ;; If a title is specified, use it.
302 (should
303 (equal
304 "Title"
305 (org-test-with-temp-text-in-file "#+TITLE: Title\nTest"
306 (org-mode)
307 (org-export-as
308 (org-export-create-backend
309 :transcoders
310 '((template . (lambda (text info)
311 (org-element-interpret-data
312 (plist-get info :title))))))))))
313 ;; If an empty title is specified, do not set it.
314 (should
315 (equal
317 (org-test-with-temp-text-in-file "#+TITLE:\nTest"
318 (org-mode)
319 (org-export-as
320 (org-export-create-backend
321 :transcoders
322 '((template . (lambda (text info)
323 (org-element-interpret-data
324 (plist-get info :title)))))))))))
326 (ert-deftest test-org-export/handle-options ()
327 "Test if export options have an impact on output."
328 ;; Test exclude tags for headlines and inlinetasks.
329 (should
330 (equal ""
331 (org-test-with-temp-text "* Head1 :noexp:"
332 (org-export-as (org-test-default-backend)
333 nil nil nil '(:exclude-tags ("noexp"))))))
334 ;; Test include tags for headlines and inlinetasks.
335 (should
336 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
337 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
338 (let ((org-tags-column 0))
339 (org-export-as (org-test-default-backend)
340 nil nil nil '(:select-tags ("exp")))))))
341 ;; If there is an include tag, ignore the section before the first
342 ;; headline, if any.
343 (should
344 (equal "* H1 :exp:\nBody\n"
345 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
346 (let ((org-tags-column 0))
347 (org-export-as (org-test-default-backend)
348 nil nil nil '(:select-tags ("exp")))))))
349 (should-not
350 (equal "* H1 :exp:\n"
351 (org-test-with-temp-text "* H1 :exp:\nBody"
352 (let ((org-tags-column 0))
353 (org-export-as (org-test-default-backend)
354 nil nil nil '(:select-tags ("exp")))))))
355 ;; Test mixing include tags and exclude tags.
356 (should
357 (string-match
358 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
359 (org-test-with-temp-text "
360 * Head1 :export:
361 ** Sub-Head1 :noexport:
362 ** Sub-Head2
363 * Head2 :noexport:
364 ** Sub-Head1 :export:"
365 (org-export-as (org-test-default-backend) nil nil nil
366 '(:select-tags ("export") :exclude-tags ("noexport"))))))
367 ;; Ignore tasks.
368 (should
369 (equal ""
370 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
371 (org-test-with-temp-text "* TODO Head1"
372 (org-export-as (org-test-default-backend)
373 nil nil nil '(:with-tasks nil))))))
374 (should
375 (equal "* TODO Head1\n"
376 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
377 (org-test-with-temp-text "* TODO Head1"
378 (org-export-as (org-test-default-backend)
379 nil nil nil '(:with-tasks t))))))
380 ;; Archived tree.
381 (should
382 (equal ""
383 (org-test-with-temp-text "* Head1 :archive:"
384 (let ((org-archive-tag "archive"))
385 (org-export-as (org-test-default-backend)
386 nil nil nil '(:with-archived-trees nil))))))
387 (should
388 (string-match
389 "\\* Head1[ \t]+:archive:"
390 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
391 (let ((org-archive-tag "archive"))
392 (org-export-as (org-test-default-backend) nil nil nil
393 '(:with-archived-trees headline))))))
394 (should
395 (string-match
396 "\\`\\* Head1[ \t]+:archive:\n\\'"
397 (org-test-with-temp-text "* Head1 :archive:"
398 (let ((org-archive-tag "archive"))
399 (org-export-as (org-test-default-backend)
400 nil nil nil '(:with-archived-trees t))))))
401 ;; Clocks.
402 (should
403 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
404 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
405 (org-export-as (org-test-default-backend)
406 nil nil nil '(:with-clocks t)))))
407 (should
408 (equal ""
409 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
410 (org-export-as (org-test-default-backend)
411 nil nil nil '(:with-clocks nil)))))
412 ;; Drawers.
413 (should
414 (equal ""
415 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
416 (org-export-as (org-test-default-backend)
417 nil nil nil '(:with-drawers nil)))))
418 (should
419 (equal ":TEST:\ncontents\n:END:\n"
420 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
421 (org-export-as (org-test-default-backend)
422 nil nil nil '(:with-drawers t)))))
423 (should
424 (equal ":FOO:\nkeep\n:END:\n"
425 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
426 (org-export-as (org-test-default-backend)
427 nil nil nil '(:with-drawers ("FOO"))))))
428 (should
429 (equal ":FOO:\nkeep\n:END:\n"
430 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
431 (org-export-as (org-test-default-backend)
432 nil nil nil '(:with-drawers (not "BAR"))))))
433 ;; Fixed-width.
434 (should
435 (equal ": A\n"
436 (org-test-with-temp-text ": A"
437 (org-export-as (org-test-default-backend) nil nil nil
438 '(:with-fixed-width t)))))
439 (should
440 (equal ""
441 (org-test-with-temp-text ": A"
442 (org-export-as (org-test-default-backend) nil nil nil
443 '(:with-fixed-width nil)))))
444 ;; Footnotes.
445 (should
446 (equal "Footnote?"
447 (let ((org-footnote-section nil))
448 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
449 (org-trim (org-export-as (org-test-default-backend)
450 nil nil nil '(:with-footnotes nil)))))))
451 (should
452 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
453 (let ((org-footnote-section nil))
454 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
455 (org-trim (org-export-as (org-test-default-backend)
456 nil nil nil '(:with-footnotes t)))))))
457 ;; Inlinetasks.
458 (when (featurep 'org-inlinetask)
459 (should
460 (equal
462 (let ((org-inlinetask-min-level 15))
463 (org-test-with-temp-text "*************** Task"
464 (org-export-as (org-test-default-backend)
465 nil nil nil '(:with-inlinetasks nil))))))
466 (should
467 (equal
469 (let ((org-inlinetask-min-level 15))
470 (org-test-with-temp-text
471 "*************** Task\nContents\n*************** END"
472 (org-export-as (org-test-default-backend)
473 nil nil nil '(:with-inlinetasks nil)))))))
474 ;; Plannings.
475 (should
476 (string-match
477 "CLOSED: \\[2012-04-29 .* 10:45\\]"
478 (let ((org-closed-string "CLOSED:"))
479 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
480 (org-export-as (org-test-default-backend)
481 nil nil nil '(:with-planning t))))))
482 (should
483 (equal ""
484 (let ((org-closed-string "CLOSED:"))
485 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
486 (org-export-as (org-test-default-backend)
487 nil nil nil '(:with-planning nil))))))
488 ;; Property Drawers.
489 (should
490 (equal "* H1\n"
491 (org-test-with-temp-text
492 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
493 (org-export-as (org-test-default-backend)
494 nil nil nil '(:with-properties nil)))))
495 (should
496 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
497 (org-test-with-temp-text
498 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
499 (org-export-as (org-test-default-backend)
500 nil nil nil '(:with-properties t)))))
501 (should
502 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
503 (org-test-with-temp-text
504 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
505 (org-export-as (org-test-default-backend)
506 nil nil nil '(:with-properties ("B"))))))
507 ;; Statistics cookies.
508 (should
509 (equal ""
510 (org-test-with-temp-text "[0/0]"
511 (org-export-as (org-test-default-backend)
512 nil nil nil '(:with-statistics-cookies nil)))))
513 ;; Tables.
514 (should
515 (equal "| A |\n"
516 (org-test-with-temp-text "| A |"
517 (org-export-as (org-test-default-backend) nil nil nil
518 '(:with-tables t)))))
519 (should
520 (equal ""
521 (org-test-with-temp-text "| A |"
522 (org-export-as (org-test-default-backend) nil nil nil
523 '(:with-tables nil))))))
525 (ert-deftest test-org-export/with-timestamps ()
526 "Test `org-export-with-timestamps' specifications."
527 ;; t value.
528 (should
529 (string-match
530 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
531 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
532 (org-export-as (org-test-default-backend)
533 nil nil nil '(:with-timestamps t)))))
534 ;; nil value.
535 (should
536 (equal
538 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
539 (org-export-as (org-test-default-backend)
540 nil nil nil '(:with-timestamps nil)))))
541 ;; `active' value.
542 (should
543 (string-match
544 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
545 (org-test-with-temp-text
546 "<2012-03-29 Thu>[2012-03-29 Thu]
548 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
549 (org-export-as (org-test-default-backend)
550 nil nil nil '(:with-timestamps active)))))
551 ;; `inactive' value.
552 (should
553 (string-match
554 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
555 (org-test-with-temp-text
556 "<2012-03-29 Thu>[2012-03-29 Thu]
558 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
559 (org-export-as (org-test-default-backend)
560 nil nil nil '(:with-timestamps inactive))))))
562 (ert-deftest test-org-export/comment-tree ()
563 "Test if export process ignores commented trees."
564 (should
565 (equal ""
566 (org-test-with-temp-text "* COMMENT Head1"
567 (org-export-as (org-test-default-backend))))))
569 (ert-deftest test-org-export/uninterpreted ()
570 "Test handling of uninterpreted elements."
571 ;; Entities.
572 (should
573 (equal "dummy\n"
574 (org-test-with-temp-text "\\alpha"
575 (org-export-as
576 (org-export-create-backend
577 :transcoders '((entity . (lambda (e c i) "dummy"))
578 (paragraph . (lambda (p c i) c))
579 (section . (lambda (s c i) c))))
580 nil nil nil '(:with-entities t)))))
581 (should
582 (equal "\\alpha\n"
583 (org-test-with-temp-text "\\alpha"
584 (org-export-as
585 (org-export-create-backend
586 :transcoders '((entity . (lambda (e c i) "dummy"))
587 (paragraph . (lambda (p c i) c))
588 (section . (lambda (s c i) c))))
589 nil nil nil '(:with-entities nil)))))
590 ;; Emphasis.
591 (should
592 (equal "dummy\n"
593 (org-test-with-temp-text "*bold*"
594 (org-export-as
595 (org-export-create-backend
596 :transcoders '((bold . (lambda (b c i) "dummy"))
597 (paragraph . (lambda (p c i) c))
598 (section . (lambda (s c i) c))))
599 nil nil nil '(:with-emphasize t)))))
600 (should
601 (equal "*bold*\n"
602 (org-test-with-temp-text "*bold*"
603 (org-export-as
604 (org-export-create-backend
605 :transcoders '((bold . (lambda (b c i) "dummy"))
606 (paragraph . (lambda (p c i) c))
607 (section . (lambda (s c i) c))))
608 nil nil nil '(:with-emphasize nil)))))
609 ;; LaTeX environment.
610 (should
611 (equal "dummy\n"
612 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
613 (org-export-as
614 (org-export-create-backend
615 :transcoders '((latex-environment . (lambda (l c i) "dummy"))
616 (section . (lambda (s c i) c))))
617 nil nil nil '(:with-latex t)))))
618 (should
619 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
620 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
621 (org-export-as
622 (org-export-create-backend
623 :transcoders '((latex-environment . (lambda (l c i) "dummy"))
624 (section . (lambda (s c i) c))))
625 nil nil nil '(:with-latex verbatim)))))
626 ;; LaTeX fragment.
627 (should
628 (equal "dummy\n"
629 (org-test-with-temp-text "$1$"
630 (org-export-as
631 (org-export-create-backend
632 :transcoders '((latex-fragment . (lambda (l c i) "dummy"))
633 (paragraph . (lambda (p c i) c))
634 (section . (lambda (s c i) c))))
635 nil nil nil '(:with-latex t)))))
636 (should
637 (equal "$1$\n"
638 (org-test-with-temp-text "$1$"
639 (org-export-as
640 (org-export-create-backend
641 :transcoders '((latex-fragment . (lambda (l c i) "dummy"))
642 (paragraph . (lambda (p c i) c))
643 (section . (lambda (s c i) c))))
644 nil nil nil '(:with-latex verbatim)))))
645 ;; Sub/superscript.
646 (should
647 (equal "adummy\n"
648 (org-test-with-temp-text "a_b"
649 (org-export-as
650 (org-export-create-backend
651 :transcoders '((subscript . (lambda (s c i) "dummy"))
652 (paragraph . (lambda (p c i) c))
653 (section . (lambda (s c i) c))))
654 nil nil nil '(:with-sub-superscript t)))))
655 (should
656 (equal "a_b\n"
657 (org-test-with-temp-text "a_b"
658 (org-export-as
659 (org-export-create-backend
660 :transcoders '((subscript . (lambda (s c i) "dummy"))
661 (paragraph . (lambda (p c i) c))
662 (section . (lambda (s c i) c))))
663 nil nil nil '(:with-sub-superscript nil)))))
664 (should
665 (equal "a_b\n"
666 (org-test-with-temp-text "a_b"
667 (org-export-as
668 (org-export-create-backend
669 :transcoders '((subscript . (lambda (s c i) "dummy"))
670 (paragraph . (lambda (p c i) c))
671 (section . (lambda (s c i) c))))
672 nil nil nil '(:with-sub-superscript {})))))
673 (should
674 (equal "adummy\n"
675 (org-test-with-temp-text "a_{b}"
676 (org-export-as
677 (org-export-create-backend
678 :transcoders '((subscript . (lambda (s c i) "dummy"))
679 (paragraph . (lambda (p c i) c))
680 (section . (lambda (s c i) c))))
681 nil nil nil '(:with-sub-superscript {})))))
682 ;; Also handle uninterpreted objects in title.
683 (should
684 (equal "a_b"
685 (org-test-with-temp-text "#+TITLE: a_b"
686 (org-export-as
687 (org-export-create-backend
688 :transcoders
689 '((subscript . (lambda (s c i) "dummy"))
690 (template . (lambda (c i) (org-export-data
691 (plist-get i :title) i)))
692 (section . (lambda (s c i) c))))
693 nil nil nil '(:with-sub-superscript nil))))))
695 (ert-deftest test-org-export/export-scope ()
696 "Test all export scopes."
697 (org-test-with-temp-text "
698 * Head1
699 ** Head2
700 text
701 *** Head3"
702 ;; Subtree.
703 (forward-line 3)
704 (should (equal (org-export-as (org-test-default-backend) 'subtree)
705 "text\n*** Head3\n"))
706 ;; Visible.
707 (goto-char (point-min))
708 (forward-line)
709 (org-cycle)
710 (should (equal (org-export-as (org-test-default-backend) nil 'visible)
711 "* Head1\n"))
712 ;; Region.
713 (goto-char (point-min))
714 (forward-line 3)
715 (transient-mark-mode 1)
716 (push-mark (point) t t)
717 (goto-char (point-at-eol))
718 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
719 ;; Subtree with a code block calling another block outside.
720 (should
721 (equal ": 3\n"
722 (org-test-with-temp-text "
723 * Head1
724 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
725 <<test>>
726 #+END_SRC
727 * Head2
728 #+NAME: test
729 #+BEGIN_SRC emacs-lisp
730 \(+ 1 2)
731 #+END_SRC"
732 (forward-line 1)
733 (org-export-as (org-test-default-backend) 'subtree))))
734 ;; Body only.
735 (let ((backend (org-test-default-backend)))
736 (setf (org-export-backend-transcoders backend)
737 (cons '(template . (lambda (body i)
738 (format "BEGIN\n%sEND" body)))
739 (org-export-backend-transcoders backend)))
740 (org-test-with-temp-text "Text"
741 (should (equal (org-export-as backend nil nil 'body-only)
742 "Text\n"))
743 (should (equal (org-export-as backend) "BEGIN\nText\nEND")))))
745 (ert-deftest test-org-export/output-file-name ()
746 "Test `org-export-output-file-name' specifications."
747 ;; Export from a file: name is built from original file name.
748 (should
749 (org-test-with-temp-text-in-file "Test"
750 (equal (concat (file-name-as-directory ".")
751 (file-name-nondirectory
752 (file-name-sans-extension (buffer-file-name))))
753 (file-name-sans-extension (org-export-output-file-name ".ext")))))
754 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
755 (should
756 (org-test-with-temp-text-in-file
757 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
758 (equal (org-export-output-file-name ".ext" t) "./test.ext")))
759 ;; From a buffer not associated to a file, too.
760 (should
761 (org-test-with-temp-text
762 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
763 (equal (org-export-output-file-name ".ext" t) "./test.ext")))
764 ;; When provided name is absolute, preserve it.
765 (should
766 (org-test-with-temp-text
767 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
768 (expand-file-name "test"))
769 (file-name-absolute-p (org-export-output-file-name ".ext" t))))
770 ;; When PUB-DIR argument is provided, use it.
771 (should
772 (org-test-with-temp-text-in-file "Test"
773 (equal (file-name-directory
774 (org-export-output-file-name ".ext" nil "dir/"))
775 "dir/")))
776 ;; When returned name would overwrite original file, add EXTENSION
777 ;; another time.
778 (should
779 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
780 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
782 (ert-deftest test-org-export/expand-include ()
783 "Test file inclusion in an Org buffer."
784 ;; Error when file isn't specified.
785 (should-error
786 (org-test-with-temp-text "#+INCLUDE: dummy.org"
787 (org-export-expand-include-keyword)))
788 ;; Full insertion with recursive inclusion.
789 (org-test-with-temp-text
790 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
791 (org-export-expand-include-keyword)
792 (should (equal (buffer-string)
793 "Small Org file with an include keyword.
795 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
797 Success!
799 * Heading
800 body\n")))
801 ;; Localized insertion.
802 (org-test-with-temp-text
803 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
804 org-test-dir)
805 (org-export-expand-include-keyword)
806 (should (equal (buffer-string)
807 "Small Org file with an include keyword.\n")))
808 ;; Insertion with constraints on headlines level.
809 (should
810 (equal
811 "* Top heading\n** Heading\nbody\n"
812 (org-test-with-temp-text
813 (format
814 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
815 org-test-dir)
816 (org-export-expand-include-keyword)
817 (buffer-string))))
818 (should
819 (equal
820 "* Top heading\n* Heading\nbody\n"
821 (org-test-with-temp-text
822 (format
823 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
824 org-test-dir)
825 (org-export-expand-include-keyword)
826 (buffer-string))))
827 ;; Inclusion within an example block.
828 (org-test-with-temp-text
829 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
830 org-test-dir)
831 (org-export-expand-include-keyword)
832 (should
833 (equal
834 (buffer-string)
835 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
836 ;; Inclusion within a src-block.
837 (org-test-with-temp-text
838 (format
839 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
840 org-test-dir)
841 (org-export-expand-include-keyword)
842 (should (equal (buffer-string)
843 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
845 (ert-deftest test-org-export/expand-macro ()
846 "Test macro expansion in an Org buffer."
847 ;; Standard macro expansion.
848 (should
849 (equal "#+MACRO: macro1 value\nvalue\n"
850 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
851 (org-export-as (org-test-default-backend)))))
852 ;; Expand specific macros.
853 (should
854 (equal "me 2012-03-29 me@here Title\n"
855 (org-test-with-temp-text
857 #+TITLE: Title
858 #+DATE: 2012-03-29
859 #+AUTHOR: me
860 #+EMAIL: me@here
861 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
862 (let ((output (org-export-as (org-test-default-backend))))
863 (substring output (string-match ".*\n\\'" output))))))
864 ;; Expand specific macros when property contained a regular macro
865 ;; already.
866 (should
867 (equal "value\n"
868 (org-test-with-temp-text "
869 #+MACRO: macro1 value
870 #+TITLE: {{{macro1}}}
871 {{{title}}}"
872 (let ((output (org-export-as (org-test-default-backend))))
873 (substring output (string-match ".*\n\\'" output))))))
874 ;; Expand macros with templates in included files.
875 (should
876 (equal "success\n"
877 (org-test-with-temp-text
878 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
879 {{{included-macro}}}" org-test-dir)
880 (let ((output (org-export-as (org-test-default-backend))))
881 (substring output (string-match ".*\n\\'" output)))))))
883 (ert-deftest test-org-export/user-ignore-list ()
884 "Test if `:ignore-list' accepts user input."
885 (let ((backend (org-test-default-backend)))
886 (setf (org-export-backend-transcoders backend)
887 (cons '(template . (lambda (body i)
888 (format "BEGIN\n%sEND" body)))
889 (org-export-backend-transcoders backend)))
890 (org-test-with-temp-text "Text"
891 (should (equal (org-export-as backend nil nil 'body-only)
892 "Text\n"))
893 (should (equal (org-export-as backend) "BEGIN\nText\nEND"))))
894 (should
895 (equal
896 "* Head1\n"
897 (let ((org-export-filter-parse-tree-functions
898 '((lambda (data backend info)
899 ;; Ignore headlines with the word "note" in their title.
900 (org-element-map data 'headline
901 (lambda (headline)
902 (when (string-match "\\<note\\>"
903 (org-element-property :raw-value
904 headline))
905 (org-export-ignore-element headline info)))
906 info)
907 data))))
908 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
909 (org-export-as (org-test-default-backend)))))))
911 (ert-deftest test-org-export/before-processing-hook ()
912 "Test `org-export-before-processing-hook'."
913 (should
914 (equal
915 "#+MACRO: mac val\nTest\n"
916 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
917 (let ((org-export-before-processing-hook
918 '((lambda (backend)
919 (while (re-search-forward "{{{" nil t)
920 (let ((object (org-element-context)))
921 (when (eq (org-element-type object) 'macro)
922 (delete-region
923 (org-element-property :begin object)
924 (org-element-property :end object)))))))))
925 (org-export-as (org-test-default-backend)))))))
927 (ert-deftest test-org-export/before-parsing-hook ()
928 "Test `org-export-before-parsing-hook'."
929 (should
930 (equal "Body 1\nBody 2\n"
931 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
932 (let ((org-export-before-parsing-hook
933 '((lambda (backend)
934 (goto-char (point-min))
935 (while (re-search-forward org-outline-regexp-bol nil t)
936 (delete-region
937 (point-at-bol) (progn (forward-line) (point))))))))
938 (org-export-as (org-test-default-backend)))))))
942 ;;; Affiliated Keywords
944 (ert-deftest test-org-export/read-attribute ()
945 "Test `org-export-read-attribute' specifications."
946 ;; Standard test.
947 (should
948 (equal
949 (org-export-read-attribute
950 :attr_html
951 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
952 (org-element-at-point)))
953 '(:a "1" :b "2")))
954 ;; Return nil on empty attribute.
955 (should-not
956 (org-export-read-attribute
957 :attr_html
958 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
959 ;; Return nil on "nil" string.
960 (should
961 (equal '(:a nil :b nil)
962 (org-export-read-attribute
963 :attr_html
964 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
965 (org-element-at-point)))))
966 ;; Return nil on empty string.
967 (should
968 (equal '(:a nil :b nil)
969 (org-export-read-attribute
970 :attr_html
971 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
972 (org-element-at-point)))))
973 ;; Return empty string when value is "".
974 (should
975 (equal '(:a "")
976 (org-export-read-attribute
977 :attr_html
978 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
979 (org-element-at-point)))))
980 ;; Return \"\" when value is """".
981 (should
982 (equal '(:a "\"\"")
983 (org-export-read-attribute
984 :attr_html
985 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
986 (org-element-at-point)))))
987 ;; Ignore text before first property.
988 (should-not
989 (member "ignore"
990 (org-export-read-attribute
991 :attr_html
992 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
993 (org-element-at-point))))))
995 (ert-deftest test-org-export/get-caption ()
996 "Test `org-export-get-caption' specifications."
997 ;; Without optional argument, return long caption
998 (should
999 (equal
1000 '("l")
1001 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1002 (org-export-get-caption (org-element-at-point)))))
1003 ;; With optional argument, return short caption.
1004 (should
1005 (equal
1006 '("s")
1007 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1008 (org-export-get-caption (org-element-at-point) t))))
1009 ;; Multiple lines are separated by white spaces.
1010 (should
1011 (equal
1012 '("a" " " "b")
1013 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1014 (org-export-get-caption (org-element-at-point))))))
1018 ;;; Back-End Tools
1020 (ert-deftest test-org-export/define-backend ()
1021 "Test back-end definition and accessors."
1022 ;; Translate table.
1023 (should
1024 (equal '((headline . my-headline-test))
1025 (let (org-export--registered-backends)
1026 (org-export-define-backend 'test '((headline . my-headline-test)))
1027 (org-export-get-all-transcoders 'test))))
1028 ;; Filters.
1029 (should
1030 (equal '((:filter-headline . my-filter))
1031 (let (org-export--registered-backends)
1032 (org-export-define-backend 'test
1033 '((headline . my-headline-test))
1034 :filters-alist '((:filter-headline . my-filter)))
1035 (org-export-backend-filters (org-export-get-backend 'test)))))
1036 ;; Options.
1037 (should
1038 (equal '((:prop value))
1039 (let (org-export--registered-backends)
1040 (org-export-define-backend 'test
1041 '((headline . my-headline-test))
1042 :options-alist '((:prop value)))
1043 (org-export-backend-options (org-export-get-backend 'test)))))
1044 ;; Menu.
1045 (should
1046 (equal '(?k "Test Export" test)
1047 (let (org-export--registered-backends)
1048 (org-export-define-backend 'test
1049 '((headline . my-headline-test))
1050 :menu-entry '(?k "Test Export" test))
1051 (org-export-backend-menu (org-export-get-backend 'test)))))
1052 ;; Export Blocks.
1053 (should
1054 (equal '(("TEST" . org-element-export-block-parser))
1055 (let (org-export--registered-backends org-element-block-name-alist)
1056 (org-export-define-backend 'test
1057 '((headline . my-headline-test))
1058 :export-block '("test"))
1059 org-element-block-name-alist))))
1061 (ert-deftest test-org-export/define-derived-backend ()
1062 "Test `org-export-define-derived-backend' specifications."
1063 ;; Error when parent back-end is not defined.
1064 (should-error
1065 (let (org-export--registered-backends)
1066 (org-export-define-derived-backend 'test 'parent)))
1067 ;; Append translation table to parent's.
1068 (should
1069 (equal '((:headline . test) (:headline . parent))
1070 (let (org-export--registered-backends)
1071 (org-export-define-backend 'parent '((:headline . parent)))
1072 (org-export-define-derived-backend 'test 'parent
1073 :translate-alist '((:headline . test)))
1074 (org-export-get-all-transcoders 'test))))
1075 ;; Options defined in the new back have priority over those defined
1076 ;; in parent.
1077 (should
1078 (eq 'test
1079 (let (org-export--registered-backends)
1080 (org-export-define-backend 'parent
1081 '((:headline . parent))
1082 :options-alist '((:a nil nil 'parent)))
1083 (org-export-define-derived-backend 'test 'parent
1084 :options-alist '((:a nil nil 'test)))
1085 (plist-get (org-export--get-global-options
1086 (org-export-get-backend 'test))
1087 :a)))))
1089 (ert-deftest test-org-export/derived-backend-p ()
1090 "Test `org-export-derived-backend-p' specifications."
1091 ;; Non-nil with direct match.
1092 (should
1093 (let (org-export--registered-backends)
1094 (org-export-define-backend 'test '((headline . test)))
1095 (org-export-derived-backend-p 'test 'test)))
1096 (should
1097 (let (org-export--registered-backends)
1098 (org-export-define-backend 'test '((headline . test)))
1099 (org-export-define-derived-backend 'test2 'test)
1100 (org-export-derived-backend-p 'test2 'test2)))
1101 ;; Non-nil with a direct parent.
1102 (should
1103 (let (org-export--registered-backends)
1104 (org-export-define-backend 'test '((headline . test)))
1105 (org-export-define-derived-backend 'test2 'test)
1106 (org-export-derived-backend-p 'test2 'test)))
1107 ;; Non-nil with an indirect parent.
1108 (should
1109 (let (org-export--registered-backends)
1110 (org-export-define-backend 'test '((headline . test)))
1111 (org-export-define-derived-backend 'test2 'test)
1112 (org-export-define-derived-backend 'test3 'test2)
1113 (org-export-derived-backend-p 'test3 'test)))
1114 ;; Nil otherwise.
1115 (should-not
1116 (let (org-export--registered-backends)
1117 (org-export-define-backend 'test '((headline . test)))
1118 (org-export-define-backend 'test2 '((headline . test2)))
1119 (org-export-derived-backend-p 'test2 'test)))
1120 (should-not
1121 (let (org-export--registered-backends)
1122 (org-export-define-backend 'test '((headline . test)))
1123 (org-export-define-backend 'test2 '((headline . test2)))
1124 (org-export-define-derived-backend 'test3 'test2)
1125 (org-export-derived-backend-p 'test3 'test))))
1127 (ert-deftest test-org-export/get-all-transcoders ()
1128 "Test `org-export-get-all-transcoders' specifications."
1129 ;; Return nil when back-end cannot be found.
1130 (should-not (org-export-get-all-transcoders nil))
1131 ;; Same as `org-export-transcoders' if no parent.
1132 (should
1133 (equal '((headline . ignore))
1134 (org-export-get-all-transcoders
1135 (org-export-create-backend
1136 :transcoders '((headline . ignore))))))
1137 ;; But inherit from all ancestors whenever possible.
1138 (should
1139 (equal '((section . ignore) (headline . ignore))
1140 (let (org-export--registered-backends)
1141 (org-export-define-backend 'b1 '((headline . ignore)))
1142 (org-export-get-all-transcoders
1143 (org-export-create-backend
1144 :parent 'b1 :transcoders '((section . ignore)))))))
1145 (should
1146 (equal '((paragraph . ignore) (section . ignore) (headline . ignore))
1147 (let (org-export--registered-backends)
1148 (org-export-define-backend 'b1 '((headline . ignore)))
1149 (org-export-define-derived-backend 'b2 'b1
1150 :translate-alist '((section . ignore)))
1151 (org-export-get-all-transcoders
1152 (org-export-create-backend
1153 :parent 'b2 :transcoders '((paragraph . ignore)))))))
1154 ;; Back-end transcoders overrule inherited ones.
1155 (should
1156 (eq 'b
1157 (let (org-export--registered-backends)
1158 (org-export-define-backend 'b1 '((headline . a)))
1159 (cdr (assq 'headline
1160 (org-export-get-all-transcoders
1161 (org-export-create-backend
1162 :parent 'b1 :transcoders '((headline . b))))))))))
1164 (ert-deftest test-org-export/get-all-options ()
1165 "Test `org-export-get-all-options' specifications."
1166 ;; Return nil when back-end cannot be found.
1167 (should-not (org-export-get-all-options nil))
1168 ;; Same as `org-export-options' if no parent.
1169 (should
1170 (equal '((headline . ignore))
1171 (org-export-get-all-options
1172 (org-export-create-backend
1173 :options '((headline . ignore))))))
1174 ;; But inherit from all ancestors whenever possible.
1175 (should
1176 (equal '((:key2 value2) (:key1 value1))
1177 (let (org-export--registered-backends)
1178 (org-export-define-backend 'b1 nil :options-alist '((:key1 value1)))
1179 (org-export-get-all-options
1180 (org-export-create-backend
1181 :parent 'b1 :options '((:key2 value2)))))))
1182 (should
1183 (equal '((:key3 value3) (:key2 value2) (:key1 value1))
1184 (let (org-export--registered-backends)
1185 (org-export-define-backend 'b1 nil :options-alist '((:key1 value1)))
1186 (org-export-define-derived-backend 'b2 'b1
1187 :options-alist '((:key2 value2)))
1188 (org-export-get-all-options
1189 (org-export-create-backend
1190 :parent 'b2 :options '((:key3 value3)))))))
1191 ;; Back-end options overrule inherited ones.
1192 (should
1193 (eq 'b
1194 (let (org-export--registered-backends)
1195 (org-export-define-backend 'b1 nil :options-alist '((:key1 . a)))
1196 (cdr (assq :key1
1197 (org-export-get-all-options
1198 (org-export-create-backend
1199 :parent 'b1 :options '((:key1 . b))))))))))
1201 (ert-deftest test-org-export/get-all-filters ()
1202 "Test `org-export-get-all-filters' specifications."
1203 ;; Return nil when back-end cannot be found.
1204 (should-not (org-export-get-all-filters nil))
1205 ;; Same as `org-export-filters' if no parent.
1206 (should
1207 (equal '((:filter-headline . ignore))
1208 (org-export-get-all-filters
1209 (org-export-create-backend
1210 :filters '((:filter-headline . ignore))))))
1211 ;; But inherit from all ancestors whenever possible.
1212 (should
1213 (equal '((:filter-section . ignore) (:filter-headline . ignore))
1214 (let (org-export--registered-backends)
1215 (org-export-define-backend 'b1
1216 nil :filters-alist '((:filter-headline . ignore)))
1217 (org-export-get-all-filters
1218 (org-export-create-backend
1219 :parent 'b1 :filters '((:filter-section . ignore)))))))
1220 (should
1221 (equal '((:filter-paragraph . ignore)
1222 (:filter-section . ignore)
1223 (:filter-headline . ignore))
1224 (let (org-export--registered-backends)
1225 (org-export-define-backend 'b1
1226 nil :filters-alist '((:filter-headline . ignore)))
1227 (org-export-define-derived-backend 'b2 'b1
1228 :filters-alist '((:filter-section . ignore)))
1229 (org-export-get-all-filters
1230 (org-export-create-backend
1231 :parent 'b2 :filters '((:filter-paragraph . ignore)))))))
1232 ;; Back-end filters overrule inherited ones.
1233 (should
1234 (eq 'b
1235 (let (org-export--registered-backends)
1236 (org-export-define-backend 'b1 '((:filter-headline . a)))
1237 (cdr (assq :filter-headline
1238 (org-export-get-all-filters
1239 (org-export-create-backend
1240 :parent 'b1 :filters '((:filter-headline . b))))))))))
1242 (ert-deftest test-org-export/with-backend ()
1243 "Test `org-export-with-backend' definition."
1244 ;; Error when calling an undefined back-end
1245 (should-error (org-export-with-backend nil "Test"))
1246 ;; Error when called back-end doesn't have an appropriate
1247 ;; transcoder.
1248 (should-error
1249 (org-export-with-backend
1250 (org-export-create-backend :transcoders '((headline . ignore)))
1251 "Test"))
1252 ;; Otherwise, export using correct transcoder
1253 (should
1254 (equal "Success"
1255 (let (org-export--registered-backends)
1256 (org-export-define-backend 'test
1257 '((plain-text . (lambda (text contents info) "Failure"))))
1258 (org-export-define-backend 'test2
1259 '((plain-text . (lambda (text contents info) "Success"))))
1260 (org-export-with-backend 'test2 "Test"))))
1261 ;; Provide correct back-end if transcoder needs to use recursive
1262 ;; calls anyway.
1263 (should
1264 (equal "Success\n"
1265 (let ((test-back-end
1266 (org-export-create-backend
1267 :transcoders
1268 '((headline . (lambda (headline contents info)
1269 (org-export-data
1270 (org-element-property :title headline)
1271 info)))
1272 (plain-text . (lambda (text info) "Success"))))))
1273 (org-export-string-as
1274 "* Test"
1275 (org-export-create-backend
1276 :transcoders
1277 '((headline . (lambda (headline contents info)
1278 (org-export-with-backend
1279 test-back-end headline contents info))))))))))
1281 (ert-deftest test-org-export/data-with-backend ()
1282 "Test `org-export-data-with-backend' specifications."
1283 ;; Error when calling an undefined back-end.
1284 (should-error (org-export-data-with-backend nil "nil" nil))
1285 ;; Otherwise, export data recursively, using correct back-end.
1286 (should
1287 (equal
1288 "Success!"
1289 (org-export-data-with-backend
1290 '(bold nil "Test")
1291 (org-export-create-backend
1292 :transcoders
1293 '((plain-text . (lambda (text info) "Success"))
1294 (bold . (lambda (bold contents info) (concat contents "!")))))
1295 '(:with-emphasize t)))))
1299 ;;; Export Snippets
1301 (ert-deftest test-org-export/export-snippet ()
1302 "Test export snippets transcoding."
1303 ;; Standard test.
1304 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1305 (let ((backend (org-test-default-backend)))
1306 (setf (org-export-backend-name backend) 'test)
1307 (setf (org-export-backend-transcoders backend)
1308 (cons (cons 'export-snippet
1309 (lambda (snippet contents info)
1310 (when (eq (org-export-snippet-backend snippet) 'test)
1311 (org-element-property :value snippet))))
1312 (org-export-backend-transcoders backend)))
1313 (let ((org-export-snippet-translation-alist nil))
1314 (should (equal (org-export-as backend) "A\n")))
1315 (let ((org-export-snippet-translation-alist '(("t" . "test"))))
1316 (should (equal (org-export-as backend) "AB\n")))))
1317 ;; Ignored export snippets do not remove any blank.
1318 (should
1319 (equal "begin end\n"
1320 (org-test-with-parsed-data "begin @@test:A@@ end"
1321 (org-export-data-with-backend
1322 tree
1323 (org-export-create-backend
1324 :transcoders
1325 '((paragraph . (lambda (paragraph contents info) contents))
1326 (section . (lambda (section contents info) contents))))
1327 info)))))
1331 ;;; Footnotes
1333 (ert-deftest test-org-export/footnotes ()
1334 "Test footnotes specifications."
1335 (let ((org-footnote-section nil)
1336 (org-export-with-footnotes t))
1337 ;; 1. Read every type of footnote.
1338 (should
1339 (equal
1340 '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
1341 (org-test-with-parsed-data
1342 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1343 (org-element-map tree 'footnote-reference
1344 (lambda (ref)
1345 (let ((def (org-export-get-footnote-definition ref info)))
1346 (cons (org-export-get-footnote-number ref info)
1347 (if (eq (org-element-property :type ref) 'inline) (car def)
1348 (car (org-element-contents
1349 (car (org-element-contents def))))))))
1350 info))))
1351 ;; 2. Test nested footnotes order.
1352 (should
1353 (equal
1354 '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
1355 (org-test-with-parsed-data
1356 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1357 (org-element-map tree 'footnote-reference
1358 (lambda (ref)
1359 (when (org-export-footnote-first-reference-p ref info)
1360 (cons (org-export-get-footnote-number ref info)
1361 (org-element-property :label ref))))
1362 info))))
1363 ;; 3. Test nested footnote in invisible definitions.
1364 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1365 ;; Hide definitions.
1366 (narrow-to-region (point) (point-at-eol))
1367 (let* ((tree (org-element-parse-buffer))
1368 (info (org-combine-plists
1369 `(:parse-tree ,tree)
1370 (org-export-collect-tree-properties
1371 tree (org-export-get-environment)))))
1372 ;; Both footnotes should be seen.
1373 (should
1374 (= (length (org-export-collect-footnote-definitions tree info)) 2))))
1375 ;; 4. Test footnotes definitions collection.
1376 (should
1377 (= 4
1378 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1380 \[fn:2] B [fn:3] [fn::D].
1382 \[fn:3] C."
1383 (length (org-export-collect-footnote-definitions tree info)))))
1384 ;; 5. Test export of footnotes defined outside parsing scope.
1385 (should
1386 (equal
1387 "ParagraphOut of scope\n"
1388 (org-test-with-temp-text "[fn:1] Out of scope
1389 * Title
1390 Paragraph[fn:1]"
1391 (let ((backend (org-test-default-backend)))
1392 (setf (org-export-backend-transcoders backend)
1393 (cons (cons 'footnote-reference
1394 (lambda (fn contents info)
1395 (org-element-interpret-data
1396 (org-export-get-footnote-definition fn info))))
1397 (org-export-backend-transcoders backend)))
1398 (forward-line)
1399 (org-export-as backend 'subtree)))))
1400 ;; 6. Footnotes without a definition should be provided a fallback
1401 ;; definition.
1402 (should
1403 (org-test-with-parsed-data "[fn:1]"
1404 (org-export-get-footnote-definition
1405 (org-element-map tree 'footnote-reference 'identity info t) info)))
1406 ;; 7. Footnote section should be ignored in TOC and in headlines
1407 ;; numbering.
1408 (should
1409 (= 1 (let ((org-footnote-section "Footnotes"))
1410 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1411 (org-export-collect-headlines info))))))
1412 (should
1413 (equal '(2)
1414 (let ((org-footnote-section "Footnotes"))
1415 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1416 (org-element-map tree 'headline
1417 (lambda (hl)
1418 (when (equal (org-element-property :raw-value hl) "H2")
1419 (org-export-get-headline-number hl info)))
1420 info t)))))))
1424 ;;; Headlines and Inlinetasks
1426 (ert-deftest test-org-export/get-relative-level ()
1427 "Test `org-export-get-relative-level' specifications."
1428 ;; Standard test.
1429 (should
1430 (equal '(1 2)
1431 (let ((org-odd-levels-only nil))
1432 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1433 (org-element-map tree 'headline
1434 (lambda (h) (org-export-get-relative-level h info))
1435 info)))))
1436 ;; Missing levels
1437 (should
1438 (equal '(1 3)
1439 (let ((org-odd-levels-only nil))
1440 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1441 (org-element-map tree 'headline
1442 (lambda (h) (org-export-get-relative-level h info))
1443 info))))))
1445 (ert-deftest test-org-export/low-level-p ()
1446 "Test `org-export-low-level-p' specifications."
1447 (should
1448 (equal
1449 '(no yes)
1450 (let ((org-odd-levels-only nil))
1451 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1452 (org-element-map tree 'headline
1453 (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
1454 (plist-put info :headline-levels 1)))))))
1456 (ert-deftest test-org-export/get-headline-number ()
1457 "Test `org-export-get-headline-number' specifications."
1458 ;; Standard test.
1459 (should
1460 (equal
1461 '((1) (1 1))
1462 (let ((org-odd-levels-only nil))
1463 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1464 (org-element-map tree 'headline
1465 (lambda (h) (org-export-get-headline-number h info))
1466 info)))))
1467 ;; Missing levels are replaced with 0.
1468 (should
1469 (equal
1470 '((1) (1 0 1))
1471 (let ((org-odd-levels-only nil))
1472 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1473 (org-element-map tree 'headline
1474 (lambda (h) (org-export-get-headline-number h info))
1475 info))))))
1477 (ert-deftest test-org-export/numbered-headline-p ()
1478 "Test `org-export-numbered-headline-p' specifications."
1479 ;; If `:section-numbers' is nil, never number headlines.
1480 (should-not
1481 (org-test-with-parsed-data "* Headline"
1482 (org-element-map tree 'headline
1483 (lambda (h) (org-export-numbered-headline-p h info))
1484 (plist-put info :section-numbers nil))))
1485 ;; If `:section-numbers' is a number, only number headlines with
1486 ;; a level greater that it.
1487 (should
1488 (equal
1489 '(yes no)
1490 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1491 (org-element-map tree 'headline
1492 (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
1493 (plist-put info :section-numbers 1)))))
1494 ;; Otherwise, headlines are always numbered.
1495 (should
1496 (org-test-with-parsed-data "* Headline"
1497 (org-element-map tree 'headline
1498 (lambda (h) (org-export-numbered-headline-p h info))
1499 (plist-put info :section-numbers t)))))
1501 (ert-deftest test-org-export/number-to-roman ()
1502 "Test `org-export-number-to-roman' specifications."
1503 ;; If number is negative, return it as a string.
1504 (should (equal (org-export-number-to-roman -1) "-1"))
1505 ;; Otherwise, return it as a roman number.
1506 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1508 (ert-deftest test-org-export/get-optional-title ()
1509 "Test `org-export-get-alt-title' specifications."
1510 ;; If ALT_TITLE property is defined, use it.
1511 (should
1512 (equal '("opt")
1513 (org-test-with-parsed-data
1514 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1515 (org-export-get-alt-title
1516 (org-element-map tree 'headline 'identity info t)
1517 info))))
1518 ;; Otherwise, fall-back to regular title.
1519 (should
1520 (equal '("Headline")
1521 (org-test-with-parsed-data "* Headline"
1522 (org-export-get-alt-title
1523 (org-element-map tree 'headline 'identity info t)
1524 info)))))
1526 (ert-deftest test-org-export/get-tags ()
1527 "Test `org-export-get-tags' specifications."
1528 (let ((org-export-exclude-tags '("noexport"))
1529 (org-export-select-tags '("export")))
1530 ;; Standard test: tags which are not a select tag, an exclude tag,
1531 ;; or specified as optional argument shouldn't be ignored.
1532 (should
1533 (org-test-with-parsed-data "* Headline :tag:"
1534 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1535 info)))
1536 ;; Exclude tags are removed.
1537 (should-not
1538 (org-test-with-parsed-data "* Headline :noexport:"
1539 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1540 info)))
1541 ;; Select tags are removed.
1542 (should-not
1543 (org-test-with-parsed-data "* Headline :export:"
1544 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1545 info)))
1546 (should
1547 (equal
1548 '("tag")
1549 (org-test-with-parsed-data "* Headline :tag:export:"
1550 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1551 info))))
1552 ;; Tags provided in the optional argument are also ignored.
1553 (should-not
1554 (org-test-with-parsed-data "* Headline :ignore:"
1555 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1556 info '("ignore"))))
1557 ;; Allow tag inheritance.
1558 (should
1559 (equal
1560 '(("tag") ("tag"))
1561 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1562 (org-element-map tree 'headline
1563 (lambda (hl) (org-export-get-tags hl info nil t)) info))))
1564 ;; Tag inheritance checks FILETAGS keywords.
1565 (should
1566 (equal
1567 '(("a" "b" "tag"))
1568 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1569 (org-element-map tree 'headline
1570 (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
1572 (ert-deftest test-org-export/get-node-property ()
1573 "Test`org-export-get-node-property' specifications."
1574 ;; Standard test.
1575 (should
1576 (equal "value"
1577 (org-test-with-parsed-data "* Headline
1578 :PROPERTIES:
1579 :prop: value
1580 :END:"
1581 (org-export-get-node-property
1582 :PROP (org-element-map tree 'headline 'identity nil t)))))
1583 ;; Test inheritance.
1584 (should
1585 (equal "value"
1586 (org-test-with-parsed-data "* Parent
1587 :PROPERTIES:
1588 :prop: value
1589 :END:
1590 ** Headline
1591 Paragraph"
1592 (org-export-get-node-property
1593 :PROP (org-element-map tree 'paragraph 'identity nil t) t))))
1594 ;; Cannot return a value before the first headline.
1595 (should-not
1596 (org-test-with-parsed-data "Paragraph
1597 * Headline
1598 :PROPERTIES:
1599 :prop: value
1600 :END:"
1601 (org-export-get-node-property
1602 :PROP (org-element-map tree 'paragraph 'identity nil t)))))
1604 (ert-deftest test-org-export/get-category ()
1605 "Test `org-export-get-category' specifications."
1606 ;; Standard test.
1607 (should
1608 (equal "value"
1609 (org-test-with-parsed-data "* Headline
1610 :PROPERTIES:
1611 :CATEGORY: value
1612 :END:"
1613 (org-export-get-category
1614 (org-element-map tree 'headline 'identity nil t) info))))
1615 ;; Test inheritance from a parent headline.
1616 (should
1617 (equal '("value" "value")
1618 (org-test-with-parsed-data "* Headline1
1619 :PROPERTIES:
1620 :CATEGORY: value
1621 :END:
1622 ** Headline2"
1623 (org-element-map tree 'headline
1624 (lambda (hl) (org-export-get-category hl info)) info))))
1625 ;; Test inheritance from #+CATEGORY keyword
1626 (should
1627 (equal "value"
1628 (org-test-with-parsed-data "#+CATEGORY: value
1629 * Headline"
1630 (org-export-get-category
1631 (org-element-map tree 'headline 'identity nil t) info))))
1632 ;; Test inheritance from file name.
1633 (should
1634 (equal "test"
1635 (org-test-with-parsed-data "* Headline"
1636 (let ((info (plist-put info :input-file "~/test.org")))
1637 (org-export-get-category
1638 (org-element-map tree 'headline 'identity nil t) info)))))
1639 ;; Fall-back value.
1640 (should
1641 (equal "???"
1642 (org-test-with-parsed-data "* Headline"
1643 (org-export-get-category
1644 (org-element-map tree 'headline 'identity nil t) info)))))
1646 (ert-deftest test-org-export/first-sibling-p ()
1647 "Test `org-export-first-sibling-p' specifications."
1648 ;; Standard test.
1649 (should
1650 (equal
1651 '(yes yes no)
1652 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1653 (org-element-map tree 'headline
1654 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
1655 info))))
1656 ;; Ignore headlines not exported.
1657 (should
1658 (equal
1659 '(yes)
1660 (let ((org-export-exclude-tags '("ignore")))
1661 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1662 (org-element-map tree 'headline
1663 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
1664 info))))))
1666 (ert-deftest test-org-export/last-sibling-p ()
1667 "Test `org-export-last-sibling-p' specifications."
1668 ;; Standard test.
1669 (should
1670 (equal
1671 '(yes no yes)
1672 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1673 (org-element-map tree 'headline
1674 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
1675 info))))
1676 ;; Ignore headlines not exported.
1677 (should
1678 (equal
1679 '(yes)
1680 (let ((org-export-exclude-tags '("ignore")))
1681 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1682 (org-element-map tree 'headline
1683 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
1684 info))))))
1686 (ert-deftest test-org-export/handle-inlinetasks ()
1687 "Test inlinetask export."
1688 ;; Inlinetask with an exclude tag.
1689 (when (featurep 'org-inlinetask)
1690 (should
1691 (equal
1693 (let ((org-inlinetask-min-level 3))
1694 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1695 (org-export-as (org-test-default-backend)
1696 nil nil nil '(:exclude-tags ("noexp")))))))
1697 ;; Inlinetask with an include tag.
1698 (should
1699 (equal
1700 "* H2\n*** Inline :exp:\n"
1701 (let ((org-inlinetask-min-level 3)
1702 (org-tags-column 0))
1703 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1704 (org-export-as (org-test-default-backend)
1705 nil nil nil '(:select-tags ("exp")))))))
1706 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1707 (should
1708 (equal ""
1709 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1710 (org-inlinetask-min-level 3))
1711 (org-test-with-temp-text "*** TODO Inline"
1712 (org-export-as (org-test-default-backend)
1713 nil nil nil '(:with-tasks nil))))))))
1717 ;;; Keywords
1719 (ert-deftest test-org-export/get-date ()
1720 "Test `org-export-get-date' specifications."
1721 ;; Return a properly formatted string when
1722 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1723 ;; consists in a single timestamp.
1724 (should
1725 (equal "29 03 2012"
1726 (let ((org-export-date-timestamp-format "%d %m %Y"))
1727 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1728 (org-export-get-date info)))))
1729 ;; Return a secondary string otherwise.
1730 (should-not
1731 (stringp
1732 (let ((org-export-date-timestamp-format nil))
1733 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1734 (org-export-get-date info)))))
1735 (should
1736 (equal '("Date")
1737 (org-test-with-parsed-data "#+DATE: Date"
1738 (org-export-get-date info))))
1739 ;; Optional argument has precedence over
1740 ;; `org-export-date-timestamp-format'.
1741 (should
1742 (equal "29 03"
1743 (let ((org-export-date-timestamp-format "%d %m %Y"))
1744 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1745 (org-export-get-date info "%d %m"))))))
1749 ;;; Links
1751 (ert-deftest test-org-export/get-coderef-format ()
1752 "Test `org-export-get-coderef-format' specifications."
1753 ;; A link without description returns "%s"
1754 (should (equal (org-export-get-coderef-format "(ref:line)" nil)
1755 "%s"))
1756 ;; Return "%s" when path is matched within description.
1757 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1758 "desc %s"))
1759 ;; Otherwise return description.
1760 (should (equal (org-export-get-coderef-format "path" "desc")
1761 "desc")))
1763 (ert-deftest test-org-export/inline-image-p ()
1764 "Test `org-export-inline-image-p' specifications."
1765 (should
1766 (org-export-inline-image-p
1767 (org-test-with-temp-text "[[#id]]"
1768 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
1769 '(("custom-id" . "id")))))
1771 (ert-deftest test-org-export/fuzzy-link ()
1772 "Test fuzzy links specifications."
1773 ;; Link to an headline should return headline's number.
1774 (org-test-with-parsed-data
1775 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1776 (should
1777 ;; Note: Headline's number is in fact a list of numbers.
1778 (equal '(2)
1779 (org-element-map tree 'link
1780 (lambda (link)
1781 (org-export-get-ordinal
1782 (org-export-resolve-fuzzy-link link info) info)) info t))))
1783 ;; Link to a target in an item should return item's number.
1784 (org-test-with-parsed-data
1785 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1786 (should
1787 ;; Note: Item's number is in fact a list of numbers.
1788 (equal '(1 2)
1789 (org-element-map tree 'link
1790 (lambda (link)
1791 (org-export-get-ordinal
1792 (org-export-resolve-fuzzy-link link info) info)) info t))))
1793 ;; Link to a target in a footnote should return footnote's number.
1794 (org-test-with-parsed-data "
1795 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1796 (should
1797 (equal '(2 3)
1798 (org-element-map tree 'link
1799 (lambda (link)
1800 (org-export-get-ordinal
1801 (org-export-resolve-fuzzy-link link info) info)) info))))
1802 ;; Link to a named element should return sequence number of that
1803 ;; element.
1804 (org-test-with-parsed-data
1805 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1806 (should
1807 (= 2
1808 (org-element-map tree 'link
1809 (lambda (link)
1810 (org-export-get-ordinal
1811 (org-export-resolve-fuzzy-link link info) info)) info t))))
1812 ;; Link to a target not within an item, a table, a footnote
1813 ;; reference or definition should return section number.
1814 (org-test-with-parsed-data
1815 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1816 (should
1817 (equal '(2)
1818 (org-element-map tree 'link
1819 (lambda (link)
1820 (org-export-get-ordinal
1821 (org-export-resolve-fuzzy-link link info) info)) info t))))
1822 ;; Space are not significant when matching a fuzzy link.
1823 (should
1824 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1825 (org-element-map tree 'link
1826 (lambda (link) (org-export-resolve-fuzzy-link link info))
1827 info t)))
1828 ;; Statistics cookies are ignored for headline match.
1829 (should
1830 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1831 (org-element-map tree 'link
1832 (lambda (link) (org-export-resolve-fuzzy-link link info))
1833 info t)))
1834 (should
1835 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1836 (org-element-map tree 'link
1837 (lambda (link) (org-export-resolve-fuzzy-link link info))
1838 info t)))
1839 ;; Headline match is position dependent.
1840 (should-not
1841 (apply
1843 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
1844 (org-element-map tree 'link
1845 (lambda (link) (org-export-resolve-fuzzy-link link info)) info)))))
1847 (ert-deftest test-org-export/resolve-coderef ()
1848 "Test `org-export-resolve-coderef' specifications."
1849 (let ((org-coderef-label-format "(ref:%s)"))
1850 ;; 1. A link to a "-n -k -r" block returns line number.
1851 (org-test-with-parsed-data
1852 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1853 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1854 (org-test-with-parsed-data
1855 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1856 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1857 ;; 2. A link to a "-n -r" block returns line number.
1858 (org-test-with-parsed-data
1859 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1860 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1861 (org-test-with-parsed-data
1862 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1863 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1864 ;; 3. A link to a "-n" block returns coderef.
1865 (org-test-with-parsed-data
1866 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1867 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1868 (org-test-with-parsed-data
1869 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1870 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1871 ;; 4. A link to a "-r" block returns line number.
1872 (org-test-with-parsed-data
1873 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1874 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1875 (org-test-with-parsed-data
1876 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1877 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1878 ;; 5. A link to a block without a switch returns coderef.
1879 (org-test-with-parsed-data
1880 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1881 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1882 (org-test-with-parsed-data
1883 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1884 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1885 ;; 6. Correctly handle continued line numbers. A "+n" switch
1886 ;; should resume numbering from previous block with numbered
1887 ;; lines, ignoring blocks not numbering lines in the process.
1888 ;; A "-n" switch resets count.
1889 (org-test-with-parsed-data "
1890 #+BEGIN_EXAMPLE -n
1891 Text.
1892 #+END_EXAMPLE
1894 #+BEGIN_SRC emacs-lisp
1895 \(- 1 1)
1896 #+END_SRC
1898 #+BEGIN_SRC emacs-lisp +n -r
1899 \(+ 1 1) (ref:addition)
1900 #+END_SRC
1902 #+BEGIN_EXAMPLE -n -r
1903 Another text. (ref:text)
1904 #+END_EXAMPLE"
1905 (should (= (org-export-resolve-coderef "addition" info) 2))
1906 (should (= (org-export-resolve-coderef "text" info) 1)))
1907 ;; 7. Recognize coderef with user-specified syntax.
1908 (org-test-with-parsed-data
1909 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1910 (should (equal (org-export-resolve-coderef "text" info) "text")))))
1912 (ert-deftest test-org-export/resolve-fuzzy-link ()
1913 "Test `org-export-resolve-fuzzy-link' specifications."
1914 ;; Match target objects.
1915 (should
1916 (org-test-with-parsed-data "<<target>> [[target]]"
1917 (org-export-resolve-fuzzy-link
1918 (org-element-map tree 'link 'identity info t) info)))
1919 ;; Match named elements.
1920 (should
1921 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1922 (org-export-resolve-fuzzy-link
1923 (org-element-map tree 'link 'identity info t) info)))
1924 ;; Match exact headline's name.
1925 (should
1926 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1927 (org-export-resolve-fuzzy-link
1928 (org-element-map tree 'link 'identity info t) info)))
1929 ;; Targets objects have priority over named elements and headline
1930 ;; titles.
1931 (should
1932 (eq 'target
1933 (org-test-with-parsed-data
1934 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1935 (org-element-type
1936 (org-export-resolve-fuzzy-link
1937 (org-element-map tree 'link 'identity info t) info)))))
1938 ;; Named elements have priority over headline titles.
1939 (should
1940 (eq 'paragraph
1941 (org-test-with-parsed-data
1942 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1943 (org-element-type
1944 (org-export-resolve-fuzzy-link
1945 (org-element-map tree 'link 'identity info t) info)))))
1946 ;; If link's path starts with a "*", only match headline titles,
1947 ;; though.
1948 (should
1949 (eq 'headline
1950 (org-test-with-parsed-data
1951 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1952 (org-element-type
1953 (org-export-resolve-fuzzy-link
1954 (org-element-map tree 'link 'identity info t) info)))))
1955 ;; Return nil if no match.
1956 (should-not
1957 (org-test-with-parsed-data "[[target]]"
1958 (org-export-resolve-fuzzy-link
1959 (org-element-map tree 'link 'identity info t) info)))
1960 ;; Match fuzzy link even when before first headline.
1961 (should
1962 (eq 'headline
1963 (org-test-with-parsed-data "[[hl]]\n* hl"
1964 (org-element-type
1965 (org-export-resolve-fuzzy-link
1966 (org-element-map tree 'link 'identity info t) info))))))
1968 (ert-deftest test-org-export/resolve-id-link ()
1969 "Test `org-export-resolve-id-link' specifications."
1970 ;; 1. Regular test for custom-id link.
1971 (org-test-with-parsed-data "* Headline1
1972 :PROPERTIES:
1973 :CUSTOM_ID: test
1974 :END:
1975 * Headline 2
1976 \[[#test]]"
1977 (should
1978 (org-export-resolve-id-link
1979 (org-element-map tree 'link 'identity info t) info)))
1980 ;; 2. Failing test for custom-id link.
1981 (org-test-with-parsed-data "* Headline1
1982 :PROPERTIES:
1983 :CUSTOM_ID: test
1984 :END:
1985 * Headline 2
1986 \[[#no-match]]"
1987 (should-not
1988 (org-export-resolve-id-link
1989 (org-element-map tree 'link 'identity info t) info)))
1990 ;; 3. Test for internal id target.
1991 (org-test-with-parsed-data "* Headline1
1992 :PROPERTIES:
1993 :ID: aaaa
1994 :END:
1995 * Headline 2
1996 \[[id:aaaa]]"
1997 (should
1998 (org-export-resolve-id-link
1999 (org-element-map tree 'link 'identity info t) info)))
2000 ;; 4. Test for external id target.
2001 (org-test-with-parsed-data "[[id:aaaa]]"
2002 (should
2003 (org-export-resolve-id-link
2004 (org-element-map tree 'link 'identity info t)
2005 (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
2007 (ert-deftest test-org-export/resolve-radio-link ()
2008 "Test `org-export-resolve-radio-link' specifications."
2009 ;; Standard test.
2010 (should
2011 (org-test-with-temp-text "<<<radio>>> radio"
2012 (org-update-radio-target-regexp)
2013 (let* ((tree (org-element-parse-buffer))
2014 (info `(:parse-tree ,tree)))
2015 (org-export-resolve-radio-link
2016 (org-element-map tree 'link 'identity info t)
2017 info))))
2018 ;; Radio targets are case-insensitive.
2019 (should
2020 (org-test-with-temp-text "<<<RADIO>>> radio"
2021 (org-update-radio-target-regexp)
2022 (let* ((tree (org-element-parse-buffer))
2023 (info `(:parse-tree ,tree)))
2024 (org-export-resolve-radio-link
2025 (org-element-map tree 'link 'identity info t)
2026 info))))
2027 ;; Radio target with objects.
2028 (should
2029 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2030 (org-update-radio-target-regexp)
2031 (let* ((tree (org-element-parse-buffer))
2032 (info `(:parse-tree ,tree)))
2033 (org-export-resolve-radio-link
2034 (org-element-map tree 'link 'identity info t)
2035 info))))
2036 ;; Radio target with objects at its beginning.
2037 (should
2038 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2039 (org-update-radio-target-regexp)
2040 (let* ((tree (org-element-parse-buffer))
2041 (info `(:parse-tree ,tree)))
2042 (org-export-resolve-radio-link
2043 (org-element-map tree 'link 'identity info t)
2044 info))))
2045 ;; Radio link next to an apostrophe.
2046 (should
2047 (org-test-with-temp-text "<<<radio>>> radio's"
2048 (org-update-radio-target-regexp)
2049 (let* ((tree (org-element-parse-buffer))
2050 (info `(:parse-tree ,tree)))
2051 (org-export-resolve-radio-link
2052 (org-element-map tree 'link 'identity info t)
2053 info))))
2054 ;; Multiple radio targets.
2055 (should
2056 (equal '("radio1" "radio2")
2057 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2058 (org-update-radio-target-regexp)
2059 (let* ((tree (org-element-parse-buffer))
2060 (info `(:parse-tree ,tree)))
2061 (org-element-map tree 'link
2062 (lambda (link)
2063 (org-element-property
2064 :value (org-export-resolve-radio-link link info)))
2065 info)))))
2066 ;; Radio target is whitespace insensitive.
2067 (should
2068 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2069 (org-update-radio-target-regexp)
2070 (let* ((tree (org-element-parse-buffer))
2071 (info `(:parse-tree ,tree)))
2072 (org-element-map tree 'link
2073 (lambda (link) (org-export-resolve-radio-link link info)) info t)))))
2077 ;;; Src-block and example-block
2079 (ert-deftest test-org-export/unravel-code ()
2080 "Test `org-export-unravel-code' function."
2081 ;; Code without reference.
2082 (should
2083 (equal '("(+ 1 1)\n")
2084 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2085 (org-export-unravel-code (org-element-at-point)))))
2086 ;; Code with reference.
2087 (should
2088 (equal '("(+ 1 1)\n" (1 . "test"))
2089 (org-test-with-temp-text
2090 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2091 (let ((org-coderef-label-format "(ref:%s)"))
2092 (org-export-unravel-code (org-element-at-point))))))
2093 ;; Code with user-defined reference.
2094 (should
2095 (equal
2096 '("(+ 1 1)\n" (1 . "test"))
2097 (org-test-with-temp-text
2098 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2099 (let ((org-coderef-label-format "(ref:%s)"))
2100 (org-export-unravel-code (org-element-at-point))))))
2101 ;; Code references keys are relative to the current block.
2102 (should
2103 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 . "one"))
2104 (org-test-with-temp-text "
2105 #+BEGIN_EXAMPLE -n
2106 \(+ 1 1)
2107 #+END_EXAMPLE
2108 #+BEGIN_EXAMPLE +n
2109 \(+ 2 2)
2110 \(+ 3 3) (ref:one)
2111 #+END_EXAMPLE"
2112 (goto-line 5)
2113 (let ((org-coderef-label-format "(ref:%s)"))
2114 (org-export-unravel-code (org-element-at-point)))))))
2116 (ert-deftest test-org-export/format-code-default ()
2117 "Test `org-export-format-code-default' specifications."
2118 ;; Return the empty string when code is empty.
2119 (should
2120 (equal ""
2121 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2122 (org-export-format-code-default
2123 (org-element-map tree 'src-block 'identity info t) info))))
2124 ;; Number lines, two whitespace characters before the actual loc.
2125 (should
2126 (equal "1 a\n2 b\n"
2127 (org-test-with-parsed-data
2128 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2129 (org-export-format-code-default
2130 (org-element-map tree 'src-block 'identity info t) info))))
2131 ;; Put references 6 whitespace characters after the widest line,
2132 ;; wrapped within parenthesis.
2133 (should
2134 (equal "123 (a)\n1 (b)\n"
2135 (let ((org-coderef-label-format "(ref:%s)"))
2136 (org-test-with-parsed-data
2137 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2138 (org-export-format-code-default
2139 (org-element-map tree 'src-block 'identity info t) info))))))
2143 ;;; Smart Quotes
2145 (ert-deftest test-org-export/activate-smart-quotes ()
2146 "Test `org-export-activate-smart-quotes' specifications."
2147 ;; Opening double quotes: standard test.
2148 (should
2149 (equal
2150 '("some &ldquo;paragraph")
2151 (let ((org-export-default-language "en"))
2152 (org-test-with-parsed-data "some \"paragraph"
2153 (org-element-map tree 'plain-text
2154 (lambda (s) (org-export-activate-smart-quotes s :html info))
2155 info)))))
2156 ;; Opening quotes: at the beginning of a paragraph.
2157 (should
2158 (equal
2159 '("&ldquo;begin")
2160 (let ((org-export-default-language "en"))
2161 (org-test-with-parsed-data "\"begin"
2162 (org-element-map tree 'plain-text
2163 (lambda (s) (org-export-activate-smart-quotes s :html info))
2164 info)))))
2165 ;; Opening quotes: after an object.
2166 (should
2167 (equal
2168 '("&ldquo;begin")
2169 (let ((org-export-default-language "en"))
2170 (org-test-with-parsed-data "=verb= \"begin"
2171 (org-element-map tree 'plain-text
2172 (lambda (s) (org-export-activate-smart-quotes s :html info))
2173 info)))))
2174 ;; Closing quotes: standard test.
2175 (should
2176 (equal
2177 '("some&rdquo; paragraph")
2178 (let ((org-export-default-language "en"))
2179 (org-test-with-parsed-data "some\" paragraph"
2180 (org-element-map tree 'plain-text
2181 (lambda (s) (org-export-activate-smart-quotes s :html info))
2182 info)))))
2183 ;; Closing quotes: at the end of a paragraph.
2184 (should
2185 (equal
2186 '("end&rdquo;")
2187 (let ((org-export-default-language "en"))
2188 (org-test-with-parsed-data "end\""
2189 (org-element-map tree 'plain-text
2190 (lambda (s) (org-export-activate-smart-quotes s :html info))
2191 info)))))
2192 ;; Apostrophe: standard test.
2193 (should
2194 (equal
2195 '("It shouldn&rsquo;t fail")
2196 (let ((org-export-default-language "en"))
2197 (org-test-with-parsed-data "It shouldn't fail"
2198 (org-element-map tree 'plain-text
2199 (lambda (s) (org-export-activate-smart-quotes s :html info))
2200 info)))))
2201 ;; Apostrophe: before an object.
2202 (should
2203 (equal
2204 '("a&rsquo;")
2205 (let ((org-export-default-language "en"))
2206 (org-test-with-parsed-data "a'=b="
2207 (org-element-map tree 'plain-text
2208 (lambda (s) (org-export-activate-smart-quotes s :html info))
2209 info)))))
2210 ;; Apostrophe: after an object.
2211 (should
2212 (equal
2213 '("&rsquo;s")
2214 (let ((org-export-default-language "en"))
2215 (org-test-with-parsed-data "=code='s"
2216 (org-element-map tree 'plain-text
2217 (lambda (s) (org-export-activate-smart-quotes s :html info))
2218 info)))))
2219 ;; Special case: isolated quotes.
2220 (should
2221 (equal '("&ldquo;" "&rdquo;")
2222 (let ((org-export-default-language "en"))
2223 (org-test-with-parsed-data "\"$x$\""
2224 (org-element-map tree 'plain-text
2225 (lambda (s) (org-export-activate-smart-quotes s :html info))
2226 info)))))
2227 ;; Smart quotes in secondary strings.
2228 (should
2229 (equal '("&ldquo;" "&rdquo;")
2230 (let ((org-export-default-language "en"))
2231 (org-test-with-parsed-data "* \"$x$\""
2232 (org-element-map tree 'plain-text
2233 (lambda (s) (org-export-activate-smart-quotes s :html info))
2234 info)))))
2235 ;; Smart quotes in document keywords.
2236 (should
2237 (equal '("&ldquo;" "&rdquo;")
2238 (let ((org-export-default-language "en"))
2239 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2240 (org-element-map (plist-get info :title) 'plain-text
2241 (lambda (s) (org-export-activate-smart-quotes s :html info))
2242 info)))))
2243 ;; Smart quotes in parsed affiliated keywords.
2244 (should
2245 (equal '("&ldquo;" "&rdquo;" "Paragraph")
2246 (let ((org-export-default-language "en"))
2247 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2248 (org-element-map tree 'plain-text
2249 (lambda (s) (org-export-activate-smart-quotes s :html info))
2250 info nil nil t))))))
2254 ;;; Tables
2256 (ert-deftest test-org-export/special-column ()
2257 "Test if the table's special column is properly recognized."
2258 ;; 1. First column is special if it contains only a special marking
2259 ;; characters or empty cells.
2260 (org-test-with-temp-text "
2261 | ! | 1 |
2262 | | 2 |"
2263 (should
2264 (org-export-table-has-special-column-p
2265 (org-element-map
2266 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
2267 ;; 2. If the column contains anything else, it isn't special.
2268 (org-test-with-temp-text "
2269 | ! | 1 |
2270 | b | 2 |"
2271 (should-not
2272 (org-export-table-has-special-column-p
2273 (org-element-map
2274 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
2275 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2276 ;; and "!".
2277 (org-test-with-temp-text "
2278 | # | 1 |
2279 | ^ | 2 |
2280 | * | 3 |
2281 | _ | 4 |
2282 | / | 5 |
2283 | $ | 6 |
2284 | ! | 7 |"
2285 (should
2286 (org-export-table-has-special-column-p
2287 (org-element-map
2288 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
2289 ;; 4. A first column with only empty cells isn't considered as
2290 ;; special.
2291 (org-test-with-temp-text "
2292 | | 1 |
2293 | | 2 |"
2294 (should-not
2295 (org-export-table-has-special-column-p
2296 (org-element-map
2297 (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
2299 (ert-deftest test-org-export/table-row-is-special-p ()
2300 "Test `org-export-table-row-is-special-p' specifications."
2301 ;; 1. A row is special if it has a special marking character in the
2302 ;; special column.
2303 (org-test-with-parsed-data "| ! | 1 |"
2304 (should
2305 (org-export-table-row-is-special-p
2306 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
2307 ;; 2. A row is special when its first field is "/"
2308 (org-test-with-parsed-data "
2309 | / | 1 |
2310 | a | b |"
2311 (should
2312 (org-export-table-row-is-special-p
2313 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
2314 ;; 3. A row only containing alignment cookies is also considered as
2315 ;; special.
2316 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2317 (should
2318 (org-export-table-row-is-special-p
2319 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
2320 ;; 4. Everything else isn't considered as special.
2321 (org-test-with-parsed-data "| \alpha | | c |"
2322 (should-not
2323 (org-export-table-row-is-special-p
2324 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
2325 ;; 5. Table's rules are never considered as special rows.
2326 (org-test-with-parsed-data "|---+---|"
2327 (should-not
2328 (org-export-table-row-is-special-p
2329 (org-element-map tree 'table-row 'identity nil 'first-match) info))))
2331 (ert-deftest test-org-export/has-header-p ()
2332 "Test `org-export-table-has-header-p' specifications."
2333 ;; 1. With an header.
2334 (org-test-with-parsed-data "
2335 | a | b |
2336 |---+---|
2337 | c | d |"
2338 (should
2339 (org-export-table-has-header-p
2340 (org-element-map tree 'table 'identity info 'first-match)
2341 info)))
2342 ;; 2. Without an header.
2343 (org-test-with-parsed-data "
2344 | a | b |
2345 | c | d |"
2346 (should-not
2347 (org-export-table-has-header-p
2348 (org-element-map tree 'table 'identity info 'first-match)
2349 info)))
2350 ;; 3. Don't get fooled with starting and ending rules.
2351 (org-test-with-parsed-data "
2352 |---+---|
2353 | a | b |
2354 | c | d |
2355 |---+---|"
2356 (should-not
2357 (org-export-table-has-header-p
2358 (org-element-map tree 'table 'identity info 'first-match)
2359 info))))
2361 (ert-deftest test-org-export/table-row-group ()
2362 "Test `org-export-table-row-group' specifications."
2363 ;; 1. A rule creates a new group.
2364 (should
2365 (equal '(1 rule 2)
2366 (org-test-with-parsed-data "
2367 | a | b |
2368 |---+---|
2369 | 1 | 2 |"
2370 (org-element-map tree 'table-row
2371 (lambda (row)
2372 (if (eq (org-element-property :type row) 'rule) 'rule
2373 (org-export-table-row-group row info)))))))
2374 ;; 2. Special rows are ignored in count.
2375 (should
2376 (equal
2377 '(rule 1)
2378 (org-test-with-parsed-data "
2379 | / | < | > |
2380 |---|---+---|
2381 | | 1 | 2 |"
2382 (org-element-map tree 'table-row
2383 (lambda (row)
2384 (if (eq (org-element-property :type row) 'rule) 'rule
2385 (org-export-table-row-group row info)))
2386 info))))
2387 ;; 3. Double rules also are ignored in count.
2388 (should
2389 (equal '(1 rule rule 2)
2390 (org-test-with-parsed-data "
2391 | a | b |
2392 |---+---|
2393 |---+---|
2394 | 1 | 2 |"
2395 (org-element-map tree 'table-row
2396 (lambda (row)
2397 (if (eq (org-element-property :type row) 'rule) 'rule
2398 (org-export-table-row-group row info))))))))
2400 (ert-deftest test-org-export/table-row-number ()
2401 "Test `org-export-table-row-number' specifications."
2402 ;; Standard test. Number is 0-indexed.
2403 (should
2404 (equal '(0 1)
2405 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2406 (org-element-map tree 'table-row
2407 (lambda (row) (org-export-table-row-number row info)) info))))
2408 ;; Number ignores separators.
2409 (should
2410 (equal '(0 1)
2411 (org-test-with-parsed-data "
2412 | a | b | c |
2413 |---+---+---|
2414 | d | e | f |"
2415 (org-element-map tree 'table-row
2416 (lambda (row) (org-export-table-row-number row info)) info))))
2417 ;; Number ignores special rows.
2418 (should
2419 (equal '(0 1)
2420 (org-test-with-parsed-data "
2421 | / | < | > |
2422 | | b | c |
2423 |---+-----+-----|
2424 | | <c> | <c> |
2425 | | e | f |"
2426 (org-element-map tree 'table-row
2427 (lambda (row) (org-export-table-row-number row info)) info)))))
2429 (ert-deftest test-org-export/table-cell-width ()
2430 "Test `org-export-table-cell-width' specifications."
2431 ;; 1. Width is primarily determined by width cookies. If no cookie
2432 ;; is found, cell's width is nil.
2433 (org-test-with-parsed-data "
2434 | / | <l> | <6> | <l7> |
2435 | | a | b | c |"
2436 (should
2437 (equal
2438 '(nil 6 7)
2439 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
2440 (org-element-map tree 'table-cell 'identity info)))))
2441 ;; 2. The last width cookie has precedence.
2442 (org-test-with-parsed-data "
2443 | <6> |
2444 | <7> |
2445 | a |"
2446 (should
2447 (equal
2448 '(7)
2449 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
2450 (org-element-map tree 'table-cell 'identity info)))))
2451 ;; 3. Valid width cookies must have a specific row.
2452 (org-test-with-parsed-data "| <6> | cell |"
2453 (should
2454 (equal
2455 '(nil nil)
2456 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
2457 (org-element-map tree 'table-cell 'identity))))))
2459 (ert-deftest test-org-export/table-cell-alignment ()
2460 "Test `org-export-table-cell-alignment' specifications."
2461 ;; 1. Alignment is primarily determined by alignment cookies.
2462 (should
2463 (equal '(left center right)
2464 (let ((org-table-number-fraction 0.5)
2465 (org-table-number-regexp "^[0-9]+$"))
2466 (org-test-with-parsed-data "| <l> | <c> | <r> |"
2467 (mapcar (lambda (cell)
2468 (org-export-table-cell-alignment cell info))
2469 (org-element-map tree 'table-cell 'identity))))))
2470 ;; 2. The last alignment cookie has precedence.
2471 (should
2472 (equal '(right right right)
2473 (org-test-with-parsed-data "
2474 | <l8> |
2475 | cell |
2476 | <r9> |"
2477 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
2478 (org-element-map tree 'table-cell 'identity)))))
2479 ;; 3. If there's no cookie, cell's contents determine alignment.
2480 ;; A column mostly made of cells containing numbers will align
2481 ;; its cells to the right.
2482 (should
2483 (equal '(right right right)
2484 (let ((org-table-number-fraction 0.5)
2485 (org-table-number-regexp "^[0-9]+$"))
2486 (org-test-with-parsed-data "
2487 | 123 |
2488 | some text |
2489 | 12345 |"
2490 (mapcar (lambda (cell)
2491 (org-export-table-cell-alignment cell info))
2492 (org-element-map tree 'table-cell 'identity))))))
2493 ;; 4. Otherwise, they will be aligned to the left.
2494 (should
2495 (equal '(left left left)
2496 (org-test-with-parsed-data "
2497 | text |
2498 | some text |
2499 | \alpha |"
2500 (mapcar (lambda (cell)
2501 (org-export-table-cell-alignment cell info))
2502 (org-element-map tree 'table-cell 'identity info))))))
2504 (ert-deftest test-org-export/table-cell-borders ()
2505 "Test `org-export-table-cell-borders' specifications."
2506 ;; 1. Recognize various column groups indicators.
2507 (org-test-with-parsed-data "| / | < | > | <> |"
2508 (should
2509 (equal
2510 '((right bottom top) (left bottom top) (right bottom top)
2511 (right left bottom top))
2512 (mapcar (lambda (cell)
2513 (org-export-table-cell-borders cell info))
2514 (org-element-map tree 'table-cell 'identity)))))
2515 ;; 2. Accept shortcuts to define column groups.
2516 (org-test-with-parsed-data "| / | < | < |"
2517 (should
2518 (equal
2519 '((right bottom top) (right left bottom top) (left bottom top))
2520 (mapcar (lambda (cell)
2521 (org-export-table-cell-borders cell info))
2522 (org-element-map tree 'table-cell 'identity)))))
2523 ;; 3. A valid column groups row must start with a "/".
2524 (org-test-with-parsed-data "
2525 | | < |
2526 | a | b |"
2527 (should
2528 (equal '((top) (top) (bottom) (bottom))
2529 (mapcar (lambda (cell)
2530 (org-export-table-cell-borders cell info))
2531 (org-element-map tree 'table-cell 'identity)))))
2532 ;; 4. Take table rules into consideration.
2533 (org-test-with-parsed-data "
2534 | 1 |
2535 |---|
2536 | 2 |"
2537 (should
2538 (equal '((below top) (bottom above))
2539 (mapcar (lambda (cell)
2540 (org-export-table-cell-borders cell info))
2541 (org-element-map tree 'table-cell 'identity)))))
2542 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2543 ;; (resp. `bottom' and `below') borders. Any special row is
2544 ;; ignored.
2545 (org-test-with-parsed-data "
2546 |---+----|
2547 | / | |
2548 | | 1 |
2549 |---+----|"
2550 (should
2551 (equal '((bottom below top above))
2552 (last
2553 (mapcar (lambda (cell)
2554 (org-export-table-cell-borders cell info))
2555 (org-element-map tree 'table-cell 'identity)))))))
2557 (ert-deftest test-org-export/table-dimensions ()
2558 "Test `org-export-table-dimensions' specifications."
2559 ;; 1. Standard test.
2560 (org-test-with-parsed-data "
2561 | 1 | 2 | 3 |
2562 | 4 | 5 | 6 |"
2563 (should
2564 (equal '(2 . 3)
2565 (org-export-table-dimensions
2566 (org-element-map tree 'table 'identity info 'first-match) info))))
2567 ;; 2. Ignore horizontal rules and special columns.
2568 (org-test-with-parsed-data "
2569 | / | < | > |
2570 | 1 | 2 | 3 |
2571 |---+---+---|
2572 | 4 | 5 | 6 |"
2573 (should
2574 (equal '(2 . 3)
2575 (org-export-table-dimensions
2576 (org-element-map tree 'table 'identity info 'first-match) info)))))
2578 (ert-deftest test-org-export/table-cell-address ()
2579 "Test `org-export-table-cell-address' specifications."
2580 ;; 1. Standard test: index is 0-based.
2581 (org-test-with-parsed-data "| a | b |"
2582 (should
2583 (equal '((0 . 0) (0 . 1))
2584 (org-element-map tree 'table-cell
2585 (lambda (cell) (org-export-table-cell-address cell info))
2586 info))))
2587 ;; 2. Special column isn't counted, nor are special rows.
2588 (org-test-with-parsed-data "
2589 | / | <> |
2590 | | c |"
2591 (should
2592 (equal '(0 . 0)
2593 (org-export-table-cell-address
2594 (car (last (org-element-map tree 'table-cell 'identity info)))
2595 info))))
2596 ;; 3. Tables rules do not count either.
2597 (org-test-with-parsed-data "
2598 | a |
2599 |---|
2600 | b |
2601 |---|
2602 | c |"
2603 (should
2604 (equal '(2 . 0)
2605 (org-export-table-cell-address
2606 (car (last (org-element-map tree 'table-cell 'identity info)))
2607 info))))
2608 ;; 4. Return nil for special cells.
2609 (org-test-with-parsed-data "| / | a |"
2610 (should-not
2611 (org-export-table-cell-address
2612 (org-element-map tree 'table-cell 'identity nil 'first-match)
2613 info))))
2615 (ert-deftest test-org-export/get-table-cell-at ()
2616 "Test `org-export-get-table-cell-at' specifications."
2617 ;; 1. Address ignores special columns, special rows and rules.
2618 (org-test-with-parsed-data "
2619 | / | <> |
2620 | | a |
2621 |---+----|
2622 | | b |"
2623 (should
2624 (equal '("b")
2625 (org-element-contents
2626 (org-export-get-table-cell-at
2627 '(1 . 0)
2628 (org-element-map tree 'table 'identity info 'first-match)
2629 info)))))
2630 ;; 2. Return value for a non-existent address is nil.
2631 (org-test-with-parsed-data "| a |"
2632 (should-not
2633 (org-export-get-table-cell-at
2634 '(2 . 2)
2635 (org-element-map tree 'table 'identity info 'first-match)
2636 info)))
2637 (org-test-with-parsed-data "| / |"
2638 (should-not
2639 (org-export-get-table-cell-at
2640 '(0 . 0)
2641 (org-element-map tree 'table 'identity info 'first-match)
2642 info))))
2644 (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
2645 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2646 ;; 1. A cell at a beginning of a row always starts a column group.
2647 (org-test-with-parsed-data "| a |"
2648 (should
2649 (org-export-table-cell-starts-colgroup-p
2650 (org-element-map tree 'table-cell 'identity info 'first-match)
2651 info)))
2652 ;; 2. Special column should be ignored when determining the
2653 ;; beginning of the row.
2654 (org-test-with-parsed-data "
2655 | / | |
2656 | | a |"
2657 (should
2658 (org-export-table-cell-starts-colgroup-p
2659 (org-element-map tree 'table-cell 'identity info 'first-match)
2660 info)))
2661 ;; 2. Explicit column groups.
2662 (org-test-with-parsed-data "
2663 | / | | < |
2664 | a | b | c |"
2665 (should
2666 (equal
2667 '(yes no yes)
2668 (org-element-map tree 'table-cell
2669 (lambda (cell)
2670 (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
2671 info)))))
2673 (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
2674 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2675 ;; 1. A cell at the end of a row always ends a column group.
2676 (org-test-with-parsed-data "| a |"
2677 (should
2678 (org-export-table-cell-ends-colgroup-p
2679 (org-element-map tree 'table-cell 'identity info 'first-match)
2680 info)))
2681 ;; 2. Special column should be ignored when determining the
2682 ;; beginning of the row.
2683 (org-test-with-parsed-data "
2684 | / | |
2685 | | a |"
2686 (should
2687 (org-export-table-cell-ends-colgroup-p
2688 (org-element-map tree 'table-cell 'identity info 'first-match)
2689 info)))
2690 ;; 3. Explicit column groups.
2691 (org-test-with-parsed-data "
2692 | / | < | |
2693 | a | b | c |"
2694 (should
2695 (equal
2696 '(yes no yes)
2697 (org-element-map tree 'table-cell
2698 (lambda (cell)
2699 (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
2700 info)))))
2702 (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
2703 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2704 ;; 1. A row at the beginning of a table always starts a row group.
2705 ;; So does a row following a table rule.
2706 (org-test-with-parsed-data "
2707 | a |
2708 |---|
2709 | b |"
2710 (should
2711 (equal
2712 '(yes no yes)
2713 (org-element-map tree 'table-row
2714 (lambda (row)
2715 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
2716 info))))
2717 ;; 2. Special rows should be ignored when determining the beginning
2718 ;; of the row.
2719 (org-test-with-parsed-data "
2720 | / | < |
2721 | | a |
2722 |---+---|
2723 | / | < |
2724 | | b |"
2725 (should
2726 (equal
2727 '(yes no yes)
2728 (org-element-map tree 'table-row
2729 (lambda (row)
2730 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
2731 info)))))
2733 (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
2734 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2735 ;; 1. A row at the end of a table always ends a row group. So does
2736 ;; a row preceding a table rule.
2737 (org-test-with-parsed-data "
2738 | a |
2739 |---|
2740 | b |"
2741 (should
2742 (equal
2743 '(yes no yes)
2744 (org-element-map tree 'table-row
2745 (lambda (row)
2746 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
2747 info))))
2748 ;; 2. Special rows should be ignored when determining the beginning
2749 ;; of the row.
2750 (org-test-with-parsed-data "
2751 | | a |
2752 | / | < |
2753 |---+---|
2754 | | b |
2755 | / | < |"
2756 (should
2757 (equal
2758 '(yes no yes)
2759 (org-element-map tree 'table-row
2760 (lambda (row)
2761 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
2762 info)))))
2764 (ert-deftest test-org-export/table-row-starts-header-p ()
2765 "Test `org-export-table-row-starts-header-p' specifications."
2766 ;; 1. Only the row starting the first row group starts the table
2767 ;; header.
2768 (org-test-with-parsed-data "
2769 | a |
2770 | b |
2771 |---|
2772 | c |"
2773 (should
2774 (equal
2775 '(yes no no no)
2776 (org-element-map tree 'table-row
2777 (lambda (row)
2778 (if (org-export-table-row-starts-header-p row info) 'yes 'no))
2779 info))))
2780 ;; 2. A row cannot start an header if there's no header in the
2781 ;; table.
2782 (org-test-with-parsed-data "
2783 | a |
2784 |---|"
2785 (should-not
2786 (org-export-table-row-starts-header-p
2787 (org-element-map tree 'table-row 'identity info 'first-match)
2788 info))))
2790 (ert-deftest test-org-export/table-row-ends-header-p ()
2791 "Test `org-export-table-row-ends-header-p' specifications."
2792 ;; 1. Only the row starting the first row group starts the table
2793 ;; header.
2794 (org-test-with-parsed-data "
2795 | a |
2796 | b |
2797 |---|
2798 | c |"
2799 (should
2800 (equal
2801 '(no yes no no)
2802 (org-element-map tree 'table-row
2803 (lambda (row)
2804 (if (org-export-table-row-ends-header-p row info) 'yes 'no))
2805 info))))
2806 ;; 2. A row cannot start an header if there's no header in the
2807 ;; table.
2808 (org-test-with-parsed-data "
2809 | a |
2810 |---|"
2811 (should-not
2812 (org-export-table-row-ends-header-p
2813 (org-element-map tree 'table-row 'identity info 'first-match)
2814 info))))
2818 ;;; Tables of Contents
2820 (ert-deftest test-org-export/collect-headlines ()
2821 "Test `org-export-collect-headlines' specifications."
2822 ;; Standard test.
2823 (should
2824 (= 2
2825 (length
2826 (org-test-with-parsed-data "* H1\n** H2"
2827 (org-export-collect-headlines info)))))
2828 ;; Do not collect headlines below optional argument.
2829 (should
2830 (= 1
2831 (length
2832 (org-test-with-parsed-data "* H1\n** H2"
2833 (org-export-collect-headlines info 1)))))
2834 ;; Never collect headlines below maximum headline level.
2835 (should
2836 (= 1
2837 (length
2838 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
2839 (org-export-collect-headlines info)))))
2840 (should
2841 (= 1
2842 (length
2843 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
2844 (org-export-collect-headlines info 2))))))
2848 ;;; Templates
2850 (ert-deftest test-org-export/inner-template ()
2851 "Test `inner-template' translator specifications."
2852 (should
2853 (equal "Success!"
2854 (org-test-with-temp-text "* Headline"
2855 (org-export-as
2856 (org-export-create-backend
2857 :transcoders
2858 '((inner-template . (lambda (contents info) "Success!"))
2859 (headline . (lambda (h c i) "Headline"))))))))
2860 ;; Inner template is applied even in a "body-only" export.
2861 (should
2862 (equal "Success!"
2863 (org-test-with-temp-text "* Headline"
2864 (org-export-as
2865 (org-export-create-backend
2866 :transcoders '((inner-template . (lambda (c i) "Success!"))
2867 (headline . (lambda (h c i) "Headline"))))
2868 nil nil 'body-only)))))
2870 (ert-deftest test-org-export/template ()
2871 "Test `template' translator specifications."
2872 (should
2873 (equal "Success!"
2874 (org-test-with-temp-text "* Headline"
2875 (org-export-as
2876 (org-export-create-backend
2877 :transcoders '((template . (lambda (contents info) "Success!"))
2878 (headline . (lambda (h c i) "Headline"))))))))
2879 ;; Template is not applied in a "body-only" export.
2880 (should-not
2881 (equal "Success!"
2882 (org-test-with-temp-text "* Headline"
2883 (org-export-as
2884 (org-export-create-backend
2885 :transcoders '((template . (lambda (contents info) "Success!"))
2886 (headline . (lambda (h c i) "Headline"))))
2887 nil nil 'body-only)))))
2891 ;;; Topology
2893 (ert-deftest test-org-export/get-next-element ()
2894 "Test `org-export-get-next-element' specifications."
2895 ;; Standard test.
2896 (should
2897 (equal "b"
2898 (org-test-with-parsed-data "* Headline\n*a* b"
2899 (org-export-get-next-element
2900 (org-element-map tree 'bold 'identity info t) info))))
2901 ;; Return nil when no previous element.
2902 (should-not
2903 (org-test-with-parsed-data "* Headline\na *b*"
2904 (org-export-get-next-element
2905 (org-element-map tree 'bold 'identity info t) info)))
2906 ;; Non-exportable elements are ignored.
2907 (should-not
2908 (let ((org-export-with-timestamps nil))
2909 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2910 (org-export-get-next-element
2911 (org-element-map tree 'entity 'identity info t) info))))
2912 ;; Find next element in secondary strings.
2913 (should
2914 (eq 'verbatim
2915 (org-test-with-parsed-data "* a =verb="
2916 (org-element-type
2917 (org-export-get-next-element
2918 (org-element-map tree 'plain-text 'identity info t) info)))))
2919 (should
2920 (eq 'verbatim
2921 (org-test-with-parsed-data "* /italic/ =verb="
2922 (org-element-type
2923 (org-export-get-next-element
2924 (org-element-map tree 'italic 'identity info t) info)))))
2925 ;; Find next element in document keywords.
2926 (should
2927 (eq 'verbatim
2928 (org-test-with-parsed-data "#+TITLE: a =verb="
2929 (org-element-type
2930 (org-export-get-next-element
2931 (org-element-map
2932 (plist-get info :title) 'plain-text 'identity info t) info)))))
2933 ;; Find next element in parsed affiliated keywords.
2934 (should
2935 (eq 'verbatim
2936 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2937 (org-element-type
2938 (org-export-get-next-element
2939 (org-element-map tree 'plain-text 'identity info t nil t) info)))))
2940 ;; With optional argument N, return a list containing all the
2941 ;; following elements.
2942 (should
2943 (equal
2944 '(bold code underline)
2945 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2946 (mapcar 'car
2947 (org-export-get-next-element
2948 (org-element-map tree 'italic 'identity info t) info t)))))
2949 ;; When N is a positive integer, return a list containing up to
2950 ;; N following elements.
2951 (should
2952 (equal
2953 '(bold code)
2954 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2955 (mapcar 'car
2956 (org-export-get-next-element
2957 (org-element-map tree 'italic 'identity info t) info 2))))))
2959 (ert-deftest test-org-export/get-previous-element ()
2960 "Test `org-export-get-previous-element' specifications."
2961 ;; Standard test.
2962 (should
2963 (equal "a "
2964 (org-test-with-parsed-data "* Headline\na *b*"
2965 (org-export-get-previous-element
2966 (org-element-map tree 'bold 'identity info t) info))))
2967 ;; Return nil when no previous element.
2968 (should-not
2969 (org-test-with-parsed-data "* Headline\n*a* b"
2970 (org-export-get-previous-element
2971 (org-element-map tree 'bold 'identity info t) info)))
2972 ;; Non-exportable elements are ignored.
2973 (should-not
2974 (let ((org-export-with-timestamps nil))
2975 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2976 (org-export-get-previous-element
2977 (org-element-map tree 'entity 'identity info t) info))))
2978 ;; Find previous element in secondary strings.
2979 (should
2980 (eq 'verbatim
2981 (org-test-with-parsed-data "* =verb= a"
2982 (org-element-type
2983 (org-export-get-previous-element
2984 (org-element-map tree 'plain-text 'identity info t) info)))))
2985 (should
2986 (eq 'verbatim
2987 (org-test-with-parsed-data "* =verb= /italic/"
2988 (org-element-type
2989 (org-export-get-previous-element
2990 (org-element-map tree 'italic 'identity info t) info)))))
2991 ;; Find previous element in document keywords.
2992 (should
2993 (eq 'verbatim
2994 (org-test-with-parsed-data "#+TITLE: =verb= a"
2995 (org-element-type
2996 (org-export-get-previous-element
2997 (org-element-map
2998 (plist-get info :title) 'plain-text 'identity info t) info)))))
2999 ;; Find previous element in parsed affiliated keywords.
3000 (should
3001 (eq 'verbatim
3002 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3003 (org-element-type
3004 (org-export-get-previous-element
3005 (org-element-map tree 'plain-text 'identity info t nil t) info)))))
3006 ;; With optional argument N, return a list containing up to
3007 ;; N previous elements.
3008 (should
3009 (equal '(underline italic bold)
3010 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3011 (mapcar 'car
3012 (org-export-get-previous-element
3013 (org-element-map tree 'code 'identity info t) info t)))))
3014 ;; When N is a positive integer, return a list containing up to
3015 ;; N previous elements.
3016 (should
3017 (equal '(italic bold)
3018 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3019 (mapcar 'car
3020 (org-export-get-previous-element
3021 (org-element-map tree 'code 'identity info t) info 2))))))
3024 (provide 'test-ox)
3025 ;;; test-org-export.el end here