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: test-ox-var value"
79 (let ((org-export-allow-bind-keywords t
))
80 (org-export-get-environment)
81 (eq test-ox-var
'value
))))
82 ;; Test with `org-export-allow-bind-keywords' set to nil.
84 (org-test-with-temp-text "#+BIND: test-ox-var value"
85 (let ((org-export-allow-bind-keywords nil
))
86 (org-export-get-environment)
87 (boundp 'test-ox-var
))))
88 ;; BIND keywords are case-insensitive.
90 (org-test-with-temp-text "#+bind: test-ox-var value"
91 (let ((org-export-allow-bind-keywords t
))
92 (org-export-get-environment)
93 (eq test-ox-var
'value
))))
94 ;; Preserve order of BIND keywords.
96 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
97 (let ((org-export-allow-bind-keywords t
))
98 (org-export-get-environment)
100 ;; Read BIND keywords in setup files.
102 (org-test-with-temp-text
103 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
104 (let ((org-export-allow-bind-keywords t
))
105 (org-export-get-environment)
106 (eq variable
'value
))))
107 ;; Verify that bound variables are seen during export.
110 (org-test-with-temp-text "#+BIND: test-ox-var value"
111 (let ((org-export-allow-bind-keywords t
)
112 org-export-registered-backends
)
113 (org-export-define-backend 'check
114 '((section .
(lambda (s c i
)
115 (if (eq test-ox-var
'value
) "Yes" "No")))))
116 (org-export-as 'check
))))))
118 (ert-deftest test-org-export
/parse-option-keyword
()
119 "Test reading all standard #+OPTIONS: items."
122 (org-export--parse-option-keyword
123 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
124 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
127 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
128 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
129 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
130 :with-footnotes t
:with-inlinetasks nil
:with-priority t
131 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
132 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
133 :with-todo-keywords t
)))
134 ;; Test some special values.
137 (org-export--parse-option-keyword
138 "arch:headline creator:comment d:(\"TEST\")
139 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
142 :with-archived-trees headline
:with-creator comment
143 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
144 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
146 (ert-deftest test-org-export
/get-inbuffer-options
()
147 "Test reading all standard export keywords."
148 ;; Properties should follow buffer order.
151 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
152 (org-export--get-inbuffer-options))
153 '(:language
"fr" :creator
"Me" :email
"email")))
154 ;; Parse document keywords.
157 (org-test-with-temp-text "#+AUTHOR: Me"
158 (org-export--get-inbuffer-options))
160 ;; Test `space' behaviour.
163 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
164 (org-export--get-inbuffer-options))
165 '(:title
("Some title with spaces"))))
166 ;; Test `newline' behaviour.
169 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
170 (org-export--get-inbuffer-options))
171 '(:description
"With\ntwo lines")))
172 ;; Test `split' behaviour.
175 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
176 (org-export--get-inbuffer-options))
177 '(:select-tags
("a" "b"))))
178 ;; Options set through SETUPFILE.
181 (org-test-with-temp-text
182 (format "#+DESCRIPTION: l1
186 #+SETUPFILE: \"%s/examples/setupfile.org\"
192 (org-export--get-inbuffer-options))
193 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
196 (ert-deftest test-org-export
/get-subtree-options
()
197 "Test setting options from headline's properties."
199 (org-test-with-temp-text "#+TITLE: Title
202 :EXPORT_TITLE: Subtree Title
206 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
207 '("Subtree Title"))))
211 (org-test-with-temp-text "#+OPTIONS: H:1
219 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
221 (org-test-with-temp-text "#+DATE: today
224 :EXPORT_DATE: 29-03-2012
228 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
230 ;; Properties with `split' behaviour are stored as a list of
234 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
237 :EXPORT_EXCLUDE_TAGS: a b
242 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
243 ;; Handle :PROPERTY+: syntax.
246 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
249 :EXPORT_EXCLUDE_TAGS: a
250 :EXPORT_EXCLUDE_TAGS+: b
255 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
256 ;; Export properties are case-insensitive.
257 (org-test-with-temp-text "* Headline
259 :EXPORT_Date: 29-03-2012
262 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
264 ;; Still grab correct options when section above is empty.
267 (org-test-with-temp-text "* H1\n** H11\n** H12"
268 (progn (forward-line 2)
269 (plist-get (org-export-get-environment nil t
) :title
))))))
271 (ert-deftest test-org-export
/handle-options
()
272 "Test if export options have an impact on output."
273 ;; Test exclude tags for headlines and inlinetasks.
276 (org-test-with-temp-text "* Head1 :noexp:"
277 (org-test-with-backend test
278 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp")))))))
279 ;; Test include tags for headlines and inlinetasks.
281 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
282 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
283 (let ((org-tags-column 0))
284 (org-test-with-backend test
285 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
286 ;; Test mixing include tags and exclude tags.
287 (org-test-with-temp-text "
289 ** Sub-Head1 :noexport:
292 ** Sub-Head1 :export:"
293 (org-test-with-backend test
296 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
299 '(:select-tags
("export") :exclude-tags
("noexport")))))))
303 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
304 (org-test-with-temp-text "* TODO Head1"
305 (org-test-with-backend test
306 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))
308 (equal "* TODO Head1\n"
309 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
310 (org-test-with-temp-text "* TODO Head1"
311 (org-test-with-backend test
312 (org-export-as 'test nil nil nil
'(:with-tasks t
)))))))
314 (org-test-with-temp-text "* Head1 :archive:"
315 (let ((org-archive-tag "archive"))
316 (org-test-with-backend test
318 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
320 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
321 (let ((org-archive-tag "archive"))
322 (org-test-with-backend test
325 "\\* Head1[ \t]+:archive:"
326 (org-export-as 'test nil nil nil
327 '(:with-archived-trees headline
)))))))
328 (org-test-with-temp-text "* Head1 :archive:"
329 (let ((org-archive-tag "archive"))
330 (org-test-with-backend test
333 "\\`\\* Head1[ \t]+:archive:\n\\'"
334 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
336 (let ((org-clock-string "CLOCK:"))
337 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
338 (org-test-with-backend test
340 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
341 "CLOCK: [2012-04-29 sun. 10:45]\n"))
343 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
345 (let ((org-drawers '("TEST")))
346 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
347 (org-test-with-backend test
348 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
350 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
351 ":TEST:\ncontents\n:END:\n")))))
352 (let ((org-drawers '("FOO" "BAR")))
353 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
354 (org-test-with-backend test
356 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
357 ":FOO:\nkeep\n:END:\n")))))
358 (let ((org-drawers '("FOO" "BAR")))
359 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
360 (org-test-with-backend test
362 (equal (org-export-as 'test nil nil nil
'(:with-drawers
(not "BAR")))
363 ":FOO:\nkeep\n:END:\n")))))
365 (when (featurep 'org-inlinetask
)
368 (let ((org-inlinetask-min-level 15))
369 (org-test-with-temp-text "*************** Task"
370 (org-test-with-backend test
371 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
375 (let ((org-inlinetask-min-level 15))
376 (org-test-with-temp-text
377 "*************** Task\nContents\n*************** END"
378 (org-test-with-backend test
379 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
382 (let ((org-closed-string "CLOSED:"))
383 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
384 (org-test-with-backend test
386 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
387 "CLOSED: [2012-04-29 sun. 10:45]\n"))
389 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
391 ;; Statistics cookies.
394 (org-test-with-temp-text "[0/0]"
395 (org-test-with-backend test
397 'test nil nil nil
'(:with-statistics-cookies nil
))))))
399 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
400 (org-test-with-backend test
402 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
403 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
405 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
407 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
408 "<2012-04-29 sun. 10:45>\n"))
410 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
411 "[2012-04-29 sun. 10:45]\n")))))
413 (ert-deftest test-org-export
/comment-tree
()
414 "Test if export process ignores commented trees."
415 (let ((org-comment-string "COMMENT"))
416 (org-test-with-temp-text "* COMMENT Head1"
417 (org-test-with-backend test
418 (should (equal (org-export-as 'test
) ""))))))
420 (ert-deftest test-org-export
/export-scope
()
421 "Test all export scopes."
422 (org-test-with-temp-text "
427 (org-test-with-backend test
430 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
432 (goto-char (point-min))
435 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
437 (goto-char (point-min))
439 (transient-mark-mode 1)
440 (push-mark (point) t t
)
441 (goto-char (point-at-eol))
442 (should (equal (org-export-as 'test
) "text\n"))))
443 ;; Subtree with a code block calling another block outside.
446 (org-test-with-temp-text "
448 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
453 #+BEGIN_SRC emacs-lisp
456 (org-test-with-backend test
458 (org-export-as 'test
'subtree
)))))
460 (org-test-with-temp-text "Text"
461 (org-test-with-backend test
463 (cdr (assq 'test org-export-registered-backends
))
465 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
466 (org-export-backend-translate-table 'test
)))
467 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
468 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
470 (ert-deftest test-org-export
/output-file-name
()
471 "Test `org-export-output-file-name' specifications."
472 ;; Export from a file: name is built from original file name.
474 (org-test-with-temp-text-in-file "Test"
475 (equal (concat (file-name-as-directory ".")
476 (file-name-nondirectory
477 (file-name-sans-extension (buffer-file-name))))
478 (file-name-sans-extension (org-export-output-file-name ".ext")))))
479 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
481 (org-test-with-temp-text-in-file
482 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
483 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
484 ;; From a buffer not associated to a file, too.
486 (org-test-with-temp-text
487 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
488 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
489 ;; When provided name is absolute, preserve it.
491 (org-test-with-temp-text
492 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
493 (expand-file-name "test"))
494 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
495 ;; When PUB-DIR argument is provided, use it.
497 (org-test-with-temp-text-in-file "Test"
498 (equal (file-name-directory
499 (org-export-output-file-name ".ext" nil
"dir/"))
501 ;; When returned name would overwrite original file, add EXTENSION
504 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
505 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
507 (ert-deftest test-org-export
/expand-include
()
508 "Test file inclusion in an Org buffer."
509 ;; Error when file isn't specified.
511 (org-test-with-temp-text "#+INCLUDE: dummy.org"
512 (org-export-expand-include-keyword)))
513 ;; Full insertion with recursive inclusion.
514 (org-test-with-temp-text
515 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
516 (org-export-expand-include-keyword)
517 (should (equal (buffer-string)
518 "Small Org file with an include keyword.
520 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
526 ;; Localized insertion.
527 (org-test-with-temp-text
528 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
530 (org-export-expand-include-keyword)
531 (should (equal (buffer-string)
532 "Small Org file with an include keyword.\n")))
533 ;; Insertion with constraints on headlines level.
536 "* Top heading\n** Heading\nbody\n"
537 (org-test-with-temp-text
539 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
541 (org-export-expand-include-keyword)
545 "* Top heading\n* Heading\nbody\n"
546 (org-test-with-temp-text
548 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
550 (org-export-expand-include-keyword)
552 ;; Inclusion within an example block.
553 (org-test-with-temp-text
554 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
556 (org-export-expand-include-keyword)
560 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
561 ;; Inclusion within a src-block.
562 (org-test-with-temp-text
564 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
566 (org-export-expand-include-keyword)
567 (should (equal (buffer-string)
568 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
570 (ert-deftest test-org-export
/expand-macro
()
571 "Test macro expansion in an Org buffer."
572 ;; Standard macro expansion.
574 (equal "#+MACRO: macro1 value\nvalue\n"
575 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
576 (org-test-with-backend test
(org-export-as 'test
)))))
577 ;; Expand specific macros.
579 (equal "me 2012-03-29 me@here Title\n"
580 (org-test-with-temp-text
586 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
587 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
588 (substring output
(string-match ".*\n\\'" output
))))))
589 ;; Expand specific macros when property contained a regular macro
593 (org-test-with-temp-text "
594 #+MACRO: macro1 value
595 #+TITLE: {{{macro1}}}
597 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
598 (substring output
(string-match ".*\n\\'" output
))))))
599 ;; Expand macros with templates in included files.
602 (org-test-with-temp-text
603 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
604 {{{included-macro}}}" org-test-dir
)
605 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
606 (substring output
(string-match ".*\n\\'" output
)))))))
608 (ert-deftest test-org-export
/user-ignore-list
()
609 "Test if `:ignore-list' accepts user input."
610 (org-test-with-backend test
611 (flet ((skip-note-head
613 ;; Ignore headlines with the word "note" in their title.
614 (org-element-map data
'headline
616 (when (string-match "\\<note\\>"
617 (org-element-property :raw-value headline
))
618 (org-export-ignore-element headline info
)))
621 ;; Install function in parse tree filters.
622 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
623 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
624 (should (equal (org-export-as 'test
) "* Head1\n")))))))
626 (ert-deftest test-org-export
/before-processing-hook
()
627 "Test `org-export-before-processing-hook'."
630 "#+MACRO: mac val\nTest\n"
631 (org-test-with-backend test
632 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
633 (let ((org-export-before-processing-hook
635 (while (re-search-forward "{{{" nil t
)
636 (let ((object (org-element-context)))
637 (when (eq (org-element-type object
) 'macro
)
639 (org-element-property :begin object
)
640 (org-element-property :end object
)))))))))
641 (org-export-as 'test
)))))))
643 (ert-deftest test-org-export
/before-parsing-hook
()
644 "Test `org-export-before-parsing-hook'."
646 (equal "Body 1\nBody 2\n"
647 (org-test-with-backend test
648 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
649 (let ((org-export-before-parsing-hook
651 (goto-char (point-min))
652 (while (re-search-forward org-outline-regexp-bol nil t
)
654 (point-at-bol) (progn (forward-line) (point))))))))
655 (org-export-as 'test
)))))))
659 ;;; Affiliated Keywords
661 (ert-deftest test-org-export
/read-attribute
()
662 "Test `org-export-read-attribute' specifications."
666 (org-export-read-attribute
668 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
669 (org-element-at-point)))
671 ;; Return nil on empty attribute.
673 (org-export-read-attribute
675 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
676 ;; Return nil on "nil" string.
678 (equal '(:a nil
:b nil
)
679 (org-export-read-attribute
681 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
682 (org-element-at-point)))))
683 ;; Return nil on empty string.
685 (equal '(:a nil
:b nil
)
686 (org-export-read-attribute
688 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
689 (org-element-at-point)))))
690 ;; Ignore text before first property.
693 (org-export-read-attribute
695 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
696 (org-element-at-point))))))
698 (ert-deftest test-org-export
/get-caption
()
699 "Test `org-export-get-caption' specifications."
700 ;; Without optional argument, return long caption
704 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
705 (org-export-get-caption (org-element-at-point)))))
706 ;; With optional argument, return short caption.
710 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
711 (org-export-get-caption (org-element-at-point) t
))))
712 ;; Multiple lines are separated by white spaces.
716 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
717 (org-export-get-caption (org-element-at-point))))))
723 (ert-deftest test-org-export
/define-backend
()
724 "Test back-end definition and accessors."
727 (equal '((headline . my-headline-test
))
728 (let (org-export-registered-backends)
729 (org-export-define-backend 'test
'((headline . my-headline-test
)))
730 (org-export-backend-translate-table 'test
))))
733 (equal '((:filter-headline . my-filter
))
734 (let (org-export-registered-backends)
735 (org-export-define-backend 'test
736 '((headline . my-headline-test
))
737 :filters-alist
'((:filter-headline . my-filter
)))
738 (org-export-backend-filters 'test
))))
741 (equal '((:prop value
))
742 (let (org-export-registered-backends)
743 (org-export-define-backend 'test
744 '((headline . my-headline-test
))
745 :options-alist
'((:prop value
)))
746 (org-export-backend-options 'test
))))
749 (equal '(?k
"Test Export" test
)
750 (let (org-export-registered-backends)
751 (org-export-define-backend 'test
752 '((headline . my-headline-test
))
753 :menu-entry
'(?k
"Test Export" test
))
754 (org-export-backend-menu 'test
))))
757 (equal '(("TEST" . org-element-export-block-parser
))
758 (let (org-export-registered-backends org-element-block-name-alist
)
759 (org-export-define-backend 'test
760 '((headline . my-headline-test
))
761 :export-block
'("test"))
762 org-element-block-name-alist
))))
764 (ert-deftest test-org-export
/define-derived-backend
()
765 "Test `org-export-define-derived-backend' specifications."
766 ;; Error when parent back-end is not defined.
768 (let (org-export-registered-backends)
769 (org-export-define-derived-backend 'test
'parent
)))
770 ;; Append translation table to parent's.
772 (equal '((:headline . test
) (:headline . parent
))
773 (let (org-export-registered-backends)
774 (org-export-define-backend 'parent
'((:headline . parent
)))
775 (org-export-define-derived-backend 'test
'parent
776 :translate-alist
'((:headline . test
)))
777 (org-export-backend-translate-table 'test
))))
778 ;; Options defined in the new back have priority over those defined
782 (let (org-export-registered-backends)
783 (org-export-define-backend 'parent
784 '((:headline . parent
))
785 :options-alist
'((:a nil nil
'parent
)))
786 (org-export-define-derived-backend 'test
'parent
787 :options-alist
'((:a nil nil
'test
)))
788 (plist-get (org-export--get-global-options 'test
) :a
)))))
790 (ert-deftest test-org-export
/derived-backend-p
()
791 "Test `org-export-derived-backend-p' specifications."
792 ;; Non-nil with direct match.
794 (let (org-export-registered-backends)
795 (org-export-define-backend 'test
'((headline . test
)))
796 (org-export-derived-backend-p 'test
'test
)))
798 (let (org-export-registered-backends)
799 (org-export-define-backend 'test
'((headline . test
)))
800 (org-export-define-derived-backend 'test2
'test
)
801 (org-export-derived-backend-p 'test2
'test2
)))
802 ;; Non-nil with a direct parent.
804 (let (org-export-registered-backends)
805 (org-export-define-backend 'test
'((headline . test
)))
806 (org-export-define-derived-backend 'test2
'test
)
807 (org-export-derived-backend-p 'test2
'test
)))
808 ;; Non-nil with an indirect parent.
810 (let (org-export-registered-backends)
811 (org-export-define-backend 'test
'((headline . test
)))
812 (org-export-define-derived-backend 'test2
'test
)
813 (org-export-define-derived-backend 'test3
'test2
)
814 (org-export-derived-backend-p 'test3
'test
)))
817 (let (org-export-registered-backends)
818 (org-export-define-backend 'test
'((headline . test
)))
819 (org-export-define-backend 'test2
'((headline . test2
)))
820 (org-export-derived-backend-p 'test2
'test
)))
822 (let (org-export-registered-backends)
823 (org-export-define-backend 'test
'((headline . test
)))
824 (org-export-define-backend 'test2
'((headline . test2
)))
825 (org-export-define-derived-backend 'test3
'test2
)
826 (org-export-derived-backend-p 'test3
'test
))))
828 (ert-deftest test-org-export
/with-backend
()
829 "Test `org-export-with-backend' definition."
830 ;; Error when calling an undefined back-end
832 (let (org-export-registered-backends)
833 (org-export-with-backend 'test
"Test")))
834 ;; Error when called back-end doesn't have an appropriate
837 (let (org-export-registered-backends)
838 (org-export-define-backend 'test
((headline . ignore
)))
839 (org-export-with-backend 'test
"Test")))
840 ;; Otherwise, export using correct transcoder
843 (let (org-export-registered-backends)
844 (org-export-define-backend 'test
845 '((plain-text .
(lambda (text contents info
) "Failure"))))
846 (org-export-define-backend 'test2
847 '((plain-text .
(lambda (text contents info
) "Success"))))
848 (org-export-with-backend 'test2
"Test")))))
850 (ert-deftest test-org-export
/data-with-translations
()
851 "Test `org-export-data-with-translations' specifications."
855 (org-export-data-with-translations
857 '((plain-text .
(lambda (text info
) "Success"))
858 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
859 '(:with-emphasize t
)))))
861 (ert-deftest test-org-export
/data-with-backend
()
862 "Test `org-export-data-with-backend' specifications."
863 ;; Error when calling an undefined back-end.
865 (let (org-export-registered-backends)
866 (org-export-data-with-backend 'test
"Test" nil
)))
867 ;; Otherwise, export data recursively, using correct back-end.
871 (let (org-export-registered-backends)
872 (org-export-define-backend 'test
873 '((plain-text .
(lambda (text info
) "Success"))
874 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
875 (org-export-data-with-backend
876 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
882 (ert-deftest test-org-export
/export-snippet
()
883 "Test export snippets transcoding."
884 (org-test-with-temp-text "@@test:A@@@@t:B@@"
885 (org-test-with-backend test
887 (cdr (assq 'test org-export-registered-backends
))
889 (cons (cons 'export-snippet
890 (lambda (snippet contents info
)
891 (when (eq (org-export-snippet-backend snippet
) 'test
)
892 (org-element-property :value snippet
))))
893 (org-export-backend-translate-table 'test
)))
894 (let ((org-export-snippet-translation-alist nil
))
895 (should (equal (org-export-as 'test
) "A\n")))
896 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
897 (should (equal (org-export-as 'test
) "AB\n")))))
898 ;; Ignored export snippets do not remove any blank.
901 (org-test-with-parsed-data "begin @@test:A@@ end"
902 (org-export-data-with-translations
904 '((paragraph .
(lambda (paragraph contents info
) contents
))
905 (section .
(lambda (section contents info
) contents
)))
912 (ert-deftest test-org-export
/footnotes
()
913 "Test footnotes specifications."
914 (let ((org-footnote-section nil
)
915 (org-export-with-footnotes t
))
916 ;; 1. Read every type of footnote.
919 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
920 (org-test-with-parsed-data
921 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
922 (org-element-map tree
'footnote-reference
924 (let ((def (org-export-get-footnote-definition ref info
)))
925 (cons (org-export-get-footnote-number ref info
)
926 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
927 (car (org-element-contents
928 (car (org-element-contents def
))))))))
930 ;; 2. Test nested footnotes order.
931 (org-test-with-parsed-data
932 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
935 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
936 (org-element-map tree
'footnote-reference
938 (when (org-export-footnote-first-reference-p ref info
)
939 (cons (org-export-get-footnote-number ref info
)
940 (org-element-property :label ref
))))
942 ;; 3. Test nested footnote in invisible definitions.
943 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
945 (narrow-to-region (point) (point-at-eol))
946 (let* ((tree (org-element-parse-buffer))
947 (info (org-combine-plists
949 (org-export-collect-tree-properties
950 tree
(org-export-get-environment)))))
951 ;; Both footnotes should be seen.
953 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
954 ;; 4. Test footnotes definitions collection.
955 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
957 \[fn:2] B [fn:3] [fn::D].
960 (should (= (length (org-export-collect-footnote-definitions tree info
))
962 ;; 5. Test export of footnotes defined outside parsing scope.
963 (org-test-with-temp-text "[fn:1] Out of scope
966 (org-test-with-backend test
968 (cdr (assq 'test org-export-registered-backends
))
970 (cons (cons 'footnote-reference
971 (lambda (fn contents info
)
972 (org-element-interpret-data
973 (org-export-get-footnote-definition fn info
))))
974 (org-export-backend-translate-table 'test
)))
976 (should (equal "ParagraphOut of scope\n"
977 (org-export-as 'test
'subtree
)))))
978 ;; 6. Footnotes without a definition should be provided a fallback
981 (org-test-with-parsed-data "[fn:1]"
982 (org-export-get-footnote-definition
983 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
984 ;; 7. Footnote section should be ignored in TOC and in headlines
987 (= 1 (let ((org-footnote-section "Footnotes"))
988 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
989 (org-export-collect-headlines info
))))))
992 (let ((org-footnote-section "Footnotes"))
993 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
994 (org-element-map tree
'headline
996 (when (equal (org-element-property :raw-value hl
) "H2")
997 (org-export-get-headline-number hl info
)))
1002 ;;; Headlines and Inlinetasks
1004 (ert-deftest test-org-export
/get-relative-level
()
1005 "Test `org-export-get-relative-level' specifications."
1009 (let ((org-odd-levels-only nil
))
1010 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1011 (org-element-map tree
'headline
1012 (lambda (h) (org-export-get-relative-level h info
))
1017 (let ((org-odd-levels-only nil
))
1018 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1019 (org-element-map tree
'headline
1020 (lambda (h) (org-export-get-relative-level h info
))
1023 (ert-deftest test-org-export
/low-level-p
()
1024 "Test `org-export-low-level-p' specifications."
1028 (let ((org-odd-levels-only nil
))
1029 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1030 (org-element-map tree
'headline
1031 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1032 (plist-put info
:headline-levels
1)))))))
1034 (ert-deftest test-org-export
/get-headline-number
()
1035 "Test `org-export-get-headline-number' specifications."
1040 (let ((org-odd-levels-only nil
))
1041 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1042 (org-element-map tree
'headline
1043 (lambda (h) (org-export-get-headline-number h info
))
1045 ;; Missing levels are replaced with 0.
1049 (let ((org-odd-levels-only nil
))
1050 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1051 (org-element-map tree
'headline
1052 (lambda (h) (org-export-get-headline-number h info
))
1055 (ert-deftest test-org-export
/numbered-headline-p
()
1056 "Test `org-export-numbered-headline-p' specifications."
1057 ;; If `:section-numbers' is nil, never number headlines.
1059 (org-test-with-parsed-data "* Headline"
1060 (org-element-map tree
'headline
1061 (lambda (h) (org-export-numbered-headline-p h info
))
1062 (plist-put info
:section-numbers nil
))))
1063 ;; If `:section-numbers' is a number, only number headlines with
1064 ;; a level greater that it.
1068 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1069 (org-element-map tree
'headline
1070 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1071 (plist-put info
:section-numbers
1)))))
1072 ;; Otherwise, headlines are always numbered.
1074 (org-test-with-parsed-data "* Headline"
1075 (org-element-map tree
'headline
1076 (lambda (h) (org-export-numbered-headline-p h info
))
1077 (plist-put info
:section-numbers t
)))))
1079 (ert-deftest test-org-export
/number-to-roman
()
1080 "Test `org-export-number-to-roman' specifications."
1081 ;; If number is negative, return it as a string.
1082 (should (equal (org-export-number-to-roman -
1) "-1"))
1083 ;; Otherwise, return it as a roman number.
1084 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1086 (ert-deftest test-org-export
/get-optional-title
()
1087 "Test `org-export-get-alt-title' specifications."
1088 ;; If ALT_TITLE property is defined, use it.
1091 (org-test-with-parsed-data
1092 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1093 (org-export-get-alt-title
1094 (org-element-map tree
'headline
'identity info t
)
1096 ;; Otherwise, fall-back to regular title.
1098 (equal '("Headline")
1099 (org-test-with-parsed-data "* Headline"
1100 (org-export-get-alt-title
1101 (org-element-map tree
'headline
'identity info t
)
1104 (ert-deftest test-org-export
/get-tags
()
1105 "Test `org-export-get-tags' specifications."
1106 (let ((org-export-exclude-tags '("noexport"))
1107 (org-export-select-tags '("export")))
1108 ;; Standard test: tags which are not a select tag, an exclude tag,
1109 ;; or specified as optional argument shouldn't be ignored.
1111 (org-test-with-parsed-data "* Headline :tag:"
1112 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1114 ;; Exclude tags are removed.
1116 (org-test-with-parsed-data "* Headline :noexport:"
1117 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1119 ;; Select tags are removed.
1121 (org-test-with-parsed-data "* Headline :export:"
1122 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1127 (org-test-with-parsed-data "* Headline :tag:export:"
1128 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1130 ;; Tags provided in the optional argument are also ignored.
1132 (org-test-with-parsed-data "* Headline :ignore:"
1133 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1135 ;; Allow tag inheritance.
1139 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1140 (org-element-map tree
'headline
1141 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1142 ;; Tag inheritance checks FILETAGS keywords.
1146 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1147 (org-element-map tree
'headline
1148 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1150 (ert-deftest test-org-export
/get-node-property
()
1151 "Test`org-export-get-node-property' specifications."
1155 (org-test-with-parsed-data "* Headline
1159 (org-export-get-node-property
1160 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1161 ;; Test inheritance.
1164 (org-test-with-parsed-data "* Parent
1170 (org-export-get-node-property
1171 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1172 ;; Cannot return a value before the first headline.
1174 (org-test-with-parsed-data "Paragraph
1179 (org-export-get-node-property
1180 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1182 (ert-deftest test-org-export
/get-category
()
1183 "Test `org-export-get-category' specifications."
1187 (org-test-with-parsed-data "* Headline
1191 (org-export-get-category
1192 (org-element-map tree
'headline
'identity nil t
) info
))))
1193 ;; Test inheritance from a parent headline.
1195 (equal '("value" "value")
1196 (org-test-with-parsed-data "* Headline1
1201 (org-element-map tree
'headline
1202 (lambda (hl) (org-export-get-category hl info
)) info
))))
1203 ;; Test inheritance from #+CATEGORY keyword
1206 (org-test-with-parsed-data "#+CATEGORY: value
1208 (org-export-get-category
1209 (org-element-map tree
'headline
'identity nil t
) info
))))
1210 ;; Test inheritance from file name.
1213 (org-test-with-parsed-data "* Headline"
1214 (let ((info (plist-put info
:input-file
"~/test.org")))
1215 (org-export-get-category
1216 (org-element-map tree
'headline
'identity nil t
) info
)))))
1220 (org-test-with-parsed-data "* Headline"
1221 (org-export-get-category
1222 (org-element-map tree
'headline
'identity nil t
) info
)))))
1224 (ert-deftest test-org-export
/first-sibling-p
()
1225 "Test `org-export-first-sibling-p' specifications."
1230 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1231 (org-element-map tree
'headline
1232 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1234 ;; Ignore headlines not exported.
1238 (let ((org-export-exclude-tags '("ignore")))
1239 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1240 (org-element-map tree
'headline
1241 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1244 (ert-deftest test-org-export
/last-sibling-p
()
1245 "Test `org-export-last-sibling-p' specifications."
1250 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1251 (org-element-map tree
'headline
1252 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1254 ;; Ignore headlines not exported.
1258 (let ((org-export-exclude-tags '("ignore")))
1259 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1260 (org-element-map tree
'headline
1261 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1264 (ert-deftest test-org-export
/handle-inlinetasks
()
1265 "Test inlinetask export."
1266 ;; Inlinetask with an exclude tag.
1267 (when (featurep 'org-inlinetask
)
1271 (let ((org-inlinetask-min-level 3))
1272 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1273 (org-test-with-backend test
1274 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp"))))))))
1275 ;; Inlinetask with an include tag.
1278 "* H2\n*** Inline :exp:\n"
1279 (let ((org-inlinetask-min-level 3)
1280 (org-tags-column 0))
1281 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1282 (org-test-with-backend test
1283 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
1284 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1287 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1288 (org-inlinetask-min-level 3))
1289 (org-test-with-temp-text "*** TODO Inline"
1290 (org-test-with-backend test
1291 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))))
1297 (ert-deftest test-org-export
/get-date
()
1298 "Test `org-export-get-date' specifications."
1299 ;; Return a properly formatted string when
1300 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1301 ;; consists in a single timestamp.
1304 (let ((org-export-date-timestamp-format "%d %m %Y"))
1305 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1306 (org-export-get-date info
)))))
1307 ;; Return a secondary string otherwise.
1310 (let ((org-export-date-timestamp-format nil
))
1311 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1312 (org-export-get-date info
)))))
1315 (org-test-with-parsed-data "#+DATE: Date"
1316 (org-export-get-date info
))))
1317 ;; Optional argument has precedence over
1318 ;; `org-export-date-timestamp-format'.
1321 (let ((org-export-date-timestamp-format "%d %m %Y"))
1322 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1323 (org-export-get-date info
"%d %m"))))))
1329 (ert-deftest test-org-export
/get-coderef-format
()
1330 "Test `org-export-get-coderef-format' specifications."
1331 ;; A link without description returns "%s"
1332 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1334 ;; Return "%s" when path is matched within description.
1335 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1337 ;; Otherwise return description.
1338 (should (equal (org-export-get-coderef-format "path" "desc")
1341 (ert-deftest test-org-export
/inline-image-p
()
1342 "Test `org-export-inline-image-p' specifications."
1344 (org-export-inline-image-p
1345 (org-test-with-temp-text "[[#id]]"
1346 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1347 '(("custom-id" .
"id")))))
1349 (ert-deftest test-org-export
/fuzzy-link
()
1350 "Test fuzzy links specifications."
1351 ;; Link to an headline should return headline's number.
1352 (org-test-with-parsed-data
1353 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1355 ;; Note: Headline's number is in fact a list of numbers.
1357 (org-element-map tree
'link
1359 (org-export-get-ordinal
1360 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1361 ;; Link to a target in an item should return item's number.
1362 (org-test-with-parsed-data
1363 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1365 ;; Note: Item's number is in fact a list of numbers.
1367 (org-element-map tree
'link
1369 (org-export-get-ordinal
1370 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1371 ;; Link to a target in a footnote should return footnote's number.
1372 (org-test-with-parsed-data "
1373 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1376 (org-element-map tree
'link
1378 (org-export-get-ordinal
1379 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1380 ;; Link to a named element should return sequence number of that
1382 (org-test-with-parsed-data
1383 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1386 (org-element-map tree
'link
1388 (org-export-get-ordinal
1389 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1390 ;; Link to a target not within an item, a table, a footnote
1391 ;; reference or definition should return section number.
1392 (org-test-with-parsed-data
1393 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1396 (org-element-map tree
'link
1398 (org-export-get-ordinal
1399 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1400 ;; Space are not significant when matching a fuzzy link.
1402 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1403 (org-element-map tree
'link
1404 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1406 ;; Statistics cookies are ignored for headline match.
1408 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1409 (org-element-map tree
'link
1410 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1413 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1414 (org-element-map tree
'link
1415 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1418 (ert-deftest test-org-export
/resolve-coderef
()
1419 "Test `org-export-resolve-coderef' specifications."
1420 (let ((org-coderef-label-format "(ref:%s)"))
1421 ;; 1. A link to a "-n -k -r" block returns line number.
1422 (org-test-with-parsed-data
1423 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1424 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1425 (org-test-with-parsed-data
1426 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1427 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1428 ;; 2. A link to a "-n -r" block returns line number.
1429 (org-test-with-parsed-data
1430 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1431 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1432 (org-test-with-parsed-data
1433 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1434 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1435 ;; 3. A link to a "-n" block returns coderef.
1436 (org-test-with-parsed-data
1437 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1438 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1439 (org-test-with-parsed-data
1440 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1441 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1442 ;; 4. A link to a "-r" block returns line number.
1443 (org-test-with-parsed-data
1444 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1445 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1446 (org-test-with-parsed-data
1447 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1448 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1449 ;; 5. A link to a block without a switch returns coderef.
1450 (org-test-with-parsed-data
1451 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1452 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1453 (org-test-with-parsed-data
1454 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1455 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1456 ;; 6. Correctly handle continued line numbers. A "+n" switch
1457 ;; should resume numbering from previous block with numbered
1458 ;; lines, ignoring blocks not numbering lines in the process.
1459 ;; A "-n" switch resets count.
1460 (org-test-with-parsed-data "
1465 #+BEGIN_SRC emacs-lisp
1469 #+BEGIN_SRC emacs-lisp +n -r
1470 \(+ 1 1) (ref:addition)
1473 #+BEGIN_EXAMPLE -n -r
1474 Another text. (ref:text)
1476 (should (= (org-export-resolve-coderef "addition" info
) 2))
1477 (should (= (org-export-resolve-coderef "text" info
) 1)))
1478 ;; 7. Recognize coderef with user-specified syntax.
1479 (org-test-with-parsed-data
1480 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1481 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1483 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1484 "Test `org-export-resolve-fuzzy-link' specifications."
1485 ;; Match target objects.
1487 (org-test-with-parsed-data "<<target>> [[target]]"
1488 (org-export-resolve-fuzzy-link
1489 (org-element-map tree
'link
'identity info t
) info
)))
1490 ;; Match named elements.
1492 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1493 (org-export-resolve-fuzzy-link
1494 (org-element-map tree
'link
'identity info t
) info
)))
1495 ;; Match exact headline's name.
1497 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1498 (org-export-resolve-fuzzy-link
1499 (org-element-map tree
'link
'identity info t
) info
)))
1500 ;; Targets objects have priority over named elements and headline
1504 (org-test-with-parsed-data
1505 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1507 (org-export-resolve-fuzzy-link
1508 (org-element-map tree
'link
'identity info t
) info
)))))
1509 ;; Named elements have priority over headline titles.
1512 (org-test-with-parsed-data
1513 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1515 (org-export-resolve-fuzzy-link
1516 (org-element-map tree
'link
'identity info t
) info
)))))
1517 ;; If link's path starts with a "*", only match headline titles,
1521 (org-test-with-parsed-data
1522 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1524 (org-export-resolve-fuzzy-link
1525 (org-element-map tree
'link
'identity info t
) info
)))))
1526 ;; Return nil if no match.
1528 (org-test-with-parsed-data "[[target]]"
1529 (org-export-resolve-fuzzy-link
1530 (org-element-map tree
'link
'identity info t
) info
))))
1532 (ert-deftest test-org-export
/resolve-id-link
()
1533 "Test `org-export-resolve-id-link' specifications."
1534 ;; 1. Regular test for custom-id link.
1535 (org-test-with-parsed-data "* Headline1
1542 (org-export-resolve-id-link
1543 (org-element-map tree
'link
'identity info t
) info
)))
1544 ;; 2. Failing test for custom-id link.
1545 (org-test-with-parsed-data "* Headline1
1552 (org-export-resolve-id-link
1553 (org-element-map tree
'link
'identity info t
) info
)))
1554 ;; 3. Test for internal id target.
1555 (org-test-with-parsed-data "* Headline1
1562 (org-export-resolve-id-link
1563 (org-element-map tree
'link
'identity info t
) info
)))
1564 ;; 4. Test for external id target.
1565 (org-test-with-parsed-data "[[id:aaaa]]"
1567 (org-export-resolve-id-link
1568 (org-element-map tree
'link
'identity info t
)
1569 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1571 (ert-deftest test-org-export
/resolve-radio-link
()
1572 "Test `org-export-resolve-radio-link' specifications."
1575 (org-test-with-temp-text "<<<radio>>> radio"
1576 (org-update-radio-target-regexp)
1577 (let* ((tree (org-element-parse-buffer))
1578 (info `(:parse-tree
,tree
)))
1579 (org-export-resolve-radio-link
1580 (org-element-map tree
'link
'identity info t
)
1582 ;; Radio targets are case-insensitive.
1584 (org-test-with-temp-text "<<<RADIO>>> radio"
1585 (org-update-radio-target-regexp)
1586 (let* ((tree (org-element-parse-buffer))
1587 (info `(:parse-tree
,tree
)))
1588 (org-export-resolve-radio-link
1589 (org-element-map tree
'link
'identity info t
)
1591 ;; Radio target with objects.
1593 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1594 (org-update-radio-target-regexp)
1595 (let* ((tree (org-element-parse-buffer))
1596 (info `(:parse-tree
,tree
)))
1597 (org-export-resolve-radio-link
1598 (org-element-map tree
'link
'identity info t
)
1603 ;;; Src-block and example-block
1605 (ert-deftest test-org-export
/unravel-code
()
1606 "Test `org-export-unravel-code' function."
1607 (let ((org-coderef-label-format "(ref:%s)"))
1608 ;; 1. Code without reference.
1609 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1610 (should (equal (org-export-unravel-code (org-element-at-point))
1612 ;; 2. Code with reference.
1613 (org-test-with-temp-text
1614 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1615 (should (equal (org-export-unravel-code (org-element-at-point))
1616 '("(+ 1 1)\n" (1 .
"test")))))
1617 ;; 3. Code with user-defined reference.
1618 (org-test-with-temp-text
1619 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1620 (should (equal (org-export-unravel-code (org-element-at-point))
1621 '("(+ 1 1)\n" (1 .
"test")))))
1622 ;; 4. Code references keys are relative to the current block.
1623 (org-test-with-temp-text "
1632 (should (equal (org-export-unravel-code (org-element-at-point))
1633 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1635 (ert-deftest test-org-export
/format-code-default
()
1636 "Test `org-export-format-code-default' specifications."
1637 ;; Return the empty string when code is empty.
1640 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1641 (org-export-format-code-default
1642 (org-element-map tree
'src-block
'identity info t
) info
))))
1643 ;; Number lines, two whitespace characters before the actual loc.
1646 (org-test-with-parsed-data
1647 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1648 (org-export-format-code-default
1649 (org-element-map tree
'src-block
'identity info t
) info
))))
1650 ;; Put references 6 whitespace characters after the widest line,
1651 ;; wrapped within parenthesis.
1653 (equal "123 (a)\n1 (b)\n"
1654 (let ((org-coderef-label-format "(ref:%s)"))
1655 (org-test-with-parsed-data
1656 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1657 (org-export-format-code-default
1658 (org-element-map tree
'src-block
'identity info t
) info
))))))
1664 (ert-deftest test-org-export
/activate-smart-quotes
()
1665 "Test `org-export-activate-smart-quotes' specifications."
1666 ;; Opening double quotes: standard test.
1669 '("some “paragraph")
1670 (let ((org-export-default-language "en"))
1671 (org-test-with-parsed-data "some \"paragraph"
1672 (org-element-map tree
'plain-text
1673 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1675 ;; Opening quotes: at the beginning of a paragraph.
1679 (let ((org-export-default-language "en"))
1680 (org-test-with-parsed-data "\"begin"
1681 (org-element-map tree
'plain-text
1682 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1684 ;; Opening quotes: after an object.
1688 (let ((org-export-default-language "en"))
1689 (org-test-with-parsed-data "=verb= \"begin"
1690 (org-element-map tree
'plain-text
1691 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1693 ;; Closing quotes: standard test.
1696 '("some” paragraph")
1697 (let ((org-export-default-language "en"))
1698 (org-test-with-parsed-data "some\" paragraph"
1699 (org-element-map tree
'plain-text
1700 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1702 ;; Closing quotes: at the end of a paragraph.
1706 (let ((org-export-default-language "en"))
1707 (org-test-with-parsed-data "end\""
1708 (org-element-map tree
'plain-text
1709 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1711 ;; Apostrophe: standard test.
1714 '("It shouldn’t fail")
1715 (let ((org-export-default-language "en"))
1716 (org-test-with-parsed-data "It shouldn't fail"
1717 (org-element-map tree
'plain-text
1718 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1720 ;; Apostrophe: before an object.
1724 (let ((org-export-default-language "en"))
1725 (org-test-with-parsed-data "a'=b="
1726 (org-element-map tree
'plain-text
1727 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1729 ;; Apostrophe: after an object.
1733 (let ((org-export-default-language "en"))
1734 (org-test-with-parsed-data "=code='s"
1735 (org-element-map tree
'plain-text
1736 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1738 ;; Special case: isolated quotes.
1740 (equal '("“" "”")
1741 (let ((org-export-default-language "en"))
1742 (org-test-with-parsed-data "\"$x$\""
1743 (org-element-map tree
'plain-text
1744 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1746 ;; Smart quotes in secondary strings.
1748 (equal '("“" "”")
1749 (let ((org-export-default-language "en"))
1750 (org-test-with-parsed-data "* \"$x$\""
1751 (org-element-map tree
'plain-text
1752 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1754 ;; Smart quotes in document keywords.
1756 (equal '("“" "”")
1757 (let ((org-export-default-language "en"))
1758 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1759 (org-element-map (plist-get info
:title
) 'plain-text
1760 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1762 ;; Smart quotes in parsed affiliated keywords.
1764 (equal '("“" "”" "Paragraph")
1765 (let ((org-export-default-language "en"))
1766 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1767 (org-element-map tree
'plain-text
1768 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1769 info nil nil t
))))))
1775 (ert-deftest test-org-export
/special-column
()
1776 "Test if the table's special column is properly recognized."
1777 ;; 1. First column is special if it contains only a special marking
1778 ;; characters or empty cells.
1779 (org-test-with-temp-text "
1783 (org-export-table-has-special-column-p
1785 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1786 ;; 2. If the column contains anything else, it isn't special.
1787 (org-test-with-temp-text "
1791 (org-export-table-has-special-column-p
1793 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1794 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1796 (org-test-with-temp-text "
1805 (org-export-table-has-special-column-p
1807 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1808 ;; 4. A first column with only empty cells isn't considered as
1810 (org-test-with-temp-text "
1814 (org-export-table-has-special-column-p
1816 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1818 (ert-deftest test-org-export
/table-row-is-special-p
()
1819 "Test `org-export-table-row-is-special-p' specifications."
1820 ;; 1. A row is special if it has a special marking character in the
1822 (org-test-with-parsed-data "| ! | 1 |"
1824 (org-export-table-row-is-special-p
1825 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1826 ;; 2. A row is special when its first field is "/"
1827 (org-test-with-parsed-data "
1831 (org-export-table-row-is-special-p
1832 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1833 ;; 3. A row only containing alignment cookies is also considered as
1835 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1837 (org-export-table-row-is-special-p
1838 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1839 ;; 4. Everything else isn't considered as special.
1840 (org-test-with-parsed-data "| \alpha | | c |"
1842 (org-export-table-row-is-special-p
1843 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1844 ;; 5. Table's rules are never considered as special rows.
1845 (org-test-with-parsed-data "|---+---|"
1847 (org-export-table-row-is-special-p
1848 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1850 (ert-deftest test-org-export
/has-header-p
()
1851 "Test `org-export-table-has-header-p' specifications."
1852 ;; 1. With an header.
1853 (org-test-with-parsed-data "
1858 (org-export-table-has-header-p
1859 (org-element-map tree
'table
'identity info
'first-match
)
1861 ;; 2. Without an header.
1862 (org-test-with-parsed-data "
1866 (org-export-table-has-header-p
1867 (org-element-map tree
'table
'identity info
'first-match
)
1869 ;; 3. Don't get fooled with starting and ending rules.
1870 (org-test-with-parsed-data "
1876 (org-export-table-has-header-p
1877 (org-element-map tree
'table
'identity info
'first-match
)
1880 (ert-deftest test-org-export
/table-row-group
()
1881 "Test `org-export-table-row-group' specifications."
1882 ;; 1. A rule creates a new group.
1883 (org-test-with-parsed-data "
1890 (mapcar (lambda (row) (org-export-table-row-group row info
))
1891 (org-element-map tree
'table-row
'identity
)))))
1892 ;; 2. Special rows are ignored in count.
1893 (org-test-with-parsed-data "
1900 (mapcar (lambda (row) (org-export-table-row-group row info
))
1901 (org-element-map tree
'table-row
'identity
)))))
1902 ;; 3. Double rules also are ignored in count.
1903 (org-test-with-parsed-data "
1911 (mapcar (lambda (row) (org-export-table-row-group row info
))
1912 (org-element-map tree
'table-row
'identity
))))))
1914 (ert-deftest test-org-export
/table-cell-width
()
1915 "Test `org-export-table-cell-width' specifications."
1916 ;; 1. Width is primarily determined by width cookies. If no cookie
1917 ;; is found, cell's width is nil.
1918 (org-test-with-parsed-data "
1919 | / | <l> | <6> | <l7> |
1924 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1925 (org-element-map tree
'table-cell
'identity info
)))))
1926 ;; 2. The last width cookie has precedence.
1927 (org-test-with-parsed-data "
1934 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1935 (org-element-map tree
'table-cell
'identity info
)))))
1936 ;; 3. Valid width cookies must have a specific row.
1937 (org-test-with-parsed-data "| <6> | cell |"
1941 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1942 (org-element-map tree
'table-cell
'identity
))))))
1944 (ert-deftest test-org-export
/table-cell-alignment
()
1945 "Test `org-export-table-cell-alignment' specifications."
1946 (let ((org-table-number-fraction 0.5)
1947 (org-table-number-regexp "^[0-9]+$"))
1948 ;; 1. Alignment is primarily determined by alignment cookies.
1949 (org-test-with-temp-text "| <l> | <c> | <r> |"
1950 (let* ((tree (org-element-parse-buffer))
1951 (info `(:parse-tree
,tree
)))
1954 '(left center right
)
1955 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1956 (org-element-map tree
'table-cell
'identity
))))))
1957 ;; 2. The last alignment cookie has precedence.
1958 (org-test-with-parsed-data "
1964 '(right right right
)
1965 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1966 (org-element-map tree
'table-cell
'identity
)))))
1967 ;; 3. If there's no cookie, cell's contents determine alignment.
1968 ;; A column mostly made of cells containing numbers will align
1969 ;; its cells to the right.
1970 (org-test-with-parsed-data "
1976 '(right right right
)
1977 (mapcar (lambda (cell)
1978 (org-export-table-cell-alignment cell info
))
1979 (org-element-map tree
'table-cell
'identity
)))))
1980 ;; 4. Otherwise, they will be aligned to the left.
1981 (org-test-with-parsed-data "
1988 (mapcar (lambda (cell)
1989 (org-export-table-cell-alignment cell info
))
1990 (org-element-map tree
'table-cell
'identity
)))))))
1992 (ert-deftest test-org-export
/table-cell-borders
()
1993 "Test `org-export-table-cell-borders' specifications."
1994 ;; 1. Recognize various column groups indicators.
1995 (org-test-with-parsed-data "| / | < | > | <> |"
1998 '((right bottom top
) (left bottom top
) (right bottom top
)
1999 (right left bottom top
))
2000 (mapcar (lambda (cell)
2001 (org-export-table-cell-borders cell info
))
2002 (org-element-map tree
'table-cell
'identity
)))))
2003 ;; 2. Accept shortcuts to define column groups.
2004 (org-test-with-parsed-data "| / | < | < |"
2007 '((right bottom top
) (right left bottom top
) (left bottom top
))
2008 (mapcar (lambda (cell)
2009 (org-export-table-cell-borders cell info
))
2010 (org-element-map tree
'table-cell
'identity
)))))
2011 ;; 3. A valid column groups row must start with a "/".
2012 (org-test-with-parsed-data "
2016 (equal '((top) (top) (bottom) (bottom))
2017 (mapcar (lambda (cell)
2018 (org-export-table-cell-borders cell info
))
2019 (org-element-map tree
'table-cell
'identity
)))))
2020 ;; 4. Take table rules into consideration.
2021 (org-test-with-parsed-data "
2026 (equal '((below top
) (bottom above
))
2027 (mapcar (lambda (cell)
2028 (org-export-table-cell-borders cell info
))
2029 (org-element-map tree
'table-cell
'identity
)))))
2030 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2031 ;; (resp. `bottom' and `below') borders. Any special row is
2033 (org-test-with-parsed-data "
2039 (equal '((bottom below top above
))
2041 (mapcar (lambda (cell)
2042 (org-export-table-cell-borders cell info
))
2043 (org-element-map tree
'table-cell
'identity
)))))))
2045 (ert-deftest test-org-export
/table-dimensions
()
2046 "Test `org-export-table-dimensions' specifications."
2047 ;; 1. Standard test.
2048 (org-test-with-parsed-data "
2053 (org-export-table-dimensions
2054 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2055 ;; 2. Ignore horizontal rules and special columns.
2056 (org-test-with-parsed-data "
2063 (org-export-table-dimensions
2064 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2066 (ert-deftest test-org-export
/table-cell-address
()
2067 "Test `org-export-table-cell-address' specifications."
2068 ;; 1. Standard test: index is 0-based.
2069 (org-test-with-parsed-data "| a | b |"
2071 (equal '((0 .
0) (0 .
1))
2072 (org-element-map tree
'table-cell
2073 (lambda (cell) (org-export-table-cell-address cell info
))
2075 ;; 2. Special column isn't counted, nor are special rows.
2076 (org-test-with-parsed-data "
2081 (org-export-table-cell-address
2082 (car (last (org-element-map tree
'table-cell
'identity info
)))
2084 ;; 3. Tables rules do not count either.
2085 (org-test-with-parsed-data "
2093 (org-export-table-cell-address
2094 (car (last (org-element-map tree
'table-cell
'identity info
)))
2096 ;; 4. Return nil for special cells.
2097 (org-test-with-parsed-data "| / | a |"
2099 (org-export-table-cell-address
2100 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2103 (ert-deftest test-org-export
/get-table-cell-at
()
2104 "Test `org-export-get-table-cell-at' specifications."
2105 ;; 1. Address ignores special columns, special rows and rules.
2106 (org-test-with-parsed-data "
2113 (org-element-contents
2114 (org-export-get-table-cell-at
2116 (org-element-map tree
'table
'identity info
'first-match
)
2118 ;; 2. Return value for a non-existent address is nil.
2119 (org-test-with-parsed-data "| a |"
2121 (org-export-get-table-cell-at
2123 (org-element-map tree
'table
'identity info
'first-match
)
2125 (org-test-with-parsed-data "| / |"
2127 (org-export-get-table-cell-at
2129 (org-element-map tree
'table
'identity info
'first-match
)
2132 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2133 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2134 ;; 1. A cell at a beginning of a row always starts a column group.
2135 (org-test-with-parsed-data "| a |"
2137 (org-export-table-cell-starts-colgroup-p
2138 (org-element-map tree
'table-cell
'identity info
'first-match
)
2140 ;; 2. Special column should be ignored when determining the
2141 ;; beginning of the row.
2142 (org-test-with-parsed-data "
2146 (org-export-table-cell-starts-colgroup-p
2147 (org-element-map tree
'table-cell
'identity info
'first-match
)
2149 ;; 2. Explicit column groups.
2150 (org-test-with-parsed-data "
2156 (org-element-map tree
'table-cell
2158 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2161 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2162 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2163 ;; 1. A cell at the end of a row always ends a column group.
2164 (org-test-with-parsed-data "| a |"
2166 (org-export-table-cell-ends-colgroup-p
2167 (org-element-map tree
'table-cell
'identity info
'first-match
)
2169 ;; 2. Special column should be ignored when determining the
2170 ;; beginning of the row.
2171 (org-test-with-parsed-data "
2175 (org-export-table-cell-ends-colgroup-p
2176 (org-element-map tree
'table-cell
'identity info
'first-match
)
2178 ;; 3. Explicit column groups.
2179 (org-test-with-parsed-data "
2185 (org-element-map tree
'table-cell
2187 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2190 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2191 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2192 ;; 1. A row at the beginning of a table always starts a row group.
2193 ;; So does a row following a table rule.
2194 (org-test-with-parsed-data "
2201 (org-element-map tree
'table-row
2203 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2205 ;; 2. Special rows should be ignored when determining the beginning
2207 (org-test-with-parsed-data "
2216 (org-element-map tree
'table-row
2218 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2221 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2222 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2223 ;; 1. A row at the end of a table always ends a row group. So does
2224 ;; a row preceding a table rule.
2225 (org-test-with-parsed-data "
2232 (org-element-map tree
'table-row
2234 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2236 ;; 2. Special rows should be ignored when determining the beginning
2238 (org-test-with-parsed-data "
2247 (org-element-map tree
'table-row
2249 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2252 (ert-deftest test-org-export
/table-row-starts-header-p
()
2253 "Test `org-export-table-row-starts-header-p' specifications."
2254 ;; 1. Only the row starting the first row group starts the table
2256 (org-test-with-parsed-data "
2264 (org-element-map tree
'table-row
2266 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2268 ;; 2. A row cannot start an header if there's no header in the
2270 (org-test-with-parsed-data "
2274 (org-export-table-row-starts-header-p
2275 (org-element-map tree
'table-row
'identity info
'first-match
)
2278 (ert-deftest test-org-export
/table-row-ends-header-p
()
2279 "Test `org-export-table-row-ends-header-p' specifications."
2280 ;; 1. Only the row starting the first row group starts the table
2282 (org-test-with-parsed-data "
2290 (org-element-map tree
'table-row
2292 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2294 ;; 2. A row cannot start an header if there's no header in the
2296 (org-test-with-parsed-data "
2300 (org-export-table-row-ends-header-p
2301 (org-element-map tree
'table-row
'identity info
'first-match
)
2308 (ert-deftest test-org-export
/inner-template
()
2309 "Test `inner-template' translator specifications."
2312 (let (org-export-registered-backends)
2313 (org-export-define-backend 'test
2314 '((inner-template .
(lambda (contents info
) "Success!"))
2315 (headline .
(lambda (h c i
) "Headline"))))
2316 (org-test-with-temp-text "* Headline"
2317 (org-export-as 'test
)))))
2318 ;; Inner template is applied even in a "body-only" export.
2321 (let (org-export-registered-backends)
2322 (org-export-define-backend 'test
2323 '((inner-template .
(lambda (contents info
) "Success!"))
2324 (headline .
(lambda (h c i
) "Headline"))))
2325 (org-test-with-temp-text "* Headline"
2326 (org-export-as 'test nil nil
'body-only
))))))
2328 (ert-deftest test-org-export
/template
()
2329 "Test `template' translator specifications."
2332 (let (org-export-registered-backends)
2333 (org-export-define-backend 'test
2334 '((template .
(lambda (contents info
) "Success!"))
2335 (headline .
(lambda (h c i
) "Headline"))))
2336 (org-test-with-temp-text "* Headline"
2337 (org-export-as 'test
)))))
2338 ;; Template is not applied in a "body-only" export.
2341 (let (org-export-registered-backends)
2342 (org-export-define-backend 'test
2343 '((template .
(lambda (contents info
) "Success!"))
2344 (headline .
(lambda (h c i
) "Headline"))))
2345 (org-test-with-temp-text "* Headline"
2346 (org-export-as 'test nil nil
'body-only
))))))
2352 (ert-deftest test-org-export
/get-next-element
()
2353 "Test `org-export-get-next-element' specifications."
2357 (org-test-with-parsed-data "* Headline\n*a* b"
2358 (org-export-get-next-element
2359 (org-element-map tree
'bold
'identity info t
) info
))))
2360 ;; Return nil when no previous element.
2362 (org-test-with-parsed-data "* Headline\na *b*"
2363 (org-export-get-next-element
2364 (org-element-map tree
'bold
'identity info t
) info
)))
2365 ;; Non-exportable elements are ignored.
2367 (let ((org-export-with-timestamps nil
))
2368 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2369 (org-export-get-next-element
2370 (org-element-map tree
'entity
'identity info t
) info
))))
2371 ;; Find next element in secondary strings.
2374 (org-test-with-parsed-data "* a =verb="
2376 (org-export-get-next-element
2377 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2378 ;; Find next element in document keywords.
2381 (org-test-with-parsed-data "#+TITLE: a =verb="
2383 (org-export-get-next-element
2385 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2386 ;; Find next element in parsed affiliated keywords.
2389 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2391 (org-export-get-next-element
2392 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2393 ;; With optional argument N, return a list containing all the
2394 ;; following elements.
2397 '(bold code underline
)
2398 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2400 (org-export-get-next-element
2401 (org-element-map tree
'italic
'identity info t
) info t
)))))
2402 ;; When N is a positive integer, return a list containing up to
2403 ;; N following elements.
2407 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2409 (org-export-get-next-element
2410 (org-element-map tree
'italic
'identity info t
) info
2))))))
2412 (ert-deftest test-org-export
/get-previous-element
()
2413 "Test `org-export-get-previous-element' specifications."
2417 (org-test-with-parsed-data "* Headline\na *b*"
2418 (org-export-get-previous-element
2419 (org-element-map tree
'bold
'identity info t
) info
))))
2420 ;; Return nil when no previous element.
2422 (org-test-with-parsed-data "* Headline\n*a* b"
2423 (org-export-get-previous-element
2424 (org-element-map tree
'bold
'identity info t
) info
)))
2425 ;; Non-exportable elements are ignored.
2427 (let ((org-export-with-timestamps nil
))
2428 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2429 (org-export-get-previous-element
2430 (org-element-map tree
'entity
'identity info t
) info
))))
2431 ;; Find previous element in secondary strings.
2434 (org-test-with-parsed-data "* =verb= a"
2436 (org-export-get-previous-element
2437 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2438 ;; Find previous element in document keywords.
2441 (org-test-with-parsed-data "#+TITLE: =verb= a"
2443 (org-export-get-previous-element
2445 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2446 ;; Find previous element in parsed affiliated keywords.
2449 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2451 (org-export-get-previous-element
2452 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2453 ;; With optional argument N, return a list containing up to
2454 ;; N previous elements.
2456 (equal '(underline italic bold
)
2457 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2459 (org-export-get-previous-element
2460 (org-element-map tree
'code
'identity info t
) info t
)))))
2461 ;; When N is a positive integer, return a list containing up to
2462 ;; N previous elements.
2464 (equal '(italic bold
)
2465 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2467 (org-export-get-previous-element
2468 (org-element-map tree
'code
'identity info t
) info
2))))))
2472 ;;; test-org-export.el end here