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