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