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