ox: Properly transfer bound variables through export process
[org-mode/org-tableheadings.git] / testing / lisp / test-ox.el
blob46f36eb8584ea33877779fbebd01542719ff84fa
1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012, 2013 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 (defmacro org-test-with-backend (backend &rest body)
28 "Execute body with an export back-end defined.
30 BACKEND is the name of the back-end. BODY is the body to
31 execute. The defined back-end simply returns parsed data as Org
32 syntax."
33 (declare (debug (form body)) (indent 1))
34 `(let ((org-export-registered-backends
35 ',(list
36 (list backend
37 :translate-alist
38 (let (transcode-table)
39 (dolist (type (append org-element-all-elements
40 org-element-all-objects)
41 transcode-table)
42 (push
43 (cons type
44 (lambda (obj contents info)
45 (funcall
46 (intern (format "org-element-%s-interpreter"
47 type))
48 obj contents)))
49 transcode-table)))))))
50 (progn ,@body)))
52 (defmacro org-test-with-parsed-data (data &rest body)
53 "Execute body with parsed data available.
55 DATA is a string containing the data to be parsed. BODY is the
56 body to execute. Parse tree is available under the `tree'
57 variable, and communication channel under `info'.
59 This function calls `org-export-collect-tree-properties'. As
60 such, `:ignore-list' (for `org-element-map') and
61 `:parse-tree' (for `org-export-get-genealogy') properties are
62 already filled in `info'."
63 (declare (debug (form body)) (indent 1))
64 `(org-test-with-temp-text ,data
65 (let* ((tree (org-element-parse-buffer))
66 (info (org-export-collect-tree-properties
67 tree (org-export-get-environment))))
68 ,@body)))
72 ;;; Internal Tests
74 (ert-deftest test-org-export/bind-keyword ()
75 "Test reading #+BIND: keywords."
76 ;; Test with `org-export-allow-bind-keywords' set to t.
77 (should
78 (org-test-with-temp-text "#+BIND: test-ox-var value"
79 (let ((org-export-allow-bind-keywords t))
80 (org-export-get-environment)
81 (eq test-ox-var 'value))))
82 ;; Test with `org-export-allow-bind-keywords' set to nil.
83 (should-not
84 (org-test-with-temp-text "#+BIND: test-ox-var value"
85 (let ((org-export-allow-bind-keywords nil))
86 (org-export-get-environment)
87 (boundp 'test-ox-var))))
88 ;; BIND keywords are case-insensitive.
89 (should
90 (org-test-with-temp-text "#+bind: test-ox-var value"
91 (let ((org-export-allow-bind-keywords t))
92 (org-export-get-environment)
93 (eq test-ox-var 'value))))
94 ;; Preserve order of BIND keywords.
95 (should
96 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
97 (let ((org-export-allow-bind-keywords t))
98 (org-export-get-environment)
99 (eq test-ox-var 2))))
100 ;; Read BIND keywords in setup files.
101 (should
102 (org-test-with-temp-text
103 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
104 (let ((org-export-allow-bind-keywords t))
105 (org-export-get-environment)
106 (eq variable 'value))))
107 ;; Verify that bound variables are seen during export.
108 (should
109 (equal "Yes\n"
110 (org-test-with-temp-text "#+BIND: test-ox-var value"
111 (let ((org-export-allow-bind-keywords t)
112 org-export-registered-backends)
113 (org-export-define-backend 'check
114 '((section . (lambda (s c i)
115 (if (eq test-ox-var 'value) "Yes" "No")))))
116 (org-export-as 'check))))))
118 (ert-deftest test-org-export/parse-option-keyword ()
119 "Test reading all standard #+OPTIONS: items."
120 (should
121 (equal
122 (org-export--parse-option-keyword
123 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
124 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
125 stat:t")
126 '(:headline-levels
127 1 :preserve-breaks t :section-numbers t :time-stamp-file t
128 :with-archived-trees t :with-author t :with-creator t :with-drawers t
129 :with-email t :with-emphasize t :with-entities t :with-fixed-width t
130 :with-footnotes t :with-inlinetasks nil :with-priority t
131 :with-special-strings t :with-statistics-cookies t :with-sub-superscript t
132 :with-toc t :with-tables t :with-tags t :with-tasks t :with-timestamps t
133 :with-todo-keywords t)))
134 ;; Test some special values.
135 (should
136 (equal
137 (org-export--parse-option-keyword
138 "arch:headline creator:comment d:(\"TEST\")
139 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
140 '( :section-numbers
142 :with-archived-trees headline :with-creator comment
143 :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
144 :with-tags not-in-toc :with-tasks todo :with-timestamps active))))
146 (ert-deftest test-org-export/get-inbuffer-options ()
147 "Test reading all standard export keywords."
148 ;; Properties should follow buffer order.
149 (should
150 (equal
151 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
152 (org-export--get-inbuffer-options))
153 '(:language "fr" :creator "Me" :email "email")))
154 ;; Parse document keywords.
155 (should
156 (equal
157 (org-test-with-temp-text "#+AUTHOR: Me"
158 (org-export--get-inbuffer-options))
159 '(:author ("Me"))))
160 ;; Test `space' behaviour.
161 (should
162 (equal
163 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
164 (org-export--get-inbuffer-options))
165 '(:title ("Some title with spaces"))))
166 ;; Test `newline' behaviour.
167 (should
168 (equal
169 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
170 (org-export--get-inbuffer-options))
171 '(:description "With\ntwo lines")))
172 ;; Test `split' behaviour.
173 (should
174 (equal
175 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
176 (org-export--get-inbuffer-options))
177 '(:select-tags ("a" "b"))))
178 ;; Options set through SETUPFILE.
179 (should
180 (equal
181 (org-test-with-temp-text
182 (format "#+DESCRIPTION: l1
183 #+LANGUAGE: es
184 #+SELECT_TAGS: a
185 #+TITLE: a
186 #+SETUPFILE: \"%s/examples/setupfile.org\"
187 #+DESCRIPTION: l3
188 #+LANGUAGE: fr
189 #+SELECT_TAGS: c
190 #+TITLE: c"
191 org-test-dir)
192 (org-export--get-inbuffer-options))
193 '(:description "l1\nl2\nl3":language "fr" :select-tags ("a" "b" "c")
194 :title ("a b c")))))
196 (ert-deftest test-org-export/get-subtree-options ()
197 "Test setting options from headline's properties."
198 ;; EXPORT_TITLE.
199 (org-test-with-temp-text "#+TITLE: Title
200 * Headline
201 :PROPERTIES:
202 :EXPORT_TITLE: Subtree Title
203 :END:
204 Paragraph"
205 (forward-line)
206 (should (equal (plist-get (org-export-get-environment nil t) :title)
207 '("Subtree Title"))))
208 :title
209 '("subtree-title")
210 ;; EXPORT_OPTIONS.
211 (org-test-with-temp-text "#+OPTIONS: H:1
212 * Headline
213 :PROPERTIES:
214 :EXPORT_OPTIONS: H:2
215 :END:
216 Paragraph"
217 (forward-line)
218 (should
219 (= 2 (plist-get (org-export-get-environment nil t) :headline-levels))))
220 ;; EXPORT_DATE.
221 (org-test-with-temp-text "#+DATE: today
222 * Headline
223 :PROPERTIES:
224 :EXPORT_DATE: 29-03-2012
225 :END:
226 Paragraph"
227 (forward-line)
228 (should (equal (plist-get (org-export-get-environment nil t) :date)
229 '("29-03-2012"))))
230 ;; Properties with `split' behaviour are stored as a list of
231 ;; strings.
232 (should
233 (equal '("a" "b")
234 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
235 * Headline
236 :PROPERTIES:
237 :EXPORT_EXCLUDE_TAGS: a b
238 :END:
239 Paragraph"
240 (progn
241 (forward-line)
242 (plist-get (org-export-get-environment nil t) :exclude-tags)))))
243 ;; Handle :PROPERTY+: syntax.
244 (should
245 (equal '("a" "b")
246 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
247 * Headline
248 :PROPERTIES:
249 :EXPORT_EXCLUDE_TAGS: a
250 :EXPORT_EXCLUDE_TAGS+: b
251 :END:
252 Paragraph"
253 (progn
254 (forward-line)
255 (plist-get (org-export-get-environment nil t) :exclude-tags)))))
256 ;; Export properties are case-insensitive.
257 (org-test-with-temp-text "* Headline
258 :PROPERTIES:
259 :EXPORT_Date: 29-03-2012
260 :END:
261 Paragraph"
262 (should (equal (plist-get (org-export-get-environment nil t) :date)
263 '("29-03-2012"))))
264 ;; Still grab correct options when section above is empty.
265 (should
266 (equal '("H1")
267 (org-test-with-temp-text "* H1\n** H11\n** H12"
268 (progn (forward-line 2)
269 (plist-get (org-export-get-environment nil t) :title))))))
271 (ert-deftest test-org-export/handle-options ()
272 "Test if export options have an impact on output."
273 ;; Test exclude tags for headlines and inlinetasks.
274 (should
275 (equal ""
276 (org-test-with-temp-text "* Head1 :noexp:"
277 (org-test-with-backend test
278 (org-export-as 'test nil nil nil '(:exclude-tags ("noexp")))))))
279 ;; Test include tags for headlines and inlinetasks.
280 (should
281 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
282 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
283 (let ((org-tags-column 0))
284 (org-test-with-backend test
285 (org-export-as 'test nil nil nil '(:select-tags ("exp"))))))))
286 ;; Test mixing include tags and exclude tags.
287 (org-test-with-temp-text "
288 * Head1 :export:
289 ** Sub-Head1 :noexport:
290 ** Sub-Head2
291 * Head2 :noexport:
292 ** Sub-Head1 :export:"
293 (org-test-with-backend test
294 (should
295 (string-match
296 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
297 (org-export-as
298 'test nil nil nil
299 '(:select-tags ("export") :exclude-tags ("noexport")))))))
300 ;; Ignore tasks.
301 (should
302 (equal ""
303 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
304 (org-test-with-temp-text "* TODO Head1"
305 (org-test-with-backend test
306 (org-export-as 'test nil nil nil '(:with-tasks nil)))))))
307 (should
308 (equal "* TODO Head1\n"
309 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
310 (org-test-with-temp-text "* TODO Head1"
311 (org-test-with-backend test
312 (org-export-as 'test nil nil nil '(:with-tasks t)))))))
313 ;; Archived tree.
314 (org-test-with-temp-text "* Head1 :archive:"
315 (let ((org-archive-tag "archive"))
316 (org-test-with-backend test
317 (should
318 (equal (org-export-as 'test nil nil nil '(:with-archived-trees nil))
319 "")))))
320 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
321 (let ((org-archive-tag "archive"))
322 (org-test-with-backend test
323 (should
324 (string-match
325 "\\* Head1[ \t]+:archive:"
326 (org-export-as 'test nil nil nil
327 '(:with-archived-trees headline)))))))
328 (org-test-with-temp-text "* Head1 :archive:"
329 (let ((org-archive-tag "archive"))
330 (org-test-with-backend test
331 (should
332 (string-match
333 "\\`\\* Head1[ \t]+:archive:\n\\'"
334 (org-export-as 'test nil nil nil '(:with-archived-trees t)))))))
335 ;; Clocks.
336 (let ((org-clock-string "CLOCK:"))
337 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
338 (org-test-with-backend test
339 (should
340 (equal (org-export-as 'test nil nil nil '(:with-clocks t))
341 "CLOCK: [2012-04-29 sun. 10:45]\n"))
342 (should
343 (equal (org-export-as 'test nil nil nil '(:with-clocks nil)) "")))))
344 ;; Drawers.
345 (let ((org-drawers '("TEST")))
346 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
347 (org-test-with-backend test
348 (should (equal (org-export-as 'test nil nil nil '(:with-drawers nil))
349 ""))
350 (should (equal (org-export-as 'test nil nil nil '(:with-drawers t))
351 ":TEST:\ncontents\n:END:\n")))))
352 (let ((org-drawers '("FOO" "BAR")))
353 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
354 (org-test-with-backend test
355 (should
356 (equal (org-export-as 'test nil nil nil '(:with-drawers ("FOO")))
357 ":FOO:\nkeep\n:END:\n")))))
358 (let ((org-drawers '("FOO" "BAR")))
359 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
360 (org-test-with-backend test
361 (should
362 (equal (org-export-as 'test nil nil nil '(:with-drawers (not "BAR")))
363 ":FOO:\nkeep\n:END:\n")))))
364 ;; Inlinetasks.
365 (when (featurep 'org-inlinetask)
366 (should
367 (equal
368 (let ((org-inlinetask-min-level 15))
369 (org-test-with-temp-text "*************** Task"
370 (org-test-with-backend test
371 (org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
372 ""))
373 (should
374 (equal
375 (let ((org-inlinetask-min-level 15))
376 (org-test-with-temp-text
377 "*************** Task\nContents\n*************** END"
378 (org-test-with-backend test
379 (org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
380 "")))
381 ;; Plannings.
382 (let ((org-closed-string "CLOSED:"))
383 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
384 (org-test-with-backend test
385 (should
386 (equal (org-export-as 'test nil nil nil '(:with-plannings t))
387 "CLOSED: [2012-04-29 sun. 10:45]\n"))
388 (should
389 (equal (org-export-as 'test nil nil nil '(:with-plannings nil))
390 "")))))
391 ;; Statistics cookies.
392 (should
393 (equal ""
394 (org-test-with-temp-text "[0/0]"
395 (org-test-with-backend test
396 (org-export-as
397 'test nil nil nil '(:with-statistics-cookies nil))))))
398 ;; Timestamps.
399 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
400 (org-test-with-backend test
401 (should
402 (equal (org-export-as 'test nil nil nil '(:with-timestamps t))
403 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
404 (should
405 (equal (org-export-as 'test nil nil nil '(:with-timestamps nil)) ""))
406 (should
407 (equal (org-export-as 'test nil nil nil '(:with-timestamps active))
408 "<2012-04-29 sun. 10:45>\n"))
409 (should
410 (equal (org-export-as 'test nil nil nil '(:with-timestamps inactive))
411 "[2012-04-29 sun. 10:45]\n")))))
413 (ert-deftest test-org-export/comment-tree ()
414 "Test if export process ignores commented trees."
415 (let ((org-comment-string "COMMENT"))
416 (org-test-with-temp-text "* COMMENT Head1"
417 (org-test-with-backend test
418 (should (equal (org-export-as 'test) ""))))))
420 (ert-deftest test-org-export/export-scope ()
421 "Test all export scopes."
422 (org-test-with-temp-text "
423 * Head1
424 ** Head2
425 text
426 *** Head3"
427 (org-test-with-backend test
428 ;; Subtree.
429 (forward-line 3)
430 (should (equal (org-export-as 'test 'subtree) "text\n*** Head3\n"))
431 ;; Visible.
432 (goto-char (point-min))
433 (forward-line)
434 (org-cycle)
435 (should (equal (org-export-as 'test nil 'visible) "* Head1\n"))
436 ;; Region.
437 (goto-char (point-min))
438 (forward-line 3)
439 (transient-mark-mode 1)
440 (push-mark (point) t t)
441 (goto-char (point-at-eol))
442 (should (equal (org-export-as 'test) "text\n"))))
443 ;; Subtree with a code block calling another block outside.
444 (should
445 (equal ": 3\n"
446 (org-test-with-temp-text "
447 * Head1
448 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
449 <<test>>
450 #+END_SRC
451 * Head2
452 #+NAME: test
453 #+BEGIN_SRC emacs-lisp
454 \(+ 1 2)
455 #+END_SRC"
456 (org-test-with-backend test
457 (forward-line 1)
458 (org-export-as 'test 'subtree)))))
459 ;; Body only.
460 (org-test-with-temp-text "Text"
461 (org-test-with-backend test
462 (plist-put
463 (cdr (assq 'test org-export-registered-backends))
464 :translate-alist
465 (cons (cons 'template (lambda (body info) (format "BEGIN\n%sEND" body)))
466 (org-export-backend-translate-table 'test)))
467 (should (equal (org-export-as 'test nil nil 'body-only) "Text\n"))
468 (should (equal (org-export-as 'test) "BEGIN\nText\nEND")))))
470 (ert-deftest test-org-export/output-file-name ()
471 "Test `org-export-output-file-name' specifications."
472 ;; Export from a file: name is built from original file name.
473 (should
474 (org-test-with-temp-text-in-file "Test"
475 (equal (concat (file-name-as-directory ".")
476 (file-name-nondirectory
477 (file-name-sans-extension (buffer-file-name))))
478 (file-name-sans-extension (org-export-output-file-name ".ext")))))
479 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
480 (should
481 (org-test-with-temp-text-in-file
482 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
483 (equal (org-export-output-file-name ".ext" t) "./test.ext")))
484 ;; From a buffer not associated to a file, too.
485 (should
486 (org-test-with-temp-text
487 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
488 (equal (org-export-output-file-name ".ext" t) "./test.ext")))
489 ;; When provided name is absolute, preserve it.
490 (should
491 (org-test-with-temp-text
492 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
493 (expand-file-name "test"))
494 (file-name-absolute-p (org-export-output-file-name ".ext" t))))
495 ;; When PUB-DIR argument is provided, use it.
496 (should
497 (org-test-with-temp-text-in-file "Test"
498 (equal (file-name-directory
499 (org-export-output-file-name ".ext" nil "dir/"))
500 "dir/")))
501 ;; When returned name would overwrite original file, add EXTENSION
502 ;; another time.
503 (should
504 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
505 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
507 (ert-deftest test-org-export/expand-include ()
508 "Test file inclusion in an Org buffer."
509 ;; Error when file isn't specified.
510 (should-error
511 (org-test-with-temp-text "#+INCLUDE: dummy.org"
512 (org-export-expand-include-keyword)))
513 ;; Full insertion with recursive inclusion.
514 (org-test-with-temp-text
515 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
516 (org-export-expand-include-keyword)
517 (should (equal (buffer-string)
518 "Small Org file with an include keyword.
520 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
522 Success!
524 * Heading
525 body\n")))
526 ;; Localized insertion.
527 (org-test-with-temp-text
528 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
529 org-test-dir)
530 (org-export-expand-include-keyword)
531 (should (equal (buffer-string)
532 "Small Org file with an include keyword.\n")))
533 ;; Insertion with constraints on headlines level.
534 (should
535 (equal
536 "* Top heading\n** Heading\nbody\n"
537 (org-test-with-temp-text
538 (format
539 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
540 org-test-dir)
541 (org-export-expand-include-keyword)
542 (buffer-string))))
543 (should
544 (equal
545 "* Top heading\n* Heading\nbody\n"
546 (org-test-with-temp-text
547 (format
548 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
549 org-test-dir)
550 (org-export-expand-include-keyword)
551 (buffer-string))))
552 ;; Inclusion within an example block.
553 (org-test-with-temp-text
554 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
555 org-test-dir)
556 (org-export-expand-include-keyword)
557 (should
558 (equal
559 (buffer-string)
560 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
561 ;; Inclusion within a src-block.
562 (org-test-with-temp-text
563 (format
564 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
565 org-test-dir)
566 (org-export-expand-include-keyword)
567 (should (equal (buffer-string)
568 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
570 (ert-deftest test-org-export/expand-macro ()
571 "Test macro expansion in an Org buffer."
572 ;; Standard macro expansion.
573 (should
574 (equal "#+MACRO: macro1 value\nvalue\n"
575 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
576 (org-test-with-backend test (org-export-as 'test)))))
577 ;; Expand specific macros.
578 (should
579 (equal "me 2012-03-29 me@here Title\n"
580 (org-test-with-temp-text
582 #+TITLE: Title
583 #+DATE: 2012-03-29
584 #+AUTHOR: me
585 #+EMAIL: me@here
586 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
587 (let ((output (org-test-with-backend test (org-export-as 'test))))
588 (substring output (string-match ".*\n\\'" output))))))
589 ;; Expand specific macros when property contained a regular macro
590 ;; already.
591 (should
592 (equal "value\n"
593 (org-test-with-temp-text "
594 #+MACRO: macro1 value
595 #+TITLE: {{{macro1}}}
596 {{{title}}}"
597 (let ((output (org-test-with-backend test (org-export-as 'test))))
598 (substring output (string-match ".*\n\\'" output))))))
599 ;; Expand macros with templates in included files.
600 (should
601 (equal "success\n"
602 (org-test-with-temp-text
603 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
604 {{{included-macro}}}" org-test-dir)
605 (let ((output (org-test-with-backend test (org-export-as 'test))))
606 (substring output (string-match ".*\n\\'" output)))))))
608 (ert-deftest test-org-export/user-ignore-list ()
609 "Test if `:ignore-list' accepts user input."
610 (org-test-with-backend test
611 (flet ((skip-note-head
612 (data backend info)
613 ;; Ignore headlines with the word "note" in their title.
614 (org-element-map data 'headline
615 (lambda (headline)
616 (when (string-match "\\<note\\>"
617 (org-element-property :raw-value headline))
618 (org-export-ignore-element headline info)))
619 info)
620 data))
621 ;; Install function in parse tree filters.
622 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
623 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
624 (should (equal (org-export-as 'test) "* Head1\n")))))))
626 (ert-deftest test-org-export/before-processing-hook ()
627 "Test `org-export-before-processing-hook'."
628 (should
629 (equal
630 "#+MACRO: mac val\nTest\n"
631 (org-test-with-backend test
632 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
633 (let ((org-export-before-processing-hook
634 '((lambda (backend)
635 (while (re-search-forward "{{{" nil t)
636 (let ((object (org-element-context)))
637 (when (eq (org-element-type object) 'macro)
638 (delete-region
639 (org-element-property :begin object)
640 (org-element-property :end object)))))))))
641 (org-export-as 'test)))))))
643 (ert-deftest test-org-export/before-parsing-hook ()
644 "Test `org-export-before-parsing-hook'."
645 (should
646 (equal "Body 1\nBody 2\n"
647 (org-test-with-backend test
648 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
649 (let ((org-export-before-parsing-hook
650 '((lambda (backend)
651 (goto-char (point-min))
652 (while (re-search-forward org-outline-regexp-bol nil t)
653 (delete-region
654 (point-at-bol) (progn (forward-line) (point))))))))
655 (org-export-as 'test)))))))
659 ;;; Affiliated Keywords
661 (ert-deftest test-org-export/read-attribute ()
662 "Test `org-export-read-attribute' specifications."
663 ;; Standard test.
664 (should
665 (equal
666 (org-export-read-attribute
667 :attr_html
668 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
669 (org-element-at-point)))
670 '(:a "1" :b "2")))
671 ;; Return nil on empty attribute.
672 (should-not
673 (org-export-read-attribute
674 :attr_html
675 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
676 ;; Return nil on "nil" string.
677 (should
678 (equal '(:a nil :b nil)
679 (org-export-read-attribute
680 :attr_html
681 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
682 (org-element-at-point)))))
683 ;; Return nil on empty string.
684 (should
685 (equal '(:a nil :b nil)
686 (org-export-read-attribute
687 :attr_html
688 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
689 (org-element-at-point)))))
690 ;; Ignore text before first property.
691 (should-not
692 (member "ignore"
693 (org-export-read-attribute
694 :attr_html
695 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
696 (org-element-at-point))))))
698 (ert-deftest test-org-export/get-caption ()
699 "Test `org-export-get-caption' specifications."
700 ;; Without optional argument, return long caption
701 (should
702 (equal
703 '("l")
704 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
705 (org-export-get-caption (org-element-at-point)))))
706 ;; With optional argument, return short caption.
707 (should
708 (equal
709 '("s")
710 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
711 (org-export-get-caption (org-element-at-point) t))))
712 ;; Multiple lines are separated by white spaces.
713 (should
714 (equal
715 '("a" " " "b")
716 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
717 (org-export-get-caption (org-element-at-point))))))
721 ;;; Back-End Tools
723 (ert-deftest test-org-export/define-backend ()
724 "Test back-end definition and accessors."
725 ;; Translate table.
726 (should
727 (equal '((headline . my-headline-test))
728 (let (org-export-registered-backends)
729 (org-export-define-backend 'test '((headline . my-headline-test)))
730 (org-export-backend-translate-table 'test))))
731 ;; Filters.
732 (should
733 (equal '((:filter-headline . my-filter))
734 (let (org-export-registered-backends)
735 (org-export-define-backend 'test
736 '((headline . my-headline-test))
737 :filters-alist '((:filter-headline . my-filter)))
738 (org-export-backend-filters 'test))))
739 ;; Options.
740 (should
741 (equal '((:prop value))
742 (let (org-export-registered-backends)
743 (org-export-define-backend 'test
744 '((headline . my-headline-test))
745 :options-alist '((:prop value)))
746 (org-export-backend-options 'test))))
747 ;; Menu.
748 (should
749 (equal '(?k "Test Export" test)
750 (let (org-export-registered-backends)
751 (org-export-define-backend 'test
752 '((headline . my-headline-test))
753 :menu-entry '(?k "Test Export" test))
754 (org-export-backend-menu 'test))))
755 ;; Export Blocks.
756 (should
757 (equal '(("TEST" . org-element-export-block-parser))
758 (let (org-export-registered-backends org-element-block-name-alist)
759 (org-export-define-backend 'test
760 '((headline . my-headline-test))
761 :export-block '("test"))
762 org-element-block-name-alist))))
764 (ert-deftest test-org-export/define-derived-backend ()
765 "Test `org-export-define-derived-backend' specifications."
766 ;; Error when parent back-end is not defined.
767 (should-error
768 (let (org-export-registered-backends)
769 (org-export-define-derived-backend 'test 'parent)))
770 ;; Append translation table to parent's.
771 (should
772 (equal '((:headline . test) (:headline . parent))
773 (let (org-export-registered-backends)
774 (org-export-define-backend 'parent '((:headline . parent)))
775 (org-export-define-derived-backend 'test 'parent
776 :translate-alist '((:headline . test)))
777 (org-export-backend-translate-table 'test))))
778 ;; Options defined in the new back have priority over those defined
779 ;; in parent.
780 (should
781 (eq 'test
782 (let (org-export-registered-backends)
783 (org-export-define-backend 'parent
784 '((:headline . parent))
785 :options-alist '((:a nil nil 'parent)))
786 (org-export-define-derived-backend 'test 'parent
787 :options-alist '((:a nil nil 'test)))
788 (plist-get (org-export--get-global-options 'test) :a)))))
790 (ert-deftest test-org-export/derived-backend-p ()
791 "Test `org-export-derived-backend-p' specifications."
792 ;; Non-nil with direct match.
793 (should
794 (let (org-export-registered-backends)
795 (org-export-define-backend 'test '((headline . test)))
796 (org-export-derived-backend-p 'test 'test)))
797 (should
798 (let (org-export-registered-backends)
799 (org-export-define-backend 'test '((headline . test)))
800 (org-export-define-derived-backend 'test2 'test)
801 (org-export-derived-backend-p 'test2 'test2)))
802 ;; Non-nil with a direct parent.
803 (should
804 (let (org-export-registered-backends)
805 (org-export-define-backend 'test '((headline . test)))
806 (org-export-define-derived-backend 'test2 'test)
807 (org-export-derived-backend-p 'test2 'test)))
808 ;; Non-nil with an indirect parent.
809 (should
810 (let (org-export-registered-backends)
811 (org-export-define-backend 'test '((headline . test)))
812 (org-export-define-derived-backend 'test2 'test)
813 (org-export-define-derived-backend 'test3 'test2)
814 (org-export-derived-backend-p 'test3 'test)))
815 ;; Nil otherwise.
816 (should-not
817 (let (org-export-registered-backends)
818 (org-export-define-backend 'test '((headline . test)))
819 (org-export-define-backend 'test2 '((headline . test2)))
820 (org-export-derived-backend-p 'test2 'test)))
821 (should-not
822 (let (org-export-registered-backends)
823 (org-export-define-backend 'test '((headline . test)))
824 (org-export-define-backend 'test2 '((headline . test2)))
825 (org-export-define-derived-backend 'test3 'test2)
826 (org-export-derived-backend-p 'test3 'test))))
828 (ert-deftest test-org-export/with-backend ()
829 "Test `org-export-with-backend' definition."
830 ;; Error when calling an undefined back-end
831 (should-error
832 (let (org-export-registered-backends)
833 (org-export-with-backend 'test "Test")))
834 ;; Error when called back-end doesn't have an appropriate
835 ;; transcoder.
836 (should-error
837 (let (org-export-registered-backends)
838 (org-export-define-backend 'test ((headline . ignore)))
839 (org-export-with-backend 'test "Test")))
840 ;; Otherwise, export using correct transcoder
841 (should
842 (equal "Success"
843 (let (org-export-registered-backends)
844 (org-export-define-backend 'test
845 '((plain-text . (lambda (text contents info) "Failure"))))
846 (org-export-define-backend 'test2
847 '((plain-text . (lambda (text contents info) "Success"))))
848 (org-export-with-backend 'test2 "Test")))))
850 (ert-deftest test-org-export/data-with-translations ()
851 "Test `org-export-data-with-translations' specifications."
852 (should
853 (equal
854 "Success!"
855 (org-export-data-with-translations
856 '(bold nil "Test")
857 '((plain-text . (lambda (text info) "Success"))
858 (bold . (lambda (bold contents info) (concat contents "!"))))
859 '(:with-emphasize t)))))
861 (ert-deftest test-org-export/data-with-backend ()
862 "Test `org-export-data-with-backend' specifications."
863 ;; Error when calling an undefined back-end.
864 (should-error
865 (let (org-export-registered-backends)
866 (org-export-data-with-backend 'test "Test" nil)))
867 ;; Otherwise, export data recursively, using correct back-end.
868 (should
869 (equal
870 "Success!"
871 (let (org-export-registered-backends)
872 (org-export-define-backend 'test
873 '((plain-text . (lambda (text info) "Success"))
874 (bold . (lambda (bold contents info) (concat contents "!")))))
875 (org-export-data-with-backend
876 '(bold nil "Test") 'test '(:with-emphasize t))))))
880 ;;; Export Snippets
882 (ert-deftest test-org-export/export-snippet ()
883 "Test export snippets transcoding."
884 (org-test-with-temp-text "@@test:A@@@@t:B@@"
885 (org-test-with-backend test
886 (plist-put
887 (cdr (assq 'test org-export-registered-backends))
888 :translate-alist
889 (cons (cons 'export-snippet
890 (lambda (snippet contents info)
891 (when (eq (org-export-snippet-backend snippet) 'test)
892 (org-element-property :value snippet))))
893 (org-export-backend-translate-table 'test)))
894 (let ((org-export-snippet-translation-alist nil))
895 (should (equal (org-export-as 'test) "A\n")))
896 (let ((org-export-snippet-translation-alist '(("t" . "test"))))
897 (should (equal (org-export-as 'test) "AB\n")))))
898 ;; Ignored export snippets do not remove any blank.
899 (should
900 (equal "begin end\n"
901 (org-test-with-parsed-data "begin @@test:A@@ end"
902 (org-export-data-with-translations
903 tree
904 '((paragraph . (lambda (paragraph contents info) contents))
905 (section . (lambda (section contents info) contents)))
906 info)))))
910 ;;; Footnotes
912 (ert-deftest test-org-export/footnotes ()
913 "Test footnotes specifications."
914 (let ((org-footnote-section nil)
915 (org-export-with-footnotes t))
916 ;; 1. Read every type of footnote.
917 (should
918 (equal
919 '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
920 (org-test-with-parsed-data
921 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
922 (org-element-map tree 'footnote-reference
923 (lambda (ref)
924 (let ((def (org-export-get-footnote-definition ref info)))
925 (cons (org-export-get-footnote-number ref info)
926 (if (eq (org-element-property :type ref) 'inline) (car def)
927 (car (org-element-contents
928 (car (org-element-contents def))))))))
929 info))))
930 ;; 2. Test nested footnotes order.
931 (org-test-with-parsed-data
932 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
933 (should
934 (equal
935 '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
936 (org-element-map tree 'footnote-reference
937 (lambda (ref)
938 (when (org-export-footnote-first-reference-p ref info)
939 (cons (org-export-get-footnote-number ref info)
940 (org-element-property :label ref))))
941 info))))
942 ;; 3. Test nested footnote in invisible definitions.
943 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
944 ;; Hide definitions.
945 (narrow-to-region (point) (point-at-eol))
946 (let* ((tree (org-element-parse-buffer))
947 (info (org-combine-plists
948 `(:parse-tree ,tree)
949 (org-export-collect-tree-properties
950 tree (org-export-get-environment)))))
951 ;; Both footnotes should be seen.
952 (should
953 (= (length (org-export-collect-footnote-definitions tree info)) 2))))
954 ;; 4. Test footnotes definitions collection.
955 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
957 \[fn:2] B [fn:3] [fn::D].
959 \[fn:3] C."
960 (should (= (length (org-export-collect-footnote-definitions tree info))
961 4)))
962 ;; 5. Test export of footnotes defined outside parsing scope.
963 (org-test-with-temp-text "[fn:1] Out of scope
964 * Title
965 Paragraph[fn:1]"
966 (org-test-with-backend test
967 (plist-put
968 (cdr (assq 'test org-export-registered-backends))
969 :translate-alist
970 (cons (cons 'footnote-reference
971 (lambda (fn contents info)
972 (org-element-interpret-data
973 (org-export-get-footnote-definition fn info))))
974 (org-export-backend-translate-table 'test)))
975 (forward-line)
976 (should (equal "ParagraphOut of scope\n"
977 (org-export-as 'test 'subtree)))))
978 ;; 6. Footnotes without a definition should be provided a fallback
979 ;; definition.
980 (should
981 (org-test-with-parsed-data "[fn:1]"
982 (org-export-get-footnote-definition
983 (org-element-map tree 'footnote-reference 'identity info t) info)))
984 ;; 7. Footnote section should be ignored in TOC and in headlines
985 ;; numbering.
986 (should
987 (= 1 (let ((org-footnote-section "Footnotes"))
988 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
989 (org-export-collect-headlines info))))))
990 (should
991 (equal '(2)
992 (let ((org-footnote-section "Footnotes"))
993 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
994 (org-element-map tree 'headline
995 (lambda (hl)
996 (when (equal (org-element-property :raw-value hl) "H2")
997 (org-export-get-headline-number hl info)))
998 info t)))))))
1002 ;;; Headlines and Inlinetasks
1004 (ert-deftest test-org-export/get-relative-level ()
1005 "Test `org-export-get-relative-level' specifications."
1006 ;; Standard test.
1007 (should
1008 (equal '(1 2)
1009 (let ((org-odd-levels-only nil))
1010 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1011 (org-element-map tree 'headline
1012 (lambda (h) (org-export-get-relative-level h info))
1013 info)))))
1014 ;; Missing levels
1015 (should
1016 (equal '(1 3)
1017 (let ((org-odd-levels-only nil))
1018 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1019 (org-element-map tree 'headline
1020 (lambda (h) (org-export-get-relative-level h info))
1021 info))))))
1023 (ert-deftest test-org-export/low-level-p ()
1024 "Test `org-export-low-level-p' specifications."
1025 (should
1026 (equal
1027 '(no yes)
1028 (let ((org-odd-levels-only nil))
1029 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1030 (org-element-map tree 'headline
1031 (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
1032 (plist-put info :headline-levels 1)))))))
1034 (ert-deftest test-org-export/get-headline-number ()
1035 "Test `org-export-get-headline-number' specifications."
1036 ;; Standard test.
1037 (should
1038 (equal
1039 '((1) (1 1))
1040 (let ((org-odd-levels-only nil))
1041 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1042 (org-element-map tree 'headline
1043 (lambda (h) (org-export-get-headline-number h info))
1044 info)))))
1045 ;; Missing levels are replaced with 0.
1046 (should
1047 (equal
1048 '((1) (1 0 1))
1049 (let ((org-odd-levels-only nil))
1050 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1051 (org-element-map tree 'headline
1052 (lambda (h) (org-export-get-headline-number h info))
1053 info))))))
1055 (ert-deftest test-org-export/numbered-headline-p ()
1056 "Test `org-export-numbered-headline-p' specifications."
1057 ;; If `:section-numbers' is nil, never number headlines.
1058 (should-not
1059 (org-test-with-parsed-data "* Headline"
1060 (org-element-map tree 'headline
1061 (lambda (h) (org-export-numbered-headline-p h info))
1062 (plist-put info :section-numbers nil))))
1063 ;; If `:section-numbers' is a number, only number headlines with
1064 ;; a level greater that it.
1065 (should
1066 (equal
1067 '(yes no)
1068 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1069 (org-element-map tree 'headline
1070 (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
1071 (plist-put info :section-numbers 1)))))
1072 ;; Otherwise, headlines are always numbered.
1073 (should
1074 (org-test-with-parsed-data "* Headline"
1075 (org-element-map tree 'headline
1076 (lambda (h) (org-export-numbered-headline-p h info))
1077 (plist-put info :section-numbers t)))))
1079 (ert-deftest test-org-export/number-to-roman ()
1080 "Test `org-export-number-to-roman' specifications."
1081 ;; If number is negative, return it as a string.
1082 (should (equal (org-export-number-to-roman -1) "-1"))
1083 ;; Otherwise, return it as a roman number.
1084 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1086 (ert-deftest test-org-export/get-optional-title ()
1087 "Test `org-export-get-alt-title' specifications."
1088 ;; If ALT_TITLE property is defined, use it.
1089 (should
1090 (equal '("opt")
1091 (org-test-with-parsed-data
1092 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1093 (org-export-get-alt-title
1094 (org-element-map tree 'headline 'identity info t)
1095 info))))
1096 ;; Otherwise, fall-back to regular title.
1097 (should
1098 (equal '("Headline")
1099 (org-test-with-parsed-data "* Headline"
1100 (org-export-get-alt-title
1101 (org-element-map tree 'headline 'identity info t)
1102 info)))))
1104 (ert-deftest test-org-export/get-tags ()
1105 "Test `org-export-get-tags' specifications."
1106 (let ((org-export-exclude-tags '("noexport"))
1107 (org-export-select-tags '("export")))
1108 ;; Standard test: tags which are not a select tag, an exclude tag,
1109 ;; or specified as optional argument shouldn't be ignored.
1110 (should
1111 (org-test-with-parsed-data "* Headline :tag:"
1112 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1113 info)))
1114 ;; Exclude tags are removed.
1115 (should-not
1116 (org-test-with-parsed-data "* Headline :noexport:"
1117 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1118 info)))
1119 ;; Select tags are removed.
1120 (should-not
1121 (org-test-with-parsed-data "* Headline :export:"
1122 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1123 info)))
1124 (should
1125 (equal
1126 '("tag")
1127 (org-test-with-parsed-data "* Headline :tag:export:"
1128 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1129 info))))
1130 ;; Tags provided in the optional argument are also ignored.
1131 (should-not
1132 (org-test-with-parsed-data "* Headline :ignore:"
1133 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1134 info '("ignore"))))
1135 ;; Allow tag inheritance.
1136 (should
1137 (equal
1138 '(("tag") ("tag"))
1139 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1140 (org-element-map tree 'headline
1141 (lambda (hl) (org-export-get-tags hl info nil t)) info))))
1142 ;; Tag inheritance checks FILETAGS keywords.
1143 (should
1144 (equal
1145 '(("a" "b" "tag"))
1146 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1147 (org-element-map tree 'headline
1148 (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
1150 (ert-deftest test-org-export/get-node-property ()
1151 "Test`org-export-get-node-property' specifications."
1152 ;; Standard test.
1153 (should
1154 (equal "value"
1155 (org-test-with-parsed-data "* Headline
1156 :PROPERTIES:
1157 :prop: value
1158 :END:"
1159 (org-export-get-node-property
1160 :PROP (org-element-map tree 'headline 'identity nil t)))))
1161 ;; Test inheritance.
1162 (should
1163 (equal "value"
1164 (org-test-with-parsed-data "* Parent
1165 :PROPERTIES:
1166 :prop: value
1167 :END:
1168 ** Headline
1169 Paragraph"
1170 (org-export-get-node-property
1171 :PROP (org-element-map tree 'paragraph 'identity nil t) t))))
1172 ;; Cannot return a value before the first headline.
1173 (should-not
1174 (org-test-with-parsed-data "Paragraph
1175 * Headline
1176 :PROPERTIES:
1177 :prop: value
1178 :END:"
1179 (org-export-get-node-property
1180 :PROP (org-element-map tree 'paragraph 'identity nil t)))))
1182 (ert-deftest test-org-export/get-category ()
1183 "Test `org-export-get-category' specifications."
1184 ;; Standard test.
1185 (should
1186 (equal "value"
1187 (org-test-with-parsed-data "* Headline
1188 :PROPERTIES:
1189 :CATEGORY: value
1190 :END:"
1191 (org-export-get-category
1192 (org-element-map tree 'headline 'identity nil t) info))))
1193 ;; Test inheritance from a parent headline.
1194 (should
1195 (equal '("value" "value")
1196 (org-test-with-parsed-data "* Headline1
1197 :PROPERTIES:
1198 :CATEGORY: value
1199 :END:
1200 ** Headline2"
1201 (org-element-map tree 'headline
1202 (lambda (hl) (org-export-get-category hl info)) info))))
1203 ;; Test inheritance from #+CATEGORY keyword
1204 (should
1205 (equal "value"
1206 (org-test-with-parsed-data "#+CATEGORY: value
1207 * Headline"
1208 (org-export-get-category
1209 (org-element-map tree 'headline 'identity nil t) info))))
1210 ;; Test inheritance from file name.
1211 (should
1212 (equal "test"
1213 (org-test-with-parsed-data "* Headline"
1214 (let ((info (plist-put info :input-file "~/test.org")))
1215 (org-export-get-category
1216 (org-element-map tree 'headline 'identity nil t) info)))))
1217 ;; Fall-back value.
1218 (should
1219 (equal "???"
1220 (org-test-with-parsed-data "* Headline"
1221 (org-export-get-category
1222 (org-element-map tree 'headline 'identity nil t) info)))))
1224 (ert-deftest test-org-export/first-sibling-p ()
1225 "Test `org-export-first-sibling-p' specifications."
1226 ;; Standard test.
1227 (should
1228 (equal
1229 '(yes yes no)
1230 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1231 (org-element-map tree 'headline
1232 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
1233 info))))
1234 ;; Ignore headlines not exported.
1235 (should
1236 (equal
1237 '(yes)
1238 (let ((org-export-exclude-tags '("ignore")))
1239 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1240 (org-element-map tree 'headline
1241 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
1242 info))))))
1244 (ert-deftest test-org-export/last-sibling-p ()
1245 "Test `org-export-last-sibling-p' specifications."
1246 ;; Standard test.
1247 (should
1248 (equal
1249 '(yes no yes)
1250 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1251 (org-element-map tree 'headline
1252 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
1253 info))))
1254 ;; Ignore headlines not exported.
1255 (should
1256 (equal
1257 '(yes)
1258 (let ((org-export-exclude-tags '("ignore")))
1259 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1260 (org-element-map tree 'headline
1261 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
1262 info))))))
1264 (ert-deftest test-org-export/handle-inlinetasks ()
1265 "Test inlinetask export."
1266 ;; Inlinetask with an exclude tag.
1267 (when (featurep 'org-inlinetask)
1268 (should
1269 (equal
1271 (let ((org-inlinetask-min-level 3))
1272 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1273 (org-test-with-backend test
1274 (org-export-as 'test nil nil nil '(:exclude-tags ("noexp"))))))))
1275 ;; Inlinetask with an include tag.
1276 (should
1277 (equal
1278 "* H2\n*** Inline :exp:\n"
1279 (let ((org-inlinetask-min-level 3)
1280 (org-tags-column 0))
1281 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1282 (org-test-with-backend test
1283 (org-export-as 'test nil nil nil '(:select-tags ("exp"))))))))
1284 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1285 (should
1286 (equal ""
1287 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1288 (org-inlinetask-min-level 3))
1289 (org-test-with-temp-text "*** TODO Inline"
1290 (org-test-with-backend test
1291 (org-export-as 'test nil nil nil '(:with-tasks nil)))))))))
1295 ;;; Links
1297 (ert-deftest test-org-export/get-coderef-format ()
1298 "Test `org-export-get-coderef-format' specifications."
1299 ;; A link without description returns "%s"
1300 (should (equal (org-export-get-coderef-format "(ref:line)" nil)
1301 "%s"))
1302 ;; Return "%s" when path is matched within description.
1303 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1304 "desc %s"))
1305 ;; Otherwise return description.
1306 (should (equal (org-export-get-coderef-format "path" "desc")
1307 "desc")))
1309 (ert-deftest test-org-export/inline-image-p ()
1310 "Test `org-export-inline-image-p' specifications."
1311 (should
1312 (org-export-inline-image-p
1313 (org-test-with-temp-text "[[#id]]"
1314 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
1315 '(("custom-id" . "id")))))
1317 (ert-deftest test-org-export/fuzzy-link ()
1318 "Test fuzzy links specifications."
1319 ;; 1. Links to invisible (keyword) targets should be ignored.
1320 (org-test-with-parsed-data
1321 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1322 (should-not
1323 (org-element-map tree 'link
1324 (lambda (link)
1325 (org-export-get-ordinal
1326 (org-export-resolve-fuzzy-link link info) info)) info)))
1327 ;; 2. Link to an headline should return headline's number.
1328 (org-test-with-parsed-data
1329 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1330 (should
1331 ;; Note: Headline's number is in fact a list of numbers.
1332 (equal '(2)
1333 (org-element-map tree 'link
1334 (lambda (link)
1335 (org-export-get-ordinal
1336 (org-export-resolve-fuzzy-link link info) info)) info t))))
1337 ;; 3. Link to a target in an item should return item's number.
1338 (org-test-with-parsed-data
1339 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1340 (should
1341 ;; Note: Item's number is in fact a list of numbers.
1342 (equal '(1 2)
1343 (org-element-map tree 'link
1344 (lambda (link)
1345 (org-export-get-ordinal
1346 (org-export-resolve-fuzzy-link link info) info)) info t))))
1347 ;; 4. Link to a target in a footnote should return footnote's
1348 ;; number.
1349 (org-test-with-parsed-data "
1350 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1351 (should
1352 (equal '(2 3)
1353 (org-element-map tree 'link
1354 (lambda (link)
1355 (org-export-get-ordinal
1356 (org-export-resolve-fuzzy-link link info) info)) info))))
1357 ;; 5. Link to a named element should return sequence number of that
1358 ;; element.
1359 (org-test-with-parsed-data
1360 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1361 (should
1362 (= 2
1363 (org-element-map tree 'link
1364 (lambda (link)
1365 (org-export-get-ordinal
1366 (org-export-resolve-fuzzy-link link info) info)) info t))))
1367 ;; 6. Link to a target not within an item, a table, a footnote
1368 ;; reference or definition should return section number.
1369 (org-test-with-parsed-data
1370 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1371 (should
1372 (equal '(2)
1373 (org-element-map tree 'link
1374 (lambda (link)
1375 (org-export-get-ordinal
1376 (org-export-resolve-fuzzy-link link info) info)) info t))))
1377 ;; 7. Space are not significant when matching a fuzzy link.
1378 (should
1379 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1380 (org-element-map tree 'link
1381 (lambda (link) (org-export-resolve-fuzzy-link link info))
1382 info t)))
1383 ;; 8. Statistics cookies are ignored for headline match.
1384 (should
1385 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1386 (org-element-map tree 'link
1387 (lambda (link) (org-export-resolve-fuzzy-link link info))
1388 info t)))
1389 (should
1390 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1391 (org-element-map tree 'link
1392 (lambda (link) (org-export-resolve-fuzzy-link link info))
1393 info t))))
1395 (ert-deftest test-org-export/resolve-coderef ()
1396 "Test `org-export-resolve-coderef' specifications."
1397 (let ((org-coderef-label-format "(ref:%s)"))
1398 ;; 1. A link to a "-n -k -r" block returns line number.
1399 (org-test-with-parsed-data
1400 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1401 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1402 (org-test-with-parsed-data
1403 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1404 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1405 ;; 2. A link to a "-n -r" block returns line number.
1406 (org-test-with-parsed-data
1407 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1408 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1409 (org-test-with-parsed-data
1410 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1411 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1412 ;; 3. A link to a "-n" block returns coderef.
1413 (org-test-with-parsed-data
1414 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1415 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1416 (org-test-with-parsed-data
1417 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1418 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1419 ;; 4. A link to a "-r" block returns line number.
1420 (org-test-with-parsed-data
1421 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1422 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1423 (org-test-with-parsed-data
1424 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1425 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1426 ;; 5. A link to a block without a switch returns coderef.
1427 (org-test-with-parsed-data
1428 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1429 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1430 (org-test-with-parsed-data
1431 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1432 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1433 ;; 6. Correctly handle continued line numbers. A "+n" switch
1434 ;; should resume numbering from previous block with numbered
1435 ;; lines, ignoring blocks not numbering lines in the process.
1436 ;; A "-n" switch resets count.
1437 (org-test-with-parsed-data "
1438 #+BEGIN_EXAMPLE -n
1439 Text.
1440 #+END_EXAMPLE
1442 #+BEGIN_SRC emacs-lisp
1443 \(- 1 1)
1444 #+END_SRC
1446 #+BEGIN_SRC emacs-lisp +n -r
1447 \(+ 1 1) (ref:addition)
1448 #+END_SRC
1450 #+BEGIN_EXAMPLE -n -r
1451 Another text. (ref:text)
1452 #+END_EXAMPLE"
1453 (should (= (org-export-resolve-coderef "addition" info) 2))
1454 (should (= (org-export-resolve-coderef "text" info) 1)))
1455 ;; 7. Recognize coderef with user-specified syntax.
1456 (org-test-with-parsed-data
1457 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1458 (should (equal (org-export-resolve-coderef "text" info) "text")))))
1460 (ert-deftest test-org-export/resolve-fuzzy-link ()
1461 "Test `org-export-resolve-fuzzy-link' specifications."
1462 ;; 1. Match target objects.
1463 (org-test-with-parsed-data "<<target>> [[target]]"
1464 (should
1465 (org-export-resolve-fuzzy-link
1466 (org-element-map tree 'link 'identity info t) info)))
1467 ;; 2. Match target elements.
1468 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1469 (should
1470 (org-export-resolve-fuzzy-link
1471 (org-element-map tree 'link 'identity info t) info)))
1472 ;; 3. Match named elements.
1473 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1474 (should
1475 (org-export-resolve-fuzzy-link
1476 (org-element-map tree 'link 'identity info t) info)))
1477 ;; 4. Match exact headline's name.
1478 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1479 (should
1480 (org-export-resolve-fuzzy-link
1481 (org-element-map tree 'link 'identity info t) info)))
1482 ;; 5. Targets objects have priority over named elements and headline
1483 ;; titles.
1484 (org-test-with-parsed-data
1485 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1486 (should
1487 (eq 'target
1488 (org-element-type
1489 (org-export-resolve-fuzzy-link
1490 (org-element-map tree 'link 'identity info t) info)))))
1491 ;; 6. Named elements have priority over headline titles.
1492 (org-test-with-parsed-data
1493 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1494 (should
1495 (eq 'paragraph
1496 (org-element-type
1497 (org-export-resolve-fuzzy-link
1498 (org-element-map tree 'link 'identity info t) info)))))
1499 ;; 7. If link's path starts with a "*", only match headline titles,
1500 ;; though.
1501 (org-test-with-parsed-data
1502 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1503 (should
1504 (eq 'headline
1505 (org-element-type
1506 (org-export-resolve-fuzzy-link
1507 (org-element-map tree 'link 'identity info t) info)))))
1508 ;; 8. Return nil if no match.
1509 (org-test-with-parsed-data "[[target]]"
1510 (should-not
1511 (org-export-resolve-fuzzy-link
1512 (org-element-map tree 'link 'identity info t) info))))
1514 (ert-deftest test-org-export/resolve-id-link ()
1515 "Test `org-export-resolve-id-link' specifications."
1516 ;; 1. Regular test for custom-id link.
1517 (org-test-with-parsed-data "* Headline1
1518 :PROPERTIES:
1519 :CUSTOM_ID: test
1520 :END:
1521 * Headline 2
1522 \[[#test]]"
1523 (should
1524 (org-export-resolve-id-link
1525 (org-element-map tree 'link 'identity info t) info)))
1526 ;; 2. Failing test for custom-id link.
1527 (org-test-with-parsed-data "* Headline1
1528 :PROPERTIES:
1529 :CUSTOM_ID: test
1530 :END:
1531 * Headline 2
1532 \[[#no-match]]"
1533 (should-not
1534 (org-export-resolve-id-link
1535 (org-element-map tree 'link 'identity info t) info)))
1536 ;; 3. Test for internal id target.
1537 (org-test-with-parsed-data "* Headline1
1538 :PROPERTIES:
1539 :ID: aaaa
1540 :END:
1541 * Headline 2
1542 \[[id:aaaa]]"
1543 (should
1544 (org-export-resolve-id-link
1545 (org-element-map tree 'link 'identity info t) info)))
1546 ;; 4. Test for external id target.
1547 (org-test-with-parsed-data "[[id:aaaa]]"
1548 (should
1549 (org-export-resolve-id-link
1550 (org-element-map tree 'link 'identity info t)
1551 (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
1553 (ert-deftest test-org-export/resolve-radio-link ()
1554 "Test `org-export-resolve-radio-link' specifications."
1555 ;; Standard test.
1556 (should
1557 (org-test-with-temp-text "<<<radio>>> radio"
1558 (org-update-radio-target-regexp)
1559 (let* ((tree (org-element-parse-buffer))
1560 (info `(:parse-tree ,tree)))
1561 (org-export-resolve-radio-link
1562 (org-element-map tree 'link 'identity info t)
1563 info))))
1564 ;; Radio targets are case-insensitive.
1565 (should
1566 (org-test-with-temp-text "<<<RADIO>>> radio"
1567 (org-update-radio-target-regexp)
1568 (let* ((tree (org-element-parse-buffer))
1569 (info `(:parse-tree ,tree)))
1570 (org-export-resolve-radio-link
1571 (org-element-map tree 'link 'identity info t)
1572 info))))
1573 ;; Radio target with objects.
1574 (should
1575 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1576 (org-update-radio-target-regexp)
1577 (let* ((tree (org-element-parse-buffer))
1578 (info `(:parse-tree ,tree)))
1579 (org-export-resolve-radio-link
1580 (org-element-map tree 'link 'identity info t)
1581 info)))))
1585 ;;; Src-block and example-block
1587 (ert-deftest test-org-export/unravel-code ()
1588 "Test `org-export-unravel-code' function."
1589 (let ((org-coderef-label-format "(ref:%s)"))
1590 ;; 1. Code without reference.
1591 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1592 (should (equal (org-export-unravel-code (org-element-at-point))
1593 '("(+ 1 1)\n"))))
1594 ;; 2. Code with reference.
1595 (org-test-with-temp-text
1596 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1597 (should (equal (org-export-unravel-code (org-element-at-point))
1598 '("(+ 1 1)\n" (1 . "test")))))
1599 ;; 3. Code with user-defined reference.
1600 (org-test-with-temp-text
1601 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1602 (should (equal (org-export-unravel-code (org-element-at-point))
1603 '("(+ 1 1)\n" (1 . "test")))))
1604 ;; 4. Code references keys are relative to the current block.
1605 (org-test-with-temp-text "
1606 #+BEGIN_EXAMPLE -n
1607 \(+ 1 1)
1608 #+END_EXAMPLE
1609 #+BEGIN_EXAMPLE +n
1610 \(+ 2 2)
1611 \(+ 3 3) (ref:one)
1612 #+END_EXAMPLE"
1613 (goto-line 5)
1614 (should (equal (org-export-unravel-code (org-element-at-point))
1615 '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
1617 (ert-deftest test-org-export/format-code-default ()
1618 "Test `org-export-format-code-default' specifications."
1619 ;; Return the empty string when code is empty.
1620 (should
1621 (equal ""
1622 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1623 (org-export-format-code-default
1624 (org-element-map tree 'src-block 'identity info t) info))))
1625 ;; Number lines, two whitespace characters before the actual loc.
1626 (should
1627 (equal "1 a\n2 b\n"
1628 (org-test-with-parsed-data
1629 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1630 (org-export-format-code-default
1631 (org-element-map tree 'src-block 'identity info t) info))))
1632 ;; Put references 6 whitespace characters after the widest line,
1633 ;; wrapped within parenthesis.
1634 (should
1635 (equal "123 (a)\n1 (b)\n"
1636 (let ((org-coderef-label-format "(ref:%s)"))
1637 (org-test-with-parsed-data
1638 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1639 (org-export-format-code-default
1640 (org-element-map tree 'src-block 'identity info t) info))))))
1644 ;;; Smart Quotes
1646 (ert-deftest test-org-export/activate-smart-quotes ()
1647 "Test `org-export-activate-smart-quotes' specifications."
1648 ;; Opening double quotes: standard test.
1649 (should
1650 (equal
1651 '("some &ldquo;paragraph")
1652 (let ((org-export-default-language "en"))
1653 (org-test-with-parsed-data "some \"paragraph"
1654 (org-element-map tree 'plain-text
1655 (lambda (s) (org-export-activate-smart-quotes s :html info))
1656 info)))))
1657 ;; Opening quotes: at the beginning of a paragraph.
1658 (should
1659 (equal
1660 '("&ldquo;begin")
1661 (let ((org-export-default-language "en"))
1662 (org-test-with-parsed-data "\"begin"
1663 (org-element-map tree 'plain-text
1664 (lambda (s) (org-export-activate-smart-quotes s :html info))
1665 info)))))
1666 ;; Opening quotes: after an object.
1667 (should
1668 (equal
1669 '("&ldquo;begin")
1670 (let ((org-export-default-language "en"))
1671 (org-test-with-parsed-data "=verb= \"begin"
1672 (org-element-map tree 'plain-text
1673 (lambda (s) (org-export-activate-smart-quotes s :html info))
1674 info)))))
1675 ;; Closing quotes: standard test.
1676 (should
1677 (equal
1678 '("some&rdquo; paragraph")
1679 (let ((org-export-default-language "en"))
1680 (org-test-with-parsed-data "some\" paragraph"
1681 (org-element-map tree 'plain-text
1682 (lambda (s) (org-export-activate-smart-quotes s :html info))
1683 info)))))
1684 ;; Closing quotes: at the end of a paragraph.
1685 (should
1686 (equal
1687 '("end&rdquo;")
1688 (let ((org-export-default-language "en"))
1689 (org-test-with-parsed-data "end\""
1690 (org-element-map tree 'plain-text
1691 (lambda (s) (org-export-activate-smart-quotes s :html info))
1692 info)))))
1693 ;; Apostrophe: standard test.
1694 (should
1695 (equal
1696 '("It shouldn&rsquo;t fail")
1697 (let ((org-export-default-language "en"))
1698 (org-test-with-parsed-data "It shouldn't fail"
1699 (org-element-map tree 'plain-text
1700 (lambda (s) (org-export-activate-smart-quotes s :html info))
1701 info)))))
1702 ;; Apostrophe: before an object.
1703 (should
1704 (equal
1705 '("a&rsquo;")
1706 (let ((org-export-default-language "en"))
1707 (org-test-with-parsed-data "a'=b="
1708 (org-element-map tree 'plain-text
1709 (lambda (s) (org-export-activate-smart-quotes s :html info))
1710 info)))))
1711 ;; Apostrophe: after an object.
1712 (should
1713 (equal
1714 '("&rsquo;s")
1715 (let ((org-export-default-language "en"))
1716 (org-test-with-parsed-data "=code='s"
1717 (org-element-map tree 'plain-text
1718 (lambda (s) (org-export-activate-smart-quotes s :html info))
1719 info)))))
1720 ;; Special case: isolated quotes.
1721 (should
1722 (equal '("&ldquo;" "&rdquo;")
1723 (let ((org-export-default-language "en"))
1724 (org-test-with-parsed-data "\"$x$\""
1725 (org-element-map tree 'plain-text
1726 (lambda (s) (org-export-activate-smart-quotes s :html info))
1727 info)))))
1728 ;; Smart quotes in secondary strings.
1729 (should
1730 (equal '("&ldquo;" "&rdquo;")
1731 (let ((org-export-default-language "en"))
1732 (org-test-with-parsed-data "* \"$x$\""
1733 (org-element-map tree 'plain-text
1734 (lambda (s) (org-export-activate-smart-quotes s :html info))
1735 info)))))
1736 ;; Smart quotes in document keywords.
1737 (should
1738 (equal '("&ldquo;" "&rdquo;")
1739 (let ((org-export-default-language "en"))
1740 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1741 (org-element-map (plist-get info :title) 'plain-text
1742 (lambda (s) (org-export-activate-smart-quotes s :html info))
1743 info)))))
1744 ;; Smart quotes in parsed affiliated keywords.
1745 (should
1746 (equal '("&ldquo;" "&rdquo;" "Paragraph")
1747 (let ((org-export-default-language "en"))
1748 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1749 (org-element-map tree 'plain-text
1750 (lambda (s) (org-export-activate-smart-quotes s :html info))
1751 info nil nil t))))))
1755 ;;; Tables
1757 (ert-deftest test-org-export/special-column ()
1758 "Test if the table's special column is properly recognized."
1759 ;; 1. First column is special if it contains only a special marking
1760 ;; characters or empty cells.
1761 (org-test-with-temp-text "
1762 | ! | 1 |
1763 | | 2 |"
1764 (should
1765 (org-export-table-has-special-column-p
1766 (org-element-map
1767 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1768 ;; 2. If the column contains anything else, it isn't special.
1769 (org-test-with-temp-text "
1770 | ! | 1 |
1771 | b | 2 |"
1772 (should-not
1773 (org-export-table-has-special-column-p
1774 (org-element-map
1775 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1776 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1777 ;; and "!".
1778 (org-test-with-temp-text "
1779 | # | 1 |
1780 | ^ | 2 |
1781 | * | 3 |
1782 | _ | 4 |
1783 | / | 5 |
1784 | $ | 6 |
1785 | ! | 7 |"
1786 (should
1787 (org-export-table-has-special-column-p
1788 (org-element-map
1789 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1790 ;; 4. A first column with only empty cells isn't considered as
1791 ;; special.
1792 (org-test-with-temp-text "
1793 | | 1 |
1794 | | 2 |"
1795 (should-not
1796 (org-export-table-has-special-column-p
1797 (org-element-map
1798 (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
1800 (ert-deftest test-org-export/table-row-is-special-p ()
1801 "Test `org-export-table-row-is-special-p' specifications."
1802 ;; 1. A row is special if it has a special marking character in the
1803 ;; special column.
1804 (org-test-with-parsed-data "| ! | 1 |"
1805 (should
1806 (org-export-table-row-is-special-p
1807 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1808 ;; 2. A row is special when its first field is "/"
1809 (org-test-with-parsed-data "
1810 | / | 1 |
1811 | a | b |"
1812 (should
1813 (org-export-table-row-is-special-p
1814 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1815 ;; 3. A row only containing alignment cookies is also considered as
1816 ;; special.
1817 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1818 (should
1819 (org-export-table-row-is-special-p
1820 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1821 ;; 4. Everything else isn't considered as special.
1822 (org-test-with-parsed-data "| \alpha | | c |"
1823 (should-not
1824 (org-export-table-row-is-special-p
1825 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1826 ;; 5. Table's rules are never considered as special rows.
1827 (org-test-with-parsed-data "|---+---|"
1828 (should-not
1829 (org-export-table-row-is-special-p
1830 (org-element-map tree 'table-row 'identity nil 'first-match) info))))
1832 (ert-deftest test-org-export/has-header-p ()
1833 "Test `org-export-table-has-header-p' specifications."
1834 ;; 1. With an header.
1835 (org-test-with-parsed-data "
1836 | a | b |
1837 |---+---|
1838 | c | d |"
1839 (should
1840 (org-export-table-has-header-p
1841 (org-element-map tree 'table 'identity info 'first-match)
1842 info)))
1843 ;; 2. Without an header.
1844 (org-test-with-parsed-data "
1845 | a | b |
1846 | c | d |"
1847 (should-not
1848 (org-export-table-has-header-p
1849 (org-element-map tree 'table 'identity info 'first-match)
1850 info)))
1851 ;; 3. Don't get fooled with starting and ending rules.
1852 (org-test-with-parsed-data "
1853 |---+---|
1854 | a | b |
1855 | c | d |
1856 |---+---|"
1857 (should-not
1858 (org-export-table-has-header-p
1859 (org-element-map tree 'table 'identity info 'first-match)
1860 info))))
1862 (ert-deftest test-org-export/table-row-group ()
1863 "Test `org-export-table-row-group' specifications."
1864 ;; 1. A rule creates a new group.
1865 (org-test-with-parsed-data "
1866 | a | b |
1867 |---+---|
1868 | 1 | 2 |"
1869 (should
1870 (equal
1871 '(1 nil 2)
1872 (mapcar (lambda (row) (org-export-table-row-group row info))
1873 (org-element-map tree 'table-row 'identity)))))
1874 ;; 2. Special rows are ignored in count.
1875 (org-test-with-parsed-data "
1876 | / | < | > |
1877 |---|---+---|
1878 | | 1 | 2 |"
1879 (should
1880 (equal
1881 '(nil nil 1)
1882 (mapcar (lambda (row) (org-export-table-row-group row info))
1883 (org-element-map tree 'table-row 'identity)))))
1884 ;; 3. Double rules also are ignored in count.
1885 (org-test-with-parsed-data "
1886 | a | b |
1887 |---+---|
1888 |---+---|
1889 | 1 | 2 |"
1890 (should
1891 (equal
1892 '(1 nil nil 2)
1893 (mapcar (lambda (row) (org-export-table-row-group row info))
1894 (org-element-map tree 'table-row 'identity))))))
1896 (ert-deftest test-org-export/table-cell-width ()
1897 "Test `org-export-table-cell-width' specifications."
1898 ;; 1. Width is primarily determined by width cookies. If no cookie
1899 ;; is found, cell's width is nil.
1900 (org-test-with-parsed-data "
1901 | / | <l> | <6> | <l7> |
1902 | | a | b | c |"
1903 (should
1904 (equal
1905 '(nil 6 7)
1906 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1907 (org-element-map tree 'table-cell 'identity info)))))
1908 ;; 2. The last width cookie has precedence.
1909 (org-test-with-parsed-data "
1910 | <6> |
1911 | <7> |
1912 | a |"
1913 (should
1914 (equal
1915 '(7)
1916 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1917 (org-element-map tree 'table-cell 'identity info)))))
1918 ;; 3. Valid width cookies must have a specific row.
1919 (org-test-with-parsed-data "| <6> | cell |"
1920 (should
1921 (equal
1922 '(nil nil)
1923 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1924 (org-element-map tree 'table-cell 'identity))))))
1926 (ert-deftest test-org-export/table-cell-alignment ()
1927 "Test `org-export-table-cell-alignment' specifications."
1928 (let ((org-table-number-fraction 0.5)
1929 (org-table-number-regexp "^[0-9]+$"))
1930 ;; 1. Alignment is primarily determined by alignment cookies.
1931 (org-test-with-temp-text "| <l> | <c> | <r> |"
1932 (let* ((tree (org-element-parse-buffer))
1933 (info `(:parse-tree ,tree)))
1934 (should
1935 (equal
1936 '(left center right)
1937 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
1938 (org-element-map tree 'table-cell 'identity))))))
1939 ;; 2. The last alignment cookie has precedence.
1940 (org-test-with-parsed-data "
1941 | <l8> |
1942 | cell |
1943 | <r9> |"
1944 (should
1945 (equal
1946 '(right right right)
1947 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
1948 (org-element-map tree 'table-cell 'identity)))))
1949 ;; 3. If there's no cookie, cell's contents determine alignment.
1950 ;; A column mostly made of cells containing numbers will align
1951 ;; its cells to the right.
1952 (org-test-with-parsed-data "
1953 | 123 |
1954 | some text |
1955 | 12345 |"
1956 (should
1957 (equal
1958 '(right right right)
1959 (mapcar (lambda (cell)
1960 (org-export-table-cell-alignment cell info))
1961 (org-element-map tree 'table-cell 'identity)))))
1962 ;; 4. Otherwise, they will be aligned to the left.
1963 (org-test-with-parsed-data "
1964 | text |
1965 | some text |
1966 | \alpha |"
1967 (should
1968 (equal
1969 '(left left left)
1970 (mapcar (lambda (cell)
1971 (org-export-table-cell-alignment cell info))
1972 (org-element-map tree 'table-cell 'identity)))))))
1974 (ert-deftest test-org-export/table-cell-borders ()
1975 "Test `org-export-table-cell-borders' specifications."
1976 ;; 1. Recognize various column groups indicators.
1977 (org-test-with-parsed-data "| / | < | > | <> |"
1978 (should
1979 (equal
1980 '((right bottom top) (left bottom top) (right bottom top)
1981 (right left bottom top))
1982 (mapcar (lambda (cell)
1983 (org-export-table-cell-borders cell info))
1984 (org-element-map tree 'table-cell 'identity)))))
1985 ;; 2. Accept shortcuts to define column groups.
1986 (org-test-with-parsed-data "| / | < | < |"
1987 (should
1988 (equal
1989 '((right bottom top) (right left bottom top) (left bottom top))
1990 (mapcar (lambda (cell)
1991 (org-export-table-cell-borders cell info))
1992 (org-element-map tree 'table-cell 'identity)))))
1993 ;; 3. A valid column groups row must start with a "/".
1994 (org-test-with-parsed-data "
1995 | | < |
1996 | a | b |"
1997 (should
1998 (equal '((top) (top) (bottom) (bottom))
1999 (mapcar (lambda (cell)
2000 (org-export-table-cell-borders cell info))
2001 (org-element-map tree 'table-cell 'identity)))))
2002 ;; 4. Take table rules into consideration.
2003 (org-test-with-parsed-data "
2004 | 1 |
2005 |---|
2006 | 2 |"
2007 (should
2008 (equal '((below top) (bottom above))
2009 (mapcar (lambda (cell)
2010 (org-export-table-cell-borders cell info))
2011 (org-element-map tree 'table-cell 'identity)))))
2012 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2013 ;; (resp. `bottom' and `below') borders. Any special row is
2014 ;; ignored.
2015 (org-test-with-parsed-data "
2016 |---+----|
2017 | / | |
2018 | | 1 |
2019 |---+----|"
2020 (should
2021 (equal '((bottom below top above))
2022 (last
2023 (mapcar (lambda (cell)
2024 (org-export-table-cell-borders cell info))
2025 (org-element-map tree 'table-cell 'identity)))))))
2027 (ert-deftest test-org-export/table-dimensions ()
2028 "Test `org-export-table-dimensions' specifications."
2029 ;; 1. Standard test.
2030 (org-test-with-parsed-data "
2031 | 1 | 2 | 3 |
2032 | 4 | 5 | 6 |"
2033 (should
2034 (equal '(2 . 3)
2035 (org-export-table-dimensions
2036 (org-element-map tree 'table 'identity info 'first-match) info))))
2037 ;; 2. Ignore horizontal rules and special columns.
2038 (org-test-with-parsed-data "
2039 | / | < | > |
2040 | 1 | 2 | 3 |
2041 |---+---+---|
2042 | 4 | 5 | 6 |"
2043 (should
2044 (equal '(2 . 3)
2045 (org-export-table-dimensions
2046 (org-element-map tree 'table 'identity info 'first-match) info)))))
2048 (ert-deftest test-org-export/table-cell-address ()
2049 "Test `org-export-table-cell-address' specifications."
2050 ;; 1. Standard test: index is 0-based.
2051 (org-test-with-parsed-data "| a | b |"
2052 (should
2053 (equal '((0 . 0) (0 . 1))
2054 (org-element-map tree 'table-cell
2055 (lambda (cell) (org-export-table-cell-address cell info))
2056 info))))
2057 ;; 2. Special column isn't counted, nor are special rows.
2058 (org-test-with-parsed-data "
2059 | / | <> |
2060 | | c |"
2061 (should
2062 (equal '(0 . 0)
2063 (org-export-table-cell-address
2064 (car (last (org-element-map tree 'table-cell 'identity info)))
2065 info))))
2066 ;; 3. Tables rules do not count either.
2067 (org-test-with-parsed-data "
2068 | a |
2069 |---|
2070 | b |
2071 |---|
2072 | c |"
2073 (should
2074 (equal '(2 . 0)
2075 (org-export-table-cell-address
2076 (car (last (org-element-map tree 'table-cell 'identity info)))
2077 info))))
2078 ;; 4. Return nil for special cells.
2079 (org-test-with-parsed-data "| / | a |"
2080 (should-not
2081 (org-export-table-cell-address
2082 (org-element-map tree 'table-cell 'identity nil 'first-match)
2083 info))))
2085 (ert-deftest test-org-export/get-table-cell-at ()
2086 "Test `org-export-get-table-cell-at' specifications."
2087 ;; 1. Address ignores special columns, special rows and rules.
2088 (org-test-with-parsed-data "
2089 | / | <> |
2090 | | a |
2091 |---+----|
2092 | | b |"
2093 (should
2094 (equal '("b")
2095 (org-element-contents
2096 (org-export-get-table-cell-at
2097 '(1 . 0)
2098 (org-element-map tree 'table 'identity info 'first-match)
2099 info)))))
2100 ;; 2. Return value for a non-existent address is nil.
2101 (org-test-with-parsed-data "| a |"
2102 (should-not
2103 (org-export-get-table-cell-at
2104 '(2 . 2)
2105 (org-element-map tree 'table 'identity info 'first-match)
2106 info)))
2107 (org-test-with-parsed-data "| / |"
2108 (should-not
2109 (org-export-get-table-cell-at
2110 '(0 . 0)
2111 (org-element-map tree 'table 'identity info 'first-match)
2112 info))))
2114 (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
2115 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2116 ;; 1. A cell at a beginning of a row always starts a column group.
2117 (org-test-with-parsed-data "| a |"
2118 (should
2119 (org-export-table-cell-starts-colgroup-p
2120 (org-element-map tree 'table-cell 'identity info 'first-match)
2121 info)))
2122 ;; 2. Special column should be ignored when determining the
2123 ;; beginning of the row.
2124 (org-test-with-parsed-data "
2125 | / | |
2126 | | a |"
2127 (should
2128 (org-export-table-cell-starts-colgroup-p
2129 (org-element-map tree 'table-cell 'identity info 'first-match)
2130 info)))
2131 ;; 2. Explicit column groups.
2132 (org-test-with-parsed-data "
2133 | / | | < |
2134 | a | b | c |"
2135 (should
2136 (equal
2137 '(yes no yes)
2138 (org-element-map tree 'table-cell
2139 (lambda (cell)
2140 (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
2141 info)))))
2143 (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
2144 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2145 ;; 1. A cell at the end of a row always ends a column group.
2146 (org-test-with-parsed-data "| a |"
2147 (should
2148 (org-export-table-cell-ends-colgroup-p
2149 (org-element-map tree 'table-cell 'identity info 'first-match)
2150 info)))
2151 ;; 2. Special column should be ignored when determining the
2152 ;; beginning of the row.
2153 (org-test-with-parsed-data "
2154 | / | |
2155 | | a |"
2156 (should
2157 (org-export-table-cell-ends-colgroup-p
2158 (org-element-map tree 'table-cell 'identity info 'first-match)
2159 info)))
2160 ;; 3. Explicit column groups.
2161 (org-test-with-parsed-data "
2162 | / | < | |
2163 | a | b | c |"
2164 (should
2165 (equal
2166 '(yes no yes)
2167 (org-element-map tree 'table-cell
2168 (lambda (cell)
2169 (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
2170 info)))))
2172 (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
2173 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2174 ;; 1. A row at the beginning of a table always starts a row group.
2175 ;; So does a row following a table rule.
2176 (org-test-with-parsed-data "
2177 | a |
2178 |---|
2179 | b |"
2180 (should
2181 (equal
2182 '(yes no yes)
2183 (org-element-map tree 'table-row
2184 (lambda (row)
2185 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
2186 info))))
2187 ;; 2. Special rows should be ignored when determining the beginning
2188 ;; of the row.
2189 (org-test-with-parsed-data "
2190 | / | < |
2191 | | a |
2192 |---+---|
2193 | / | < |
2194 | | b |"
2195 (should
2196 (equal
2197 '(yes no yes)
2198 (org-element-map tree 'table-row
2199 (lambda (row)
2200 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
2201 info)))))
2203 (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
2204 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2205 ;; 1. A row at the end of a table always ends a row group. So does
2206 ;; a row preceding a table rule.
2207 (org-test-with-parsed-data "
2208 | a |
2209 |---|
2210 | b |"
2211 (should
2212 (equal
2213 '(yes no yes)
2214 (org-element-map tree 'table-row
2215 (lambda (row)
2216 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
2217 info))))
2218 ;; 2. Special rows should be ignored when determining the beginning
2219 ;; of the row.
2220 (org-test-with-parsed-data "
2221 | | a |
2222 | / | < |
2223 |---+---|
2224 | | b |
2225 | / | < |"
2226 (should
2227 (equal
2228 '(yes no yes)
2229 (org-element-map tree 'table-row
2230 (lambda (row)
2231 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
2232 info)))))
2234 (ert-deftest test-org-export/table-row-starts-header-p ()
2235 "Test `org-export-table-row-starts-header-p' specifications."
2236 ;; 1. Only the row starting the first row group starts the table
2237 ;; header.
2238 (org-test-with-parsed-data "
2239 | a |
2240 | b |
2241 |---|
2242 | c |"
2243 (should
2244 (equal
2245 '(yes no no no)
2246 (org-element-map tree 'table-row
2247 (lambda (row)
2248 (if (org-export-table-row-starts-header-p row info) 'yes 'no))
2249 info))))
2250 ;; 2. A row cannot start an header if there's no header in the
2251 ;; table.
2252 (org-test-with-parsed-data "
2253 | a |
2254 |---|"
2255 (should-not
2256 (org-export-table-row-starts-header-p
2257 (org-element-map tree 'table-row 'identity info 'first-match)
2258 info))))
2260 (ert-deftest test-org-export/table-row-ends-header-p ()
2261 "Test `org-export-table-row-ends-header-p' specifications."
2262 ;; 1. Only the row starting the first row group starts the table
2263 ;; header.
2264 (org-test-with-parsed-data "
2265 | a |
2266 | b |
2267 |---|
2268 | c |"
2269 (should
2270 (equal
2271 '(no yes no no)
2272 (org-element-map tree 'table-row
2273 (lambda (row)
2274 (if (org-export-table-row-ends-header-p row info) 'yes 'no))
2275 info))))
2276 ;; 2. A row cannot start an header if there's no header in the
2277 ;; table.
2278 (org-test-with-parsed-data "
2279 | a |
2280 |---|"
2281 (should-not
2282 (org-export-table-row-ends-header-p
2283 (org-element-map tree 'table-row 'identity info 'first-match)
2284 info))))
2288 ;;; Templates
2290 (ert-deftest test-org-export/inner-template ()
2291 "Test `inner-template' translator specifications."
2292 (should
2293 (equal "Success!"
2294 (let (org-export-registered-backends)
2295 (org-export-define-backend 'test
2296 '((inner-template . (lambda (contents info) "Success!"))
2297 (headline . (lambda (h c i) "Headline"))))
2298 (org-test-with-temp-text "* Headline"
2299 (org-export-as 'test)))))
2300 ;; Inner template is applied even in a "body-only" export.
2301 (should
2302 (equal "Success!"
2303 (let (org-export-registered-backends)
2304 (org-export-define-backend 'test
2305 '((inner-template . (lambda (contents info) "Success!"))
2306 (headline . (lambda (h c i) "Headline"))))
2307 (org-test-with-temp-text "* Headline"
2308 (org-export-as 'test nil nil 'body-only))))))
2310 (ert-deftest test-org-export/template ()
2311 "Test `template' translator specifications."
2312 (should
2313 (equal "Success!"
2314 (let (org-export-registered-backends)
2315 (org-export-define-backend 'test
2316 '((template . (lambda (contents info) "Success!"))
2317 (headline . (lambda (h c i) "Headline"))))
2318 (org-test-with-temp-text "* Headline"
2319 (org-export-as 'test)))))
2320 ;; Template is not applied in a "body-only" export.
2321 (should-not
2322 (equal "Success!"
2323 (let (org-export-registered-backends)
2324 (org-export-define-backend 'test
2325 '((template . (lambda (contents info) "Success!"))
2326 (headline . (lambda (h c i) "Headline"))))
2327 (org-test-with-temp-text "* Headline"
2328 (org-export-as 'test nil nil 'body-only))))))
2332 ;;; Topology
2334 (ert-deftest test-org-export/get-next-element ()
2335 "Test `org-export-get-next-element' specifications."
2336 ;; Standard test.
2337 (should
2338 (equal "b"
2339 (org-test-with-parsed-data "* Headline\n*a* b"
2340 (org-export-get-next-element
2341 (org-element-map tree 'bold 'identity info t) info))))
2342 ;; Return nil when no previous element.
2343 (should-not
2344 (org-test-with-parsed-data "* Headline\na *b*"
2345 (org-export-get-next-element
2346 (org-element-map tree 'bold 'identity info t) info)))
2347 ;; Non-exportable elements are ignored.
2348 (should-not
2349 (let ((org-export-with-timestamps nil))
2350 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2351 (org-export-get-next-element
2352 (org-element-map tree 'entity 'identity info t) info))))
2353 ;; Find next element in secondary strings.
2354 (should
2355 (eq 'verbatim
2356 (org-test-with-parsed-data "* a =verb="
2357 (org-element-type
2358 (org-export-get-next-element
2359 (org-element-map tree 'plain-text 'identity info t) info)))))
2360 ;; Find next element in document keywords.
2361 (should
2362 (eq 'verbatim
2363 (org-test-with-parsed-data "#+TITLE: a =verb="
2364 (org-element-type
2365 (org-export-get-next-element
2366 (org-element-map
2367 (plist-get info :title) 'plain-text 'identity info t) info)))))
2368 ;; Find next element in parsed affiliated keywords.
2369 (should
2370 (eq 'verbatim
2371 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2372 (org-element-type
2373 (org-export-get-next-element
2374 (org-element-map tree 'plain-text 'identity info t nil t) info)))))
2375 ;; With optional argument N, return a list containing all the
2376 ;; following elements.
2377 (should
2378 (equal
2379 '(bold code underline)
2380 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2381 (mapcar 'car
2382 (org-export-get-next-element
2383 (org-element-map tree 'italic 'identity info t) info t)))))
2384 ;; When N is a positive integer, return a list containing up to
2385 ;; N following elements.
2386 (should
2387 (equal
2388 '(bold code)
2389 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2390 (mapcar 'car
2391 (org-export-get-next-element
2392 (org-element-map tree 'italic 'identity info t) info 2))))))
2394 (ert-deftest test-org-export/get-previous-element ()
2395 "Test `org-export-get-previous-element' specifications."
2396 ;; Standard test.
2397 (should
2398 (equal "a "
2399 (org-test-with-parsed-data "* Headline\na *b*"
2400 (org-export-get-previous-element
2401 (org-element-map tree 'bold 'identity info t) info))))
2402 ;; Return nil when no previous element.
2403 (should-not
2404 (org-test-with-parsed-data "* Headline\n*a* b"
2405 (org-export-get-previous-element
2406 (org-element-map tree 'bold 'identity info t) info)))
2407 ;; Non-exportable elements are ignored.
2408 (should-not
2409 (let ((org-export-with-timestamps nil))
2410 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2411 (org-export-get-previous-element
2412 (org-element-map tree 'entity 'identity info t) info))))
2413 ;; Find previous element in secondary strings.
2414 (should
2415 (eq 'verbatim
2416 (org-test-with-parsed-data "* =verb= a"
2417 (org-element-type
2418 (org-export-get-previous-element
2419 (org-element-map tree 'plain-text 'identity info t) info)))))
2420 ;; Find previous element in document keywords.
2421 (should
2422 (eq 'verbatim
2423 (org-test-with-parsed-data "#+TITLE: =verb= a"
2424 (org-element-type
2425 (org-export-get-previous-element
2426 (org-element-map
2427 (plist-get info :title) 'plain-text 'identity info t) info)))))
2428 ;; Find previous element in parsed affiliated keywords.
2429 (should
2430 (eq 'verbatim
2431 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2432 (org-element-type
2433 (org-export-get-previous-element
2434 (org-element-map tree 'plain-text 'identity info t nil t) info)))))
2435 ;; With optional argument N, return a list containing up to
2436 ;; N previous elements.
2437 (should
2438 (equal '(underline italic bold)
2439 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2440 (mapcar 'car
2441 (org-export-get-previous-element
2442 (org-element-map tree 'code 'identity info t) info t)))))
2443 ;; When N is a positive integer, return a list containing up to
2444 ;; N previous elements.
2445 (should
2446 (equal '(italic bold)
2447 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2448 (mapcar 'car
2449 (org-export-get-previous-element
2450 (org-element-map tree 'code 'identity info t) info 2))))))
2453 (provide 'test-ox)
2454 ;;; test-org-export.el end here