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