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.
488 (org-test-with-temp-text
490 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
492 (org-export-expand-include-keyword)
493 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
494 ;; Inclusion within an example block.
495 (org-test-with-temp-text
496 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
498 (org-export-expand-include-keyword)
502 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
503 ;; Inclusion within a src-block.
504 (org-test-with-temp-text
506 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
508 (org-export-expand-include-keyword)
509 (should (equal (buffer-string)
510 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
512 (ert-deftest test-org-export
/expand-macro
()
513 "Test macro expansion in an Org buffer."
514 ;; Standard macro expansion.
516 (equal "#+MACRO: macro1 value\nvalue\n"
517 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
518 (org-test-with-backend test
(org-export-as 'test
)))))
519 ;; Expand specific macros.
521 (equal "me 2012-03-29 me@here Title\n"
522 (org-test-with-temp-text
528 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
529 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
530 (substring output
(string-match ".*\n\\'" output
))))))
531 ;; Expand specific macros when property contained a regular macro
535 (org-test-with-temp-text "
536 #+MACRO: macro1 value
537 #+TITLE: {{{macro1}}}
539 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
540 (substring output
(string-match ".*\n\\'" output
))))))
541 ;; Expand macros with templates in included files.
544 (org-test-with-temp-text
545 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
546 {{{included-macro}}}" org-test-dir
)
547 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
548 (substring output
(string-match ".*\n\\'" output
)))))))
550 (ert-deftest test-org-export
/user-ignore-list
()
551 "Test if `:ignore-list' accepts user input."
552 (org-test-with-backend test
553 (flet ((skip-note-head
555 ;; Ignore headlines with the word "note" in their title.
559 (when (string-match "\\<note\\>"
560 (org-element-property :raw-value headline
))
561 (org-export-ignore-element headline info
)))
564 ;; Install function in parse tree filters.
565 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
566 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
567 (should (equal (org-export-as 'test
) "* Head1\n")))))))
569 (ert-deftest test-org-export
/before-processing-hook
()
570 "Test `org-export-before-processing-hook'."
573 "#+MACRO: mac val\nTest\n"
574 (org-test-with-backend test
575 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
576 (let ((org-export-before-processing-hook
578 (while (re-search-forward "{{{" nil t
)
579 (let ((object (org-element-context)))
580 (when (eq (org-element-type object
) 'macro
)
582 (org-element-property :begin object
)
583 (org-element-property :end object
)))))))))
584 (org-export-as 'test
)))))))
586 (ert-deftest test-org-export
/before-parsing-hook
()
587 "Test `org-export-before-parsing-hook'."
589 (equal "Body 1\nBody 2\n"
590 (org-test-with-backend test
591 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
592 (let ((org-export-before-parsing-hook
594 (goto-char (point-min))
595 (while (re-search-forward org-outline-regexp-bol nil t
)
597 (point-at-bol) (progn (forward-line) (point))))))))
598 (org-export-as 'test
)))))))
602 ;;; Affiliated Keywords
604 (ert-deftest test-org-export
/read-attribute
()
605 "Test `org-export-read-attribute' specifications."
609 (org-export-read-attribute
611 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
612 (org-element-at-point)))
614 ;; Return nil on empty attribute.
616 (org-export-read-attribute
618 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
620 (ert-deftest test-org-export
/get-caption
()
621 "Test `org-export-get-caption' specifications."
622 ;; Without optional argument, return long caption
626 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
627 (org-export-get-caption (org-element-at-point)))))
628 ;; With optional argument, return short caption.
632 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
633 (org-export-get-caption (org-element-at-point) t
))))
634 ;; Multiple lines are separated by white spaces.
638 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
639 (org-export-get-caption (org-element-at-point))))))
645 (ert-deftest test-org-export
/define-backend
()
646 "Test back-end definition and accessors."
649 (equal '((headline . my-headline-test
))
650 (let (org-export-registered-backends)
651 (org-export-define-backend test
((headline . my-headline-test
)))
652 (org-export-backend-translate-table 'test
))))
655 (equal '((:filter-headline . my-filter
))
656 (let (org-export-registered-backends)
657 (org-export-define-backend test
658 ((headline . my-headline-test
))
659 :filters-alist
((:filter-headline . my-filter
)))
660 (org-export-backend-filters 'test
))))
663 (equal '((:prop value
))
664 (let (org-export-registered-backends)
665 (org-export-define-backend test
666 ((headline . my-headline-test
))
667 :options-alist
((:prop value
)))
668 (org-export-backend-options 'test
))))
671 (equal '(?k
"Test Export" test
)
672 (let (org-export-registered-backends)
673 (org-export-define-backend test
674 ((headline . my-headline-test
))
675 :menu-entry
(?k
"Test Export" test
))
676 (org-export-backend-menu 'test
))))
679 (equal '(("TEST" . org-element-export-block-parser
))
680 (let (org-export-registered-backends org-element-block-name-alist
)
681 (org-export-define-backend test
682 ((headline . my-headline-test
))
683 :export-block
("test"))
684 org-element-block-name-alist
))))
686 (ert-deftest test-org-export
/define-derived-backend
()
687 "Test `org-export-define-derived-backend' specifications."
688 ;; Error when parent back-end is not defined.
690 (let (org-export-registered-backends)
691 (org-export-define-derived-backend test parent
)))
692 ;; Append translation table to parent's.
694 (equal '((:headline . test
) (:headline . parent
))
695 (let (org-export-registered-backends)
696 (org-export-define-backend parent
((:headline . parent
)))
697 (org-export-define-derived-backend test parent
698 :translate-alist
((:headline . test
)))
699 (org-export-backend-translate-table 'test
))))
700 ;; Options defined in the new back have priority over those defined
704 (let (org-export-registered-backends)
705 (org-export-define-backend parent
706 ((:headline . parent
))
707 :options-alist
((:a nil nil
'parent
)))
708 (org-export-define-derived-backend test parent
709 :options-alist
((:a nil nil
'test
)))
710 (plist-get (org-export--get-global-options 'test
) :a
)))))
712 (ert-deftest test-org-export
/derived-backend-p
()
713 "Test `org-export-derived-backend-p' specifications."
714 ;; Non-nil with direct match.
716 (let (org-export-registered-backends)
717 (org-export-define-backend test
((headline . test
)))
718 (org-export-derived-backend-p 'test
'test
)))
720 (let (org-export-registered-backends)
721 (org-export-define-backend test
((headline . test
)))
722 (org-export-define-derived-backend test2 test
)
723 (org-export-derived-backend-p 'test2
'test2
)))
724 ;; Non-nil with a direct parent.
726 (let (org-export-registered-backends)
727 (org-export-define-backend test
((headline . test
)))
728 (org-export-define-derived-backend test2 test
)
729 (org-export-derived-backend-p 'test2
'test
)))
730 ;; Non-nil with an indirect parent.
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-define-derived-backend test3 test2
)
736 (org-export-derived-backend-p 'test3
'test
)))
739 (let (org-export-registered-backends)
740 (org-export-define-backend test
((headline . test
)))
741 (org-export-define-backend test2
((headline . test2
)))
742 (org-export-derived-backend-p 'test2
'test
)))
744 (let (org-export-registered-backends)
745 (org-export-define-backend test
((headline . test
)))
746 (org-export-define-backend test2
((headline . test2
)))
747 (org-export-define-derived-backend test3 test2
)
748 (org-export-derived-backend-p 'test3
'test
))))
750 (ert-deftest test-org-export
/with-backend
()
751 "Test `org-export-with-backend' definition."
752 ;; Error when calling an undefined back-end
754 (let (org-export-registered-backends)
755 (org-export-with-backend 'test
"Test")))
756 ;; Error when called back-end doesn't have an appropriate
759 (let (org-export-registered-backends)
760 (org-export-define-backend test
((headline . ignore
)))
761 (org-export-with-backend 'test
"Test")))
762 ;; Otherwise, export using correct transcoder
765 (let (org-export-registered-backends)
766 (org-export-define-backend test
767 ((plain-text .
(lambda (text contents info
) "Failure"))))
768 (org-export-define-backend test2
769 ((plain-text .
(lambda (text contents info
) "Success"))))
770 (org-export-with-backend 'test2
"Test")))))
772 (ert-deftest test-org-export
/data-with-translations
()
773 "Test `org-export-data-with-translations' specifications."
777 (org-export-data-with-translations
779 '((plain-text .
(lambda (text info
) "Success"))
780 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
781 '(:with-emphasize t
)))))
783 (ert-deftest test-org-export
/data-with-backend
()
784 "Test `org-export-data-with-backend' specifications."
785 ;; Error when calling an undefined back-end.
787 (let (org-export-registered-backends)
788 (org-export-data-with-backend 'test
"Test" nil
)))
789 ;; Otherwise, export data recursively, using correct back-end.
793 (let (org-export-registered-backends)
794 (org-export-define-backend test
795 ((plain-text .
(lambda (text info
) "Success"))
796 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
797 (org-export-data-with-backend
798 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
804 (ert-deftest test-org-export
/export-snippet
()
805 "Test export snippets transcoding."
806 (org-test-with-temp-text "@@test:A@@@@t:B@@"
807 (org-test-with-backend test
809 (cdr (assq 'test org-export-registered-backends
))
811 (cons (cons 'export-snippet
812 (lambda (snippet contents info
)
813 (when (eq (org-export-snippet-backend snippet
) 'test
)
814 (org-element-property :value snippet
))))
815 (org-export-backend-translate-table 'test
)))
816 (let ((org-export-snippet-translation-alist nil
))
817 (should (equal (org-export-as 'test
) "A\n")))
818 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
819 (should (equal (org-export-as 'test
) "AB\n"))))))
825 (ert-deftest test-org-export
/footnotes
()
826 "Test footnotes specifications."
827 (let ((org-footnote-section nil
)
828 (org-export-with-footnotes t
))
829 ;; 1. Read every type of footnote.
832 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
833 (org-test-with-parsed-data
834 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
836 tree
'footnote-reference
838 (let ((def (org-export-get-footnote-definition ref info
)))
839 (cons (org-export-get-footnote-number ref info
)
840 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
841 (car (org-element-contents
842 (car (org-element-contents def
))))))))
844 ;; 2. Test nested footnotes order.
845 (org-test-with-parsed-data
846 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
849 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
851 tree
'footnote-reference
853 (when (org-export-footnote-first-reference-p ref info
)
854 (cons (org-export-get-footnote-number ref info
)
855 (org-element-property :label ref
))))
857 ;; 3. Test nested footnote in invisible definitions.
858 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
860 (narrow-to-region (point) (point-at-eol))
861 (let* ((tree (org-element-parse-buffer))
862 (info (org-combine-plists
864 (org-export-collect-tree-properties
865 tree
(org-export-get-environment)))))
866 ;; Both footnotes should be seen.
868 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
869 ;; 4. Test footnotes definitions collection.
870 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
872 \[fn:2] B [fn:3] [fn::D].
875 (should (= (length (org-export-collect-footnote-definitions tree info
))
877 ;; 5. Test export of footnotes defined outside parsing scope.
878 (org-test-with-temp-text "[fn:1] Out of scope
881 (org-test-with-backend test
883 (cdr (assq 'test org-export-registered-backends
))
885 (cons (cons 'footnote-reference
886 (lambda (fn contents info
)
887 (org-element-interpret-data
888 (org-export-get-footnote-definition fn info
))))
889 (org-export-backend-translate-table 'test
)))
891 (should (equal "ParagraphOut of scope\n"
892 (org-export-as 'test
'subtree
)))))
893 ;; 6. Footnotes without a definition should be provided a fallback
896 (org-test-with-parsed-data "[fn:1]"
897 (org-export-get-footnote-definition
898 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
899 ;; 7. Footnote section should be ignored in TOC and in headlines
902 (= 1 (let ((org-footnote-section "Footnotes"))
903 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
904 (org-export-collect-headlines info
))))))
907 (let ((org-footnote-section "Footnotes"))
908 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
909 (org-element-map tree
'headline
911 (when (equal (org-element-property :raw-value hl
) "H2")
912 (org-export-get-headline-number hl info
)))
917 ;;; Headlines and Inlinetasks
919 (ert-deftest test-org-export
/get-relative-level
()
920 "Test `org-export-get-relative-level' specifications."
924 (let ((org-odd-levels-only nil
))
925 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
928 (lambda (h) (org-export-get-relative-level h info
))
933 (let ((org-odd-levels-only nil
))
934 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
937 (lambda (h) (org-export-get-relative-level h info
))
940 (ert-deftest test-org-export
/low-level-p
()
941 "Test `org-export-low-level-p' specifications."
945 (let ((org-odd-levels-only nil
))
946 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
949 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
950 (plist-put info
:headline-levels
1)))))))
952 (ert-deftest test-org-export
/get-headline-number
()
953 "Test `org-export-get-headline-number' specifications."
958 (let ((org-odd-levels-only nil
))
959 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
962 (lambda (h) (org-export-get-headline-number h info
))
964 ;; Missing levels are replaced with 0.
968 (let ((org-odd-levels-only nil
))
969 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
972 (lambda (h) (org-export-get-headline-number h info
))
975 (ert-deftest test-org-export
/numbered-headline-p
()
976 "Test `org-export-numbered-headline-p' specifications."
977 ;; If `:section-numbers' is nil, never number headlines.
979 (org-test-with-parsed-data "* Headline"
982 (lambda (h) (org-export-numbered-headline-p h info
))
983 (plist-put info
:section-numbers nil
))))
984 ;; If `:section-numbers' is a number, only number headlines with
985 ;; a level greater that it.
989 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
992 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
993 (plist-put info
:section-numbers
1)))))
994 ;; Otherwise, headlines are always numbered.
996 (org-test-with-parsed-data "* Headline"
999 (lambda (h) (org-export-numbered-headline-p h info
))
1000 (plist-put info
:section-numbers t
)))))
1002 (ert-deftest test-org-export
/number-to-roman
()
1003 "Test `org-export-number-to-roman' specifications."
1004 ;; If number is negative, return it as a string.
1005 (should (equal (org-export-number-to-roman -
1) "-1"))
1006 ;; Otherwise, return it as a roman number.
1007 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1009 (ert-deftest test-org-export
/get-tags
()
1010 "Test `org-export-get-tags' specifications."
1011 (let ((org-export-exclude-tags '("noexport"))
1012 (org-export-select-tags '("export")))
1013 ;; Standard test: tags which are not a select tag, an exclude tag,
1014 ;; or specified as optional argument shouldn't be ignored.
1016 (org-test-with-parsed-data "* Headline :tag:"
1017 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1019 ;; Exclude tags are removed.
1021 (org-test-with-parsed-data "* Headline :noexport:"
1022 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1024 ;; Select tags are removed.
1026 (org-test-with-parsed-data "* Headline :export:"
1027 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1032 (org-test-with-parsed-data "* Headline :tag:export:"
1033 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1035 ;; Tags provided in the optional argument are also ignored.
1037 (org-test-with-parsed-data "* Headline :ignore:"
1038 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1040 ;; Allow tag inheritance.
1044 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1047 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1048 ;; Tag inheritance checks FILETAGS keywords.
1052 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1055 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1057 (ert-deftest test-org-export
/get-node-property
()
1058 "Test`org-export-get-node-property' specifications."
1062 (org-test-with-parsed-data "* Headline
1066 (org-export-get-node-property
1067 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1068 ;; Test inheritance.
1071 (org-test-with-parsed-data "* Parent
1077 (org-export-get-node-property
1078 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1079 ;; Cannot return a value before the first headline.
1081 (org-test-with-parsed-data "Paragraph
1086 (org-export-get-node-property
1087 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1089 (ert-deftest test-org-export
/get-category
()
1090 "Test `org-export-get-category' specifications."
1094 (org-test-with-parsed-data "* Headline
1098 (org-export-get-category
1099 (org-element-map tree
'headline
'identity nil t
) info
))))
1100 ;; Test inheritance from a parent headline.
1102 (equal '("value" "value")
1103 (org-test-with-parsed-data "* Headline1
1110 (lambda (hl) (org-export-get-category hl info
)) info
))))
1111 ;; Test inheritance from #+CATEGORY keyword
1114 (org-test-with-parsed-data "#+CATEGORY: value
1116 (org-export-get-category
1117 (org-element-map tree
'headline
'identity nil t
) info
))))
1118 ;; Test inheritance from file name.
1121 (org-test-with-parsed-data "* Headline"
1122 (let ((info (plist-put info
:input-file
"~/test.org")))
1123 (org-export-get-category
1124 (org-element-map tree
'headline
'identity nil t
) info
)))))
1128 (org-test-with-parsed-data "* Headline"
1129 (org-export-get-category
1130 (org-element-map tree
'headline
'identity nil t
) info
)))))
1132 (ert-deftest test-org-export
/first-sibling-p
()
1133 "Test `org-export-first-sibling-p' specifications."
1138 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1141 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1143 ;; Ignore headlines not exported.
1147 (let ((org-export-exclude-tags '("ignore")))
1148 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1151 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1154 (ert-deftest test-org-export
/last-sibling-p
()
1155 "Test `org-export-last-sibling-p' specifications."
1160 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1163 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1165 ;; Ignore headlines not exported.
1169 (let ((org-export-exclude-tags '("ignore")))
1170 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1173 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1180 (ert-deftest test-org-export
/get-coderef-format
()
1181 "Test `org-export-get-coderef-format' specifications."
1182 ;; A link without description returns "%s"
1183 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1185 ;; Return "%s" when path is matched within description.
1186 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1188 ;; Otherwise return description.
1189 (should (equal (org-export-get-coderef-format "path" "desc")
1192 (ert-deftest test-org-export
/inline-image-p
()
1193 "Test `org-export-inline-image-p' specifications."
1195 (org-export-inline-image-p
1196 (org-test-with-temp-text "[[#id]]"
1198 (org-element-parse-buffer) 'link
'identity nil t
))
1199 '(("custom-id" .
"id")))))
1201 (ert-deftest test-org-export
/fuzzy-link
()
1202 "Test fuzzy links specifications."
1203 ;; 1. Links to invisible (keyword) targets should be ignored.
1204 (org-test-with-parsed-data
1205 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1210 (org-export-get-ordinal
1211 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1212 ;; 2. Link to an headline should return headline's number.
1213 (org-test-with-parsed-data
1214 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1216 ;; Note: Headline's number is in fact a list of numbers.
1221 (org-export-get-ordinal
1222 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1223 ;; 3. Link to a target in an item should return item's number.
1224 (org-test-with-parsed-data
1225 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1227 ;; Note: Item's number is in fact a list of numbers.
1232 (org-export-get-ordinal
1233 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1234 ;; 4. Link to a target in a footnote should return footnote's
1236 (org-test-with-parsed-data "
1237 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1243 (org-export-get-ordinal
1244 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1245 ;; 5. Link to a named element should return sequence number of that
1247 (org-test-with-parsed-data
1248 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1254 (org-export-get-ordinal
1255 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1256 ;; 6. Link to a target not within an item, a table, a footnote
1257 ;; reference or definition should return section number.
1258 (org-test-with-parsed-data
1259 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1265 (org-export-get-ordinal
1266 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1267 ;; 7. Space are not significant when matching a fuzzy link.
1269 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1270 (org-element-map tree
'link
1271 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1273 ;; 8. Statistics cookies are ignored for headline match.
1275 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1276 (org-element-map tree
'link
1277 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1280 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1281 (org-element-map tree
'link
1282 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1285 (ert-deftest test-org-export
/resolve-coderef
()
1286 "Test `org-export-resolve-coderef' specifications."
1287 (let ((org-coderef-label-format "(ref:%s)"))
1288 ;; 1. A link to a "-n -k -r" block returns line number.
1289 (org-test-with-parsed-data
1290 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1291 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1292 (org-test-with-parsed-data
1293 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1294 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1295 ;; 2. A link to a "-n -r" block returns line number.
1296 (org-test-with-parsed-data
1297 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1298 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1299 (org-test-with-parsed-data
1300 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1301 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1302 ;; 3. A link to a "-n" block returns coderef.
1303 (org-test-with-parsed-data
1304 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1305 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1306 (org-test-with-parsed-data
1307 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1308 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1309 ;; 4. A link to a "-r" block returns line number.
1310 (org-test-with-parsed-data
1311 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1312 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1313 (org-test-with-parsed-data
1314 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1315 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1316 ;; 5. A link to a block without a switch returns coderef.
1317 (org-test-with-parsed-data
1318 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1319 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1320 (org-test-with-parsed-data
1321 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1322 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1323 ;; 6. Correctly handle continued line numbers. A "+n" switch
1324 ;; should resume numbering from previous block with numbered
1325 ;; lines, ignoring blocks not numbering lines in the process.
1326 ;; A "-n" switch resets count.
1327 (org-test-with-parsed-data "
1332 #+BEGIN_SRC emacs-lisp
1336 #+BEGIN_SRC emacs-lisp +n -r
1337 \(+ 1 1) (ref:addition)
1340 #+BEGIN_EXAMPLE -n -r
1341 Another text. (ref:text)
1343 (should (= (org-export-resolve-coderef "addition" info
) 2))
1344 (should (= (org-export-resolve-coderef "text" info
) 1)))
1345 ;; 7. Recognize coderef with user-specified syntax.
1346 (org-test-with-parsed-data
1347 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1348 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1350 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1351 "Test `org-export-resolve-fuzzy-link' specifications."
1352 ;; 1. Match target objects.
1353 (org-test-with-parsed-data "<<target>> [[target]]"
1355 (org-export-resolve-fuzzy-link
1356 (org-element-map tree
'link
'identity info t
) info
)))
1357 ;; 2. Match target elements.
1358 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1360 (org-export-resolve-fuzzy-link
1361 (org-element-map tree
'link
'identity info t
) info
)))
1362 ;; 3. Match named elements.
1363 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1365 (org-export-resolve-fuzzy-link
1366 (org-element-map tree
'link
'identity info t
) info
)))
1367 ;; 4. Match exact headline's name.
1368 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1370 (org-export-resolve-fuzzy-link
1371 (org-element-map tree
'link
'identity info t
) info
)))
1372 ;; 5. Targets objects have priority over named elements and headline
1374 (org-test-with-parsed-data
1375 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1379 (org-export-resolve-fuzzy-link
1380 (org-element-map tree
'link
'identity info t
) info
)))))
1381 ;; 6. Named elements have priority over headline titles.
1382 (org-test-with-parsed-data
1383 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1387 (org-export-resolve-fuzzy-link
1388 (org-element-map tree
'link
'identity info t
) info
)))))
1389 ;; 7. If link's path starts with a "*", only match headline titles,
1391 (org-test-with-parsed-data
1392 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1396 (org-export-resolve-fuzzy-link
1397 (org-element-map tree
'link
'identity info t
) info
)))))
1398 ;; 8. Return nil if no match.
1399 (org-test-with-parsed-data "[[target]]"
1401 (org-export-resolve-fuzzy-link
1402 (org-element-map tree
'link
'identity info t
) info
))))
1404 (ert-deftest test-org-export
/resolve-id-link
()
1405 "Test `org-export-resolve-id-link' specifications."
1406 ;; 1. Regular test for custom-id link.
1407 (org-test-with-parsed-data "* Headline1
1414 (org-export-resolve-id-link
1415 (org-element-map tree
'link
'identity info t
) info
)))
1416 ;; 2. Failing test for custom-id link.
1417 (org-test-with-parsed-data "* Headline1
1424 (org-export-resolve-id-link
1425 (org-element-map tree
'link
'identity info t
) info
)))
1426 ;; 3. Test for internal id target.
1427 (org-test-with-parsed-data "* Headline1
1434 (org-export-resolve-id-link
1435 (org-element-map tree
'link
'identity info t
) info
)))
1436 ;; 4. Test for external id target.
1437 (org-test-with-parsed-data "[[id:aaaa]]"
1439 (org-export-resolve-id-link
1440 (org-element-map tree
'link
'identity info t
)
1441 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1443 (ert-deftest test-org-export
/resolve-radio-link
()
1444 "Test `org-export-resolve-radio-link' specifications."
1447 (org-test-with-temp-text "<<<radio>>> radio"
1448 (org-update-radio-target-regexp)
1449 (let* ((tree (org-element-parse-buffer))
1450 (info `(:parse-tree
,tree
)))
1451 (org-export-resolve-radio-link
1452 (org-element-map tree
'link
'identity info t
)
1454 ;; Radio targets are case-insensitive.
1456 (org-test-with-temp-text "<<<RADIO>>> radio"
1457 (org-update-radio-target-regexp)
1458 (let* ((tree (org-element-parse-buffer))
1459 (info `(:parse-tree
,tree
)))
1460 (org-export-resolve-radio-link
1461 (org-element-map tree
'link
'identity info t
)
1463 ;; Radio target with objects.
1465 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1466 (org-update-radio-target-regexp)
1467 (let* ((tree (org-element-parse-buffer))
1468 (info `(:parse-tree
,tree
)))
1469 (org-export-resolve-radio-link
1470 (org-element-map tree
'link
'identity info t
)
1475 ;;; Src-block and example-block
1477 (ert-deftest test-org-export
/unravel-code
()
1478 "Test `org-export-unravel-code' function."
1479 (let ((org-coderef-label-format "(ref:%s)"))
1480 ;; 1. Code without reference.
1481 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1482 (should (equal (org-export-unravel-code (org-element-at-point))
1484 ;; 2. Code with reference.
1485 (org-test-with-temp-text
1486 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1487 (should (equal (org-export-unravel-code (org-element-at-point))
1488 '("(+ 1 1)\n" (1 .
"test")))))
1489 ;; 3. Code with user-defined reference.
1490 (org-test-with-temp-text
1491 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1492 (should (equal (org-export-unravel-code (org-element-at-point))
1493 '("(+ 1 1)\n" (1 .
"test")))))
1494 ;; 4. Code references keys are relative to the current block.
1495 (org-test-with-temp-text "
1504 (should (equal (org-export-unravel-code (org-element-at-point))
1505 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1511 (ert-deftest test-org-export
/activate-smart-quotes
()
1512 "Test `org-export-activate-smart-quotes' specifications."
1513 ;; Opening double quotes: standard test.
1516 '("some “paragraph")
1517 (let ((org-export-default-language "en"))
1518 (org-test-with-parsed-data "some \"paragraph"
1521 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1523 ;; Opening quotes: at the beginning of a paragraph.
1527 (let ((org-export-default-language "en"))
1528 (org-test-with-parsed-data "\"begin"
1531 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1533 ;; Opening quotes: after an object.
1537 (let ((org-export-default-language "en"))
1538 (org-test-with-parsed-data "=verb= \"begin"
1541 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1543 ;; Closing quotes: standard test.
1546 '("some” paragraph")
1547 (let ((org-export-default-language "en"))
1548 (org-test-with-parsed-data "some\" paragraph"
1551 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1553 ;; Closing quotes: at the end of a paragraph.
1557 (let ((org-export-default-language "en"))
1558 (org-test-with-parsed-data "end\""
1561 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1563 ;; Apostrophe: standard test.
1566 '("It shouldn’t fail")
1567 (let ((org-export-default-language "en"))
1568 (org-test-with-parsed-data "It shouldn't fail"
1571 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1573 ;; Apostrophe: before an object.
1577 (let ((org-export-default-language "en"))
1578 (org-test-with-parsed-data "a'=b="
1581 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1583 ;; Apostrophe: after an object.
1587 (let ((org-export-default-language "en"))
1588 (org-test-with-parsed-data "=code='s"
1591 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1593 ;; Special case: isolated quotes.
1595 (equal '("“" "”")
1596 (let ((org-export-default-language "en"))
1597 (org-test-with-parsed-data "\"$x$\""
1600 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1602 ;; Smart quotes in secondary strings.
1604 (equal '("“" "”")
1605 (let ((org-export-default-language "en"))
1606 (org-test-with-parsed-data "* \"$x$\""
1609 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1611 ;; Smart quotes in document keywords.
1613 (equal '("“" "”")
1614 (let ((org-export-default-language "en"))
1615 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1617 (plist-get info
:title
) 'plain-text
1618 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1620 ;; Smart quotes in parsed affiliated keywords.
1622 (equal '("“" "”" "Paragraph")
1623 (let ((org-export-default-language "en"))
1624 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1627 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1628 info nil nil t
))))))
1634 (ert-deftest test-org-export
/special-column
()
1635 "Test if the table's special column is properly recognized."
1636 ;; 1. First column is special if it contains only a special marking
1637 ;; characters or empty cells.
1638 (org-test-with-temp-text "
1642 (org-export-table-has-special-column-p
1644 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1645 ;; 2. If the column contains anything else, it isn't special.
1646 (org-test-with-temp-text "
1650 (org-export-table-has-special-column-p
1652 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1653 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1655 (org-test-with-temp-text "
1664 (org-export-table-has-special-column-p
1666 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1667 ;; 4. A first column with only empty cells isn't considered as
1669 (org-test-with-temp-text "
1673 (org-export-table-has-special-column-p
1675 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1677 (ert-deftest test-org-export
/table-row-is-special-p
()
1678 "Test `org-export-table-row-is-special-p' specifications."
1679 ;; 1. A row is special if it has a special marking character in the
1681 (org-test-with-parsed-data "| ! | 1 |"
1683 (org-export-table-row-is-special-p
1684 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1685 ;; 2. A row is special when its first field is "/"
1686 (org-test-with-parsed-data "
1690 (org-export-table-row-is-special-p
1691 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1692 ;; 3. A row only containing alignment cookies is also considered as
1694 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1696 (org-export-table-row-is-special-p
1697 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1698 ;; 4. Everything else isn't considered as special.
1699 (org-test-with-parsed-data "| \alpha | | c |"
1701 (org-export-table-row-is-special-p
1702 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1703 ;; 5. Table's rules are never considered as special rows.
1704 (org-test-with-parsed-data "|---+---|"
1706 (org-export-table-row-is-special-p
1707 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1709 (ert-deftest test-org-export
/has-header-p
()
1710 "Test `org-export-table-has-header-p' specifications."
1711 ;; 1. With an header.
1712 (org-test-with-parsed-data "
1717 (org-export-table-has-header-p
1718 (org-element-map tree
'table
'identity info
'first-match
)
1720 ;; 2. Without an header.
1721 (org-test-with-parsed-data "
1725 (org-export-table-has-header-p
1726 (org-element-map tree
'table
'identity info
'first-match
)
1728 ;; 3. Don't get fooled with starting and ending rules.
1729 (org-test-with-parsed-data "
1735 (org-export-table-has-header-p
1736 (org-element-map tree
'table
'identity info
'first-match
)
1739 (ert-deftest test-org-export
/table-row-group
()
1740 "Test `org-export-table-row-group' specifications."
1741 ;; 1. A rule creates a new group.
1742 (org-test-with-parsed-data "
1749 (mapcar (lambda (row) (org-export-table-row-group row info
))
1750 (org-element-map tree
'table-row
'identity
)))))
1751 ;; 2. Special rows are ignored in count.
1752 (org-test-with-parsed-data "
1759 (mapcar (lambda (row) (org-export-table-row-group row info
))
1760 (org-element-map tree
'table-row
'identity
)))))
1761 ;; 3. Double rules also are ignored in count.
1762 (org-test-with-parsed-data "
1770 (mapcar (lambda (row) (org-export-table-row-group row info
))
1771 (org-element-map tree
'table-row
'identity
))))))
1773 (ert-deftest test-org-export
/table-cell-width
()
1774 "Test `org-export-table-cell-width' specifications."
1775 ;; 1. Width is primarily determined by width cookies. If no cookie
1776 ;; is found, cell's width is nil.
1777 (org-test-with-parsed-data "
1778 | / | <l> | <6> | <l7> |
1783 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1784 (org-element-map tree
'table-cell
'identity info
)))))
1785 ;; 2. The last width cookie has precedence.
1786 (org-test-with-parsed-data "
1793 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1794 (org-element-map tree
'table-cell
'identity info
)))))
1795 ;; 3. Valid width cookies must have a specific row.
1796 (org-test-with-parsed-data "| <6> | cell |"
1800 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1801 (org-element-map tree
'table-cell
'identity
))))))
1803 (ert-deftest test-org-export
/table-cell-alignment
()
1804 "Test `org-export-table-cell-alignment' specifications."
1805 (let ((org-table-number-fraction 0.5)
1806 (org-table-number-regexp "^[0-9]+$"))
1807 ;; 1. Alignment is primarily determined by alignment cookies.
1808 (org-test-with-temp-text "| <l> | <c> | <r> |"
1809 (let* ((tree (org-element-parse-buffer))
1810 (info `(:parse-tree
,tree
)))
1813 '(left center right
)
1814 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1815 (org-element-map tree
'table-cell
'identity
))))))
1816 ;; 2. The last alignment cookie has precedence.
1817 (org-test-with-parsed-data "
1823 '(right right right
)
1824 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1825 (org-element-map tree
'table-cell
'identity
)))))
1826 ;; 3. If there's no cookie, cell's contents determine alignment.
1827 ;; A column mostly made of cells containing numbers will align
1828 ;; its cells to the right.
1829 (org-test-with-parsed-data "
1835 '(right right right
)
1836 (mapcar (lambda (cell)
1837 (org-export-table-cell-alignment cell info
))
1838 (org-element-map tree
'table-cell
'identity
)))))
1839 ;; 4. Otherwise, they will be aligned to the left.
1840 (org-test-with-parsed-data "
1847 (mapcar (lambda (cell)
1848 (org-export-table-cell-alignment cell info
))
1849 (org-element-map tree
'table-cell
'identity
)))))))
1851 (ert-deftest test-org-export
/table-cell-borders
()
1852 "Test `org-export-table-cell-borders' specifications."
1853 ;; 1. Recognize various column groups indicators.
1854 (org-test-with-parsed-data "| / | < | > | <> |"
1857 '((right bottom top
) (left bottom top
) (right bottom top
)
1858 (right left bottom top
))
1859 (mapcar (lambda (cell)
1860 (org-export-table-cell-borders cell info
))
1861 (org-element-map tree
'table-cell
'identity
)))))
1862 ;; 2. Accept shortcuts to define column groups.
1863 (org-test-with-parsed-data "| / | < | < |"
1866 '((right bottom top
) (right left bottom top
) (left bottom top
))
1867 (mapcar (lambda (cell)
1868 (org-export-table-cell-borders cell info
))
1869 (org-element-map tree
'table-cell
'identity
)))))
1870 ;; 3. A valid column groups row must start with a "/".
1871 (org-test-with-parsed-data "
1875 (equal '((top) (top) (bottom) (bottom))
1876 (mapcar (lambda (cell)
1877 (org-export-table-cell-borders cell info
))
1878 (org-element-map tree
'table-cell
'identity
)))))
1879 ;; 4. Take table rules into consideration.
1880 (org-test-with-parsed-data "
1885 (equal '((below top
) (bottom above
))
1886 (mapcar (lambda (cell)
1887 (org-export-table-cell-borders cell info
))
1888 (org-element-map tree
'table-cell
'identity
)))))
1889 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1890 ;; (resp. `bottom' and `below') borders. Any special row is
1892 (org-test-with-parsed-data "
1898 (equal '((bottom below top above
))
1900 (mapcar (lambda (cell)
1901 (org-export-table-cell-borders cell info
))
1902 (org-element-map tree
'table-cell
'identity
)))))))
1904 (ert-deftest test-org-export
/table-dimensions
()
1905 "Test `org-export-table-dimensions' specifications."
1906 ;; 1. Standard test.
1907 (org-test-with-parsed-data "
1912 (org-export-table-dimensions
1913 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1914 ;; 2. Ignore horizontal rules and special columns.
1915 (org-test-with-parsed-data "
1922 (org-export-table-dimensions
1923 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1925 (ert-deftest test-org-export
/table-cell-address
()
1926 "Test `org-export-table-cell-address' specifications."
1927 ;; 1. Standard test: index is 0-based.
1928 (org-test-with-parsed-data "| a | b |"
1930 (equal '((0 .
0) (0 .
1))
1933 (lambda (cell) (org-export-table-cell-address cell info
))
1935 ;; 2. Special column isn't counted, nor are special rows.
1936 (org-test-with-parsed-data "
1941 (org-export-table-cell-address
1942 (car (last (org-element-map tree
'table-cell
'identity info
)))
1944 ;; 3. Tables rules do not count either.
1945 (org-test-with-parsed-data "
1953 (org-export-table-cell-address
1954 (car (last (org-element-map tree
'table-cell
'identity info
)))
1956 ;; 4. Return nil for special cells.
1957 (org-test-with-parsed-data "| / | a |"
1959 (org-export-table-cell-address
1960 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1963 (ert-deftest test-org-export
/get-table-cell-at
()
1964 "Test `org-export-get-table-cell-at' specifications."
1965 ;; 1. Address ignores special columns, special rows and rules.
1966 (org-test-with-parsed-data "
1973 (org-element-contents
1974 (org-export-get-table-cell-at
1976 (org-element-map tree
'table
'identity info
'first-match
)
1978 ;; 2. Return value for a non-existent address is nil.
1979 (org-test-with-parsed-data "| a |"
1981 (org-export-get-table-cell-at
1983 (org-element-map tree
'table
'identity info
'first-match
)
1985 (org-test-with-parsed-data "| / |"
1987 (org-export-get-table-cell-at
1989 (org-element-map tree
'table
'identity info
'first-match
)
1992 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1993 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1994 ;; 1. A cell at a beginning of a row always starts a column group.
1995 (org-test-with-parsed-data "| a |"
1997 (org-export-table-cell-starts-colgroup-p
1998 (org-element-map tree
'table-cell
'identity info
'first-match
)
2000 ;; 2. Special column should be ignored when determining the
2001 ;; beginning of the row.
2002 (org-test-with-parsed-data "
2006 (org-export-table-cell-starts-colgroup-p
2007 (org-element-map tree
'table-cell
'identity info
'first-match
)
2009 ;; 2. Explicit column groups.
2010 (org-test-with-parsed-data "
2019 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2022 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2023 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2024 ;; 1. A cell at the end of a row always ends a column group.
2025 (org-test-with-parsed-data "| a |"
2027 (org-export-table-cell-ends-colgroup-p
2028 (org-element-map tree
'table-cell
'identity info
'first-match
)
2030 ;; 2. Special column should be ignored when determining the
2031 ;; beginning of the row.
2032 (org-test-with-parsed-data "
2036 (org-export-table-cell-ends-colgroup-p
2037 (org-element-map tree
'table-cell
'identity info
'first-match
)
2039 ;; 3. Explicit column groups.
2040 (org-test-with-parsed-data "
2049 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2052 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2053 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2054 ;; 1. A row at the beginning of a table always starts a row group.
2055 ;; So does a row following a table rule.
2056 (org-test-with-parsed-data "
2066 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2068 ;; 2. Special rows should be ignored when determining the beginning
2070 (org-test-with-parsed-data "
2082 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2085 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2086 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2087 ;; 1. A row at the end of a table always ends a row group. So does
2088 ;; a row preceding a table rule.
2089 (org-test-with-parsed-data "
2099 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2101 ;; 2. Special rows should be ignored when determining the beginning
2103 (org-test-with-parsed-data "
2115 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2118 (ert-deftest test-org-export
/table-row-starts-header-p
()
2119 "Test `org-export-table-row-starts-header-p' specifications."
2120 ;; 1. Only the row starting the first row group starts the table
2122 (org-test-with-parsed-data "
2133 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2135 ;; 2. A row cannot start an header if there's no header in the
2137 (org-test-with-parsed-data "
2141 (org-export-table-row-starts-header-p
2142 (org-element-map tree
'table-row
'identity info
'first-match
)
2145 (ert-deftest test-org-export
/table-row-ends-header-p
()
2146 "Test `org-export-table-row-ends-header-p' specifications."
2147 ;; 1. Only the row starting the first row group starts the table
2149 (org-test-with-parsed-data "
2160 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2162 ;; 2. A row cannot start an header if there's no header in the
2164 (org-test-with-parsed-data "
2168 (org-export-table-row-ends-header-p
2169 (org-element-map tree
'table-row
'identity info
'first-match
)
2176 (ert-deftest test-org-export
/inner-template
()
2177 "Test `inner-template' translator specifications."
2180 (let (org-export-registered-backends)
2181 (org-export-define-backend test
2182 ((inner-template .
(lambda (contents info
) "Success!"))
2183 (headline .
(lambda (h c i
) "Headline"))))
2184 (org-test-with-temp-text "* Headline"
2185 (org-export-as 'test
)))))
2186 ;; Inner template is applied even in a "body-only" export.
2189 (let (org-export-registered-backends)
2190 (org-export-define-backend test
2191 ((inner-template .
(lambda (contents info
) "Success!"))
2192 (headline .
(lambda (h c i
) "Headline"))))
2193 (org-test-with-temp-text "* Headline"
2194 (org-export-as 'test nil nil
'body-only
))))))
2196 (ert-deftest test-org-export
/template
()
2197 "Test `template' translator specifications."
2200 (let (org-export-registered-backends)
2201 (org-export-define-backend test
2202 ((template .
(lambda (contents info
) "Success!"))
2203 (headline .
(lambda (h c i
) "Headline"))))
2204 (org-test-with-temp-text "* Headline"
2205 (org-export-as 'test
)))))
2206 ;; Template is not applied in a "body-only" export.
2209 (let (org-export-registered-backends)
2210 (org-export-define-backend test
2211 ((template .
(lambda (contents info
) "Success!"))
2212 (headline .
(lambda (h c i
) "Headline"))))
2213 (org-test-with-temp-text "* Headline"
2214 (org-export-as 'test nil nil
'body-only
))))))
2220 (ert-deftest test-org-export
/get-next-element
()
2221 "Test `org-export-get-next-element' specifications."
2225 (org-test-with-parsed-data "* Headline\n*a* b"
2226 (org-export-get-next-element
2227 (org-element-map tree
'bold
'identity info t
) info
))))
2228 ;; Return nil when no previous element.
2230 (org-test-with-parsed-data "* Headline\na *b*"
2231 (org-export-get-next-element
2232 (org-element-map tree
'bold
'identity info t
) info
)))
2233 ;; Non-exportable elements are ignored.
2235 (let ((org-export-with-timestamps nil
))
2236 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2237 (org-export-get-next-element
2238 (org-element-map tree
'entity
'identity info t
) info
))))
2239 ;; Find next element in secondary strings.
2242 (org-test-with-parsed-data "* a =verb="
2244 (org-export-get-next-element
2245 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2246 ;; Find next element in document keywords.
2249 (org-test-with-parsed-data "#+TITLE: a =verb="
2251 (org-export-get-next-element
2253 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2254 ;; Find next element in parsed affiliated keywords.
2257 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2259 (org-export-get-next-element
2260 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2261 ;; With optional argument N, return a list containing all the
2262 ;; following elements.
2265 '(bold code underline
)
2266 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2268 (org-export-get-next-element
2269 (org-element-map tree
'italic
'identity info t
) info t
)))))
2270 ;; When N is a positive integer, return a list containing up to
2271 ;; N following elements.
2275 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2277 (org-export-get-next-element
2278 (org-element-map tree
'italic
'identity info t
) info
2))))))
2280 (ert-deftest test-org-export
/get-previous-element
()
2281 "Test `org-export-get-previous-element' specifications."
2285 (org-test-with-parsed-data "* Headline\na *b*"
2286 (org-export-get-previous-element
2287 (org-element-map tree
'bold
'identity info t
) info
))))
2288 ;; Return nil when no previous element.
2290 (org-test-with-parsed-data "* Headline\n*a* b"
2291 (org-export-get-previous-element
2292 (org-element-map tree
'bold
'identity info t
) info
)))
2293 ;; Non-exportable elements are ignored.
2295 (let ((org-export-with-timestamps nil
))
2296 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2297 (org-export-get-previous-element
2298 (org-element-map tree
'entity
'identity info t
) info
))))
2299 ;; Find previous element in secondary strings.
2302 (org-test-with-parsed-data "* =verb= a"
2304 (org-export-get-previous-element
2305 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2306 ;; Find previous element in document keywords.
2309 (org-test-with-parsed-data "#+TITLE: =verb= a"
2311 (org-export-get-previous-element
2313 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2314 ;; Find previous element in parsed affiliated keywords.
2317 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2319 (org-export-get-previous-element
2320 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2321 ;; With optional argument N, return a list containing up to
2322 ;; N previous elements.
2324 (equal '(bold italic underline
)
2325 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2327 (org-export-get-previous-element
2328 (org-element-map tree
'code
'identity info t
) info t
)))))
2329 ;; When N is a positive integer, return a list containing up to
2330 ;; N previous elements.
2332 (equal '(bold italic
)
2333 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2335 (org-export-get-previous-element
2336 (org-element-map tree
'code
'identity info t
) info
2))))))
2340 ;;; test-org-export.el end here