ox: White spaces after export snippets are never ignored
[org-mode.git] / testing / lisp / test-ox.el
blob8832bcdd43d80440f9bf51c9d10e9d0f0727a658
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 data 'headline
592 (lambda (headline)
593 (when (string-match "\\<note\\>"
594 (org-element-property :raw-value headline))
595 (org-export-ignore-element headline info)))
596 info)
597 data))
598 ;; Install function in parse tree filters.
599 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
600 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
601 (should (equal (org-export-as 'test) "* Head1\n")))))))
603 (ert-deftest test-org-export/before-processing-hook ()
604 "Test `org-export-before-processing-hook'."
605 (should
606 (equal
607 "#+MACRO: mac val\nTest\n"
608 (org-test-with-backend test
609 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
610 (let ((org-export-before-processing-hook
611 '((lambda (backend)
612 (while (re-search-forward "{{{" nil t)
613 (let ((object (org-element-context)))
614 (when (eq (org-element-type object) 'macro)
615 (delete-region
616 (org-element-property :begin object)
617 (org-element-property :end object)))))))))
618 (org-export-as 'test)))))))
620 (ert-deftest test-org-export/before-parsing-hook ()
621 "Test `org-export-before-parsing-hook'."
622 (should
623 (equal "Body 1\nBody 2\n"
624 (org-test-with-backend test
625 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
626 (let ((org-export-before-parsing-hook
627 '((lambda (backend)
628 (goto-char (point-min))
629 (while (re-search-forward org-outline-regexp-bol nil t)
630 (delete-region
631 (point-at-bol) (progn (forward-line) (point))))))))
632 (org-export-as 'test)))))))
636 ;;; Affiliated Keywords
638 (ert-deftest test-org-export/read-attribute ()
639 "Test `org-export-read-attribute' specifications."
640 ;; Standard test.
641 (should
642 (equal
643 (org-export-read-attribute
644 :attr_html
645 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
646 (org-element-at-point)))
647 '(:a "1" :b "2")))
648 ;; Return nil on empty attribute.
649 (should-not
650 (org-export-read-attribute
651 :attr_html
652 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
653 ;; Return nil on "nil" string.
654 (should
655 (equal '(:a nil :b nil)
656 (org-export-read-attribute
657 :attr_html
658 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
659 (org-element-at-point)))))
660 ;; Return nil on empty string.
661 (should
662 (equal '(:a nil :b nil)
663 (org-export-read-attribute
664 :attr_html
665 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
666 (org-element-at-point)))))
667 ;; Ignore text before first property.
668 (should-not
669 (member "ignore"
670 (org-export-read-attribute
671 :attr_html
672 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
673 (org-element-at-point))))))
675 (ert-deftest test-org-export/get-caption ()
676 "Test `org-export-get-caption' specifications."
677 ;; Without optional argument, return long caption
678 (should
679 (equal
680 '("l")
681 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
682 (org-export-get-caption (org-element-at-point)))))
683 ;; With optional argument, return short caption.
684 (should
685 (equal
686 '("s")
687 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
688 (org-export-get-caption (org-element-at-point) t))))
689 ;; Multiple lines are separated by white spaces.
690 (should
691 (equal
692 '("a" " " "b")
693 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
694 (org-export-get-caption (org-element-at-point))))))
698 ;;; Back-End Tools
700 (ert-deftest test-org-export/define-backend ()
701 "Test back-end definition and accessors."
702 ;; Translate table.
703 (should
704 (equal '((headline . my-headline-test))
705 (let (org-export-registered-backends)
706 (org-export-define-backend 'test '((headline . my-headline-test)))
707 (org-export-backend-translate-table 'test))))
708 ;; Filters.
709 (should
710 (equal '((:filter-headline . my-filter))
711 (let (org-export-registered-backends)
712 (org-export-define-backend 'test
713 '((headline . my-headline-test))
714 :filters-alist '((:filter-headline . my-filter)))
715 (org-export-backend-filters 'test))))
716 ;; Options.
717 (should
718 (equal '((:prop value))
719 (let (org-export-registered-backends)
720 (org-export-define-backend 'test
721 '((headline . my-headline-test))
722 :options-alist '((:prop value)))
723 (org-export-backend-options 'test))))
724 ;; Menu.
725 (should
726 (equal '(?k "Test Export" test)
727 (let (org-export-registered-backends)
728 (org-export-define-backend 'test
729 '((headline . my-headline-test))
730 :menu-entry '(?k "Test Export" test))
731 (org-export-backend-menu 'test))))
732 ;; Export Blocks.
733 (should
734 (equal '(("TEST" . org-element-export-block-parser))
735 (let (org-export-registered-backends org-element-block-name-alist)
736 (org-export-define-backend 'test
737 '((headline . my-headline-test))
738 :export-block '("test"))
739 org-element-block-name-alist))))
741 (ert-deftest test-org-export/define-derived-backend ()
742 "Test `org-export-define-derived-backend' specifications."
743 ;; Error when parent back-end is not defined.
744 (should-error
745 (let (org-export-registered-backends)
746 (org-export-define-derived-backend 'test 'parent)))
747 ;; Append translation table to parent's.
748 (should
749 (equal '((:headline . test) (:headline . parent))
750 (let (org-export-registered-backends)
751 (org-export-define-backend 'parent '((:headline . parent)))
752 (org-export-define-derived-backend 'test 'parent
753 :translate-alist '((:headline . test)))
754 (org-export-backend-translate-table 'test))))
755 ;; Options defined in the new back have priority over those defined
756 ;; in parent.
757 (should
758 (eq 'test
759 (let (org-export-registered-backends)
760 (org-export-define-backend 'parent
761 '((:headline . parent))
762 :options-alist '((:a nil nil 'parent)))
763 (org-export-define-derived-backend 'test 'parent
764 :options-alist '((:a nil nil 'test)))
765 (plist-get (org-export--get-global-options 'test) :a)))))
767 (ert-deftest test-org-export/derived-backend-p ()
768 "Test `org-export-derived-backend-p' specifications."
769 ;; Non-nil with direct match.
770 (should
771 (let (org-export-registered-backends)
772 (org-export-define-backend 'test '((headline . test)))
773 (org-export-derived-backend-p 'test 'test)))
774 (should
775 (let (org-export-registered-backends)
776 (org-export-define-backend 'test '((headline . test)))
777 (org-export-define-derived-backend 'test2 'test)
778 (org-export-derived-backend-p 'test2 'test2)))
779 ;; Non-nil with a direct parent.
780 (should
781 (let (org-export-registered-backends)
782 (org-export-define-backend 'test '((headline . test)))
783 (org-export-define-derived-backend 'test2 'test)
784 (org-export-derived-backend-p 'test2 'test)))
785 ;; Non-nil with an indirect parent.
786 (should
787 (let (org-export-registered-backends)
788 (org-export-define-backend 'test '((headline . test)))
789 (org-export-define-derived-backend 'test2 'test)
790 (org-export-define-derived-backend 'test3 'test2)
791 (org-export-derived-backend-p 'test3 'test)))
792 ;; Nil otherwise.
793 (should-not
794 (let (org-export-registered-backends)
795 (org-export-define-backend 'test '((headline . test)))
796 (org-export-define-backend 'test2 '((headline . test2)))
797 (org-export-derived-backend-p 'test2 'test)))
798 (should-not
799 (let (org-export-registered-backends)
800 (org-export-define-backend 'test '((headline . test)))
801 (org-export-define-backend 'test2 '((headline . test2)))
802 (org-export-define-derived-backend 'test3 'test2)
803 (org-export-derived-backend-p 'test3 'test))))
805 (ert-deftest test-org-export/with-backend ()
806 "Test `org-export-with-backend' definition."
807 ;; Error when calling an undefined back-end
808 (should-error
809 (let (org-export-registered-backends)
810 (org-export-with-backend 'test "Test")))
811 ;; Error when called back-end doesn't have an appropriate
812 ;; transcoder.
813 (should-error
814 (let (org-export-registered-backends)
815 (org-export-define-backend 'test ((headline . ignore)))
816 (org-export-with-backend 'test "Test")))
817 ;; Otherwise, export using correct transcoder
818 (should
819 (equal "Success"
820 (let (org-export-registered-backends)
821 (org-export-define-backend 'test
822 '((plain-text . (lambda (text contents info) "Failure"))))
823 (org-export-define-backend 'test2
824 '((plain-text . (lambda (text contents info) "Success"))))
825 (org-export-with-backend 'test2 "Test")))))
827 (ert-deftest test-org-export/data-with-translations ()
828 "Test `org-export-data-with-translations' specifications."
829 (should
830 (equal
831 "Success!"
832 (org-export-data-with-translations
833 '(bold nil "Test")
834 '((plain-text . (lambda (text info) "Success"))
835 (bold . (lambda (bold contents info) (concat contents "!"))))
836 '(:with-emphasize t)))))
838 (ert-deftest test-org-export/data-with-backend ()
839 "Test `org-export-data-with-backend' specifications."
840 ;; Error when calling an undefined back-end.
841 (should-error
842 (let (org-export-registered-backends)
843 (org-export-data-with-backend 'test "Test" nil)))
844 ;; Otherwise, export data recursively, using correct back-end.
845 (should
846 (equal
847 "Success!"
848 (let (org-export-registered-backends)
849 (org-export-define-backend 'test
850 '((plain-text . (lambda (text info) "Success"))
851 (bold . (lambda (bold contents info) (concat contents "!")))))
852 (org-export-data-with-backend
853 '(bold nil "Test") 'test '(:with-emphasize t))))))
857 ;;; Export Snippets
859 (ert-deftest test-org-export/export-snippet ()
860 "Test export snippets transcoding."
861 (org-test-with-temp-text "@@test:A@@@@t:B@@"
862 (org-test-with-backend test
863 (plist-put
864 (cdr (assq 'test org-export-registered-backends))
865 :translate-alist
866 (cons (cons 'export-snippet
867 (lambda (snippet contents info)
868 (when (eq (org-export-snippet-backend snippet) 'test)
869 (org-element-property :value snippet))))
870 (org-export-backend-translate-table 'test)))
871 (let ((org-export-snippet-translation-alist nil))
872 (should (equal (org-export-as 'test) "A\n")))
873 (let ((org-export-snippet-translation-alist '(("t" . "test"))))
874 (should (equal (org-export-as 'test) "AB\n")))))
875 ;; Ignored export snippets do not remove any blank.
876 (should
877 (equal "begin end\n"
878 (org-test-with-parsed-data "begin @@test:A@@ end"
879 (org-export-data-with-translations
880 tree
881 '((paragraph . (lambda (paragraph contents info) contents))
882 (section . (lambda (section contents info) contents)))
883 info)))))
887 ;;; Footnotes
889 (ert-deftest test-org-export/footnotes ()
890 "Test footnotes specifications."
891 (let ((org-footnote-section nil)
892 (org-export-with-footnotes t))
893 ;; 1. Read every type of footnote.
894 (should
895 (equal
896 '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
897 (org-test-with-parsed-data
898 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
899 (org-element-map tree 'footnote-reference
900 (lambda (ref)
901 (let ((def (org-export-get-footnote-definition ref info)))
902 (cons (org-export-get-footnote-number ref info)
903 (if (eq (org-element-property :type ref) 'inline) (car def)
904 (car (org-element-contents
905 (car (org-element-contents def))))))))
906 info))))
907 ;; 2. Test nested footnotes order.
908 (org-test-with-parsed-data
909 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
910 (should
911 (equal
912 '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
913 (org-element-map tree 'footnote-reference
914 (lambda (ref)
915 (when (org-export-footnote-first-reference-p ref info)
916 (cons (org-export-get-footnote-number ref info)
917 (org-element-property :label ref))))
918 info))))
919 ;; 3. Test nested footnote in invisible definitions.
920 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
921 ;; Hide definitions.
922 (narrow-to-region (point) (point-at-eol))
923 (let* ((tree (org-element-parse-buffer))
924 (info (org-combine-plists
925 `(:parse-tree ,tree)
926 (org-export-collect-tree-properties
927 tree (org-export-get-environment)))))
928 ;; Both footnotes should be seen.
929 (should
930 (= (length (org-export-collect-footnote-definitions tree info)) 2))))
931 ;; 4. Test footnotes definitions collection.
932 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
934 \[fn:2] B [fn:3] [fn::D].
936 \[fn:3] C."
937 (should (= (length (org-export-collect-footnote-definitions tree info))
938 4)))
939 ;; 5. Test export of footnotes defined outside parsing scope.
940 (org-test-with-temp-text "[fn:1] Out of scope
941 * Title
942 Paragraph[fn:1]"
943 (org-test-with-backend test
944 (plist-put
945 (cdr (assq 'test org-export-registered-backends))
946 :translate-alist
947 (cons (cons 'footnote-reference
948 (lambda (fn contents info)
949 (org-element-interpret-data
950 (org-export-get-footnote-definition fn info))))
951 (org-export-backend-translate-table 'test)))
952 (forward-line)
953 (should (equal "ParagraphOut of scope\n"
954 (org-export-as 'test 'subtree)))))
955 ;; 6. Footnotes without a definition should be provided a fallback
956 ;; definition.
957 (should
958 (org-test-with-parsed-data "[fn:1]"
959 (org-export-get-footnote-definition
960 (org-element-map tree 'footnote-reference 'identity info t) info)))
961 ;; 7. Footnote section should be ignored in TOC and in headlines
962 ;; numbering.
963 (should
964 (= 1 (let ((org-footnote-section "Footnotes"))
965 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
966 (org-export-collect-headlines info))))))
967 (should
968 (equal '(2)
969 (let ((org-footnote-section "Footnotes"))
970 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
971 (org-element-map tree 'headline
972 (lambda (hl)
973 (when (equal (org-element-property :raw-value hl) "H2")
974 (org-export-get-headline-number hl info)))
975 info t)))))))
979 ;;; Headlines and Inlinetasks
981 (ert-deftest test-org-export/get-relative-level ()
982 "Test `org-export-get-relative-level' specifications."
983 ;; Standard test.
984 (should
985 (equal '(1 2)
986 (let ((org-odd-levels-only nil))
987 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
988 (org-element-map tree 'headline
989 (lambda (h) (org-export-get-relative-level h info))
990 info)))))
991 ;; Missing levels
992 (should
993 (equal '(1 3)
994 (let ((org-odd-levels-only nil))
995 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
996 (org-element-map tree 'headline
997 (lambda (h) (org-export-get-relative-level h info))
998 info))))))
1000 (ert-deftest test-org-export/low-level-p ()
1001 "Test `org-export-low-level-p' specifications."
1002 (should
1003 (equal
1004 '(no yes)
1005 (let ((org-odd-levels-only nil))
1006 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1007 (org-element-map tree 'headline
1008 (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
1009 (plist-put info :headline-levels 1)))))))
1011 (ert-deftest test-org-export/get-headline-number ()
1012 "Test `org-export-get-headline-number' specifications."
1013 ;; Standard test.
1014 (should
1015 (equal
1016 '((1) (1 1))
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-headline-number h info))
1021 info)))))
1022 ;; Missing levels are replaced with 0.
1023 (should
1024 (equal
1025 '((1) (1 0 1))
1026 (let ((org-odd-levels-only nil))
1027 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1028 (org-element-map tree 'headline
1029 (lambda (h) (org-export-get-headline-number h info))
1030 info))))))
1032 (ert-deftest test-org-export/numbered-headline-p ()
1033 "Test `org-export-numbered-headline-p' specifications."
1034 ;; If `:section-numbers' is nil, never number headlines.
1035 (should-not
1036 (org-test-with-parsed-data "* Headline"
1037 (org-element-map 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 tree 'headline
1047 (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
1048 (plist-put info :section-numbers 1)))))
1049 ;; Otherwise, headlines are always numbered.
1050 (should
1051 (org-test-with-parsed-data "* Headline"
1052 (org-element-map tree 'headline
1053 (lambda (h) (org-export-numbered-headline-p h info))
1054 (plist-put info :section-numbers t)))))
1056 (ert-deftest test-org-export/number-to-roman ()
1057 "Test `org-export-number-to-roman' specifications."
1058 ;; If number is negative, return it as a string.
1059 (should (equal (org-export-number-to-roman -1) "-1"))
1060 ;; Otherwise, return it as a roman number.
1061 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1063 (ert-deftest test-org-export/get-optional-title ()
1064 "Test `org-export-get-alt-title' specifications."
1065 ;; If ALT_TITLE property is defined, use it.
1066 (should
1067 (equal '("opt")
1068 (org-test-with-parsed-data
1069 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1070 (org-export-get-alt-title
1071 (org-element-map tree 'headline 'identity info t)
1072 info))))
1073 ;; Otherwise, fall-back to regular title.
1074 (should
1075 (equal '("Headline")
1076 (org-test-with-parsed-data "* Headline"
1077 (org-export-get-alt-title
1078 (org-element-map tree 'headline 'identity info t)
1079 info)))))
1081 (ert-deftest test-org-export/get-tags ()
1082 "Test `org-export-get-tags' specifications."
1083 (let ((org-export-exclude-tags '("noexport"))
1084 (org-export-select-tags '("export")))
1085 ;; Standard test: tags which are not a select tag, an exclude tag,
1086 ;; or specified as optional argument shouldn't be ignored.
1087 (should
1088 (org-test-with-parsed-data "* Headline :tag:"
1089 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1090 info)))
1091 ;; Exclude tags are removed.
1092 (should-not
1093 (org-test-with-parsed-data "* Headline :noexport:"
1094 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1095 info)))
1096 ;; Select tags are removed.
1097 (should-not
1098 (org-test-with-parsed-data "* Headline :export:"
1099 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1100 info)))
1101 (should
1102 (equal
1103 '("tag")
1104 (org-test-with-parsed-data "* Headline :tag:export:"
1105 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1106 info))))
1107 ;; Tags provided in the optional argument are also ignored.
1108 (should-not
1109 (org-test-with-parsed-data "* Headline :ignore:"
1110 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
1111 info '("ignore"))))
1112 ;; Allow tag inheritance.
1113 (should
1114 (equal
1115 '(("tag") ("tag"))
1116 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1117 (org-element-map tree 'headline
1118 (lambda (hl) (org-export-get-tags hl info nil t)) info))))
1119 ;; Tag inheritance checks FILETAGS keywords.
1120 (should
1121 (equal
1122 '(("a" "b" "tag"))
1123 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1124 (org-element-map tree 'headline
1125 (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
1127 (ert-deftest test-org-export/get-node-property ()
1128 "Test`org-export-get-node-property' specifications."
1129 ;; Standard test.
1130 (should
1131 (equal "value"
1132 (org-test-with-parsed-data "* Headline
1133 :PROPERTIES:
1134 :prop: value
1135 :END:"
1136 (org-export-get-node-property
1137 :PROP (org-element-map tree 'headline 'identity nil t)))))
1138 ;; Test inheritance.
1139 (should
1140 (equal "value"
1141 (org-test-with-parsed-data "* Parent
1142 :PROPERTIES:
1143 :prop: value
1144 :END:
1145 ** Headline
1146 Paragraph"
1147 (org-export-get-node-property
1148 :PROP (org-element-map tree 'paragraph 'identity nil t) t))))
1149 ;; Cannot return a value before the first headline.
1150 (should-not
1151 (org-test-with-parsed-data "Paragraph
1152 * Headline
1153 :PROPERTIES:
1154 :prop: value
1155 :END:"
1156 (org-export-get-node-property
1157 :PROP (org-element-map tree 'paragraph 'identity nil t)))))
1159 (ert-deftest test-org-export/get-category ()
1160 "Test `org-export-get-category' specifications."
1161 ;; Standard test.
1162 (should
1163 (equal "value"
1164 (org-test-with-parsed-data "* Headline
1165 :PROPERTIES:
1166 :CATEGORY: value
1167 :END:"
1168 (org-export-get-category
1169 (org-element-map tree 'headline 'identity nil t) info))))
1170 ;; Test inheritance from a parent headline.
1171 (should
1172 (equal '("value" "value")
1173 (org-test-with-parsed-data "* Headline1
1174 :PROPERTIES:
1175 :CATEGORY: value
1176 :END:
1177 ** Headline2"
1178 (org-element-map tree 'headline
1179 (lambda (hl) (org-export-get-category hl info)) info))))
1180 ;; Test inheritance from #+CATEGORY keyword
1181 (should
1182 (equal "value"
1183 (org-test-with-parsed-data "#+CATEGORY: value
1184 * Headline"
1185 (org-export-get-category
1186 (org-element-map tree 'headline 'identity nil t) info))))
1187 ;; Test inheritance from file name.
1188 (should
1189 (equal "test"
1190 (org-test-with-parsed-data "* Headline"
1191 (let ((info (plist-put info :input-file "~/test.org")))
1192 (org-export-get-category
1193 (org-element-map tree 'headline 'identity nil t) info)))))
1194 ;; Fall-back value.
1195 (should
1196 (equal "???"
1197 (org-test-with-parsed-data "* Headline"
1198 (org-export-get-category
1199 (org-element-map tree 'headline 'identity nil t) info)))))
1201 (ert-deftest test-org-export/first-sibling-p ()
1202 "Test `org-export-first-sibling-p' specifications."
1203 ;; Standard test.
1204 (should
1205 (equal
1206 '(yes yes no)
1207 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1208 (org-element-map tree 'headline
1209 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
1210 info))))
1211 ;; Ignore headlines not exported.
1212 (should
1213 (equal
1214 '(yes)
1215 (let ((org-export-exclude-tags '("ignore")))
1216 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1217 (org-element-map tree 'headline
1218 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
1219 info))))))
1221 (ert-deftest test-org-export/last-sibling-p ()
1222 "Test `org-export-last-sibling-p' specifications."
1223 ;; Standard test.
1224 (should
1225 (equal
1226 '(yes no yes)
1227 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1228 (org-element-map tree 'headline
1229 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
1230 info))))
1231 ;; Ignore headlines not exported.
1232 (should
1233 (equal
1234 '(yes)
1235 (let ((org-export-exclude-tags '("ignore")))
1236 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1237 (org-element-map tree 'headline
1238 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
1239 info))))))
1241 (ert-deftest test-org-export/handle-inlinetasks ()
1242 "Test inlinetask export."
1243 ;; Inlinetask with an exclude tag.
1244 (when (featurep 'org-inlinetask)
1245 (should
1246 (equal
1248 (let ((org-inlinetask-min-level 3))
1249 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1250 (org-test-with-backend test
1251 (org-export-as 'test nil nil nil '(:exclude-tags ("noexp"))))))))
1252 ;; Inlinetask with an include tag.
1253 (should
1254 (equal
1255 "* H2\n*** Inline :exp:\n"
1256 (let ((org-inlinetask-min-level 3)
1257 (org-tags-column 0))
1258 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1259 (org-test-with-backend test
1260 (org-export-as 'test nil nil nil '(:select-tags ("exp"))))))))
1261 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1262 (should
1263 (equal ""
1264 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1265 (org-inlinetask-min-level 3))
1266 (org-test-with-temp-text "*** TODO Inline"
1267 (org-test-with-backend test
1268 (org-export-as 'test nil nil nil '(:with-tasks nil)))))))))
1272 ;;; Links
1274 (ert-deftest test-org-export/get-coderef-format ()
1275 "Test `org-export-get-coderef-format' specifications."
1276 ;; A link without description returns "%s"
1277 (should (equal (org-export-get-coderef-format "(ref:line)" nil)
1278 "%s"))
1279 ;; Return "%s" when path is matched within description.
1280 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1281 "desc %s"))
1282 ;; Otherwise return description.
1283 (should (equal (org-export-get-coderef-format "path" "desc")
1284 "desc")))
1286 (ert-deftest test-org-export/inline-image-p ()
1287 "Test `org-export-inline-image-p' specifications."
1288 (should
1289 (org-export-inline-image-p
1290 (org-test-with-temp-text "[[#id]]"
1291 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
1292 '(("custom-id" . "id")))))
1294 (ert-deftest test-org-export/fuzzy-link ()
1295 "Test fuzzy links specifications."
1296 ;; 1. Links to invisible (keyword) targets should be ignored.
1297 (org-test-with-parsed-data
1298 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1299 (should-not
1300 (org-element-map tree 'link
1301 (lambda (link)
1302 (org-export-get-ordinal
1303 (org-export-resolve-fuzzy-link link info) info)) info)))
1304 ;; 2. Link to an headline should return headline's number.
1305 (org-test-with-parsed-data
1306 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1307 (should
1308 ;; Note: Headline's number is in fact a list of numbers.
1309 (equal '(2)
1310 (org-element-map tree 'link
1311 (lambda (link)
1312 (org-export-get-ordinal
1313 (org-export-resolve-fuzzy-link link info) info)) info t))))
1314 ;; 3. Link to a target in an item should return item's number.
1315 (org-test-with-parsed-data
1316 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1317 (should
1318 ;; Note: Item's number is in fact a list of numbers.
1319 (equal '(1 2)
1320 (org-element-map tree 'link
1321 (lambda (link)
1322 (org-export-get-ordinal
1323 (org-export-resolve-fuzzy-link link info) info)) info t))))
1324 ;; 4. Link to a target in a footnote should return footnote's
1325 ;; number.
1326 (org-test-with-parsed-data "
1327 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1328 (should
1329 (equal '(2 3)
1330 (org-element-map tree 'link
1331 (lambda (link)
1332 (org-export-get-ordinal
1333 (org-export-resolve-fuzzy-link link info) info)) info))))
1334 ;; 5. Link to a named element should return sequence number of that
1335 ;; element.
1336 (org-test-with-parsed-data
1337 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1338 (should
1339 (= 2
1340 (org-element-map tree 'link
1341 (lambda (link)
1342 (org-export-get-ordinal
1343 (org-export-resolve-fuzzy-link link info) info)) info t))))
1344 ;; 6. Link to a target not within an item, a table, a footnote
1345 ;; reference or definition should return section number.
1346 (org-test-with-parsed-data
1347 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1348 (should
1349 (equal '(2)
1350 (org-element-map tree 'link
1351 (lambda (link)
1352 (org-export-get-ordinal
1353 (org-export-resolve-fuzzy-link link info) info)) info t))))
1354 ;; 7. Space are not significant when matching a fuzzy link.
1355 (should
1356 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1357 (org-element-map tree 'link
1358 (lambda (link) (org-export-resolve-fuzzy-link link info))
1359 info t)))
1360 ;; 8. Statistics cookies are ignored for headline match.
1361 (should
1362 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1363 (org-element-map tree 'link
1364 (lambda (link) (org-export-resolve-fuzzy-link link info))
1365 info t)))
1366 (should
1367 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1368 (org-element-map tree 'link
1369 (lambda (link) (org-export-resolve-fuzzy-link link info))
1370 info t))))
1372 (ert-deftest test-org-export/resolve-coderef ()
1373 "Test `org-export-resolve-coderef' specifications."
1374 (let ((org-coderef-label-format "(ref:%s)"))
1375 ;; 1. A link to a "-n -k -r" block returns line number.
1376 (org-test-with-parsed-data
1377 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1378 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1379 (org-test-with-parsed-data
1380 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1381 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1382 ;; 2. A link to a "-n -r" block returns line number.
1383 (org-test-with-parsed-data
1384 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1385 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1386 (org-test-with-parsed-data
1387 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1388 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1389 ;; 3. A link to a "-n" block returns coderef.
1390 (org-test-with-parsed-data
1391 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1392 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1393 (org-test-with-parsed-data
1394 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1395 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1396 ;; 4. A link to a "-r" block returns line number.
1397 (org-test-with-parsed-data
1398 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1399 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1400 (org-test-with-parsed-data
1401 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1402 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1403 ;; 5. A link to a block without a switch returns coderef.
1404 (org-test-with-parsed-data
1405 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1406 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1407 (org-test-with-parsed-data
1408 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1409 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1410 ;; 6. Correctly handle continued line numbers. A "+n" switch
1411 ;; should resume numbering from previous block with numbered
1412 ;; lines, ignoring blocks not numbering lines in the process.
1413 ;; A "-n" switch resets count.
1414 (org-test-with-parsed-data "
1415 #+BEGIN_EXAMPLE -n
1416 Text.
1417 #+END_EXAMPLE
1419 #+BEGIN_SRC emacs-lisp
1420 \(- 1 1)
1421 #+END_SRC
1423 #+BEGIN_SRC emacs-lisp +n -r
1424 \(+ 1 1) (ref:addition)
1425 #+END_SRC
1427 #+BEGIN_EXAMPLE -n -r
1428 Another text. (ref:text)
1429 #+END_EXAMPLE"
1430 (should (= (org-export-resolve-coderef "addition" info) 2))
1431 (should (= (org-export-resolve-coderef "text" info) 1)))
1432 ;; 7. Recognize coderef with user-specified syntax.
1433 (org-test-with-parsed-data
1434 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1435 (should (equal (org-export-resolve-coderef "text" info) "text")))))
1437 (ert-deftest test-org-export/resolve-fuzzy-link ()
1438 "Test `org-export-resolve-fuzzy-link' specifications."
1439 ;; 1. Match target objects.
1440 (org-test-with-parsed-data "<<target>> [[target]]"
1441 (should
1442 (org-export-resolve-fuzzy-link
1443 (org-element-map tree 'link 'identity info t) info)))
1444 ;; 2. Match target elements.
1445 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1446 (should
1447 (org-export-resolve-fuzzy-link
1448 (org-element-map tree 'link 'identity info t) info)))
1449 ;; 3. Match named elements.
1450 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1451 (should
1452 (org-export-resolve-fuzzy-link
1453 (org-element-map tree 'link 'identity info t) info)))
1454 ;; 4. Match exact headline's name.
1455 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1456 (should
1457 (org-export-resolve-fuzzy-link
1458 (org-element-map tree 'link 'identity info t) info)))
1459 ;; 5. Targets objects have priority over named elements and headline
1460 ;; titles.
1461 (org-test-with-parsed-data
1462 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1463 (should
1464 (eq 'target
1465 (org-element-type
1466 (org-export-resolve-fuzzy-link
1467 (org-element-map tree 'link 'identity info t) info)))))
1468 ;; 6. Named elements have priority over headline titles.
1469 (org-test-with-parsed-data
1470 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1471 (should
1472 (eq 'paragraph
1473 (org-element-type
1474 (org-export-resolve-fuzzy-link
1475 (org-element-map tree 'link 'identity info t) info)))))
1476 ;; 7. If link's path starts with a "*", only match headline titles,
1477 ;; though.
1478 (org-test-with-parsed-data
1479 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1480 (should
1481 (eq 'headline
1482 (org-element-type
1483 (org-export-resolve-fuzzy-link
1484 (org-element-map tree 'link 'identity info t) info)))))
1485 ;; 8. Return nil if no match.
1486 (org-test-with-parsed-data "[[target]]"
1487 (should-not
1488 (org-export-resolve-fuzzy-link
1489 (org-element-map tree 'link 'identity info t) info))))
1491 (ert-deftest test-org-export/resolve-id-link ()
1492 "Test `org-export-resolve-id-link' specifications."
1493 ;; 1. Regular test for custom-id link.
1494 (org-test-with-parsed-data "* Headline1
1495 :PROPERTIES:
1496 :CUSTOM_ID: test
1497 :END:
1498 * Headline 2
1499 \[[#test]]"
1500 (should
1501 (org-export-resolve-id-link
1502 (org-element-map tree 'link 'identity info t) info)))
1503 ;; 2. Failing test for custom-id link.
1504 (org-test-with-parsed-data "* Headline1
1505 :PROPERTIES:
1506 :CUSTOM_ID: test
1507 :END:
1508 * Headline 2
1509 \[[#no-match]]"
1510 (should-not
1511 (org-export-resolve-id-link
1512 (org-element-map tree 'link 'identity info t) info)))
1513 ;; 3. Test for internal id target.
1514 (org-test-with-parsed-data "* Headline1
1515 :PROPERTIES:
1516 :ID: aaaa
1517 :END:
1518 * Headline 2
1519 \[[id:aaaa]]"
1520 (should
1521 (org-export-resolve-id-link
1522 (org-element-map tree 'link 'identity info t) info)))
1523 ;; 4. Test for external id target.
1524 (org-test-with-parsed-data "[[id:aaaa]]"
1525 (should
1526 (org-export-resolve-id-link
1527 (org-element-map tree 'link 'identity info t)
1528 (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
1530 (ert-deftest test-org-export/resolve-radio-link ()
1531 "Test `org-export-resolve-radio-link' specifications."
1532 ;; Standard test.
1533 (should
1534 (org-test-with-temp-text "<<<radio>>> radio"
1535 (org-update-radio-target-regexp)
1536 (let* ((tree (org-element-parse-buffer))
1537 (info `(:parse-tree ,tree)))
1538 (org-export-resolve-radio-link
1539 (org-element-map tree 'link 'identity info t)
1540 info))))
1541 ;; Radio targets are case-insensitive.
1542 (should
1543 (org-test-with-temp-text "<<<RADIO>>> radio"
1544 (org-update-radio-target-regexp)
1545 (let* ((tree (org-element-parse-buffer))
1546 (info `(:parse-tree ,tree)))
1547 (org-export-resolve-radio-link
1548 (org-element-map tree 'link 'identity info t)
1549 info))))
1550 ;; Radio target with objects.
1551 (should
1552 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1553 (org-update-radio-target-regexp)
1554 (let* ((tree (org-element-parse-buffer))
1555 (info `(:parse-tree ,tree)))
1556 (org-export-resolve-radio-link
1557 (org-element-map tree 'link 'identity info t)
1558 info)))))
1562 ;;; Src-block and example-block
1564 (ert-deftest test-org-export/unravel-code ()
1565 "Test `org-export-unravel-code' function."
1566 (let ((org-coderef-label-format "(ref:%s)"))
1567 ;; 1. Code without reference.
1568 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1569 (should (equal (org-export-unravel-code (org-element-at-point))
1570 '("(+ 1 1)\n"))))
1571 ;; 2. Code with reference.
1572 (org-test-with-temp-text
1573 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1574 (should (equal (org-export-unravel-code (org-element-at-point))
1575 '("(+ 1 1)\n" (1 . "test")))))
1576 ;; 3. Code with user-defined reference.
1577 (org-test-with-temp-text
1578 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1579 (should (equal (org-export-unravel-code (org-element-at-point))
1580 '("(+ 1 1)\n" (1 . "test")))))
1581 ;; 4. Code references keys are relative to the current block.
1582 (org-test-with-temp-text "
1583 #+BEGIN_EXAMPLE -n
1584 \(+ 1 1)
1585 #+END_EXAMPLE
1586 #+BEGIN_EXAMPLE +n
1587 \(+ 2 2)
1588 \(+ 3 3) (ref:one)
1589 #+END_EXAMPLE"
1590 (goto-line 5)
1591 (should (equal (org-export-unravel-code (org-element-at-point))
1592 '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
1594 (ert-deftest test-org-export/format-code-default ()
1595 "Test `org-export-format-code-default' specifications."
1596 ;; Return the empty string when code is empty.
1597 (should
1598 (equal ""
1599 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1600 (org-export-format-code-default
1601 (org-element-map tree 'src-block 'identity info t) info))))
1602 ;; Number lines, two whitespace characters before the actual loc.
1603 (should
1604 (equal "1 a\n2 b\n"
1605 (org-test-with-parsed-data
1606 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1607 (org-export-format-code-default
1608 (org-element-map tree 'src-block 'identity info t) info))))
1609 ;; Put references 6 whitespace characters after the widest line,
1610 ;; wrapped within parenthesis.
1611 (should
1612 (equal "123 (a)\n1 (b)\n"
1613 (let ((org-coderef-label-format "(ref:%s)"))
1614 (org-test-with-parsed-data
1615 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1616 (org-export-format-code-default
1617 (org-element-map tree 'src-block 'identity info t) info))))))
1621 ;;; Smart Quotes
1623 (ert-deftest test-org-export/activate-smart-quotes ()
1624 "Test `org-export-activate-smart-quotes' specifications."
1625 ;; Opening double quotes: standard test.
1626 (should
1627 (equal
1628 '("some &ldquo;paragraph")
1629 (let ((org-export-default-language "en"))
1630 (org-test-with-parsed-data "some \"paragraph"
1631 (org-element-map tree 'plain-text
1632 (lambda (s) (org-export-activate-smart-quotes s :html info))
1633 info)))))
1634 ;; Opening quotes: at the beginning of a paragraph.
1635 (should
1636 (equal
1637 '("&ldquo;begin")
1638 (let ((org-export-default-language "en"))
1639 (org-test-with-parsed-data "\"begin"
1640 (org-element-map tree 'plain-text
1641 (lambda (s) (org-export-activate-smart-quotes s :html info))
1642 info)))))
1643 ;; Opening quotes: after an object.
1644 (should
1645 (equal
1646 '("&ldquo;begin")
1647 (let ((org-export-default-language "en"))
1648 (org-test-with-parsed-data "=verb= \"begin"
1649 (org-element-map tree 'plain-text
1650 (lambda (s) (org-export-activate-smart-quotes s :html info))
1651 info)))))
1652 ;; Closing quotes: standard test.
1653 (should
1654 (equal
1655 '("some&rdquo; paragraph")
1656 (let ((org-export-default-language "en"))
1657 (org-test-with-parsed-data "some\" paragraph"
1658 (org-element-map tree 'plain-text
1659 (lambda (s) (org-export-activate-smart-quotes s :html info))
1660 info)))))
1661 ;; Closing quotes: at the end of a paragraph.
1662 (should
1663 (equal
1664 '("end&rdquo;")
1665 (let ((org-export-default-language "en"))
1666 (org-test-with-parsed-data "end\""
1667 (org-element-map tree 'plain-text
1668 (lambda (s) (org-export-activate-smart-quotes s :html info))
1669 info)))))
1670 ;; Apostrophe: standard test.
1671 (should
1672 (equal
1673 '("It shouldn&rsquo;t fail")
1674 (let ((org-export-default-language "en"))
1675 (org-test-with-parsed-data "It shouldn't fail"
1676 (org-element-map tree 'plain-text
1677 (lambda (s) (org-export-activate-smart-quotes s :html info))
1678 info)))))
1679 ;; Apostrophe: before an object.
1680 (should
1681 (equal
1682 '("a&rsquo;")
1683 (let ((org-export-default-language "en"))
1684 (org-test-with-parsed-data "a'=b="
1685 (org-element-map tree 'plain-text
1686 (lambda (s) (org-export-activate-smart-quotes s :html info))
1687 info)))))
1688 ;; Apostrophe: after an object.
1689 (should
1690 (equal
1691 '("&rsquo;s")
1692 (let ((org-export-default-language "en"))
1693 (org-test-with-parsed-data "=code='s"
1694 (org-element-map tree 'plain-text
1695 (lambda (s) (org-export-activate-smart-quotes s :html info))
1696 info)))))
1697 ;; Special case: isolated quotes.
1698 (should
1699 (equal '("&ldquo;" "&rdquo;")
1700 (let ((org-export-default-language "en"))
1701 (org-test-with-parsed-data "\"$x$\""
1702 (org-element-map tree 'plain-text
1703 (lambda (s) (org-export-activate-smart-quotes s :html info))
1704 info)))))
1705 ;; Smart quotes in secondary strings.
1706 (should
1707 (equal '("&ldquo;" "&rdquo;")
1708 (let ((org-export-default-language "en"))
1709 (org-test-with-parsed-data "* \"$x$\""
1710 (org-element-map tree 'plain-text
1711 (lambda (s) (org-export-activate-smart-quotes s :html info))
1712 info)))))
1713 ;; Smart quotes in document keywords.
1714 (should
1715 (equal '("&ldquo;" "&rdquo;")
1716 (let ((org-export-default-language "en"))
1717 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1718 (org-element-map (plist-get info :title) 'plain-text
1719 (lambda (s) (org-export-activate-smart-quotes s :html info))
1720 info)))))
1721 ;; Smart quotes in parsed affiliated keywords.
1722 (should
1723 (equal '("&ldquo;" "&rdquo;" "Paragraph")
1724 (let ((org-export-default-language "en"))
1725 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1726 (org-element-map tree 'plain-text
1727 (lambda (s) (org-export-activate-smart-quotes s :html info))
1728 info nil nil t))))))
1732 ;;; Tables
1734 (ert-deftest test-org-export/special-column ()
1735 "Test if the table's special column is properly recognized."
1736 ;; 1. First column is special if it contains only a special marking
1737 ;; characters or empty cells.
1738 (org-test-with-temp-text "
1739 | ! | 1 |
1740 | | 2 |"
1741 (should
1742 (org-export-table-has-special-column-p
1743 (org-element-map
1744 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1745 ;; 2. If the column contains anything else, it isn't special.
1746 (org-test-with-temp-text "
1747 | ! | 1 |
1748 | b | 2 |"
1749 (should-not
1750 (org-export-table-has-special-column-p
1751 (org-element-map
1752 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1753 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1754 ;; and "!".
1755 (org-test-with-temp-text "
1756 | # | 1 |
1757 | ^ | 2 |
1758 | * | 3 |
1759 | _ | 4 |
1760 | / | 5 |
1761 | $ | 6 |
1762 | ! | 7 |"
1763 (should
1764 (org-export-table-has-special-column-p
1765 (org-element-map
1766 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1767 ;; 4. A first column with only empty cells isn't considered as
1768 ;; special.
1769 (org-test-with-temp-text "
1770 | | 1 |
1771 | | 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)))))
1777 (ert-deftest test-org-export/table-row-is-special-p ()
1778 "Test `org-export-table-row-is-special-p' specifications."
1779 ;; 1. A row is special if it has a special marking character in the
1780 ;; special column.
1781 (org-test-with-parsed-data "| ! | 1 |"
1782 (should
1783 (org-export-table-row-is-special-p
1784 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1785 ;; 2. A row is special when its first field is "/"
1786 (org-test-with-parsed-data "
1787 | / | 1 |
1788 | a | b |"
1789 (should
1790 (org-export-table-row-is-special-p
1791 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1792 ;; 3. A row only containing alignment cookies is also considered as
1793 ;; special.
1794 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1795 (should
1796 (org-export-table-row-is-special-p
1797 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1798 ;; 4. Everything else isn't considered as special.
1799 (org-test-with-parsed-data "| \alpha | | c |"
1800 (should-not
1801 (org-export-table-row-is-special-p
1802 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1803 ;; 5. Table's rules are never considered as special rows.
1804 (org-test-with-parsed-data "|---+---|"
1805 (should-not
1806 (org-export-table-row-is-special-p
1807 (org-element-map tree 'table-row 'identity nil 'first-match) info))))
1809 (ert-deftest test-org-export/has-header-p ()
1810 "Test `org-export-table-has-header-p' specifications."
1811 ;; 1. With an header.
1812 (org-test-with-parsed-data "
1813 | a | b |
1814 |---+---|
1815 | c | d |"
1816 (should
1817 (org-export-table-has-header-p
1818 (org-element-map tree 'table 'identity info 'first-match)
1819 info)))
1820 ;; 2. Without an header.
1821 (org-test-with-parsed-data "
1822 | a | b |
1823 | c | d |"
1824 (should-not
1825 (org-export-table-has-header-p
1826 (org-element-map tree 'table 'identity info 'first-match)
1827 info)))
1828 ;; 3. Don't get fooled with starting and ending rules.
1829 (org-test-with-parsed-data "
1830 |---+---|
1831 | a | b |
1832 | c | d |
1833 |---+---|"
1834 (should-not
1835 (org-export-table-has-header-p
1836 (org-element-map tree 'table 'identity info 'first-match)
1837 info))))
1839 (ert-deftest test-org-export/table-row-group ()
1840 "Test `org-export-table-row-group' specifications."
1841 ;; 1. A rule creates a new group.
1842 (org-test-with-parsed-data "
1843 | a | b |
1844 |---+---|
1845 | 1 | 2 |"
1846 (should
1847 (equal
1848 '(1 nil 2)
1849 (mapcar (lambda (row) (org-export-table-row-group row info))
1850 (org-element-map tree 'table-row 'identity)))))
1851 ;; 2. Special rows are ignored in count.
1852 (org-test-with-parsed-data "
1853 | / | < | > |
1854 |---|---+---|
1855 | | 1 | 2 |"
1856 (should
1857 (equal
1858 '(nil nil 1)
1859 (mapcar (lambda (row) (org-export-table-row-group row info))
1860 (org-element-map tree 'table-row 'identity)))))
1861 ;; 3. Double rules also are ignored in count.
1862 (org-test-with-parsed-data "
1863 | a | b |
1864 |---+---|
1865 |---+---|
1866 | 1 | 2 |"
1867 (should
1868 (equal
1869 '(1 nil nil 2)
1870 (mapcar (lambda (row) (org-export-table-row-group row info))
1871 (org-element-map tree 'table-row 'identity))))))
1873 (ert-deftest test-org-export/table-cell-width ()
1874 "Test `org-export-table-cell-width' specifications."
1875 ;; 1. Width is primarily determined by width cookies. If no cookie
1876 ;; is found, cell's width is nil.
1877 (org-test-with-parsed-data "
1878 | / | <l> | <6> | <l7> |
1879 | | a | b | c |"
1880 (should
1881 (equal
1882 '(nil 6 7)
1883 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1884 (org-element-map tree 'table-cell 'identity info)))))
1885 ;; 2. The last width cookie has precedence.
1886 (org-test-with-parsed-data "
1887 | <6> |
1888 | <7> |
1889 | a |"
1890 (should
1891 (equal
1892 '(7)
1893 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1894 (org-element-map tree 'table-cell 'identity info)))))
1895 ;; 3. Valid width cookies must have a specific row.
1896 (org-test-with-parsed-data "| <6> | cell |"
1897 (should
1898 (equal
1899 '(nil nil)
1900 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1901 (org-element-map tree 'table-cell 'identity))))))
1903 (ert-deftest test-org-export/table-cell-alignment ()
1904 "Test `org-export-table-cell-alignment' specifications."
1905 (let ((org-table-number-fraction 0.5)
1906 (org-table-number-regexp "^[0-9]+$"))
1907 ;; 1. Alignment is primarily determined by alignment cookies.
1908 (org-test-with-temp-text "| <l> | <c> | <r> |"
1909 (let* ((tree (org-element-parse-buffer))
1910 (info `(:parse-tree ,tree)))
1911 (should
1912 (equal
1913 '(left center right)
1914 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
1915 (org-element-map tree 'table-cell 'identity))))))
1916 ;; 2. The last alignment cookie has precedence.
1917 (org-test-with-parsed-data "
1918 | <l8> |
1919 | cell |
1920 | <r9> |"
1921 (should
1922 (equal
1923 '(right right right)
1924 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
1925 (org-element-map tree 'table-cell 'identity)))))
1926 ;; 3. If there's no cookie, cell's contents determine alignment.
1927 ;; A column mostly made of cells containing numbers will align
1928 ;; its cells to the right.
1929 (org-test-with-parsed-data "
1930 | 123 |
1931 | some text |
1932 | 12345 |"
1933 (should
1934 (equal
1935 '(right right right)
1936 (mapcar (lambda (cell)
1937 (org-export-table-cell-alignment cell info))
1938 (org-element-map tree 'table-cell 'identity)))))
1939 ;; 4. Otherwise, they will be aligned to the left.
1940 (org-test-with-parsed-data "
1941 | text |
1942 | some text |
1943 | \alpha |"
1944 (should
1945 (equal
1946 '(left left left)
1947 (mapcar (lambda (cell)
1948 (org-export-table-cell-alignment cell info))
1949 (org-element-map tree 'table-cell 'identity)))))))
1951 (ert-deftest test-org-export/table-cell-borders ()
1952 "Test `org-export-table-cell-borders' specifications."
1953 ;; 1. Recognize various column groups indicators.
1954 (org-test-with-parsed-data "| / | < | > | <> |"
1955 (should
1956 (equal
1957 '((right bottom top) (left bottom top) (right bottom top)
1958 (right left bottom top))
1959 (mapcar (lambda (cell)
1960 (org-export-table-cell-borders cell info))
1961 (org-element-map tree 'table-cell 'identity)))))
1962 ;; 2. Accept shortcuts to define column groups.
1963 (org-test-with-parsed-data "| / | < | < |"
1964 (should
1965 (equal
1966 '((right bottom top) (right left bottom top) (left bottom top))
1967 (mapcar (lambda (cell)
1968 (org-export-table-cell-borders cell info))
1969 (org-element-map tree 'table-cell 'identity)))))
1970 ;; 3. A valid column groups row must start with a "/".
1971 (org-test-with-parsed-data "
1972 | | < |
1973 | a | b |"
1974 (should
1975 (equal '((top) (top) (bottom) (bottom))
1976 (mapcar (lambda (cell)
1977 (org-export-table-cell-borders cell info))
1978 (org-element-map tree 'table-cell 'identity)))))
1979 ;; 4. Take table rules into consideration.
1980 (org-test-with-parsed-data "
1981 | 1 |
1982 |---|
1983 | 2 |"
1984 (should
1985 (equal '((below top) (bottom above))
1986 (mapcar (lambda (cell)
1987 (org-export-table-cell-borders cell info))
1988 (org-element-map tree 'table-cell 'identity)))))
1989 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1990 ;; (resp. `bottom' and `below') borders. Any special row is
1991 ;; ignored.
1992 (org-test-with-parsed-data "
1993 |---+----|
1994 | / | |
1995 | | 1 |
1996 |---+----|"
1997 (should
1998 (equal '((bottom below top above))
1999 (last
2000 (mapcar (lambda (cell)
2001 (org-export-table-cell-borders cell info))
2002 (org-element-map tree 'table-cell 'identity)))))))
2004 (ert-deftest test-org-export/table-dimensions ()
2005 "Test `org-export-table-dimensions' specifications."
2006 ;; 1. Standard test.
2007 (org-test-with-parsed-data "
2008 | 1 | 2 | 3 |
2009 | 4 | 5 | 6 |"
2010 (should
2011 (equal '(2 . 3)
2012 (org-export-table-dimensions
2013 (org-element-map tree 'table 'identity info 'first-match) info))))
2014 ;; 2. Ignore horizontal rules and special columns.
2015 (org-test-with-parsed-data "
2016 | / | < | > |
2017 | 1 | 2 | 3 |
2018 |---+---+---|
2019 | 4 | 5 | 6 |"
2020 (should
2021 (equal '(2 . 3)
2022 (org-export-table-dimensions
2023 (org-element-map tree 'table 'identity info 'first-match) info)))))
2025 (ert-deftest test-org-export/table-cell-address ()
2026 "Test `org-export-table-cell-address' specifications."
2027 ;; 1. Standard test: index is 0-based.
2028 (org-test-with-parsed-data "| a | b |"
2029 (should
2030 (equal '((0 . 0) (0 . 1))
2031 (org-element-map tree 'table-cell
2032 (lambda (cell) (org-export-table-cell-address cell info))
2033 info))))
2034 ;; 2. Special column isn't counted, nor are special rows.
2035 (org-test-with-parsed-data "
2036 | / | <> |
2037 | | c |"
2038 (should
2039 (equal '(0 . 0)
2040 (org-export-table-cell-address
2041 (car (last (org-element-map tree 'table-cell 'identity info)))
2042 info))))
2043 ;; 3. Tables rules do not count either.
2044 (org-test-with-parsed-data "
2045 | a |
2046 |---|
2047 | b |
2048 |---|
2049 | c |"
2050 (should
2051 (equal '(2 . 0)
2052 (org-export-table-cell-address
2053 (car (last (org-element-map tree 'table-cell 'identity info)))
2054 info))))
2055 ;; 4. Return nil for special cells.
2056 (org-test-with-parsed-data "| / | a |"
2057 (should-not
2058 (org-export-table-cell-address
2059 (org-element-map tree 'table-cell 'identity nil 'first-match)
2060 info))))
2062 (ert-deftest test-org-export/get-table-cell-at ()
2063 "Test `org-export-get-table-cell-at' specifications."
2064 ;; 1. Address ignores special columns, special rows and rules.
2065 (org-test-with-parsed-data "
2066 | / | <> |
2067 | | a |
2068 |---+----|
2069 | | b |"
2070 (should
2071 (equal '("b")
2072 (org-element-contents
2073 (org-export-get-table-cell-at
2074 '(1 . 0)
2075 (org-element-map tree 'table 'identity info 'first-match)
2076 info)))))
2077 ;; 2. Return value for a non-existent address is nil.
2078 (org-test-with-parsed-data "| a |"
2079 (should-not
2080 (org-export-get-table-cell-at
2081 '(2 . 2)
2082 (org-element-map tree 'table 'identity info 'first-match)
2083 info)))
2084 (org-test-with-parsed-data "| / |"
2085 (should-not
2086 (org-export-get-table-cell-at
2087 '(0 . 0)
2088 (org-element-map tree 'table 'identity info 'first-match)
2089 info))))
2091 (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
2092 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2093 ;; 1. A cell at a beginning of a row always starts a column group.
2094 (org-test-with-parsed-data "| a |"
2095 (should
2096 (org-export-table-cell-starts-colgroup-p
2097 (org-element-map tree 'table-cell 'identity info 'first-match)
2098 info)))
2099 ;; 2. Special column should be ignored when determining the
2100 ;; beginning of the row.
2101 (org-test-with-parsed-data "
2102 | / | |
2103 | | a |"
2104 (should
2105 (org-export-table-cell-starts-colgroup-p
2106 (org-element-map tree 'table-cell 'identity info 'first-match)
2107 info)))
2108 ;; 2. Explicit column groups.
2109 (org-test-with-parsed-data "
2110 | / | | < |
2111 | a | b | c |"
2112 (should
2113 (equal
2114 '(yes no yes)
2115 (org-element-map tree 'table-cell
2116 (lambda (cell)
2117 (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
2118 info)))))
2120 (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
2121 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2122 ;; 1. A cell at the end of a row always ends a column group.
2123 (org-test-with-parsed-data "| a |"
2124 (should
2125 (org-export-table-cell-ends-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-ends-colgroup-p
2135 (org-element-map tree 'table-cell 'identity info 'first-match)
2136 info)))
2137 ;; 3. 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 tree 'table-cell
2145 (lambda (cell)
2146 (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
2147 info)))))
2149 (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
2150 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2151 ;; 1. A row at the beginning of a table always starts a row group.
2152 ;; So does a row following a table rule.
2153 (org-test-with-parsed-data "
2154 | a |
2155 |---|
2156 | b |"
2157 (should
2158 (equal
2159 '(yes no yes)
2160 (org-element-map tree 'table-row
2161 (lambda (row)
2162 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
2163 info))))
2164 ;; 2. Special rows should be ignored when determining the beginning
2165 ;; of the row.
2166 (org-test-with-parsed-data "
2167 | / | < |
2168 | | a |
2169 |---+---|
2170 | / | < |
2171 | | b |"
2172 (should
2173 (equal
2174 '(yes no yes)
2175 (org-element-map tree 'table-row
2176 (lambda (row)
2177 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
2178 info)))))
2180 (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
2181 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2182 ;; 1. A row at the end of a table always ends a row group. So does
2183 ;; a row preceding 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 tree 'table-row
2192 (lambda (row)
2193 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
2194 info))))
2195 ;; 2. Special rows should be ignored when determining the beginning
2196 ;; of the row.
2197 (org-test-with-parsed-data "
2198 | | a |
2199 | / | < |
2200 |---+---|
2201 | | b |
2202 | / | < |"
2203 (should
2204 (equal
2205 '(yes no yes)
2206 (org-element-map tree 'table-row
2207 (lambda (row)
2208 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
2209 info)))))
2211 (ert-deftest test-org-export/table-row-starts-header-p ()
2212 "Test `org-export-table-row-starts-header-p' specifications."
2213 ;; 1. Only the row starting the first row group starts the table
2214 ;; header.
2215 (org-test-with-parsed-data "
2216 | a |
2217 | b |
2218 |---|
2219 | c |"
2220 (should
2221 (equal
2222 '(yes no no no)
2223 (org-element-map tree 'table-row
2224 (lambda (row)
2225 (if (org-export-table-row-starts-header-p row info) 'yes 'no))
2226 info))))
2227 ;; 2. A row cannot start an header if there's no header in the
2228 ;; table.
2229 (org-test-with-parsed-data "
2230 | a |
2231 |---|"
2232 (should-not
2233 (org-export-table-row-starts-header-p
2234 (org-element-map tree 'table-row 'identity info 'first-match)
2235 info))))
2237 (ert-deftest test-org-export/table-row-ends-header-p ()
2238 "Test `org-export-table-row-ends-header-p' specifications."
2239 ;; 1. Only the row starting the first row group starts the table
2240 ;; header.
2241 (org-test-with-parsed-data "
2242 | a |
2243 | b |
2244 |---|
2245 | c |"
2246 (should
2247 (equal
2248 '(no yes no no)
2249 (org-element-map tree 'table-row
2250 (lambda (row)
2251 (if (org-export-table-row-ends-header-p row info) 'yes 'no))
2252 info))))
2253 ;; 2. A row cannot start an header if there's no header in the
2254 ;; table.
2255 (org-test-with-parsed-data "
2256 | a |
2257 |---|"
2258 (should-not
2259 (org-export-table-row-ends-header-p
2260 (org-element-map tree 'table-row 'identity info 'first-match)
2261 info))))
2265 ;;; Templates
2267 (ert-deftest test-org-export/inner-template ()
2268 "Test `inner-template' translator specifications."
2269 (should
2270 (equal "Success!"
2271 (let (org-export-registered-backends)
2272 (org-export-define-backend 'test
2273 '((inner-template . (lambda (contents info) "Success!"))
2274 (headline . (lambda (h c i) "Headline"))))
2275 (org-test-with-temp-text "* Headline"
2276 (org-export-as 'test)))))
2277 ;; Inner template is applied even in a "body-only" export.
2278 (should
2279 (equal "Success!"
2280 (let (org-export-registered-backends)
2281 (org-export-define-backend 'test
2282 '((inner-template . (lambda (contents info) "Success!"))
2283 (headline . (lambda (h c i) "Headline"))))
2284 (org-test-with-temp-text "* Headline"
2285 (org-export-as 'test nil nil 'body-only))))))
2287 (ert-deftest test-org-export/template ()
2288 "Test `template' translator specifications."
2289 (should
2290 (equal "Success!"
2291 (let (org-export-registered-backends)
2292 (org-export-define-backend 'test
2293 '((template . (lambda (contents info) "Success!"))
2294 (headline . (lambda (h c i) "Headline"))))
2295 (org-test-with-temp-text "* Headline"
2296 (org-export-as 'test)))))
2297 ;; Template is not applied in a "body-only" export.
2298 (should-not
2299 (equal "Success!"
2300 (let (org-export-registered-backends)
2301 (org-export-define-backend 'test
2302 '((template . (lambda (contents info) "Success!"))
2303 (headline . (lambda (h c i) "Headline"))))
2304 (org-test-with-temp-text "* Headline"
2305 (org-export-as 'test nil nil 'body-only))))))
2309 ;;; Topology
2311 (ert-deftest test-org-export/get-next-element ()
2312 "Test `org-export-get-next-element' specifications."
2313 ;; Standard test.
2314 (should
2315 (equal "b"
2316 (org-test-with-parsed-data "* Headline\n*a* b"
2317 (org-export-get-next-element
2318 (org-element-map tree 'bold 'identity info t) info))))
2319 ;; Return nil when no previous element.
2320 (should-not
2321 (org-test-with-parsed-data "* Headline\na *b*"
2322 (org-export-get-next-element
2323 (org-element-map tree 'bold 'identity info t) info)))
2324 ;; Non-exportable elements are ignored.
2325 (should-not
2326 (let ((org-export-with-timestamps nil))
2327 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2328 (org-export-get-next-element
2329 (org-element-map tree 'entity 'identity info t) info))))
2330 ;; Find next element in secondary strings.
2331 (should
2332 (eq 'verbatim
2333 (org-test-with-parsed-data "* a =verb="
2334 (org-element-type
2335 (org-export-get-next-element
2336 (org-element-map tree 'plain-text 'identity info t) info)))))
2337 ;; Find next element in document keywords.
2338 (should
2339 (eq 'verbatim
2340 (org-test-with-parsed-data "#+TITLE: a =verb="
2341 (org-element-type
2342 (org-export-get-next-element
2343 (org-element-map
2344 (plist-get info :title) 'plain-text 'identity info t) info)))))
2345 ;; Find next element in parsed affiliated keywords.
2346 (should
2347 (eq 'verbatim
2348 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2349 (org-element-type
2350 (org-export-get-next-element
2351 (org-element-map tree 'plain-text 'identity info t nil t) info)))))
2352 ;; With optional argument N, return a list containing all the
2353 ;; following elements.
2354 (should
2355 (equal
2356 '(bold code underline)
2357 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2358 (mapcar 'car
2359 (org-export-get-next-element
2360 (org-element-map tree 'italic 'identity info t) info t)))))
2361 ;; When N is a positive integer, return a list containing up to
2362 ;; N following elements.
2363 (should
2364 (equal
2365 '(bold code)
2366 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2367 (mapcar 'car
2368 (org-export-get-next-element
2369 (org-element-map tree 'italic 'identity info t) info 2))))))
2371 (ert-deftest test-org-export/get-previous-element ()
2372 "Test `org-export-get-previous-element' specifications."
2373 ;; Standard test.
2374 (should
2375 (equal "a "
2376 (org-test-with-parsed-data "* Headline\na *b*"
2377 (org-export-get-previous-element
2378 (org-element-map tree 'bold 'identity info t) info))))
2379 ;; Return nil when no previous element.
2380 (should-not
2381 (org-test-with-parsed-data "* Headline\n*a* b"
2382 (org-export-get-previous-element
2383 (org-element-map tree 'bold 'identity info t) info)))
2384 ;; Non-exportable elements are ignored.
2385 (should-not
2386 (let ((org-export-with-timestamps nil))
2387 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2388 (org-export-get-previous-element
2389 (org-element-map tree 'entity 'identity info t) info))))
2390 ;; Find previous element in secondary strings.
2391 (should
2392 (eq 'verbatim
2393 (org-test-with-parsed-data "* =verb= a"
2394 (org-element-type
2395 (org-export-get-previous-element
2396 (org-element-map tree 'plain-text 'identity info t) info)))))
2397 ;; Find previous element in document keywords.
2398 (should
2399 (eq 'verbatim
2400 (org-test-with-parsed-data "#+TITLE: =verb= a"
2401 (org-element-type
2402 (org-export-get-previous-element
2403 (org-element-map
2404 (plist-get info :title) 'plain-text 'identity info t) info)))))
2405 ;; Find previous element in parsed affiliated keywords.
2406 (should
2407 (eq 'verbatim
2408 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2409 (org-element-type
2410 (org-export-get-previous-element
2411 (org-element-map tree 'plain-text 'identity info t nil t) info)))))
2412 ;; With optional argument N, return a list containing up to
2413 ;; N previous elements.
2414 (should
2415 (equal '(underline italic bold)
2416 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2417 (mapcar 'car
2418 (org-export-get-previous-element
2419 (org-element-map tree 'code 'identity info t) info t)))))
2420 ;; When N is a positive integer, return a list containing up to
2421 ;; N previous elements.
2422 (should
2423 (equal '(italic bold)
2424 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2425 (mapcar 'car
2426 (org-export-get-previous-element
2427 (org-element-map tree 'code 'identity info t) info 2))))))
2430 (provide 'test-ox)
2431 ;;; test-org-export.el end here