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-optional-title
()
1022 "Test `org-export-get-optional-title' specifications."
1023 ;; If OPTIONAL_TITLE property is defined, use it.
1026 (org-test-with-parsed-data
1027 "* Headline\n:PROPERTIES:\n:OPTIONAL_TITLE: opt\n:END:"
1028 (org-export-get-optional-title
1029 (org-element-map tree
'headline
'identity info t
)
1031 ;; Otherwise, fall-back to regular title.
1033 (equal '("Headline")
1034 (org-test-with-parsed-data "* Headline"
1035 (org-export-get-optional-title
1036 (org-element-map tree
'headline
'identity info t
)
1039 (ert-deftest test-org-export
/get-tags
()
1040 "Test `org-export-get-tags' specifications."
1041 (let ((org-export-exclude-tags '("noexport"))
1042 (org-export-select-tags '("export")))
1043 ;; Standard test: tags which are not a select tag, an exclude tag,
1044 ;; or specified as optional argument shouldn't be ignored.
1046 (org-test-with-parsed-data "* Headline :tag:"
1047 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1049 ;; Exclude tags are removed.
1051 (org-test-with-parsed-data "* Headline :noexport:"
1052 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1054 ;; Select tags are removed.
1056 (org-test-with-parsed-data "* Headline :export:"
1057 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1062 (org-test-with-parsed-data "* Headline :tag:export:"
1063 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1065 ;; Tags provided in the optional argument are also ignored.
1067 (org-test-with-parsed-data "* Headline :ignore:"
1068 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1070 ;; Allow tag inheritance.
1074 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1077 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1078 ;; Tag inheritance checks FILETAGS keywords.
1082 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1085 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1087 (ert-deftest test-org-export
/get-node-property
()
1088 "Test`org-export-get-node-property' specifications."
1092 (org-test-with-parsed-data "* Headline
1096 (org-export-get-node-property
1097 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1098 ;; Test inheritance.
1101 (org-test-with-parsed-data "* Parent
1107 (org-export-get-node-property
1108 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1109 ;; Cannot return a value before the first headline.
1111 (org-test-with-parsed-data "Paragraph
1116 (org-export-get-node-property
1117 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1119 (ert-deftest test-org-export
/get-category
()
1120 "Test `org-export-get-category' specifications."
1124 (org-test-with-parsed-data "* Headline
1128 (org-export-get-category
1129 (org-element-map tree
'headline
'identity nil t
) info
))))
1130 ;; Test inheritance from a parent headline.
1132 (equal '("value" "value")
1133 (org-test-with-parsed-data "* Headline1
1140 (lambda (hl) (org-export-get-category hl info
)) info
))))
1141 ;; Test inheritance from #+CATEGORY keyword
1144 (org-test-with-parsed-data "#+CATEGORY: value
1146 (org-export-get-category
1147 (org-element-map tree
'headline
'identity nil t
) info
))))
1148 ;; Test inheritance from file name.
1151 (org-test-with-parsed-data "* Headline"
1152 (let ((info (plist-put info
:input-file
"~/test.org")))
1153 (org-export-get-category
1154 (org-element-map tree
'headline
'identity nil t
) info
)))))
1158 (org-test-with-parsed-data "* Headline"
1159 (org-export-get-category
1160 (org-element-map tree
'headline
'identity nil t
) info
)))))
1162 (ert-deftest test-org-export
/first-sibling-p
()
1163 "Test `org-export-first-sibling-p' specifications."
1168 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1171 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1173 ;; Ignore headlines not exported.
1177 (let ((org-export-exclude-tags '("ignore")))
1178 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1181 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1184 (ert-deftest test-org-export
/last-sibling-p
()
1185 "Test `org-export-last-sibling-p' specifications."
1190 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1193 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1195 ;; Ignore headlines not exported.
1199 (let ((org-export-exclude-tags '("ignore")))
1200 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1203 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1210 (ert-deftest test-org-export
/get-coderef-format
()
1211 "Test `org-export-get-coderef-format' specifications."
1212 ;; A link without description returns "%s"
1213 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1215 ;; Return "%s" when path is matched within description.
1216 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1218 ;; Otherwise return description.
1219 (should (equal (org-export-get-coderef-format "path" "desc")
1222 (ert-deftest test-org-export
/inline-image-p
()
1223 "Test `org-export-inline-image-p' specifications."
1225 (org-export-inline-image-p
1226 (org-test-with-temp-text "[[#id]]"
1228 (org-element-parse-buffer) 'link
'identity nil t
))
1229 '(("custom-id" .
"id")))))
1231 (ert-deftest test-org-export
/fuzzy-link
()
1232 "Test fuzzy links specifications."
1233 ;; 1. Links to invisible (keyword) targets should be ignored.
1234 (org-test-with-parsed-data
1235 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1240 (org-export-get-ordinal
1241 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1242 ;; 2. Link to an headline should return headline's number.
1243 (org-test-with-parsed-data
1244 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1246 ;; Note: Headline's number is in fact a list of numbers.
1251 (org-export-get-ordinal
1252 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1253 ;; 3. Link to a target in an item should return item's number.
1254 (org-test-with-parsed-data
1255 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1257 ;; Note: Item's number is in fact a list of numbers.
1262 (org-export-get-ordinal
1263 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1264 ;; 4. Link to a target in a footnote should return footnote's
1266 (org-test-with-parsed-data "
1267 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1273 (org-export-get-ordinal
1274 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1275 ;; 5. Link to a named element should return sequence number of that
1277 (org-test-with-parsed-data
1278 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1284 (org-export-get-ordinal
1285 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1286 ;; 6. Link to a target not within an item, a table, a footnote
1287 ;; reference or definition should return section number.
1288 (org-test-with-parsed-data
1289 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1295 (org-export-get-ordinal
1296 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1297 ;; 7. Space are not significant when matching a fuzzy link.
1299 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1300 (org-element-map tree
'link
1301 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1303 ;; 8. Statistics cookies are ignored for headline match.
1305 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1306 (org-element-map tree
'link
1307 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1310 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1311 (org-element-map tree
'link
1312 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1315 (ert-deftest test-org-export
/resolve-coderef
()
1316 "Test `org-export-resolve-coderef' specifications."
1317 (let ((org-coderef-label-format "(ref:%s)"))
1318 ;; 1. A link to a "-n -k -r" block returns line number.
1319 (org-test-with-parsed-data
1320 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1321 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1322 (org-test-with-parsed-data
1323 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1324 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1325 ;; 2. A link to a "-n -r" block returns line number.
1326 (org-test-with-parsed-data
1327 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1328 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1329 (org-test-with-parsed-data
1330 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1331 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1332 ;; 3. A link to a "-n" block returns coderef.
1333 (org-test-with-parsed-data
1334 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1335 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1336 (org-test-with-parsed-data
1337 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1338 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1339 ;; 4. A link to a "-r" block returns line number.
1340 (org-test-with-parsed-data
1341 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1342 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1343 (org-test-with-parsed-data
1344 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1345 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1346 ;; 5. A link to a block without a switch returns coderef.
1347 (org-test-with-parsed-data
1348 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1349 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1350 (org-test-with-parsed-data
1351 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1352 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1353 ;; 6. Correctly handle continued line numbers. A "+n" switch
1354 ;; should resume numbering from previous block with numbered
1355 ;; lines, ignoring blocks not numbering lines in the process.
1356 ;; A "-n" switch resets count.
1357 (org-test-with-parsed-data "
1362 #+BEGIN_SRC emacs-lisp
1366 #+BEGIN_SRC emacs-lisp +n -r
1367 \(+ 1 1) (ref:addition)
1370 #+BEGIN_EXAMPLE -n -r
1371 Another text. (ref:text)
1373 (should (= (org-export-resolve-coderef "addition" info
) 2))
1374 (should (= (org-export-resolve-coderef "text" info
) 1)))
1375 ;; 7. Recognize coderef with user-specified syntax.
1376 (org-test-with-parsed-data
1377 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1378 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1380 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1381 "Test `org-export-resolve-fuzzy-link' specifications."
1382 ;; 1. Match target objects.
1383 (org-test-with-parsed-data "<<target>> [[target]]"
1385 (org-export-resolve-fuzzy-link
1386 (org-element-map tree
'link
'identity info t
) info
)))
1387 ;; 2. Match target elements.
1388 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1390 (org-export-resolve-fuzzy-link
1391 (org-element-map tree
'link
'identity info t
) info
)))
1392 ;; 3. Match named elements.
1393 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1395 (org-export-resolve-fuzzy-link
1396 (org-element-map tree
'link
'identity info t
) info
)))
1397 ;; 4. Match exact headline's name.
1398 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1400 (org-export-resolve-fuzzy-link
1401 (org-element-map tree
'link
'identity info t
) info
)))
1402 ;; 5. Targets objects have priority over named elements and headline
1404 (org-test-with-parsed-data
1405 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1409 (org-export-resolve-fuzzy-link
1410 (org-element-map tree
'link
'identity info t
) info
)))))
1411 ;; 6. Named elements have priority over headline titles.
1412 (org-test-with-parsed-data
1413 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1417 (org-export-resolve-fuzzy-link
1418 (org-element-map tree
'link
'identity info t
) info
)))))
1419 ;; 7. If link's path starts with a "*", only match headline titles,
1421 (org-test-with-parsed-data
1422 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1426 (org-export-resolve-fuzzy-link
1427 (org-element-map tree
'link
'identity info t
) info
)))))
1428 ;; 8. Return nil if no match.
1429 (org-test-with-parsed-data "[[target]]"
1431 (org-export-resolve-fuzzy-link
1432 (org-element-map tree
'link
'identity info t
) info
))))
1434 (ert-deftest test-org-export
/resolve-id-link
()
1435 "Test `org-export-resolve-id-link' specifications."
1436 ;; 1. Regular test for custom-id link.
1437 (org-test-with-parsed-data "* Headline1
1444 (org-export-resolve-id-link
1445 (org-element-map tree
'link
'identity info t
) info
)))
1446 ;; 2. Failing test for custom-id link.
1447 (org-test-with-parsed-data "* Headline1
1454 (org-export-resolve-id-link
1455 (org-element-map tree
'link
'identity info t
) info
)))
1456 ;; 3. Test for internal id target.
1457 (org-test-with-parsed-data "* Headline1
1464 (org-export-resolve-id-link
1465 (org-element-map tree
'link
'identity info t
) info
)))
1466 ;; 4. Test for external id target.
1467 (org-test-with-parsed-data "[[id:aaaa]]"
1469 (org-export-resolve-id-link
1470 (org-element-map tree
'link
'identity info t
)
1471 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1473 (ert-deftest test-org-export
/resolve-radio-link
()
1474 "Test `org-export-resolve-radio-link' specifications."
1477 (org-test-with-temp-text "<<<radio>>> radio"
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
)
1484 ;; Radio targets are case-insensitive.
1486 (org-test-with-temp-text "<<<RADIO>>> radio"
1487 (org-update-radio-target-regexp)
1488 (let* ((tree (org-element-parse-buffer))
1489 (info `(:parse-tree
,tree
)))
1490 (org-export-resolve-radio-link
1491 (org-element-map tree
'link
'identity info t
)
1493 ;; Radio target with objects.
1495 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1496 (org-update-radio-target-regexp)
1497 (let* ((tree (org-element-parse-buffer))
1498 (info `(:parse-tree
,tree
)))
1499 (org-export-resolve-radio-link
1500 (org-element-map tree
'link
'identity info t
)
1505 ;;; Src-block and example-block
1507 (ert-deftest test-org-export
/unravel-code
()
1508 "Test `org-export-unravel-code' function."
1509 (let ((org-coderef-label-format "(ref:%s)"))
1510 ;; 1. Code without reference.
1511 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1512 (should (equal (org-export-unravel-code (org-element-at-point))
1514 ;; 2. Code with reference.
1515 (org-test-with-temp-text
1516 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1517 (should (equal (org-export-unravel-code (org-element-at-point))
1518 '("(+ 1 1)\n" (1 .
"test")))))
1519 ;; 3. Code with user-defined reference.
1520 (org-test-with-temp-text
1521 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1522 (should (equal (org-export-unravel-code (org-element-at-point))
1523 '("(+ 1 1)\n" (1 .
"test")))))
1524 ;; 4. Code references keys are relative to the current block.
1525 (org-test-with-temp-text "
1534 (should (equal (org-export-unravel-code (org-element-at-point))
1535 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1541 (ert-deftest test-org-export
/activate-smart-quotes
()
1542 "Test `org-export-activate-smart-quotes' specifications."
1543 ;; Opening double 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 ;; Opening quotes: at the beginning of a paragraph.
1557 (let ((org-export-default-language "en"))
1558 (org-test-with-parsed-data "\"begin"
1561 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1563 ;; Opening quotes: after an object.
1567 (let ((org-export-default-language "en"))
1568 (org-test-with-parsed-data "=verb= \"begin"
1571 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1573 ;; Closing quotes: standard test.
1576 '("some” paragraph")
1577 (let ((org-export-default-language "en"))
1578 (org-test-with-parsed-data "some\" paragraph"
1581 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1583 ;; Closing quotes: at the end of a paragraph.
1587 (let ((org-export-default-language "en"))
1588 (org-test-with-parsed-data "end\""
1591 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1593 ;; Apostrophe: standard test.
1596 '("It shouldn’t fail")
1597 (let ((org-export-default-language "en"))
1598 (org-test-with-parsed-data "It shouldn't fail"
1601 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1603 ;; Apostrophe: before an object.
1607 (let ((org-export-default-language "en"))
1608 (org-test-with-parsed-data "a'=b="
1611 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1613 ;; Apostrophe: after an object.
1617 (let ((org-export-default-language "en"))
1618 (org-test-with-parsed-data "=code='s"
1621 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1623 ;; Special case: isolated quotes.
1625 (equal '("“" "”")
1626 (let ((org-export-default-language "en"))
1627 (org-test-with-parsed-data "\"$x$\""
1630 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1632 ;; Smart quotes in secondary strings.
1634 (equal '("“" "”")
1635 (let ((org-export-default-language "en"))
1636 (org-test-with-parsed-data "* \"$x$\""
1639 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1641 ;; Smart quotes in document keywords.
1643 (equal '("“" "”")
1644 (let ((org-export-default-language "en"))
1645 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1647 (plist-get info
:title
) 'plain-text
1648 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1650 ;; Smart quotes in parsed affiliated keywords.
1652 (equal '("“" "”" "Paragraph")
1653 (let ((org-export-default-language "en"))
1654 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1657 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1658 info nil nil t
))))))
1664 (ert-deftest test-org-export
/special-column
()
1665 "Test if the table's special column is properly recognized."
1666 ;; 1. First column is special if it contains only a special marking
1667 ;; characters or empty cells.
1668 (org-test-with-temp-text "
1672 (org-export-table-has-special-column-p
1674 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1675 ;; 2. If the column contains anything else, it isn't special.
1676 (org-test-with-temp-text "
1680 (org-export-table-has-special-column-p
1682 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1683 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1685 (org-test-with-temp-text "
1694 (org-export-table-has-special-column-p
1696 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1697 ;; 4. A first column with only empty cells isn't considered as
1699 (org-test-with-temp-text "
1703 (org-export-table-has-special-column-p
1705 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1707 (ert-deftest test-org-export
/table-row-is-special-p
()
1708 "Test `org-export-table-row-is-special-p' specifications."
1709 ;; 1. A row is special if it has a special marking character in the
1711 (org-test-with-parsed-data "| ! | 1 |"
1713 (org-export-table-row-is-special-p
1714 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1715 ;; 2. A row is special when its first field is "/"
1716 (org-test-with-parsed-data "
1720 (org-export-table-row-is-special-p
1721 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1722 ;; 3. A row only containing alignment cookies is also considered as
1724 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1726 (org-export-table-row-is-special-p
1727 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1728 ;; 4. Everything else isn't considered as special.
1729 (org-test-with-parsed-data "| \alpha | | c |"
1731 (org-export-table-row-is-special-p
1732 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1733 ;; 5. Table's rules are never considered as special rows.
1734 (org-test-with-parsed-data "|---+---|"
1736 (org-export-table-row-is-special-p
1737 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1739 (ert-deftest test-org-export
/has-header-p
()
1740 "Test `org-export-table-has-header-p' specifications."
1741 ;; 1. With an header.
1742 (org-test-with-parsed-data "
1747 (org-export-table-has-header-p
1748 (org-element-map tree
'table
'identity info
'first-match
)
1750 ;; 2. Without an header.
1751 (org-test-with-parsed-data "
1755 (org-export-table-has-header-p
1756 (org-element-map tree
'table
'identity info
'first-match
)
1758 ;; 3. Don't get fooled with starting and ending rules.
1759 (org-test-with-parsed-data "
1765 (org-export-table-has-header-p
1766 (org-element-map tree
'table
'identity info
'first-match
)
1769 (ert-deftest test-org-export
/table-row-group
()
1770 "Test `org-export-table-row-group' specifications."
1771 ;; 1. A rule creates a new group.
1772 (org-test-with-parsed-data "
1779 (mapcar (lambda (row) (org-export-table-row-group row info
))
1780 (org-element-map tree
'table-row
'identity
)))))
1781 ;; 2. Special rows are ignored in count.
1782 (org-test-with-parsed-data "
1789 (mapcar (lambda (row) (org-export-table-row-group row info
))
1790 (org-element-map tree
'table-row
'identity
)))))
1791 ;; 3. Double rules also are ignored in count.
1792 (org-test-with-parsed-data "
1800 (mapcar (lambda (row) (org-export-table-row-group row info
))
1801 (org-element-map tree
'table-row
'identity
))))))
1803 (ert-deftest test-org-export
/table-cell-width
()
1804 "Test `org-export-table-cell-width' specifications."
1805 ;; 1. Width is primarily determined by width cookies. If no cookie
1806 ;; is found, cell's width is nil.
1807 (org-test-with-parsed-data "
1808 | / | <l> | <6> | <l7> |
1813 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1814 (org-element-map tree
'table-cell
'identity info
)))))
1815 ;; 2. The last width cookie has precedence.
1816 (org-test-with-parsed-data "
1823 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1824 (org-element-map tree
'table-cell
'identity info
)))))
1825 ;; 3. Valid width cookies must have a specific row.
1826 (org-test-with-parsed-data "| <6> | cell |"
1830 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1831 (org-element-map tree
'table-cell
'identity
))))))
1833 (ert-deftest test-org-export
/table-cell-alignment
()
1834 "Test `org-export-table-cell-alignment' specifications."
1835 (let ((org-table-number-fraction 0.5)
1836 (org-table-number-regexp "^[0-9]+$"))
1837 ;; 1. Alignment is primarily determined by alignment cookies.
1838 (org-test-with-temp-text "| <l> | <c> | <r> |"
1839 (let* ((tree (org-element-parse-buffer))
1840 (info `(:parse-tree
,tree
)))
1843 '(left center right
)
1844 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1845 (org-element-map tree
'table-cell
'identity
))))))
1846 ;; 2. The last alignment cookie has precedence.
1847 (org-test-with-parsed-data "
1853 '(right right right
)
1854 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1855 (org-element-map tree
'table-cell
'identity
)))))
1856 ;; 3. If there's no cookie, cell's contents determine alignment.
1857 ;; A column mostly made of cells containing numbers will align
1858 ;; its cells to the right.
1859 (org-test-with-parsed-data "
1865 '(right right right
)
1866 (mapcar (lambda (cell)
1867 (org-export-table-cell-alignment cell info
))
1868 (org-element-map tree
'table-cell
'identity
)))))
1869 ;; 4. Otherwise, they will be aligned to the left.
1870 (org-test-with-parsed-data "
1877 (mapcar (lambda (cell)
1878 (org-export-table-cell-alignment cell info
))
1879 (org-element-map tree
'table-cell
'identity
)))))))
1881 (ert-deftest test-org-export
/table-cell-borders
()
1882 "Test `org-export-table-cell-borders' specifications."
1883 ;; 1. Recognize various column groups indicators.
1884 (org-test-with-parsed-data "| / | < | > | <> |"
1887 '((right bottom top
) (left bottom top
) (right bottom top
)
1888 (right left bottom top
))
1889 (mapcar (lambda (cell)
1890 (org-export-table-cell-borders cell info
))
1891 (org-element-map tree
'table-cell
'identity
)))))
1892 ;; 2. Accept shortcuts to define column groups.
1893 (org-test-with-parsed-data "| / | < | < |"
1896 '((right bottom top
) (right left bottom top
) (left bottom top
))
1897 (mapcar (lambda (cell)
1898 (org-export-table-cell-borders cell info
))
1899 (org-element-map tree
'table-cell
'identity
)))))
1900 ;; 3. A valid column groups row must start with a "/".
1901 (org-test-with-parsed-data "
1905 (equal '((top) (top) (bottom) (bottom))
1906 (mapcar (lambda (cell)
1907 (org-export-table-cell-borders cell info
))
1908 (org-element-map tree
'table-cell
'identity
)))))
1909 ;; 4. Take table rules into consideration.
1910 (org-test-with-parsed-data "
1915 (equal '((below top
) (bottom above
))
1916 (mapcar (lambda (cell)
1917 (org-export-table-cell-borders cell info
))
1918 (org-element-map tree
'table-cell
'identity
)))))
1919 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1920 ;; (resp. `bottom' and `below') borders. Any special row is
1922 (org-test-with-parsed-data "
1928 (equal '((bottom below top above
))
1930 (mapcar (lambda (cell)
1931 (org-export-table-cell-borders cell info
))
1932 (org-element-map tree
'table-cell
'identity
)))))))
1934 (ert-deftest test-org-export
/table-dimensions
()
1935 "Test `org-export-table-dimensions' specifications."
1936 ;; 1. Standard test.
1937 (org-test-with-parsed-data "
1942 (org-export-table-dimensions
1943 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1944 ;; 2. Ignore horizontal rules and special columns.
1945 (org-test-with-parsed-data "
1952 (org-export-table-dimensions
1953 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1955 (ert-deftest test-org-export
/table-cell-address
()
1956 "Test `org-export-table-cell-address' specifications."
1957 ;; 1. Standard test: index is 0-based.
1958 (org-test-with-parsed-data "| a | b |"
1960 (equal '((0 .
0) (0 .
1))
1963 (lambda (cell) (org-export-table-cell-address cell info
))
1965 ;; 2. Special column isn't counted, nor are special rows.
1966 (org-test-with-parsed-data "
1971 (org-export-table-cell-address
1972 (car (last (org-element-map tree
'table-cell
'identity info
)))
1974 ;; 3. Tables rules do not count either.
1975 (org-test-with-parsed-data "
1983 (org-export-table-cell-address
1984 (car (last (org-element-map tree
'table-cell
'identity info
)))
1986 ;; 4. Return nil for special cells.
1987 (org-test-with-parsed-data "| / | a |"
1989 (org-export-table-cell-address
1990 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1993 (ert-deftest test-org-export
/get-table-cell-at
()
1994 "Test `org-export-get-table-cell-at' specifications."
1995 ;; 1. Address ignores special columns, special rows and rules.
1996 (org-test-with-parsed-data "
2003 (org-element-contents
2004 (org-export-get-table-cell-at
2006 (org-element-map tree
'table
'identity info
'first-match
)
2008 ;; 2. Return value for a non-existent address is nil.
2009 (org-test-with-parsed-data "| a |"
2011 (org-export-get-table-cell-at
2013 (org-element-map tree
'table
'identity info
'first-match
)
2015 (org-test-with-parsed-data "| / |"
2017 (org-export-get-table-cell-at
2019 (org-element-map tree
'table
'identity info
'first-match
)
2022 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2023 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2024 ;; 1. A cell at a beginning of a row always starts a column group.
2025 (org-test-with-parsed-data "| a |"
2027 (org-export-table-cell-starts-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-starts-colgroup-p
2037 (org-element-map tree
'table-cell
'identity info
'first-match
)
2039 ;; 2. Explicit column groups.
2040 (org-test-with-parsed-data "
2049 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2052 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2053 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2054 ;; 1. A cell at the end of a row always ends a column group.
2055 (org-test-with-parsed-data "| a |"
2057 (org-export-table-cell-ends-colgroup-p
2058 (org-element-map tree
'table-cell
'identity info
'first-match
)
2060 ;; 2. Special column should be ignored when determining the
2061 ;; beginning of the row.
2062 (org-test-with-parsed-data "
2066 (org-export-table-cell-ends-colgroup-p
2067 (org-element-map tree
'table-cell
'identity info
'first-match
)
2069 ;; 3. Explicit column groups.
2070 (org-test-with-parsed-data "
2079 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2082 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2083 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2084 ;; 1. A row at the beginning of a table always starts a row group.
2085 ;; So does a row following a table rule.
2086 (org-test-with-parsed-data "
2096 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2098 ;; 2. Special rows should be ignored when determining the beginning
2100 (org-test-with-parsed-data "
2112 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2115 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2116 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2117 ;; 1. A row at the end of a table always ends a row group. So does
2118 ;; a row preceding a table rule.
2119 (org-test-with-parsed-data "
2129 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2131 ;; 2. Special rows should be ignored when determining the beginning
2133 (org-test-with-parsed-data "
2145 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2148 (ert-deftest test-org-export
/table-row-starts-header-p
()
2149 "Test `org-export-table-row-starts-header-p' specifications."
2150 ;; 1. Only the row starting the first row group starts the table
2152 (org-test-with-parsed-data "
2163 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2165 ;; 2. A row cannot start an header if there's no header in the
2167 (org-test-with-parsed-data "
2171 (org-export-table-row-starts-header-p
2172 (org-element-map tree
'table-row
'identity info
'first-match
)
2175 (ert-deftest test-org-export
/table-row-ends-header-p
()
2176 "Test `org-export-table-row-ends-header-p' specifications."
2177 ;; 1. Only the row starting the first row group starts the table
2179 (org-test-with-parsed-data "
2190 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2192 ;; 2. A row cannot start an header if there's no header in the
2194 (org-test-with-parsed-data "
2198 (org-export-table-row-ends-header-p
2199 (org-element-map tree
'table-row
'identity info
'first-match
)
2206 (ert-deftest test-org-export
/inner-template
()
2207 "Test `inner-template' translator specifications."
2210 (let (org-export-registered-backends)
2211 (org-export-define-backend test
2212 ((inner-template .
(lambda (contents info
) "Success!"))
2213 (headline .
(lambda (h c i
) "Headline"))))
2214 (org-test-with-temp-text "* Headline"
2215 (org-export-as 'test
)))))
2216 ;; Inner template is applied even in a "body-only" export.
2219 (let (org-export-registered-backends)
2220 (org-export-define-backend test
2221 ((inner-template .
(lambda (contents info
) "Success!"))
2222 (headline .
(lambda (h c i
) "Headline"))))
2223 (org-test-with-temp-text "* Headline"
2224 (org-export-as 'test nil nil
'body-only
))))))
2226 (ert-deftest test-org-export
/template
()
2227 "Test `template' translator specifications."
2230 (let (org-export-registered-backends)
2231 (org-export-define-backend test
2232 ((template .
(lambda (contents info
) "Success!"))
2233 (headline .
(lambda (h c i
) "Headline"))))
2234 (org-test-with-temp-text "* Headline"
2235 (org-export-as 'test
)))))
2236 ;; Template is not applied in a "body-only" export.
2239 (let (org-export-registered-backends)
2240 (org-export-define-backend test
2241 ((template .
(lambda (contents info
) "Success!"))
2242 (headline .
(lambda (h c i
) "Headline"))))
2243 (org-test-with-temp-text "* Headline"
2244 (org-export-as 'test nil nil
'body-only
))))))
2250 (ert-deftest test-org-export
/get-next-element
()
2251 "Test `org-export-get-next-element' specifications."
2255 (org-test-with-parsed-data "* Headline\n*a* b"
2256 (org-export-get-next-element
2257 (org-element-map tree
'bold
'identity info t
) info
))))
2258 ;; Return nil when no previous element.
2260 (org-test-with-parsed-data "* Headline\na *b*"
2261 (org-export-get-next-element
2262 (org-element-map tree
'bold
'identity info t
) info
)))
2263 ;; Non-exportable elements are ignored.
2265 (let ((org-export-with-timestamps nil
))
2266 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2267 (org-export-get-next-element
2268 (org-element-map tree
'entity
'identity info t
) info
))))
2269 ;; Find next element in secondary strings.
2272 (org-test-with-parsed-data "* a =verb="
2274 (org-export-get-next-element
2275 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2276 ;; Find next element in document keywords.
2279 (org-test-with-parsed-data "#+TITLE: a =verb="
2281 (org-export-get-next-element
2283 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2284 ;; Find next element in parsed affiliated keywords.
2287 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2289 (org-export-get-next-element
2290 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2291 ;; With optional argument N, return a list containing all the
2292 ;; following elements.
2295 '(bold code underline
)
2296 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2298 (org-export-get-next-element
2299 (org-element-map tree
'italic
'identity info t
) info t
)))))
2300 ;; When N is a positive integer, return a list containing up to
2301 ;; N following elements.
2305 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2307 (org-export-get-next-element
2308 (org-element-map tree
'italic
'identity info t
) info
2))))))
2310 (ert-deftest test-org-export
/get-previous-element
()
2311 "Test `org-export-get-previous-element' specifications."
2315 (org-test-with-parsed-data "* Headline\na *b*"
2316 (org-export-get-previous-element
2317 (org-element-map tree
'bold
'identity info t
) info
))))
2318 ;; Return nil when no previous element.
2320 (org-test-with-parsed-data "* Headline\n*a* b"
2321 (org-export-get-previous-element
2322 (org-element-map tree
'bold
'identity info t
) info
)))
2323 ;; Non-exportable elements are ignored.
2325 (let ((org-export-with-timestamps nil
))
2326 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2327 (org-export-get-previous-element
2328 (org-element-map tree
'entity
'identity info t
) info
))))
2329 ;; Find previous element in secondary strings.
2332 (org-test-with-parsed-data "* =verb= a"
2334 (org-export-get-previous-element
2335 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2336 ;; Find previous element in document keywords.
2339 (org-test-with-parsed-data "#+TITLE: =verb= a"
2341 (org-export-get-previous-element
2343 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2344 ;; Find previous element in parsed affiliated keywords.
2347 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2349 (org-export-get-previous-element
2350 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2351 ;; With optional argument N, return a list containing up to
2352 ;; N previous elements.
2354 (equal '(underline italic bold
)
2355 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2357 (org-export-get-previous-element
2358 (org-element-map tree
'code
'identity info t
) info t
)))))
2359 ;; When N is a positive integer, return a list containing up to
2360 ;; N previous elements.
2362 (equal '(italic bold
)
2363 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2365 (org-export-get-previous-element
2366 (org-element-map tree
'code
'identity info t
) info
2))))))
2370 ;;; test-org-export.el end here