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