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/>.
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
33 (declare (debug (form body
)) (indent 1))
34 `(let ((org-export-registered-backends
38 (let (transcode-table)
39 (dolist (type (append org-element-all-elements
40 org-element-all-objects
)
44 (lambda (obj contents info
)
46 (intern (format "org-element-%s-interpreter"
49 transcode-table
)))))))
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))))
74 (ert-deftest test-org-export
/bind-keyword
()
75 "Test reading #+BIND: keywords."
76 ;; Test with `org-export-allow-bind-keywords' set to t.
78 (org-test-with-temp-text "#+BIND: variable value"
79 (let ((org-export-allow-bind-keywords t
))
80 (org-export--install-letbind-maybe)
81 (eq variable
'value
))))
82 ;; Test with `org-export-allow-bind-keywords' set to nil.
84 (org-test-with-temp-text "#+BIND: variable value"
85 (let ((org-export-allow-bind-keywords nil
))
86 (org-export--install-letbind-maybe)
88 ;; BIND keywords are case-insensitive.
90 (org-test-with-temp-text "#+bind: variable value"
91 (let ((org-export-allow-bind-keywords t
))
92 (org-export--install-letbind-maybe)
93 (eq variable
'value
)))))
95 (ert-deftest test-org-export
/parse-option-keyword
()
96 "Test reading all standard #+OPTIONS: items."
99 (org-export--parse-option-keyword
100 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
101 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
104 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
105 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
106 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
107 :with-footnotes t
:with-inlinetasks nil
:with-priority t
108 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
109 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
110 :with-todo-keywords t
)))
111 ;; Test some special values.
114 (org-export--parse-option-keyword
115 "arch:headline creator:comment d:(\"TEST\")
116 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
119 :with-archived-trees headline
:with-creator comment
120 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
121 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
123 (ert-deftest test-org-export
/get-inbuffer-options
()
124 "Test reading all standard export keywords."
127 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
130 #+DESCRIPTION: Testing
131 #+DESCRIPTION: with two lines
132 #+EMAIL: some@email.org
133 #+EXCLUDE_TAGS: noexport invisible
136 #+SELECT_TAGS: export
138 #+TITLE: with spaces"
139 (org-export--get-inbuffer-options))
141 ("Me, Myself and I") :creator
"Idem" :date
("Today")
142 :description
"Testing\nwith two lines" :email
"some@email.org"
143 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
144 :select-tags
("export") :title
("Some title with spaces")))))
146 (ert-deftest test-org-export
/get-subtree-options
()
147 "Test setting options from headline's properties."
149 (org-test-with-temp-text "#+TITLE: Title
152 :EXPORT_TITLE: Subtree Title
156 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
157 '("Subtree Title"))))
161 (org-test-with-temp-text "#+OPTIONS: H:1
169 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
171 (org-test-with-temp-text "#+DATE: today
174 :EXPORT_DATE: 29-03-2012
178 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
180 ;; Properties with `split' behaviour are stored as a list of
184 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
187 :EXPORT_EXCLUDE_TAGS: a b
192 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
193 ;; Handle :PROPERTY+: syntax.
196 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
199 :EXPORT_EXCLUDE_TAGS: a
200 :EXPORT_EXCLUDE_TAGS+: b
205 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
206 ;; Export properties are case-insensitive.
207 (org-test-with-temp-text "* Headline
209 :EXPORT_Date: 29-03-2012
212 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
214 ;; Still grab correct options when section above is empty.
217 (org-test-with-temp-text "* H1\n** H11\n** H12"
218 (progn (forward-line 2)
219 (plist-get (org-export-get-environment nil t
) :title
))))))
221 (ert-deftest test-org-export
/handle-options
()
222 "Test if export options have an impact on output."
223 ;; Test exclude tags.
224 (org-test-with-temp-text "* Head1 :noexport:"
225 (org-test-with-backend test
227 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
229 ;; Test include tags.
230 (org-test-with-temp-text "
233 ** Sub-Head2.1 :export:
236 (org-test-with-backend test
239 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
240 (let ((org-tags-column 0))
241 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
242 ;; Test mixing include tags and exclude tags.
243 (org-test-with-temp-text "
245 ** Sub-Head1 :noexport:
248 ** Sub-Head1 :export:"
249 (org-test-with-backend test
252 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
255 '(:select-tags
("export") :exclude-tags
("noexport")))))))
257 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
258 (org-test-with-temp-text "* TODO Head1"
259 (org-test-with-backend test
260 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
262 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
263 (org-test-with-temp-text "* TODO Head1"
264 (org-test-with-backend test
265 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
266 "* TODO Head1\n")))))
268 (org-test-with-temp-text "* Head1 :archive:"
269 (let ((org-archive-tag "archive"))
270 (org-test-with-backend test
272 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
274 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
275 (let ((org-archive-tag "archive"))
276 (org-test-with-backend test
279 "\\* Head1[ \t]+:archive:"
280 (org-export-as 'test nil nil nil
281 '(:with-archived-trees headline
)))))))
282 (org-test-with-temp-text "* Head1 :archive:"
283 (let ((org-archive-tag "archive"))
284 (org-test-with-backend test
287 "\\`\\* Head1[ \t]+:archive:\n\\'"
288 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
290 (let ((org-clock-string "CLOCK:"))
291 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
292 (org-test-with-backend test
294 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
295 "CLOCK: [2012-04-29 sun. 10:45]\n"))
297 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
299 (let ((org-drawers '("TEST")))
300 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
301 (org-test-with-backend test
302 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
304 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
305 ":TEST:\ncontents\n:END:\n")))))
306 (let ((org-drawers '("FOO" "BAR")))
307 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
308 (org-test-with-backend test
310 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
311 ":FOO:\nkeep\n:END:\n")))))
312 (let ((org-drawers '("FOO" "BAR")))
313 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
314 (org-test-with-backend test
316 (equal (org-export-as 'test nil nil nil
'(:with-drawers
(not "BAR")))
317 ":FOO:\nkeep\n:END:\n")))))
319 (when (featurep 'org-inlinetask
)
322 (let ((org-inlinetask-min-level 15))
323 (org-test-with-temp-text "*************** Task"
324 (org-test-with-backend test
325 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
329 (let ((org-inlinetask-min-level 15))
330 (org-test-with-temp-text
331 "*************** Task\nContents\n*************** END"
332 (org-test-with-backend test
333 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
336 (let ((org-closed-string "CLOSED:"))
337 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
338 (org-test-with-backend test
340 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
341 "CLOSED: [2012-04-29 sun. 10:45]\n"))
343 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
345 ;; Statistics cookies.
348 (org-test-with-temp-text "[0/0]"
349 (org-test-with-backend test
351 'test nil nil nil
'(:with-statistics-cookies nil
))))))
353 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
354 (org-test-with-backend test
356 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
357 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
359 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
361 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
362 "<2012-04-29 sun. 10:45>\n"))
364 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
365 "[2012-04-29 sun. 10:45]\n")))))
367 (ert-deftest test-org-export
/comment-tree
()
368 "Test if export process ignores commented trees."
369 (let ((org-comment-string "COMMENT"))
370 (org-test-with-temp-text "* COMMENT Head1"
371 (org-test-with-backend test
372 (should (equal (org-export-as 'test
) ""))))))
374 (ert-deftest test-org-export
/export-scope
()
375 "Test all export scopes."
376 (org-test-with-temp-text "
381 (org-test-with-backend test
384 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
386 (goto-char (point-min))
389 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
391 (goto-char (point-min))
393 (transient-mark-mode 1)
394 (push-mark (point) t t
)
395 (goto-char (point-at-eol))
396 (should (equal (org-export-as 'test
) "text\n"))))
397 ;; Subtree with a code block calling another block outside.
400 (org-test-with-temp-text "
402 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
407 #+BEGIN_SRC emacs-lisp
410 (org-test-with-backend test
412 (org-export-as 'test
'subtree
)))))
414 (org-test-with-temp-text "Text"
415 (org-test-with-backend test
417 (cdr (assq 'test org-export-registered-backends
))
419 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
420 (org-export-backend-translate-table 'test
)))
421 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
422 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
424 (ert-deftest test-org-export
/output-file-name
()
425 "Test `org-export-output-file-name' specifications."
426 ;; Export from a file: name is built from original file name.
428 (org-test-with-temp-text-in-file "Test"
429 (equal (concat (file-name-as-directory ".")
430 (file-name-nondirectory
431 (file-name-sans-extension (buffer-file-name))))
432 (file-name-sans-extension (org-export-output-file-name ".ext")))))
433 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
435 (org-test-with-temp-text-in-file
436 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
437 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
438 ;; From a buffer not associated to a file, too.
440 (org-test-with-temp-text
441 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
442 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
443 ;; When provided name is absolute, preserve it.
445 (org-test-with-temp-text
446 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
447 (expand-file-name "test"))
448 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
449 ;; When PUB-DIR argument is provided, use it.
451 (org-test-with-temp-text-in-file "Test"
452 (equal (file-name-directory
453 (org-export-output-file-name ".ext" nil
"dir/"))
455 ;; When returned name would overwrite original file, add EXTENSION
458 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
459 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
461 (ert-deftest test-org-export
/expand-include
()
462 "Test file inclusion in an Org buffer."
463 ;; Error when file isn't specified.
465 (org-test-with-temp-text "#+INCLUDE: dummy.org"
466 (org-export-expand-include-keyword)))
467 ;; Full insertion with recursive inclusion.
468 (org-test-with-temp-text
469 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
470 (org-export-expand-include-keyword)
471 (should (equal (buffer-string)
472 "Small Org file with an include keyword.
474 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
480 ;; Localized insertion.
481 (org-test-with-temp-text
482 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
484 (org-export-expand-include-keyword)
485 (should (equal (buffer-string)
486 "Small Org file with an include keyword.\n")))
487 ;; Insertion with constraints on headlines level.
490 "* Top heading\n** Heading\nbody\n"
491 (org-test-with-temp-text
493 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
495 (org-export-expand-include-keyword)
499 "* Top heading\n* Heading\nbody\n"
500 (org-test-with-temp-text
502 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
504 (org-export-expand-include-keyword)
506 ;; Inclusion within an example block.
507 (org-test-with-temp-text
508 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
510 (org-export-expand-include-keyword)
514 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
515 ;; Inclusion within a src-block.
516 (org-test-with-temp-text
518 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
520 (org-export-expand-include-keyword)
521 (should (equal (buffer-string)
522 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
524 (ert-deftest test-org-export
/expand-macro
()
525 "Test macro expansion in an Org buffer."
526 ;; Standard macro expansion.
528 (equal "#+MACRO: macro1 value\nvalue\n"
529 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
530 (org-test-with-backend test
(org-export-as 'test
)))))
531 ;; Expand specific macros.
533 (equal "me 2012-03-29 me@here Title\n"
534 (org-test-with-temp-text
540 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
541 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
542 (substring output
(string-match ".*\n\\'" output
))))))
543 ;; Expand specific macros when property contained a regular macro
547 (org-test-with-temp-text "
548 #+MACRO: macro1 value
549 #+TITLE: {{{macro1}}}
551 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
552 (substring output
(string-match ".*\n\\'" output
))))))
553 ;; Expand macros with templates in included files.
556 (org-test-with-temp-text
557 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
558 {{{included-macro}}}" org-test-dir
)
559 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
560 (substring output
(string-match ".*\n\\'" output
)))))))
562 (ert-deftest test-org-export
/user-ignore-list
()
563 "Test if `:ignore-list' accepts user input."
564 (org-test-with-backend test
565 (flet ((skip-note-head
567 ;; Ignore headlines with the word "note" in their title.
571 (when (string-match "\\<note\\>"
572 (org-element-property :raw-value headline
))
573 (org-export-ignore-element headline info
)))
576 ;; Install function in parse tree filters.
577 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
578 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
579 (should (equal (org-export-as 'test
) "* Head1\n")))))))
581 (ert-deftest test-org-export
/before-processing-hook
()
582 "Test `org-export-before-processing-hook'."
585 "#+MACRO: mac val\nTest\n"
586 (org-test-with-backend test
587 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
588 (let ((org-export-before-processing-hook
590 (while (re-search-forward "{{{" nil t
)
591 (let ((object (org-element-context)))
592 (when (eq (org-element-type object
) 'macro
)
594 (org-element-property :begin object
)
595 (org-element-property :end object
)))))))))
596 (org-export-as 'test
)))))))
598 (ert-deftest test-org-export
/before-parsing-hook
()
599 "Test `org-export-before-parsing-hook'."
601 (equal "Body 1\nBody 2\n"
602 (org-test-with-backend test
603 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
604 (let ((org-export-before-parsing-hook
606 (goto-char (point-min))
607 (while (re-search-forward org-outline-regexp-bol nil t
)
609 (point-at-bol) (progn (forward-line) (point))))))))
610 (org-export-as 'test
)))))))
614 ;;; Affiliated Keywords
616 (ert-deftest test-org-export
/read-attribute
()
617 "Test `org-export-read-attribute' specifications."
621 (org-export-read-attribute
623 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
624 (org-element-at-point)))
626 ;; Return nil on empty attribute.
628 (org-export-read-attribute
630 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
632 (ert-deftest test-org-export
/get-caption
()
633 "Test `org-export-get-caption' specifications."
634 ;; Without optional argument, return long caption
638 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
639 (org-export-get-caption (org-element-at-point)))))
640 ;; With optional argument, return short caption.
644 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
645 (org-export-get-caption (org-element-at-point) t
))))
646 ;; Multiple lines are separated by white spaces.
650 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
651 (org-export-get-caption (org-element-at-point))))))
657 (ert-deftest test-org-export
/define-backend
()
658 "Test back-end definition and accessors."
661 (equal '((headline . my-headline-test
))
662 (let (org-export-registered-backends)
663 (org-export-define-backend test
((headline . my-headline-test
)))
664 (org-export-backend-translate-table 'test
))))
667 (equal '((:filter-headline . my-filter
))
668 (let (org-export-registered-backends)
669 (org-export-define-backend test
670 ((headline . my-headline-test
))
671 :filters-alist
((:filter-headline . my-filter
)))
672 (org-export-backend-filters 'test
))))
675 (equal '((:prop value
))
676 (let (org-export-registered-backends)
677 (org-export-define-backend test
678 ((headline . my-headline-test
))
679 :options-alist
((:prop value
)))
680 (org-export-backend-options 'test
))))
683 (equal '(?k
"Test Export" test
)
684 (let (org-export-registered-backends)
685 (org-export-define-backend test
686 ((headline . my-headline-test
))
687 :menu-entry
(?k
"Test Export" test
))
688 (org-export-backend-menu 'test
))))
691 (equal '(("TEST" . org-element-export-block-parser
))
692 (let (org-export-registered-backends org-element-block-name-alist
)
693 (org-export-define-backend test
694 ((headline . my-headline-test
))
695 :export-block
("test"))
696 org-element-block-name-alist
))))
698 (ert-deftest test-org-export
/define-derived-backend
()
699 "Test `org-export-define-derived-backend' specifications."
700 ;; Error when parent back-end is not defined.
702 (let (org-export-registered-backends)
703 (org-export-define-derived-backend test parent
)))
704 ;; Append translation table to parent's.
706 (equal '((:headline . test
) (:headline . parent
))
707 (let (org-export-registered-backends)
708 (org-export-define-backend parent
((:headline . parent
)))
709 (org-export-define-derived-backend test parent
710 :translate-alist
((:headline . test
)))
711 (org-export-backend-translate-table 'test
))))
712 ;; Options defined in the new back have priority over those defined
716 (let (org-export-registered-backends)
717 (org-export-define-backend parent
718 ((:headline . parent
))
719 :options-alist
((:a nil nil
'parent
)))
720 (org-export-define-derived-backend test parent
721 :options-alist
((:a nil nil
'test
)))
722 (plist-get (org-export--get-global-options 'test
) :a
)))))
724 (ert-deftest test-org-export
/derived-backend-p
()
725 "Test `org-export-derived-backend-p' specifications."
726 ;; Non-nil with direct match.
728 (let (org-export-registered-backends)
729 (org-export-define-backend test
((headline . test
)))
730 (org-export-derived-backend-p 'test
'test
)))
732 (let (org-export-registered-backends)
733 (org-export-define-backend test
((headline . test
)))
734 (org-export-define-derived-backend test2 test
)
735 (org-export-derived-backend-p 'test2
'test2
)))
736 ;; Non-nil with a direct parent.
738 (let (org-export-registered-backends)
739 (org-export-define-backend test
((headline . test
)))
740 (org-export-define-derived-backend test2 test
)
741 (org-export-derived-backend-p 'test2
'test
)))
742 ;; Non-nil with an indirect parent.
744 (let (org-export-registered-backends)
745 (org-export-define-backend test
((headline . test
)))
746 (org-export-define-derived-backend test2 test
)
747 (org-export-define-derived-backend test3 test2
)
748 (org-export-derived-backend-p 'test3
'test
)))
751 (let (org-export-registered-backends)
752 (org-export-define-backend test
((headline . test
)))
753 (org-export-define-backend test2
((headline . test2
)))
754 (org-export-derived-backend-p 'test2
'test
)))
756 (let (org-export-registered-backends)
757 (org-export-define-backend test
((headline . test
)))
758 (org-export-define-backend test2
((headline . test2
)))
759 (org-export-define-derived-backend test3 test2
)
760 (org-export-derived-backend-p 'test3
'test
))))
762 (ert-deftest test-org-export
/with-backend
()
763 "Test `org-export-with-backend' definition."
764 ;; Error when calling an undefined back-end
766 (let (org-export-registered-backends)
767 (org-export-with-backend 'test
"Test")))
768 ;; Error when called back-end doesn't have an appropriate
771 (let (org-export-registered-backends)
772 (org-export-define-backend test
((headline . ignore
)))
773 (org-export-with-backend 'test
"Test")))
774 ;; Otherwise, export using correct transcoder
777 (let (org-export-registered-backends)
778 (org-export-define-backend test
779 ((plain-text .
(lambda (text contents info
) "Failure"))))
780 (org-export-define-backend test2
781 ((plain-text .
(lambda (text contents info
) "Success"))))
782 (org-export-with-backend 'test2
"Test")))))
784 (ert-deftest test-org-export
/data-with-translations
()
785 "Test `org-export-data-with-translations' specifications."
789 (org-export-data-with-translations
791 '((plain-text .
(lambda (text info
) "Success"))
792 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
793 '(:with-emphasize t
)))))
795 (ert-deftest test-org-export
/data-with-backend
()
796 "Test `org-export-data-with-backend' specifications."
797 ;; Error when calling an undefined back-end.
799 (let (org-export-registered-backends)
800 (org-export-data-with-backend 'test
"Test" nil
)))
801 ;; Otherwise, export data recursively, using correct back-end.
805 (let (org-export-registered-backends)
806 (org-export-define-backend test
807 ((plain-text .
(lambda (text info
) "Success"))
808 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
809 (org-export-data-with-backend
810 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
816 (ert-deftest test-org-export
/export-snippet
()
817 "Test export snippets transcoding."
818 (org-test-with-temp-text "@@test:A@@@@t:B@@"
819 (org-test-with-backend test
821 (cdr (assq 'test org-export-registered-backends
))
823 (cons (cons 'export-snippet
824 (lambda (snippet contents info
)
825 (when (eq (org-export-snippet-backend snippet
) 'test
)
826 (org-element-property :value snippet
))))
827 (org-export-backend-translate-table 'test
)))
828 (let ((org-export-snippet-translation-alist nil
))
829 (should (equal (org-export-as 'test
) "A\n")))
830 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
831 (should (equal (org-export-as 'test
) "AB\n"))))))
837 (ert-deftest test-org-export
/footnotes
()
838 "Test footnotes specifications."
839 (let ((org-footnote-section nil
)
840 (org-export-with-footnotes t
))
841 ;; 1. Read every type of footnote.
844 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
845 (org-test-with-parsed-data
846 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
848 tree
'footnote-reference
850 (let ((def (org-export-get-footnote-definition ref info
)))
851 (cons (org-export-get-footnote-number ref info
)
852 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
853 (car (org-element-contents
854 (car (org-element-contents def
))))))))
856 ;; 2. Test nested footnotes order.
857 (org-test-with-parsed-data
858 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
861 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
863 tree
'footnote-reference
865 (when (org-export-footnote-first-reference-p ref info
)
866 (cons (org-export-get-footnote-number ref info
)
867 (org-element-property :label ref
))))
869 ;; 3. Test nested footnote in invisible definitions.
870 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
872 (narrow-to-region (point) (point-at-eol))
873 (let* ((tree (org-element-parse-buffer))
874 (info (org-combine-plists
876 (org-export-collect-tree-properties
877 tree
(org-export-get-environment)))))
878 ;; Both footnotes should be seen.
880 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
881 ;; 4. Test footnotes definitions collection.
882 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
884 \[fn:2] B [fn:3] [fn::D].
887 (should (= (length (org-export-collect-footnote-definitions tree info
))
889 ;; 5. Test export of footnotes defined outside parsing scope.
890 (org-test-with-temp-text "[fn:1] Out of scope
893 (org-test-with-backend test
895 (cdr (assq 'test org-export-registered-backends
))
897 (cons (cons 'footnote-reference
898 (lambda (fn contents info
)
899 (org-element-interpret-data
900 (org-export-get-footnote-definition fn info
))))
901 (org-export-backend-translate-table 'test
)))
903 (should (equal "ParagraphOut of scope\n"
904 (org-export-as 'test
'subtree
)))))
905 ;; 6. Footnotes without a definition should be provided a fallback
908 (org-test-with-parsed-data "[fn:1]"
909 (org-export-get-footnote-definition
910 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
911 ;; 7. Footnote section should be ignored in TOC and in headlines
914 (= 1 (let ((org-footnote-section "Footnotes"))
915 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
916 (org-export-collect-headlines info
))))))
919 (let ((org-footnote-section "Footnotes"))
920 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
921 (org-element-map tree
'headline
923 (when (equal (org-element-property :raw-value hl
) "H2")
924 (org-export-get-headline-number hl info
)))
929 ;;; Headlines and Inlinetasks
931 (ert-deftest test-org-export
/get-relative-level
()
932 "Test `org-export-get-relative-level' specifications."
936 (let ((org-odd-levels-only nil
))
937 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
940 (lambda (h) (org-export-get-relative-level h info
))
945 (let ((org-odd-levels-only nil
))
946 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
949 (lambda (h) (org-export-get-relative-level h info
))
952 (ert-deftest test-org-export
/low-level-p
()
953 "Test `org-export-low-level-p' specifications."
957 (let ((org-odd-levels-only nil
))
958 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
961 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
962 (plist-put info
:headline-levels
1)))))))
964 (ert-deftest test-org-export
/get-headline-number
()
965 "Test `org-export-get-headline-number' specifications."
970 (let ((org-odd-levels-only nil
))
971 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
974 (lambda (h) (org-export-get-headline-number h info
))
976 ;; Missing levels are replaced with 0.
980 (let ((org-odd-levels-only nil
))
981 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
984 (lambda (h) (org-export-get-headline-number h info
))
987 (ert-deftest test-org-export
/numbered-headline-p
()
988 "Test `org-export-numbered-headline-p' specifications."
989 ;; If `:section-numbers' is nil, never number headlines.
991 (org-test-with-parsed-data "* Headline"
994 (lambda (h) (org-export-numbered-headline-p h info
))
995 (plist-put info
:section-numbers nil
))))
996 ;; If `:section-numbers' is a number, only number headlines with
997 ;; a level greater that it.
1001 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1004 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1005 (plist-put info
:section-numbers
1)))))
1006 ;; Otherwise, headlines are always numbered.
1008 (org-test-with-parsed-data "* Headline"
1011 (lambda (h) (org-export-numbered-headline-p h info
))
1012 (plist-put info
:section-numbers t
)))))
1014 (ert-deftest test-org-export
/number-to-roman
()
1015 "Test `org-export-number-to-roman' specifications."
1016 ;; If number is negative, return it as a string.
1017 (should (equal (org-export-number-to-roman -
1) "-1"))
1018 ;; Otherwise, return it as a roman number.
1019 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1021 (ert-deftest test-org-export
/get-tags
()
1022 "Test `org-export-get-tags' specifications."
1023 (let ((org-export-exclude-tags '("noexport"))
1024 (org-export-select-tags '("export")))
1025 ;; Standard test: tags which are not a select tag, an exclude tag,
1026 ;; or specified as optional argument shouldn't be ignored.
1028 (org-test-with-parsed-data "* Headline :tag:"
1029 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1031 ;; Exclude tags are removed.
1033 (org-test-with-parsed-data "* Headline :noexport:"
1034 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1036 ;; Select tags are removed.
1038 (org-test-with-parsed-data "* Headline :export:"
1039 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1044 (org-test-with-parsed-data "* Headline :tag:export:"
1045 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1047 ;; Tags provided in the optional argument are also ignored.
1049 (org-test-with-parsed-data "* Headline :ignore:"
1050 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1052 ;; Allow tag inheritance.
1056 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1059 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1060 ;; Tag inheritance checks FILETAGS keywords.
1064 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1067 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1069 (ert-deftest test-org-export
/get-node-property
()
1070 "Test`org-export-get-node-property' specifications."
1074 (org-test-with-parsed-data "* Headline
1078 (org-export-get-node-property
1079 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1080 ;; Test inheritance.
1083 (org-test-with-parsed-data "* Parent
1089 (org-export-get-node-property
1090 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1091 ;; Cannot return a value before the first headline.
1093 (org-test-with-parsed-data "Paragraph
1098 (org-export-get-node-property
1099 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1101 (ert-deftest test-org-export
/get-category
()
1102 "Test `org-export-get-category' specifications."
1106 (org-test-with-parsed-data "* Headline
1110 (org-export-get-category
1111 (org-element-map tree
'headline
'identity nil t
) info
))))
1112 ;; Test inheritance from a parent headline.
1114 (equal '("value" "value")
1115 (org-test-with-parsed-data "* Headline1
1122 (lambda (hl) (org-export-get-category hl info
)) info
))))
1123 ;; Test inheritance from #+CATEGORY keyword
1126 (org-test-with-parsed-data "#+CATEGORY: value
1128 (org-export-get-category
1129 (org-element-map tree
'headline
'identity nil t
) info
))))
1130 ;; Test inheritance from file name.
1133 (org-test-with-parsed-data "* Headline"
1134 (let ((info (plist-put info
:input-file
"~/test.org")))
1135 (org-export-get-category
1136 (org-element-map tree
'headline
'identity nil t
) info
)))))
1140 (org-test-with-parsed-data "* Headline"
1141 (org-export-get-category
1142 (org-element-map tree
'headline
'identity nil t
) info
)))))
1144 (ert-deftest test-org-export
/first-sibling-p
()
1145 "Test `org-export-first-sibling-p' specifications."
1150 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1153 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1155 ;; Ignore headlines not exported.
1159 (let ((org-export-exclude-tags '("ignore")))
1160 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1163 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1166 (ert-deftest test-org-export
/last-sibling-p
()
1167 "Test `org-export-last-sibling-p' specifications."
1172 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1175 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1177 ;; Ignore headlines not exported.
1181 (let ((org-export-exclude-tags '("ignore")))
1182 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1185 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1192 (ert-deftest test-org-export
/get-coderef-format
()
1193 "Test `org-export-get-coderef-format' specifications."
1194 ;; A link without description returns "%s"
1195 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1197 ;; Return "%s" when path is matched within description.
1198 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1200 ;; Otherwise return description.
1201 (should (equal (org-export-get-coderef-format "path" "desc")
1204 (ert-deftest test-org-export
/inline-image-p
()
1205 "Test `org-export-inline-image-p' specifications."
1207 (org-export-inline-image-p
1208 (org-test-with-temp-text "[[#id]]"
1210 (org-element-parse-buffer) 'link
'identity nil t
))
1211 '(("custom-id" .
"id")))))
1213 (ert-deftest test-org-export
/fuzzy-link
()
1214 "Test fuzzy links specifications."
1215 ;; 1. Links to invisible (keyword) targets should be ignored.
1216 (org-test-with-parsed-data
1217 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1222 (org-export-get-ordinal
1223 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1224 ;; 2. Link to an headline should return headline's number.
1225 (org-test-with-parsed-data
1226 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1228 ;; Note: Headline's number is in fact a list of numbers.
1233 (org-export-get-ordinal
1234 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1235 ;; 3. Link to a target in an item should return item's number.
1236 (org-test-with-parsed-data
1237 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1239 ;; Note: Item's number is in fact a list of numbers.
1244 (org-export-get-ordinal
1245 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1246 ;; 4. Link to a target in a footnote should return footnote's
1248 (org-test-with-parsed-data "
1249 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1255 (org-export-get-ordinal
1256 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1257 ;; 5. Link to a named element should return sequence number of that
1259 (org-test-with-parsed-data
1260 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1266 (org-export-get-ordinal
1267 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1268 ;; 6. Link to a target not within an item, a table, a footnote
1269 ;; reference or definition should return section number.
1270 (org-test-with-parsed-data
1271 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1277 (org-export-get-ordinal
1278 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1279 ;; 7. Space are not significant when matching a fuzzy link.
1281 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1282 (org-element-map tree
'link
1283 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1285 ;; 8. Statistics cookies are ignored for headline match.
1287 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1288 (org-element-map tree
'link
1289 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1292 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1293 (org-element-map tree
'link
1294 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1297 (ert-deftest test-org-export
/resolve-coderef
()
1298 "Test `org-export-resolve-coderef' specifications."
1299 (let ((org-coderef-label-format "(ref:%s)"))
1300 ;; 1. A link to a "-n -k -r" block returns line number.
1301 (org-test-with-parsed-data
1302 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1303 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1304 (org-test-with-parsed-data
1305 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1306 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1307 ;; 2. A link to a "-n -r" block returns line number.
1308 (org-test-with-parsed-data
1309 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1310 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1311 (org-test-with-parsed-data
1312 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1313 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1314 ;; 3. A link to a "-n" block returns coderef.
1315 (org-test-with-parsed-data
1316 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1317 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1318 (org-test-with-parsed-data
1319 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1320 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1321 ;; 4. A link to a "-r" block returns line number.
1322 (org-test-with-parsed-data
1323 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1324 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1325 (org-test-with-parsed-data
1326 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1327 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1328 ;; 5. A link to a block without a switch returns coderef.
1329 (org-test-with-parsed-data
1330 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1331 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1332 (org-test-with-parsed-data
1333 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1334 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1335 ;; 6. Correctly handle continued line numbers. A "+n" switch
1336 ;; should resume numbering from previous block with numbered
1337 ;; lines, ignoring blocks not numbering lines in the process.
1338 ;; A "-n" switch resets count.
1339 (org-test-with-parsed-data "
1344 #+BEGIN_SRC emacs-lisp
1348 #+BEGIN_SRC emacs-lisp +n -r
1349 \(+ 1 1) (ref:addition)
1352 #+BEGIN_EXAMPLE -n -r
1353 Another text. (ref:text)
1355 (should (= (org-export-resolve-coderef "addition" info
) 2))
1356 (should (= (org-export-resolve-coderef "text" info
) 1)))
1357 ;; 7. Recognize coderef with user-specified syntax.
1358 (org-test-with-parsed-data
1359 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1360 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1362 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1363 "Test `org-export-resolve-fuzzy-link' specifications."
1364 ;; 1. Match target objects.
1365 (org-test-with-parsed-data "<<target>> [[target]]"
1367 (org-export-resolve-fuzzy-link
1368 (org-element-map tree
'link
'identity info t
) info
)))
1369 ;; 2. Match target elements.
1370 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1372 (org-export-resolve-fuzzy-link
1373 (org-element-map tree
'link
'identity info t
) info
)))
1374 ;; 3. Match named elements.
1375 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1377 (org-export-resolve-fuzzy-link
1378 (org-element-map tree
'link
'identity info t
) info
)))
1379 ;; 4. Match exact headline's name.
1380 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1382 (org-export-resolve-fuzzy-link
1383 (org-element-map tree
'link
'identity info t
) info
)))
1384 ;; 5. Targets objects have priority over named elements and headline
1386 (org-test-with-parsed-data
1387 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1391 (org-export-resolve-fuzzy-link
1392 (org-element-map tree
'link
'identity info t
) info
)))))
1393 ;; 6. Named elements have priority over headline titles.
1394 (org-test-with-parsed-data
1395 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1399 (org-export-resolve-fuzzy-link
1400 (org-element-map tree
'link
'identity info t
) info
)))))
1401 ;; 7. If link's path starts with a "*", only match headline titles,
1403 (org-test-with-parsed-data
1404 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1408 (org-export-resolve-fuzzy-link
1409 (org-element-map tree
'link
'identity info t
) info
)))))
1410 ;; 8. Return nil if no match.
1411 (org-test-with-parsed-data "[[target]]"
1413 (org-export-resolve-fuzzy-link
1414 (org-element-map tree
'link
'identity info t
) info
))))
1416 (ert-deftest test-org-export
/resolve-id-link
()
1417 "Test `org-export-resolve-id-link' specifications."
1418 ;; 1. Regular test for custom-id link.
1419 (org-test-with-parsed-data "* Headline1
1426 (org-export-resolve-id-link
1427 (org-element-map tree
'link
'identity info t
) info
)))
1428 ;; 2. Failing test for custom-id link.
1429 (org-test-with-parsed-data "* Headline1
1436 (org-export-resolve-id-link
1437 (org-element-map tree
'link
'identity info t
) info
)))
1438 ;; 3. Test for internal id target.
1439 (org-test-with-parsed-data "* Headline1
1446 (org-export-resolve-id-link
1447 (org-element-map tree
'link
'identity info t
) info
)))
1448 ;; 4. Test for external id target.
1449 (org-test-with-parsed-data "[[id:aaaa]]"
1451 (org-export-resolve-id-link
1452 (org-element-map tree
'link
'identity info t
)
1453 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1455 (ert-deftest test-org-export
/resolve-radio-link
()
1456 "Test `org-export-resolve-radio-link' specifications."
1459 (org-test-with-temp-text "<<<radio>>> radio"
1460 (org-update-radio-target-regexp)
1461 (let* ((tree (org-element-parse-buffer))
1462 (info `(:parse-tree
,tree
)))
1463 (org-export-resolve-radio-link
1464 (org-element-map tree
'link
'identity info t
)
1466 ;; Radio targets are case-insensitive.
1468 (org-test-with-temp-text "<<<RADIO>>> radio"
1469 (org-update-radio-target-regexp)
1470 (let* ((tree (org-element-parse-buffer))
1471 (info `(:parse-tree
,tree
)))
1472 (org-export-resolve-radio-link
1473 (org-element-map tree
'link
'identity info t
)
1475 ;; Radio target with objects.
1477 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1478 (org-update-radio-target-regexp)
1479 (let* ((tree (org-element-parse-buffer))
1480 (info `(:parse-tree
,tree
)))
1481 (org-export-resolve-radio-link
1482 (org-element-map tree
'link
'identity info t
)
1487 ;;; Src-block and example-block
1489 (ert-deftest test-org-export
/unravel-code
()
1490 "Test `org-export-unravel-code' function."
1491 (let ((org-coderef-label-format "(ref:%s)"))
1492 ;; 1. Code without reference.
1493 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1494 (should (equal (org-export-unravel-code (org-element-at-point))
1496 ;; 2. Code with reference.
1497 (org-test-with-temp-text
1498 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1499 (should (equal (org-export-unravel-code (org-element-at-point))
1500 '("(+ 1 1)\n" (1 .
"test")))))
1501 ;; 3. Code with user-defined reference.
1502 (org-test-with-temp-text
1503 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1504 (should (equal (org-export-unravel-code (org-element-at-point))
1505 '("(+ 1 1)\n" (1 .
"test")))))
1506 ;; 4. Code references keys are relative to the current block.
1507 (org-test-with-temp-text "
1516 (should (equal (org-export-unravel-code (org-element-at-point))
1517 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1523 (ert-deftest test-org-export
/activate-smart-quotes
()
1524 "Test `org-export-activate-smart-quotes' specifications."
1525 ;; Opening double quotes: standard test.
1528 '("some “paragraph")
1529 (let ((org-export-default-language "en"))
1530 (org-test-with-parsed-data "some \"paragraph"
1533 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1535 ;; Opening quotes: at the beginning of a paragraph.
1539 (let ((org-export-default-language "en"))
1540 (org-test-with-parsed-data "\"begin"
1543 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1545 ;; Opening quotes: after an object.
1549 (let ((org-export-default-language "en"))
1550 (org-test-with-parsed-data "=verb= \"begin"
1553 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1555 ;; Closing quotes: standard test.
1558 '("some” paragraph")
1559 (let ((org-export-default-language "en"))
1560 (org-test-with-parsed-data "some\" paragraph"
1563 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1565 ;; Closing quotes: at the end of a paragraph.
1569 (let ((org-export-default-language "en"))
1570 (org-test-with-parsed-data "end\""
1573 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1575 ;; Apostrophe: standard test.
1578 '("It shouldn’t fail")
1579 (let ((org-export-default-language "en"))
1580 (org-test-with-parsed-data "It shouldn't fail"
1583 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1585 ;; Apostrophe: before an object.
1589 (let ((org-export-default-language "en"))
1590 (org-test-with-parsed-data "a'=b="
1593 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1595 ;; Apostrophe: after an object.
1599 (let ((org-export-default-language "en"))
1600 (org-test-with-parsed-data "=code='s"
1603 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1605 ;; Special case: isolated quotes.
1607 (equal '("“" "”")
1608 (let ((org-export-default-language "en"))
1609 (org-test-with-parsed-data "\"$x$\""
1612 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1614 ;; Smart quotes in secondary strings.
1616 (equal '("“" "”")
1617 (let ((org-export-default-language "en"))
1618 (org-test-with-parsed-data "* \"$x$\""
1621 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1623 ;; Smart quotes in document keywords.
1625 (equal '("“" "”")
1626 (let ((org-export-default-language "en"))
1627 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1629 (plist-get info
:title
) 'plain-text
1630 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1632 ;; Smart quotes in parsed affiliated keywords.
1634 (equal '("“" "”" "Paragraph")
1635 (let ((org-export-default-language "en"))
1636 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1639 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1640 info nil nil t
))))))
1646 (ert-deftest test-org-export
/special-column
()
1647 "Test if the table's special column is properly recognized."
1648 ;; 1. First column is special if it contains only a special marking
1649 ;; characters or empty cells.
1650 (org-test-with-temp-text "
1654 (org-export-table-has-special-column-p
1656 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1657 ;; 2. If the column contains anything else, it isn't special.
1658 (org-test-with-temp-text "
1662 (org-export-table-has-special-column-p
1664 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1665 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1667 (org-test-with-temp-text "
1676 (org-export-table-has-special-column-p
1678 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1679 ;; 4. A first column with only empty cells isn't considered as
1681 (org-test-with-temp-text "
1685 (org-export-table-has-special-column-p
1687 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1689 (ert-deftest test-org-export
/table-row-is-special-p
()
1690 "Test `org-export-table-row-is-special-p' specifications."
1691 ;; 1. A row is special if it has a special marking character in the
1693 (org-test-with-parsed-data "| ! | 1 |"
1695 (org-export-table-row-is-special-p
1696 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1697 ;; 2. A row is special when its first field is "/"
1698 (org-test-with-parsed-data "
1702 (org-export-table-row-is-special-p
1703 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1704 ;; 3. A row only containing alignment cookies is also considered as
1706 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1708 (org-export-table-row-is-special-p
1709 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1710 ;; 4. Everything else isn't considered as special.
1711 (org-test-with-parsed-data "| \alpha | | c |"
1713 (org-export-table-row-is-special-p
1714 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1715 ;; 5. Table's rules are never considered as special rows.
1716 (org-test-with-parsed-data "|---+---|"
1718 (org-export-table-row-is-special-p
1719 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1721 (ert-deftest test-org-export
/has-header-p
()
1722 "Test `org-export-table-has-header-p' specifications."
1723 ;; 1. With an header.
1724 (org-test-with-parsed-data "
1729 (org-export-table-has-header-p
1730 (org-element-map tree
'table
'identity info
'first-match
)
1732 ;; 2. Without an header.
1733 (org-test-with-parsed-data "
1737 (org-export-table-has-header-p
1738 (org-element-map tree
'table
'identity info
'first-match
)
1740 ;; 3. Don't get fooled with starting and ending rules.
1741 (org-test-with-parsed-data "
1747 (org-export-table-has-header-p
1748 (org-element-map tree
'table
'identity info
'first-match
)
1751 (ert-deftest test-org-export
/table-row-group
()
1752 "Test `org-export-table-row-group' specifications."
1753 ;; 1. A rule creates a new group.
1754 (org-test-with-parsed-data "
1761 (mapcar (lambda (row) (org-export-table-row-group row info
))
1762 (org-element-map tree
'table-row
'identity
)))))
1763 ;; 2. Special rows are ignored in count.
1764 (org-test-with-parsed-data "
1771 (mapcar (lambda (row) (org-export-table-row-group row info
))
1772 (org-element-map tree
'table-row
'identity
)))))
1773 ;; 3. Double rules also are ignored in count.
1774 (org-test-with-parsed-data "
1782 (mapcar (lambda (row) (org-export-table-row-group row info
))
1783 (org-element-map tree
'table-row
'identity
))))))
1785 (ert-deftest test-org-export
/table-cell-width
()
1786 "Test `org-export-table-cell-width' specifications."
1787 ;; 1. Width is primarily determined by width cookies. If no cookie
1788 ;; is found, cell's width is nil.
1789 (org-test-with-parsed-data "
1790 | / | <l> | <6> | <l7> |
1795 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1796 (org-element-map tree
'table-cell
'identity info
)))))
1797 ;; 2. The last width cookie has precedence.
1798 (org-test-with-parsed-data "
1805 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1806 (org-element-map tree
'table-cell
'identity info
)))))
1807 ;; 3. Valid width cookies must have a specific row.
1808 (org-test-with-parsed-data "| <6> | cell |"
1812 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1813 (org-element-map tree
'table-cell
'identity
))))))
1815 (ert-deftest test-org-export
/table-cell-alignment
()
1816 "Test `org-export-table-cell-alignment' specifications."
1817 (let ((org-table-number-fraction 0.5)
1818 (org-table-number-regexp "^[0-9]+$"))
1819 ;; 1. Alignment is primarily determined by alignment cookies.
1820 (org-test-with-temp-text "| <l> | <c> | <r> |"
1821 (let* ((tree (org-element-parse-buffer))
1822 (info `(:parse-tree
,tree
)))
1825 '(left center right
)
1826 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1827 (org-element-map tree
'table-cell
'identity
))))))
1828 ;; 2. The last alignment cookie has precedence.
1829 (org-test-with-parsed-data "
1835 '(right right right
)
1836 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1837 (org-element-map tree
'table-cell
'identity
)))))
1838 ;; 3. If there's no cookie, cell's contents determine alignment.
1839 ;; A column mostly made of cells containing numbers will align
1840 ;; its cells to the right.
1841 (org-test-with-parsed-data "
1847 '(right right right
)
1848 (mapcar (lambda (cell)
1849 (org-export-table-cell-alignment cell info
))
1850 (org-element-map tree
'table-cell
'identity
)))))
1851 ;; 4. Otherwise, they will be aligned to the left.
1852 (org-test-with-parsed-data "
1859 (mapcar (lambda (cell)
1860 (org-export-table-cell-alignment cell info
))
1861 (org-element-map tree
'table-cell
'identity
)))))))
1863 (ert-deftest test-org-export
/table-cell-borders
()
1864 "Test `org-export-table-cell-borders' specifications."
1865 ;; 1. Recognize various column groups indicators.
1866 (org-test-with-parsed-data "| / | < | > | <> |"
1869 '((right bottom top
) (left bottom top
) (right bottom top
)
1870 (right left bottom top
))
1871 (mapcar (lambda (cell)
1872 (org-export-table-cell-borders cell info
))
1873 (org-element-map tree
'table-cell
'identity
)))))
1874 ;; 2. Accept shortcuts to define column groups.
1875 (org-test-with-parsed-data "| / | < | < |"
1878 '((right bottom top
) (right left bottom top
) (left bottom top
))
1879 (mapcar (lambda (cell)
1880 (org-export-table-cell-borders cell info
))
1881 (org-element-map tree
'table-cell
'identity
)))))
1882 ;; 3. A valid column groups row must start with a "/".
1883 (org-test-with-parsed-data "
1887 (equal '((top) (top) (bottom) (bottom))
1888 (mapcar (lambda (cell)
1889 (org-export-table-cell-borders cell info
))
1890 (org-element-map tree
'table-cell
'identity
)))))
1891 ;; 4. Take table rules into consideration.
1892 (org-test-with-parsed-data "
1897 (equal '((below top
) (bottom above
))
1898 (mapcar (lambda (cell)
1899 (org-export-table-cell-borders cell info
))
1900 (org-element-map tree
'table-cell
'identity
)))))
1901 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1902 ;; (resp. `bottom' and `below') borders. Any special row is
1904 (org-test-with-parsed-data "
1910 (equal '((bottom below top above
))
1912 (mapcar (lambda (cell)
1913 (org-export-table-cell-borders cell info
))
1914 (org-element-map tree
'table-cell
'identity
)))))))
1916 (ert-deftest test-org-export
/table-dimensions
()
1917 "Test `org-export-table-dimensions' specifications."
1918 ;; 1. Standard test.
1919 (org-test-with-parsed-data "
1924 (org-export-table-dimensions
1925 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1926 ;; 2. Ignore horizontal rules and special columns.
1927 (org-test-with-parsed-data "
1934 (org-export-table-dimensions
1935 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1937 (ert-deftest test-org-export
/table-cell-address
()
1938 "Test `org-export-table-cell-address' specifications."
1939 ;; 1. Standard test: index is 0-based.
1940 (org-test-with-parsed-data "| a | b |"
1942 (equal '((0 .
0) (0 .
1))
1945 (lambda (cell) (org-export-table-cell-address cell info
))
1947 ;; 2. Special column isn't counted, nor are special rows.
1948 (org-test-with-parsed-data "
1953 (org-export-table-cell-address
1954 (car (last (org-element-map tree
'table-cell
'identity info
)))
1956 ;; 3. Tables rules do not count either.
1957 (org-test-with-parsed-data "
1965 (org-export-table-cell-address
1966 (car (last (org-element-map tree
'table-cell
'identity info
)))
1968 ;; 4. Return nil for special cells.
1969 (org-test-with-parsed-data "| / | a |"
1971 (org-export-table-cell-address
1972 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1975 (ert-deftest test-org-export
/get-table-cell-at
()
1976 "Test `org-export-get-table-cell-at' specifications."
1977 ;; 1. Address ignores special columns, special rows and rules.
1978 (org-test-with-parsed-data "
1985 (org-element-contents
1986 (org-export-get-table-cell-at
1988 (org-element-map tree
'table
'identity info
'first-match
)
1990 ;; 2. Return value for a non-existent address is nil.
1991 (org-test-with-parsed-data "| a |"
1993 (org-export-get-table-cell-at
1995 (org-element-map tree
'table
'identity info
'first-match
)
1997 (org-test-with-parsed-data "| / |"
1999 (org-export-get-table-cell-at
2001 (org-element-map tree
'table
'identity info
'first-match
)
2004 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2005 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2006 ;; 1. A cell at a beginning of a row always starts a column group.
2007 (org-test-with-parsed-data "| a |"
2009 (org-export-table-cell-starts-colgroup-p
2010 (org-element-map tree
'table-cell
'identity info
'first-match
)
2012 ;; 2. Special column should be ignored when determining the
2013 ;; beginning of the row.
2014 (org-test-with-parsed-data "
2018 (org-export-table-cell-starts-colgroup-p
2019 (org-element-map tree
'table-cell
'identity info
'first-match
)
2021 ;; 2. Explicit column groups.
2022 (org-test-with-parsed-data "
2031 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2034 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2035 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2036 ;; 1. A cell at the end of a row always ends a column group.
2037 (org-test-with-parsed-data "| a |"
2039 (org-export-table-cell-ends-colgroup-p
2040 (org-element-map tree
'table-cell
'identity info
'first-match
)
2042 ;; 2. Special column should be ignored when determining the
2043 ;; beginning of the row.
2044 (org-test-with-parsed-data "
2048 (org-export-table-cell-ends-colgroup-p
2049 (org-element-map tree
'table-cell
'identity info
'first-match
)
2051 ;; 3. Explicit column groups.
2052 (org-test-with-parsed-data "
2061 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2064 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2065 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2066 ;; 1. A row at the beginning of a table always starts a row group.
2067 ;; So does a row following a table rule.
2068 (org-test-with-parsed-data "
2078 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2080 ;; 2. Special rows should be ignored when determining the beginning
2082 (org-test-with-parsed-data "
2094 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2097 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2098 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2099 ;; 1. A row at the end of a table always ends a row group. So does
2100 ;; a row preceding a table rule.
2101 (org-test-with-parsed-data "
2111 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2113 ;; 2. Special rows should be ignored when determining the beginning
2115 (org-test-with-parsed-data "
2127 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2130 (ert-deftest test-org-export
/table-row-starts-header-p
()
2131 "Test `org-export-table-row-starts-header-p' specifications."
2132 ;; 1. Only the row starting the first row group starts the table
2134 (org-test-with-parsed-data "
2145 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2147 ;; 2. A row cannot start an header if there's no header in the
2149 (org-test-with-parsed-data "
2153 (org-export-table-row-starts-header-p
2154 (org-element-map tree
'table-row
'identity info
'first-match
)
2157 (ert-deftest test-org-export
/table-row-ends-header-p
()
2158 "Test `org-export-table-row-ends-header-p' specifications."
2159 ;; 1. Only the row starting the first row group starts the table
2161 (org-test-with-parsed-data "
2172 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2174 ;; 2. A row cannot start an header if there's no header in the
2176 (org-test-with-parsed-data "
2180 (org-export-table-row-ends-header-p
2181 (org-element-map tree
'table-row
'identity info
'first-match
)
2188 (ert-deftest test-org-export
/inner-template
()
2189 "Test `inner-template' translator specifications."
2192 (let (org-export-registered-backends)
2193 (org-export-define-backend test
2194 ((inner-template .
(lambda (contents info
) "Success!"))
2195 (headline .
(lambda (h c i
) "Headline"))))
2196 (org-test-with-temp-text "* Headline"
2197 (org-export-as 'test
)))))
2198 ;; Inner template is applied even in a "body-only" export.
2201 (let (org-export-registered-backends)
2202 (org-export-define-backend test
2203 ((inner-template .
(lambda (contents info
) "Success!"))
2204 (headline .
(lambda (h c i
) "Headline"))))
2205 (org-test-with-temp-text "* Headline"
2206 (org-export-as 'test nil nil
'body-only
))))))
2208 (ert-deftest test-org-export
/template
()
2209 "Test `template' translator specifications."
2212 (let (org-export-registered-backends)
2213 (org-export-define-backend test
2214 ((template .
(lambda (contents info
) "Success!"))
2215 (headline .
(lambda (h c i
) "Headline"))))
2216 (org-test-with-temp-text "* Headline"
2217 (org-export-as 'test
)))))
2218 ;; Template is not applied in a "body-only" export.
2221 (let (org-export-registered-backends)
2222 (org-export-define-backend test
2223 ((template .
(lambda (contents info
) "Success!"))
2224 (headline .
(lambda (h c i
) "Headline"))))
2225 (org-test-with-temp-text "* Headline"
2226 (org-export-as 'test nil nil
'body-only
))))))
2232 (ert-deftest test-org-export
/get-next-element
()
2233 "Test `org-export-get-next-element' specifications."
2237 (org-test-with-parsed-data "* Headline\n*a* b"
2238 (org-export-get-next-element
2239 (org-element-map tree
'bold
'identity info t
) info
))))
2240 ;; Return nil when no previous element.
2242 (org-test-with-parsed-data "* Headline\na *b*"
2243 (org-export-get-next-element
2244 (org-element-map tree
'bold
'identity info t
) info
)))
2245 ;; Non-exportable elements are ignored.
2247 (let ((org-export-with-timestamps nil
))
2248 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2249 (org-export-get-next-element
2250 (org-element-map tree
'entity
'identity info t
) info
))))
2251 ;; Find next element in secondary strings.
2254 (org-test-with-parsed-data "* a =verb="
2256 (org-export-get-next-element
2257 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2258 ;; Find next element in document keywords.
2261 (org-test-with-parsed-data "#+TITLE: a =verb="
2263 (org-export-get-next-element
2265 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2266 ;; Find next element in parsed affiliated keywords.
2269 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2271 (org-export-get-next-element
2272 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2273 ;; With optional argument N, return a list containing all the
2274 ;; following elements.
2277 '(bold code underline
)
2278 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2280 (org-export-get-next-element
2281 (org-element-map tree
'italic
'identity info t
) info t
)))))
2282 ;; When N is a positive integer, return a list containing up to
2283 ;; N following elements.
2287 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2289 (org-export-get-next-element
2290 (org-element-map tree
'italic
'identity info t
) info
2))))))
2292 (ert-deftest test-org-export
/get-previous-element
()
2293 "Test `org-export-get-previous-element' specifications."
2297 (org-test-with-parsed-data "* Headline\na *b*"
2298 (org-export-get-previous-element
2299 (org-element-map tree
'bold
'identity info t
) info
))))
2300 ;; Return nil when no previous element.
2302 (org-test-with-parsed-data "* Headline\n*a* b"
2303 (org-export-get-previous-element
2304 (org-element-map tree
'bold
'identity info t
) info
)))
2305 ;; Non-exportable elements are ignored.
2307 (let ((org-export-with-timestamps nil
))
2308 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2309 (org-export-get-previous-element
2310 (org-element-map tree
'entity
'identity info t
) info
))))
2311 ;; Find previous element in secondary strings.
2314 (org-test-with-parsed-data "* =verb= a"
2316 (org-export-get-previous-element
2317 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2318 ;; Find previous element in document keywords.
2321 (org-test-with-parsed-data "#+TITLE: =verb= a"
2323 (org-export-get-previous-element
2325 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2326 ;; Find previous element in parsed affiliated keywords.
2329 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2331 (org-export-get-previous-element
2332 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2333 ;; With optional argument N, return a list containing up to
2334 ;; N previous elements.
2336 (equal '(bold italic underline
)
2337 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2339 (org-export-get-previous-element
2340 (org-element-map tree
'code
'identity info t
) info t
)))))
2341 ;; When N is a positive integer, return a list containing up to
2342 ;; N previous elements.
2344 (equal '(bold italic
)
2345 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2347 (org-export-get-previous-element
2348 (org-element-map tree
'code
'identity info t
) info
2))))))
2352 ;;; test-org-export.el end here