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 (defun org-test-default-backend ()
28 "Return a default export back-end.
29 This back-end simply returns parsed data as Org syntax."
30 (org-export-create-backend
31 :transcoders
(let (transcode-table)
32 (dolist (type (append org-element-all-elements
33 org-element-all-objects
)
37 (lambda (obj contents info
)
39 (intern (format "org-element-%s-interpreter"
44 (defmacro org-test-with-parsed-data
(data &rest body
)
45 "Execute body with parsed data available.
47 DATA is a string containing the data to be parsed. BODY is the
48 body to execute. Parse tree is available under the `tree'
49 variable, and communication channel under `info'.
51 This function calls `org-export-collect-tree-properties'. As
52 such, `:ignore-list' (for `org-element-map') and
53 `:parse-tree' (for `org-export-get-genealogy') properties are
54 already filled in `info'."
55 (declare (debug (form body
)) (indent 1))
56 `(org-test-with-temp-text ,data
57 (let* ((tree (org-element-parse-buffer))
58 (info (org-export-collect-tree-properties
59 tree
(org-export-get-environment))))
66 (ert-deftest test-org-export
/bind-keyword
()
67 "Test reading #+BIND: keywords."
68 ;; Test with `org-export-allow-bind-keywords' set to t.
70 (org-test-with-temp-text "#+BIND: test-ox-var value"
71 (let ((org-export-allow-bind-keywords t
))
72 (org-export-get-environment)
73 (eq test-ox-var
'value
))))
74 ;; Test with `org-export-allow-bind-keywords' set to nil.
76 (org-test-with-temp-text "#+BIND: test-ox-var value"
77 (let ((org-export-allow-bind-keywords nil
))
78 (org-export-get-environment)
79 (boundp 'test-ox-var
))))
80 ;; BIND keywords are case-insensitive.
82 (org-test-with-temp-text "#+bind: test-ox-var value"
83 (let ((org-export-allow-bind-keywords t
))
84 (org-export-get-environment)
85 (eq test-ox-var
'value
))))
86 ;; Preserve order of BIND keywords.
88 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
89 (let ((org-export-allow-bind-keywords t
))
90 (org-export-get-environment)
92 ;; Read BIND keywords in setup files.
94 (org-test-with-temp-text
95 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
96 (let ((org-export-allow-bind-keywords t
))
97 (org-export-get-environment)
98 (eq variable
'value
))))
99 ;; Verify that bound variables are seen during export.
102 (org-test-with-temp-text "#+BIND: test-ox-var value"
103 (let ((org-export-allow-bind-keywords t
))
105 (org-export-create-backend
107 '((section .
(lambda (s c i
)
108 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
110 (ert-deftest test-org-export
/parse-option-keyword
()
111 "Test reading all standard #+OPTIONS: items."
114 (org-export--parse-option-keyword
115 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
116 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
119 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
120 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
121 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
122 :with-footnotes t
:with-inlinetasks nil
:with-priority t
123 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
124 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
125 :with-todo-keywords t
)))
126 ;; Test some special values.
129 (org-export--parse-option-keyword
130 "arch:headline creator:comment d:(\"TEST\")
131 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
134 :with-archived-trees headline
:with-creator comment
135 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
136 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
138 (ert-deftest test-org-export
/get-inbuffer-options
()
139 "Test reading all standard export keywords."
140 ;; Properties should follow buffer order.
143 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
144 (org-export--get-inbuffer-options))
145 '(:language
"fr" :creator
"Me" :email
"email")))
146 ;; Parse document keywords.
149 (org-test-with-temp-text "#+AUTHOR: Me"
150 (org-export--get-inbuffer-options))
152 ;; Test `space' behaviour.
155 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
156 (org-export--get-inbuffer-options))
157 '(:title
("Some title with spaces"))))
158 ;; Test `newline' behaviour.
161 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
162 (org-export--get-inbuffer-options))
163 '(:description
"With\ntwo lines")))
164 ;; Test `split' behaviour.
167 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
168 (org-export--get-inbuffer-options))
169 '(:select-tags
("a" "b"))))
170 ;; Options set through SETUPFILE.
173 (org-test-with-temp-text
174 (format "#+DESCRIPTION: l1
178 #+SETUPFILE: \"%s/examples/setupfile.org\"
184 (org-export--get-inbuffer-options))
185 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
187 ;; More than one property can refer to the same buffer keyword.
189 (equal '(:k2
"value" :k1
"value")
190 (let ((backend (org-export-create-backend
191 :options
'((:k1
"KEYWORD")
193 (org-test-with-temp-text "#+KEYWORD: value"
194 (org-export--get-inbuffer-options backend
))))))
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
/set-title
()
272 "Test title setting."
273 ;; If no title if specified, use file name.
277 (org-test-with-temp-text-in-file "Test"
280 (org-export-create-backend
282 '((template .
(lambda (text info
)
283 (org-element-interpret-data
284 (plist-get info
:title
) info
))))))
285 (file-name-nondirectory
286 (file-name-sans-extension (buffer-file-name)))))))
287 ;; If no title is specified, and no file is associated to the
288 ;; buffer, use buffer's name.
292 (org-test-with-temp-text "Test"
295 (org-export-create-backend
297 '((template .
(lambda (text info
)
298 (org-element-interpret-data
299 (plist-get info
:title
) info
))))))
301 ;; If a title is specified, use it.
305 (org-test-with-temp-text-in-file "#+TITLE: Title\nTest"
308 (org-export-create-backend
310 '((template .
(lambda (text info
)
311 (org-element-interpret-data
312 (plist-get info
:title
) info
)))))))))
313 ;; If an empty title is specified, do not set it.
317 (org-test-with-temp-text-in-file "#+TITLE:\nTest"
320 (org-export-create-backend
322 '((template .
(lambda (text info
)
323 (org-element-interpret-data
324 (plist-get info
:title
) info
))))))))))
326 (ert-deftest test-org-export
/handle-options
()
327 "Test if export options have an impact on output."
328 ;; Test exclude tags for headlines and inlinetasks.
331 (org-test-with-temp-text "* Head1 :noexp:"
332 (org-export-as (org-test-default-backend)
333 nil nil nil
'(:exclude-tags
("noexp"))))))
334 ;; Test include tags for headlines and inlinetasks.
336 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
337 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
338 (let ((org-tags-column 0))
339 (org-export-as (org-test-default-backend)
340 nil nil nil
'(:select-tags
("exp")))))))
341 ;; Test mixing include tags and exclude tags.
344 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
345 (org-test-with-temp-text "
347 ** Sub-Head1 :noexport:
350 ** Sub-Head1 :export:"
351 (org-export-as (org-test-default-backend) nil nil nil
352 '(:select-tags
("export") :exclude-tags
("noexport"))))))
356 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
357 (org-test-with-temp-text "* TODO Head1"
358 (org-export-as (org-test-default-backend)
359 nil nil nil
'(:with-tasks nil
))))))
361 (equal "* TODO Head1\n"
362 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
363 (org-test-with-temp-text "* TODO Head1"
364 (org-export-as (org-test-default-backend)
365 nil nil nil
'(:with-tasks t
))))))
369 (org-test-with-temp-text "* Head1 :archive:"
370 (let ((org-archive-tag "archive"))
371 (org-export-as (org-test-default-backend)
372 nil nil nil
'(:with-archived-trees nil
))))))
375 "\\* Head1[ \t]+:archive:"
376 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
377 (let ((org-archive-tag "archive"))
378 (org-export-as (org-test-default-backend) nil nil nil
379 '(:with-archived-trees headline
))))))
382 "\\`\\* Head1[ \t]+:archive:\n\\'"
383 (org-test-with-temp-text "* Head1 :archive:"
384 (let ((org-archive-tag "archive"))
385 (org-export-as (org-test-default-backend)
386 nil nil nil
'(:with-archived-trees t
))))))
389 (equal "CLOCK: [2012-04-29 sun. 10:45]\n"
390 (let ((org-clock-string "CLOCK:"))
391 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
392 (org-export-as (org-test-default-backend)
393 nil nil nil
'(:with-clocks t
))))))
396 (let ((org-clock-string "CLOCK:"))
397 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
398 (org-export-as (org-test-default-backend)
399 nil nil nil
'(:with-clocks nil
))))))
403 (let ((org-drawers '("TEST")))
404 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
405 (org-export-as (org-test-default-backend)
406 nil nil nil
'(:with-drawers nil
))))))
408 (equal ":TEST:\ncontents\n:END:\n"
409 (let ((org-drawers '("TEST")))
410 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
411 (org-export-as (org-test-default-backend)
412 nil nil nil
'(:with-drawers t
))))))
414 (equal ":FOO:\nkeep\n:END:\n"
415 (let ((org-drawers '("FOO" "BAR")))
416 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
417 (org-export-as (org-test-default-backend)
418 nil nil nil
'(:with-drawers
("FOO")))))))
420 (equal ":FOO:\nkeep\n:END:\n"
421 (let ((org-drawers '("FOO" "BAR")))
422 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
423 (org-export-as (org-test-default-backend)
424 nil nil nil
'(:with-drawers
(not "BAR")))))))
428 (let ((org-footnote-section nil
))
429 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
430 (org-trim (org-export-as (org-test-default-backend)
431 nil nil nil
'(:with-footnotes nil
)))))))
433 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
434 (let ((org-footnote-section nil
))
435 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
436 (org-trim (org-export-as (org-test-default-backend)
437 nil nil nil
'(:with-footnotes t
)))))))
439 (when (featurep 'org-inlinetask
)
443 (let ((org-inlinetask-min-level 15))
444 (org-test-with-temp-text "*************** Task"
445 (org-export-as (org-test-default-backend)
446 nil nil nil
'(:with-inlinetasks nil
))))))
450 (let ((org-inlinetask-min-level 15))
451 (org-test-with-temp-text
452 "*************** Task\nContents\n*************** END"
453 (org-export-as (org-test-default-backend)
454 nil nil nil
'(:with-inlinetasks nil
)))))))
457 (equal "CLOSED: [2012-04-29 sun. 10:45]\n"
458 (let ((org-closed-string "CLOSED:"))
459 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
460 (org-export-as (org-test-default-backend)
461 nil nil nil
'(:with-planning t
))))))
464 (let ((org-closed-string "CLOSED:"))
465 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
466 (org-export-as (org-test-default-backend)
467 nil nil nil
'(:with-planning nil
))))))
468 ;; Statistics cookies.
471 (org-test-with-temp-text "[0/0]"
472 (org-export-as (org-test-default-backend)
473 nil nil nil
'(:with-statistics-cookies nil
))))))
475 (ert-deftest test-org-export
/with-timestamps
()
476 "Test `org-export-with-timestamps' specifications."
480 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"
481 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
482 (org-export-as (org-test-default-backend)
483 nil nil nil
'(:with-timestamps t
)))))
488 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
489 (org-export-as (org-test-default-backend)
490 nil nil nil
'(:with-timestamps nil
)))))
494 "<2012-03-29 Thu>\n\nParagraph <2012-03-29 Thu>[2012-03-29 Thu]"
495 (org-test-with-temp-text
496 "<2012-03-29 Thu>[2012-03-29 Thu]
498 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
499 (org-trim (org-export-as (org-test-default-backend)
500 nil nil nil
'(:with-timestamps active
))))))
504 "[2012-03-29 Thu]\n\nParagraph <2012-03-29 Thu>[2012-03-29 Thu]"
505 (org-test-with-temp-text
506 "<2012-03-29 Thu>[2012-03-29 Thu]
508 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
509 (org-trim (org-export-as (org-test-default-backend)
510 nil nil nil
'(:with-timestamps inactive
)))))))
512 (ert-deftest test-org-export
/comment-tree
()
513 "Test if export process ignores commented trees."
516 (let ((org-comment-string "COMMENT"))
517 (org-test-with-temp-text "* COMMENT Head1"
518 (org-export-as (org-test-default-backend)))))))
520 (ert-deftest test-org-export
/export-scope
()
521 "Test all export scopes."
522 (org-test-with-temp-text "
529 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
530 "text\n*** Head3\n"))
532 (goto-char (point-min))
535 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
538 (goto-char (point-min))
540 (transient-mark-mode 1)
541 (push-mark (point) t t
)
542 (goto-char (point-at-eol))
543 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
544 ;; Subtree with a code block calling another block outside.
547 (org-test-with-temp-text "
549 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
554 #+BEGIN_SRC emacs-lisp
558 (org-export-as (org-test-default-backend) 'subtree
))))
560 (let ((backend (org-test-default-backend)))
561 (setf (org-export-backend-transcoders backend
)
562 (cons '(template .
(lambda (body i
)
563 (format "BEGIN\n%sEND" body
)))
564 (org-export-backend-transcoders backend
)))
565 (org-test-with-temp-text "Text"
566 (should (equal (org-export-as backend nil nil
'body-only
)
568 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
570 (ert-deftest test-org-export
/output-file-name
()
571 "Test `org-export-output-file-name' specifications."
572 ;; Export from a file: name is built from original file name.
574 (org-test-with-temp-text-in-file "Test"
575 (equal (concat (file-name-as-directory ".")
576 (file-name-nondirectory
577 (file-name-sans-extension (buffer-file-name))))
578 (file-name-sans-extension (org-export-output-file-name ".ext")))))
579 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
581 (org-test-with-temp-text-in-file
582 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
583 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
584 ;; From a buffer not associated to a file, too.
586 (org-test-with-temp-text
587 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
588 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
589 ;; When provided name is absolute, preserve it.
591 (org-test-with-temp-text
592 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
593 (expand-file-name "test"))
594 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
595 ;; When PUB-DIR argument is provided, use it.
597 (org-test-with-temp-text-in-file "Test"
598 (equal (file-name-directory
599 (org-export-output-file-name ".ext" nil
"dir/"))
601 ;; When returned name would overwrite original file, add EXTENSION
604 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
605 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
607 (ert-deftest test-org-export
/expand-include
()
608 "Test file inclusion in an Org buffer."
609 ;; Error when file isn't specified.
611 (org-test-with-temp-text "#+INCLUDE: dummy.org"
612 (org-export-expand-include-keyword)))
613 ;; Full insertion with recursive inclusion.
614 (org-test-with-temp-text
615 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
616 (org-export-expand-include-keyword)
617 (should (equal (buffer-string)
618 "Small Org file with an include keyword.
620 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
626 ;; Localized insertion.
627 (org-test-with-temp-text
628 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
630 (org-export-expand-include-keyword)
631 (should (equal (buffer-string)
632 "Small Org file with an include keyword.\n")))
633 ;; Insertion with constraints on headlines level.
636 "* Top heading\n** Heading\nbody\n"
637 (org-test-with-temp-text
639 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
641 (org-export-expand-include-keyword)
645 "* Top heading\n* Heading\nbody\n"
646 (org-test-with-temp-text
648 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
650 (org-export-expand-include-keyword)
652 ;; Inclusion within an example block.
653 (org-test-with-temp-text
654 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
656 (org-export-expand-include-keyword)
660 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
661 ;; Inclusion within a src-block.
662 (org-test-with-temp-text
664 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
666 (org-export-expand-include-keyword)
667 (should (equal (buffer-string)
668 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
670 (ert-deftest test-org-export
/expand-macro
()
671 "Test macro expansion in an Org buffer."
672 ;; Standard macro expansion.
674 (equal "#+MACRO: macro1 value\nvalue\n"
675 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
676 (org-export-as (org-test-default-backend)))))
677 ;; Expand specific macros.
679 (equal "me 2012-03-29 me@here Title\n"
680 (org-test-with-temp-text
686 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
687 (let ((output (org-export-as (org-test-default-backend))))
688 (substring output
(string-match ".*\n\\'" output
))))))
689 ;; Expand specific macros when property contained a regular macro
693 (org-test-with-temp-text "
694 #+MACRO: macro1 value
695 #+TITLE: {{{macro1}}}
697 (let ((output (org-export-as (org-test-default-backend))))
698 (substring output
(string-match ".*\n\\'" output
))))))
699 ;; Expand macros with templates in included files.
702 (org-test-with-temp-text
703 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
704 {{{included-macro}}}" org-test-dir
)
705 (let ((output (org-export-as (org-test-default-backend))))
706 (substring output
(string-match ".*\n\\'" output
)))))))
708 (ert-deftest test-org-export
/user-ignore-list
()
709 "Test if `:ignore-list' accepts user input."
710 (let ((backend (org-test-default-backend)))
711 (setf (org-export-backend-transcoders backend
)
712 (cons '(template .
(lambda (body i
)
713 (format "BEGIN\n%sEND" body
)))
714 (org-export-backend-transcoders backend
)))
715 (org-test-with-temp-text "Text"
716 (should (equal (org-export-as backend nil nil
'body-only
)
718 (should (equal (org-export-as backend
) "BEGIN\nText\nEND"))))
722 (let ((org-export-filter-parse-tree-functions
723 '((lambda (data backend info
)
724 ;; Ignore headlines with the word "note" in their title.
725 (org-element-map data
'headline
727 (when (string-match "\\<note\\>"
728 (org-element-property :raw-value
730 (org-export-ignore-element headline info
)))
733 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
734 (org-export-as (org-test-default-backend)))))))
736 (ert-deftest test-org-export
/before-processing-hook
()
737 "Test `org-export-before-processing-hook'."
740 "#+MACRO: mac val\nTest\n"
741 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
742 (let ((org-export-before-processing-hook
744 (while (re-search-forward "{{{" nil t
)
745 (let ((object (org-element-context)))
746 (when (eq (org-element-type object
) 'macro
)
748 (org-element-property :begin object
)
749 (org-element-property :end object
)))))))))
750 (org-export-as (org-test-default-backend)))))))
752 (ert-deftest test-org-export
/before-parsing-hook
()
753 "Test `org-export-before-parsing-hook'."
755 (equal "Body 1\nBody 2\n"
756 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
757 (let ((org-export-before-parsing-hook
759 (goto-char (point-min))
760 (while (re-search-forward org-outline-regexp-bol nil t
)
762 (point-at-bol) (progn (forward-line) (point))))))))
763 (org-export-as (org-test-default-backend)))))))
767 ;;; Affiliated Keywords
769 (ert-deftest test-org-export
/read-attribute
()
770 "Test `org-export-read-attribute' specifications."
774 (org-export-read-attribute
776 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
777 (org-element-at-point)))
779 ;; Return nil on empty attribute.
781 (org-export-read-attribute
783 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
784 ;; Return nil on "nil" string.
786 (equal '(:a nil
:b nil
)
787 (org-export-read-attribute
789 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
790 (org-element-at-point)))))
791 ;; Return nil on empty string.
793 (equal '(:a nil
:b nil
)
794 (org-export-read-attribute
796 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
797 (org-element-at-point)))))
798 ;; Return empty string when value is "".
801 (org-export-read-attribute
803 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
804 (org-element-at-point)))))
805 ;; Return \"\" when value is """".
808 (org-export-read-attribute
810 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
811 (org-element-at-point)))))
812 ;; Ignore text before first property.
815 (org-export-read-attribute
817 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
818 (org-element-at-point))))))
820 (ert-deftest test-org-export
/get-caption
()
821 "Test `org-export-get-caption' specifications."
822 ;; Without optional argument, return long caption
826 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
827 (org-export-get-caption (org-element-at-point)))))
828 ;; With optional argument, return short caption.
832 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
833 (org-export-get-caption (org-element-at-point) t
))))
834 ;; Multiple lines are separated by white spaces.
838 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
839 (org-export-get-caption (org-element-at-point))))))
845 (ert-deftest test-org-export
/define-backend
()
846 "Test back-end definition and accessors."
849 (equal '((headline . my-headline-test
))
850 (let (org-export--registered-backends)
851 (org-export-define-backend 'test
'((headline . my-headline-test
)))
852 (org-export-get-all-transcoders 'test
))))
855 (equal '((:filter-headline . my-filter
))
856 (let (org-export--registered-backends)
857 (org-export-define-backend 'test
858 '((headline . my-headline-test
))
859 :filters-alist
'((:filter-headline . my-filter
)))
860 (org-export-backend-filters (org-export-get-backend 'test
)))))
863 (equal '((:prop value
))
864 (let (org-export--registered-backends)
865 (org-export-define-backend 'test
866 '((headline . my-headline-test
))
867 :options-alist
'((:prop value
)))
868 (org-export-backend-options (org-export-get-backend 'test
)))))
871 (equal '(?k
"Test Export" test
)
872 (let (org-export--registered-backends)
873 (org-export-define-backend 'test
874 '((headline . my-headline-test
))
875 :menu-entry
'(?k
"Test Export" test
))
876 (org-export-backend-menu (org-export-get-backend 'test
)))))
879 (equal '(("TEST" . org-element-export-block-parser
))
880 (let (org-export--registered-backends org-element-block-name-alist
)
881 (org-export-define-backend 'test
882 '((headline . my-headline-test
))
883 :export-block
'("test"))
884 org-element-block-name-alist
))))
886 (ert-deftest test-org-export
/define-derived-backend
()
887 "Test `org-export-define-derived-backend' specifications."
888 ;; Error when parent back-end is not defined.
890 (let (org-export--registered-backends)
891 (org-export-define-derived-backend 'test
'parent
)))
892 ;; Append translation table to parent's.
894 (equal '((:headline . test
) (:headline . parent
))
895 (let (org-export--registered-backends)
896 (org-export-define-backend 'parent
'((:headline . parent
)))
897 (org-export-define-derived-backend 'test
'parent
898 :translate-alist
'((:headline . test
)))
899 (org-export-get-all-transcoders 'test
))))
900 ;; Options defined in the new back have priority over those defined
904 (let (org-export--registered-backends)
905 (org-export-define-backend 'parent
906 '((:headline . parent
))
907 :options-alist
'((:a nil nil
'parent
)))
908 (org-export-define-derived-backend 'test
'parent
909 :options-alist
'((:a nil nil
'test
)))
910 (plist-get (org-export--get-global-options
911 (org-export-get-backend 'test
))
914 (ert-deftest test-org-export
/derived-backend-p
()
915 "Test `org-export-derived-backend-p' specifications."
916 ;; Non-nil with direct match.
918 (let (org-export--registered-backends)
919 (org-export-define-backend 'test
'((headline . test
)))
920 (org-export-derived-backend-p 'test
'test
)))
922 (let (org-export--registered-backends)
923 (org-export-define-backend 'test
'((headline . test
)))
924 (org-export-define-derived-backend 'test2
'test
)
925 (org-export-derived-backend-p 'test2
'test2
)))
926 ;; Non-nil with a direct parent.
928 (let (org-export--registered-backends)
929 (org-export-define-backend 'test
'((headline . test
)))
930 (org-export-define-derived-backend 'test2
'test
)
931 (org-export-derived-backend-p 'test2
'test
)))
932 ;; Non-nil with an indirect parent.
934 (let (org-export--registered-backends)
935 (org-export-define-backend 'test
'((headline . test
)))
936 (org-export-define-derived-backend 'test2
'test
)
937 (org-export-define-derived-backend 'test3
'test2
)
938 (org-export-derived-backend-p 'test3
'test
)))
941 (let (org-export--registered-backends)
942 (org-export-define-backend 'test
'((headline . test
)))
943 (org-export-define-backend 'test2
'((headline . test2
)))
944 (org-export-derived-backend-p 'test2
'test
)))
946 (let (org-export--registered-backends)
947 (org-export-define-backend 'test
'((headline . test
)))
948 (org-export-define-backend 'test2
'((headline . test2
)))
949 (org-export-define-derived-backend 'test3
'test2
)
950 (org-export-derived-backend-p 'test3
'test
))))
952 (ert-deftest test-org-export
/get-all-transcoders
()
953 "Test `org-export-get-all-transcoders' specifications."
954 ;; Return nil when back-end cannot be found.
955 (should-not (org-export-get-all-transcoders nil
))
956 ;; Same as `org-export-transcoders' if no parent.
958 (equal '((headline . ignore
))
959 (org-export-get-all-transcoders
960 (org-export-create-backend
961 :transcoders
'((headline . ignore
))))))
962 ;; But inherit from all ancestors whenever possible.
964 (equal '((section . ignore
) (headline . ignore
))
965 (let (org-export--registered-backends)
966 (org-export-define-backend 'b1
'((headline . ignore
)))
967 (org-export-get-all-transcoders
968 (org-export-create-backend
969 :parent
'b1
:transcoders
'((section . ignore
)))))))
971 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
972 (let (org-export--registered-backends)
973 (org-export-define-backend 'b1
'((headline . ignore
)))
974 (org-export-define-derived-backend 'b2
'b1
975 :translate-alist
'((section . ignore
)))
976 (org-export-get-all-transcoders
977 (org-export-create-backend
978 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
979 ;; Back-end transcoders overrule inherited ones.
982 (let (org-export--registered-backends)
983 (org-export-define-backend 'b1
'((headline . a
)))
985 (org-export-get-all-transcoders
986 (org-export-create-backend
987 :parent
'b1
:transcoders
'((headline . b
))))))))))
989 (ert-deftest test-org-export
/get-all-options
()
990 "Test `org-export-get-all-options' specifications."
991 ;; Return nil when back-end cannot be found.
992 (should-not (org-export-get-all-options nil
))
993 ;; Same as `org-export-options' if no parent.
995 (equal '((headline . ignore
))
996 (org-export-get-all-options
997 (org-export-create-backend
998 :options
'((headline . ignore
))))))
999 ;; But inherit from all ancestors whenever possible.
1001 (equal '((:key2 value2
) (:key1 value1
))
1002 (let (org-export--registered-backends)
1003 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1004 (org-export-get-all-options
1005 (org-export-create-backend
1006 :parent
'b1
:options
'((:key2 value2
)))))))
1008 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1009 (let (org-export--registered-backends)
1010 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1011 (org-export-define-derived-backend 'b2
'b1
1012 :options-alist
'((:key2 value2
)))
1013 (org-export-get-all-options
1014 (org-export-create-backend
1015 :parent
'b2
:options
'((:key3 value3
)))))))
1016 ;; Back-end options overrule inherited ones.
1019 (let (org-export--registered-backends)
1020 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1022 (org-export-get-all-options
1023 (org-export-create-backend
1024 :parent
'b1
:options
'((:key1 . b
))))))))))
1026 (ert-deftest test-org-export
/get-all-filters
()
1027 "Test `org-export-get-all-filters' specifications."
1028 ;; Return nil when back-end cannot be found.
1029 (should-not (org-export-get-all-filters nil
))
1030 ;; Same as `org-export-filters' if no parent.
1032 (equal '((:filter-headline . ignore
))
1033 (org-export-get-all-filters
1034 (org-export-create-backend
1035 :filters
'((:filter-headline . ignore
))))))
1036 ;; But inherit from all ancestors whenever possible.
1038 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1039 (let (org-export--registered-backends)
1040 (org-export-define-backend 'b1
1041 nil
:filters-alist
'((:filter-headline . ignore
)))
1042 (org-export-get-all-filters
1043 (org-export-create-backend
1044 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1046 (equal '((:filter-paragraph . ignore
)
1047 (:filter-section . ignore
)
1048 (:filter-headline . ignore
))
1049 (let (org-export--registered-backends)
1050 (org-export-define-backend 'b1
1051 nil
:filters-alist
'((:filter-headline . ignore
)))
1052 (org-export-define-derived-backend 'b2
'b1
1053 :filters-alist
'((:filter-section . ignore
)))
1054 (org-export-get-all-filters
1055 (org-export-create-backend
1056 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1057 ;; Back-end filters overrule inherited ones.
1060 (let (org-export--registered-backends)
1061 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1062 (cdr (assq :filter-headline
1063 (org-export-get-all-filters
1064 (org-export-create-backend
1065 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1067 (ert-deftest test-org-export
/with-backend
()
1068 "Test `org-export-with-backend' definition."
1069 ;; Error when calling an undefined back-end
1070 (should-error (org-export-with-backend nil
"Test"))
1071 ;; Error when called back-end doesn't have an appropriate
1074 (org-export-with-backend
1075 (org-export-create-backend :transcoders
'((headline . ignore
)))
1077 ;; Otherwise, export using correct transcoder
1080 (let (org-export--registered-backends)
1081 (org-export-define-backend 'test
1082 '((plain-text .
(lambda (text contents info
) "Failure"))))
1083 (org-export-define-backend 'test2
1084 '((plain-text .
(lambda (text contents info
) "Success"))))
1085 (org-export-with-backend 'test2
"Test"))))
1086 ;; Provide correct back-end if transcoder needs to use recursive
1090 (let ((test-back-end
1091 (org-export-create-backend
1093 '((headline .
(lambda (headline contents info
)
1095 (org-element-property :title headline
)
1097 (plain-text .
(lambda (text info
) "Success"))))))
1098 (org-export-string-as
1100 (org-export-create-backend
1102 '((headline .
(lambda (headline contents info
)
1103 (org-export-with-backend
1104 test-back-end headline contents info
))))))))))
1106 (ert-deftest test-org-export
/data-with-backend
()
1107 "Test `org-export-data-with-backend' specifications."
1108 ;; Error when calling an undefined back-end.
1109 (should-error (org-export-data-with-backend nil
"nil" nil
))
1110 ;; Otherwise, export data recursively, using correct back-end.
1114 (org-export-data-with-backend
1116 (org-export-create-backend
1118 '((plain-text .
(lambda (text info
) "Success"))
1119 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1120 '(:with-emphasize t
)))))
1126 (ert-deftest test-org-export
/export-snippet
()
1127 "Test export snippets transcoding."
1129 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1130 (let ((backend (org-test-default-backend)))
1131 (setf (org-export-backend-name backend
) 'test
)
1132 (setf (org-export-backend-transcoders backend
)
1133 (cons (cons 'export-snippet
1134 (lambda (snippet contents info
)
1135 (when (eq (org-export-snippet-backend snippet
) 'test
)
1136 (org-element-property :value snippet
))))
1137 (org-export-backend-transcoders backend
)))
1138 (let ((org-export-snippet-translation-alist nil
))
1139 (should (equal (org-export-as backend
) "A\n")))
1140 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1141 (should (equal (org-export-as backend
) "AB\n")))))
1142 ;; Ignored export snippets do not remove any blank.
1144 (equal "begin end\n"
1145 (org-test-with-parsed-data "begin @@test:A@@ end"
1146 (org-export-data-with-backend
1148 (org-export-create-backend
1150 '((paragraph .
(lambda (paragraph contents info
) contents
))
1151 (section .
(lambda (section contents info
) contents
))))
1158 (ert-deftest test-org-export
/footnotes
()
1159 "Test footnotes specifications."
1160 (let ((org-footnote-section nil
)
1161 (org-export-with-footnotes t
))
1162 ;; 1. Read every type of footnote.
1165 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1166 (org-test-with-parsed-data
1167 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1168 (org-element-map tree
'footnote-reference
1170 (let ((def (org-export-get-footnote-definition ref info
)))
1171 (cons (org-export-get-footnote-number ref info
)
1172 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1173 (car (org-element-contents
1174 (car (org-element-contents def
))))))))
1176 ;; 2. Test nested footnotes order.
1179 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
1180 (org-test-with-parsed-data
1181 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1182 (org-element-map tree
'footnote-reference
1184 (when (org-export-footnote-first-reference-p ref info
)
1185 (cons (org-export-get-footnote-number ref info
)
1186 (org-element-property :label ref
))))
1188 ;; 3. Test nested footnote in invisible definitions.
1189 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1190 ;; Hide definitions.
1191 (narrow-to-region (point) (point-at-eol))
1192 (let* ((tree (org-element-parse-buffer))
1193 (info (org-combine-plists
1194 `(:parse-tree
,tree
)
1195 (org-export-collect-tree-properties
1196 tree
(org-export-get-environment)))))
1197 ;; Both footnotes should be seen.
1199 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
1200 ;; 4. Test footnotes definitions collection.
1203 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1205 \[fn:2] B [fn:3] [fn::D].
1208 (length (org-export-collect-footnote-definitions tree info
)))))
1209 ;; 5. Test export of footnotes defined outside parsing scope.
1212 "ParagraphOut of scope\n"
1213 (org-test-with-temp-text "[fn:1] Out of scope
1216 (let ((backend (org-test-default-backend)))
1217 (setf (org-export-backend-transcoders backend
)
1218 (cons (cons 'footnote-reference
1219 (lambda (fn contents info
)
1220 (org-element-interpret-data
1221 (org-export-get-footnote-definition fn info
))))
1222 (org-export-backend-transcoders backend
)))
1224 (org-export-as backend
'subtree
)))))
1225 ;; 6. Footnotes without a definition should be provided a fallback
1228 (org-test-with-parsed-data "[fn:1]"
1229 (org-export-get-footnote-definition
1230 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1231 ;; 7. Footnote section should be ignored in TOC and in headlines
1234 (= 1 (let ((org-footnote-section "Footnotes"))
1235 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1236 (org-export-collect-headlines info
))))))
1239 (let ((org-footnote-section "Footnotes"))
1240 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1241 (org-element-map tree
'headline
1243 (when (equal (org-element-property :raw-value hl
) "H2")
1244 (org-export-get-headline-number hl info
)))
1249 ;;; Headlines and Inlinetasks
1251 (ert-deftest test-org-export
/get-relative-level
()
1252 "Test `org-export-get-relative-level' specifications."
1256 (let ((org-odd-levels-only nil
))
1257 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1258 (org-element-map tree
'headline
1259 (lambda (h) (org-export-get-relative-level h info
))
1264 (let ((org-odd-levels-only nil
))
1265 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1266 (org-element-map tree
'headline
1267 (lambda (h) (org-export-get-relative-level h info
))
1270 (ert-deftest test-org-export
/low-level-p
()
1271 "Test `org-export-low-level-p' specifications."
1275 (let ((org-odd-levels-only nil
))
1276 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1277 (org-element-map tree
'headline
1278 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1279 (plist-put info
:headline-levels
1)))))))
1281 (ert-deftest test-org-export
/get-headline-number
()
1282 "Test `org-export-get-headline-number' specifications."
1287 (let ((org-odd-levels-only nil
))
1288 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1289 (org-element-map tree
'headline
1290 (lambda (h) (org-export-get-headline-number h info
))
1292 ;; Missing levels are replaced with 0.
1296 (let ((org-odd-levels-only nil
))
1297 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1298 (org-element-map tree
'headline
1299 (lambda (h) (org-export-get-headline-number h info
))
1302 (ert-deftest test-org-export
/numbered-headline-p
()
1303 "Test `org-export-numbered-headline-p' specifications."
1304 ;; If `:section-numbers' is nil, never number headlines.
1306 (org-test-with-parsed-data "* Headline"
1307 (org-element-map tree
'headline
1308 (lambda (h) (org-export-numbered-headline-p h info
))
1309 (plist-put info
:section-numbers nil
))))
1310 ;; If `:section-numbers' is a number, only number headlines with
1311 ;; a level greater that it.
1315 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1316 (org-element-map tree
'headline
1317 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1318 (plist-put info
:section-numbers
1)))))
1319 ;; Otherwise, headlines are always numbered.
1321 (org-test-with-parsed-data "* Headline"
1322 (org-element-map tree
'headline
1323 (lambda (h) (org-export-numbered-headline-p h info
))
1324 (plist-put info
:section-numbers t
)))))
1326 (ert-deftest test-org-export
/number-to-roman
()
1327 "Test `org-export-number-to-roman' specifications."
1328 ;; If number is negative, return it as a string.
1329 (should (equal (org-export-number-to-roman -
1) "-1"))
1330 ;; Otherwise, return it as a roman number.
1331 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1333 (ert-deftest test-org-export
/get-optional-title
()
1334 "Test `org-export-get-alt-title' specifications."
1335 ;; If ALT_TITLE property is defined, use it.
1338 (org-test-with-parsed-data
1339 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1340 (org-export-get-alt-title
1341 (org-element-map tree
'headline
'identity info t
)
1343 ;; Otherwise, fall-back to regular title.
1345 (equal '("Headline")
1346 (org-test-with-parsed-data "* Headline"
1347 (org-export-get-alt-title
1348 (org-element-map tree
'headline
'identity info t
)
1351 (ert-deftest test-org-export
/get-tags
()
1352 "Test `org-export-get-tags' specifications."
1353 (let ((org-export-exclude-tags '("noexport"))
1354 (org-export-select-tags '("export")))
1355 ;; Standard test: tags which are not a select tag, an exclude tag,
1356 ;; or specified as optional argument shouldn't be ignored.
1358 (org-test-with-parsed-data "* Headline :tag:"
1359 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1361 ;; Exclude tags are removed.
1363 (org-test-with-parsed-data "* Headline :noexport:"
1364 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1366 ;; Select tags are removed.
1368 (org-test-with-parsed-data "* Headline :export:"
1369 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1374 (org-test-with-parsed-data "* Headline :tag:export:"
1375 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1377 ;; Tags provided in the optional argument are also ignored.
1379 (org-test-with-parsed-data "* Headline :ignore:"
1380 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1382 ;; Allow tag inheritance.
1386 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1387 (org-element-map tree
'headline
1388 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1389 ;; Tag inheritance checks FILETAGS keywords.
1393 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1394 (org-element-map tree
'headline
1395 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1397 (ert-deftest test-org-export
/get-node-property
()
1398 "Test`org-export-get-node-property' specifications."
1402 (org-test-with-parsed-data "* Headline
1406 (org-export-get-node-property
1407 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1408 ;; Test inheritance.
1411 (org-test-with-parsed-data "* Parent
1417 (org-export-get-node-property
1418 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1419 ;; Cannot return a value before the first headline.
1421 (org-test-with-parsed-data "Paragraph
1426 (org-export-get-node-property
1427 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1429 (ert-deftest test-org-export
/get-category
()
1430 "Test `org-export-get-category' specifications."
1434 (org-test-with-parsed-data "* Headline
1438 (org-export-get-category
1439 (org-element-map tree
'headline
'identity nil t
) info
))))
1440 ;; Test inheritance from a parent headline.
1442 (equal '("value" "value")
1443 (org-test-with-parsed-data "* Headline1
1448 (org-element-map tree
'headline
1449 (lambda (hl) (org-export-get-category hl info
)) info
))))
1450 ;; Test inheritance from #+CATEGORY keyword
1453 (org-test-with-parsed-data "#+CATEGORY: value
1455 (org-export-get-category
1456 (org-element-map tree
'headline
'identity nil t
) info
))))
1457 ;; Test inheritance from file name.
1460 (org-test-with-parsed-data "* Headline"
1461 (let ((info (plist-put info
:input-file
"~/test.org")))
1462 (org-export-get-category
1463 (org-element-map tree
'headline
'identity nil t
) info
)))))
1467 (org-test-with-parsed-data "* Headline"
1468 (org-export-get-category
1469 (org-element-map tree
'headline
'identity nil t
) info
)))))
1471 (ert-deftest test-org-export
/first-sibling-p
()
1472 "Test `org-export-first-sibling-p' specifications."
1477 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1478 (org-element-map tree
'headline
1479 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1481 ;; Ignore headlines not exported.
1485 (let ((org-export-exclude-tags '("ignore")))
1486 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1487 (org-element-map tree
'headline
1488 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1491 (ert-deftest test-org-export
/last-sibling-p
()
1492 "Test `org-export-last-sibling-p' specifications."
1497 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1498 (org-element-map tree
'headline
1499 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1501 ;; Ignore headlines not exported.
1505 (let ((org-export-exclude-tags '("ignore")))
1506 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1507 (org-element-map tree
'headline
1508 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1511 (ert-deftest test-org-export
/handle-inlinetasks
()
1512 "Test inlinetask export."
1513 ;; Inlinetask with an exclude tag.
1514 (when (featurep 'org-inlinetask
)
1518 (let ((org-inlinetask-min-level 3))
1519 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1520 (org-export-as (org-test-default-backend)
1521 nil nil nil
'(:exclude-tags
("noexp")))))))
1522 ;; Inlinetask with an include tag.
1525 "* H2\n*** Inline :exp:\n"
1526 (let ((org-inlinetask-min-level 3)
1527 (org-tags-column 0))
1528 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1529 (org-export-as (org-test-default-backend)
1530 nil nil nil
'(:select-tags
("exp")))))))
1531 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1534 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1535 (org-inlinetask-min-level 3))
1536 (org-test-with-temp-text "*** TODO Inline"
1537 (org-export-as (org-test-default-backend)
1538 nil nil nil
'(:with-tasks nil
))))))))
1544 (ert-deftest test-org-export
/get-date
()
1545 "Test `org-export-get-date' specifications."
1546 ;; Return a properly formatted string when
1547 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1548 ;; consists in a single timestamp.
1551 (let ((org-export-date-timestamp-format "%d %m %Y"))
1552 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1553 (org-export-get-date info
)))))
1554 ;; Return a secondary string otherwise.
1557 (let ((org-export-date-timestamp-format nil
))
1558 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1559 (org-export-get-date info
)))))
1562 (org-test-with-parsed-data "#+DATE: Date"
1563 (org-export-get-date info
))))
1564 ;; Optional argument has precedence over
1565 ;; `org-export-date-timestamp-format'.
1568 (let ((org-export-date-timestamp-format "%d %m %Y"))
1569 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1570 (org-export-get-date info
"%d %m"))))))
1576 (ert-deftest test-org-export
/get-coderef-format
()
1577 "Test `org-export-get-coderef-format' specifications."
1578 ;; A link without description returns "%s"
1579 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1581 ;; Return "%s" when path is matched within description.
1582 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1584 ;; Otherwise return description.
1585 (should (equal (org-export-get-coderef-format "path" "desc")
1588 (ert-deftest test-org-export
/inline-image-p
()
1589 "Test `org-export-inline-image-p' specifications."
1591 (org-export-inline-image-p
1592 (org-test-with-temp-text "[[#id]]"
1593 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1594 '(("custom-id" .
"id")))))
1596 (ert-deftest test-org-export
/fuzzy-link
()
1597 "Test fuzzy links specifications."
1598 ;; Link to an headline should return headline's number.
1599 (org-test-with-parsed-data
1600 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1602 ;; Note: Headline's number is in fact a list of numbers.
1604 (org-element-map tree
'link
1606 (org-export-get-ordinal
1607 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1608 ;; Link to a target in an item should return item's number.
1609 (org-test-with-parsed-data
1610 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1612 ;; Note: Item's number is in fact a list of numbers.
1614 (org-element-map tree
'link
1616 (org-export-get-ordinal
1617 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1618 ;; Link to a target in a footnote should return footnote's number.
1619 (org-test-with-parsed-data "
1620 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1623 (org-element-map tree
'link
1625 (org-export-get-ordinal
1626 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1627 ;; Link to a named element should return sequence number of that
1629 (org-test-with-parsed-data
1630 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1633 (org-element-map tree
'link
1635 (org-export-get-ordinal
1636 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1637 ;; Link to a target not within an item, a table, a footnote
1638 ;; reference or definition should return section number.
1639 (org-test-with-parsed-data
1640 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1643 (org-element-map tree
'link
1645 (org-export-get-ordinal
1646 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1647 ;; Space are not significant when matching a fuzzy link.
1649 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1650 (org-element-map tree
'link
1651 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1653 ;; Statistics cookies are ignored for headline match.
1655 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1656 (org-element-map tree
'link
1657 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1660 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1661 (org-element-map tree
'link
1662 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1664 ;; Headline match is position dependent.
1668 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
1669 (org-element-map tree
'link
1670 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
1672 (ert-deftest test-org-export
/resolve-coderef
()
1673 "Test `org-export-resolve-coderef' specifications."
1674 (let ((org-coderef-label-format "(ref:%s)"))
1675 ;; 1. A link to a "-n -k -r" block returns line number.
1676 (org-test-with-parsed-data
1677 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1678 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1679 (org-test-with-parsed-data
1680 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1681 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1682 ;; 2. A link to a "-n -r" block returns line number.
1683 (org-test-with-parsed-data
1684 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1685 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1686 (org-test-with-parsed-data
1687 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1688 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1689 ;; 3. A link to a "-n" block returns coderef.
1690 (org-test-with-parsed-data
1691 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1692 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1693 (org-test-with-parsed-data
1694 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1695 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1696 ;; 4. A link to a "-r" block returns line number.
1697 (org-test-with-parsed-data
1698 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1699 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1700 (org-test-with-parsed-data
1701 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1702 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1703 ;; 5. A link to a block without a switch returns coderef.
1704 (org-test-with-parsed-data
1705 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1706 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1707 (org-test-with-parsed-data
1708 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1709 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1710 ;; 6. Correctly handle continued line numbers. A "+n" switch
1711 ;; should resume numbering from previous block with numbered
1712 ;; lines, ignoring blocks not numbering lines in the process.
1713 ;; A "-n" switch resets count.
1714 (org-test-with-parsed-data "
1719 #+BEGIN_SRC emacs-lisp
1723 #+BEGIN_SRC emacs-lisp +n -r
1724 \(+ 1 1) (ref:addition)
1727 #+BEGIN_EXAMPLE -n -r
1728 Another text. (ref:text)
1730 (should (= (org-export-resolve-coderef "addition" info
) 2))
1731 (should (= (org-export-resolve-coderef "text" info
) 1)))
1732 ;; 7. Recognize coderef with user-specified syntax.
1733 (org-test-with-parsed-data
1734 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1735 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1737 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1738 "Test `org-export-resolve-fuzzy-link' specifications."
1739 ;; Match target objects.
1741 (org-test-with-parsed-data "<<target>> [[target]]"
1742 (org-export-resolve-fuzzy-link
1743 (org-element-map tree
'link
'identity info t
) info
)))
1744 ;; Match named elements.
1746 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1747 (org-export-resolve-fuzzy-link
1748 (org-element-map tree
'link
'identity info t
) info
)))
1749 ;; Match exact headline's name.
1751 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1752 (org-export-resolve-fuzzy-link
1753 (org-element-map tree
'link
'identity info t
) info
)))
1754 ;; Targets objects have priority over named elements and headline
1758 (org-test-with-parsed-data
1759 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1761 (org-export-resolve-fuzzy-link
1762 (org-element-map tree
'link
'identity info t
) info
)))))
1763 ;; Named elements have priority over headline titles.
1766 (org-test-with-parsed-data
1767 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1769 (org-export-resolve-fuzzy-link
1770 (org-element-map tree
'link
'identity info t
) info
)))))
1771 ;; If link's path starts with a "*", only match headline titles,
1775 (org-test-with-parsed-data
1776 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1778 (org-export-resolve-fuzzy-link
1779 (org-element-map tree
'link
'identity info t
) info
)))))
1780 ;; Return nil if no match.
1782 (org-test-with-parsed-data "[[target]]"
1783 (org-export-resolve-fuzzy-link
1784 (org-element-map tree
'link
'identity info t
) info
)))
1785 ;; Match fuzzy link even when before first headline.
1788 (org-test-with-parsed-data "[[hl]]\n* hl"
1790 (org-export-resolve-fuzzy-link
1791 (org-element-map tree
'link
'identity info t
) info
))))))
1793 (ert-deftest test-org-export
/resolve-id-link
()
1794 "Test `org-export-resolve-id-link' specifications."
1795 ;; 1. Regular test for custom-id link.
1796 (org-test-with-parsed-data "* Headline1
1803 (org-export-resolve-id-link
1804 (org-element-map tree
'link
'identity info t
) info
)))
1805 ;; 2. Failing test for custom-id link.
1806 (org-test-with-parsed-data "* Headline1
1813 (org-export-resolve-id-link
1814 (org-element-map tree
'link
'identity info t
) info
)))
1815 ;; 3. Test for internal id target.
1816 (org-test-with-parsed-data "* Headline1
1823 (org-export-resolve-id-link
1824 (org-element-map tree
'link
'identity info t
) info
)))
1825 ;; 4. Test for external id target.
1826 (org-test-with-parsed-data "[[id:aaaa]]"
1828 (org-export-resolve-id-link
1829 (org-element-map tree
'link
'identity info t
)
1830 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1832 (ert-deftest test-org-export
/resolve-radio-link
()
1833 "Test `org-export-resolve-radio-link' specifications."
1836 (org-test-with-temp-text "<<<radio>>> radio"
1837 (org-update-radio-target-regexp)
1838 (let* ((tree (org-element-parse-buffer))
1839 (info `(:parse-tree
,tree
)))
1840 (org-export-resolve-radio-link
1841 (org-element-map tree
'link
'identity info t
)
1843 ;; Radio targets are case-insensitive.
1845 (org-test-with-temp-text "<<<RADIO>>> radio"
1846 (org-update-radio-target-regexp)
1847 (let* ((tree (org-element-parse-buffer))
1848 (info `(:parse-tree
,tree
)))
1849 (org-export-resolve-radio-link
1850 (org-element-map tree
'link
'identity info t
)
1852 ;; Radio target with objects.
1854 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1855 (org-update-radio-target-regexp)
1856 (let* ((tree (org-element-parse-buffer))
1857 (info `(:parse-tree
,tree
)))
1858 (org-export-resolve-radio-link
1859 (org-element-map tree
'link
'identity info t
)
1861 ;; Multiple radio targets.
1863 (equal '("radio1" "radio2")
1864 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
1865 (org-update-radio-target-regexp)
1866 (let* ((tree (org-element-parse-buffer))
1867 (info `(:parse-tree
,tree
)))
1868 (org-element-map tree
'link
1870 (org-element-property
1871 :value
(org-export-resolve-radio-link link info
)))
1873 ;; Radio target is whitespace insensitive.
1875 (org-test-with-temp-text "<<<a radio>>> a\n radio"
1876 (org-update-radio-target-regexp)
1877 (let* ((tree (org-element-parse-buffer))
1878 (info `(:parse-tree
,tree
)))
1879 (org-element-map tree
'link
1880 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
1884 ;;; Src-block and example-block
1886 (ert-deftest test-org-export
/unravel-code
()
1887 "Test `org-export-unravel-code' function."
1888 ;; Code without reference.
1890 (equal '("(+ 1 1)\n")
1891 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1892 (org-export-unravel-code (org-element-at-point)))))
1893 ;; Code with reference.
1895 (equal '("(+ 1 1)\n" (1 .
"test"))
1896 (org-test-with-temp-text
1897 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1898 (let ((org-coderef-label-format "(ref:%s)"))
1899 (org-export-unravel-code (org-element-at-point))))))
1900 ;; Code with user-defined reference.
1903 '("(+ 1 1)\n" (1 .
"test"))
1904 (org-test-with-temp-text
1905 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1906 (let ((org-coderef-label-format "(ref:%s)"))
1907 (org-export-unravel-code (org-element-at-point))))))
1908 ;; Code references keys are relative to the current block.
1910 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
1911 (org-test-with-temp-text "
1920 (let ((org-coderef-label-format "(ref:%s)"))
1921 (org-export-unravel-code (org-element-at-point)))))))
1923 (ert-deftest test-org-export
/format-code-default
()
1924 "Test `org-export-format-code-default' specifications."
1925 ;; Return the empty string when code is empty.
1928 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1929 (org-export-format-code-default
1930 (org-element-map tree
'src-block
'identity info t
) info
))))
1931 ;; Number lines, two whitespace characters before the actual loc.
1934 (org-test-with-parsed-data
1935 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1936 (org-export-format-code-default
1937 (org-element-map tree
'src-block
'identity info t
) info
))))
1938 ;; Put references 6 whitespace characters after the widest line,
1939 ;; wrapped within parenthesis.
1941 (equal "123 (a)\n1 (b)\n"
1942 (let ((org-coderef-label-format "(ref:%s)"))
1943 (org-test-with-parsed-data
1944 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1945 (org-export-format-code-default
1946 (org-element-map tree
'src-block
'identity info t
) info
))))))
1952 (ert-deftest test-org-export
/activate-smart-quotes
()
1953 "Test `org-export-activate-smart-quotes' specifications."
1954 ;; Opening double quotes: standard test.
1957 '("some “paragraph")
1958 (let ((org-export-default-language "en"))
1959 (org-test-with-parsed-data "some \"paragraph"
1960 (org-element-map tree
'plain-text
1961 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1963 ;; Opening quotes: at the beginning of a paragraph.
1967 (let ((org-export-default-language "en"))
1968 (org-test-with-parsed-data "\"begin"
1969 (org-element-map tree
'plain-text
1970 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1972 ;; Opening quotes: after an object.
1976 (let ((org-export-default-language "en"))
1977 (org-test-with-parsed-data "=verb= \"begin"
1978 (org-element-map tree
'plain-text
1979 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1981 ;; Closing quotes: standard test.
1984 '("some” paragraph")
1985 (let ((org-export-default-language "en"))
1986 (org-test-with-parsed-data "some\" paragraph"
1987 (org-element-map tree
'plain-text
1988 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1990 ;; Closing quotes: at the end of a paragraph.
1994 (let ((org-export-default-language "en"))
1995 (org-test-with-parsed-data "end\""
1996 (org-element-map tree
'plain-text
1997 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1999 ;; Apostrophe: standard test.
2002 '("It shouldn’t fail")
2003 (let ((org-export-default-language "en"))
2004 (org-test-with-parsed-data "It shouldn't fail"
2005 (org-element-map tree
'plain-text
2006 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2008 ;; Apostrophe: before an object.
2012 (let ((org-export-default-language "en"))
2013 (org-test-with-parsed-data "a'=b="
2014 (org-element-map tree
'plain-text
2015 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2017 ;; Apostrophe: after an object.
2021 (let ((org-export-default-language "en"))
2022 (org-test-with-parsed-data "=code='s"
2023 (org-element-map tree
'plain-text
2024 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2026 ;; Special case: isolated quotes.
2028 (equal '("“" "”")
2029 (let ((org-export-default-language "en"))
2030 (org-test-with-parsed-data "\"$x$\""
2031 (org-element-map tree
'plain-text
2032 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2034 ;; Smart quotes in secondary strings.
2036 (equal '("“" "”")
2037 (let ((org-export-default-language "en"))
2038 (org-test-with-parsed-data "* \"$x$\""
2039 (org-element-map tree
'plain-text
2040 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2042 ;; Smart quotes in document keywords.
2044 (equal '("“" "”")
2045 (let ((org-export-default-language "en"))
2046 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2047 (org-element-map (plist-get info
:title
) 'plain-text
2048 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2050 ;; Smart quotes in parsed affiliated keywords.
2052 (equal '("“" "”" "Paragraph")
2053 (let ((org-export-default-language "en"))
2054 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2055 (org-element-map tree
'plain-text
2056 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2057 info nil nil t
))))))
2063 (ert-deftest test-org-export
/special-column
()
2064 "Test if the table's special column is properly recognized."
2065 ;; 1. First column is special if it contains only a special marking
2066 ;; characters or empty cells.
2067 (org-test-with-temp-text "
2071 (org-export-table-has-special-column-p
2073 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2074 ;; 2. If the column contains anything else, it isn't special.
2075 (org-test-with-temp-text "
2079 (org-export-table-has-special-column-p
2081 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2082 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2084 (org-test-with-temp-text "
2093 (org-export-table-has-special-column-p
2095 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2096 ;; 4. A first column with only empty cells isn't considered as
2098 (org-test-with-temp-text "
2102 (org-export-table-has-special-column-p
2104 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2106 (ert-deftest test-org-export
/table-row-is-special-p
()
2107 "Test `org-export-table-row-is-special-p' specifications."
2108 ;; 1. A row is special if it has a special marking character in the
2110 (org-test-with-parsed-data "| ! | 1 |"
2112 (org-export-table-row-is-special-p
2113 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2114 ;; 2. A row is special when its first field is "/"
2115 (org-test-with-parsed-data "
2119 (org-export-table-row-is-special-p
2120 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2121 ;; 3. A row only containing alignment cookies is also considered as
2123 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2125 (org-export-table-row-is-special-p
2126 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2127 ;; 4. Everything else isn't considered as special.
2128 (org-test-with-parsed-data "| \alpha | | c |"
2130 (org-export-table-row-is-special-p
2131 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2132 ;; 5. Table's rules are never considered as special rows.
2133 (org-test-with-parsed-data "|---+---|"
2135 (org-export-table-row-is-special-p
2136 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2138 (ert-deftest test-org-export
/has-header-p
()
2139 "Test `org-export-table-has-header-p' specifications."
2140 ;; 1. With an header.
2141 (org-test-with-parsed-data "
2146 (org-export-table-has-header-p
2147 (org-element-map tree
'table
'identity info
'first-match
)
2149 ;; 2. Without an header.
2150 (org-test-with-parsed-data "
2154 (org-export-table-has-header-p
2155 (org-element-map tree
'table
'identity info
'first-match
)
2157 ;; 3. Don't get fooled with starting and ending rules.
2158 (org-test-with-parsed-data "
2164 (org-export-table-has-header-p
2165 (org-element-map tree
'table
'identity info
'first-match
)
2168 (ert-deftest test-org-export
/table-row-group
()
2169 "Test `org-export-table-row-group' specifications."
2170 ;; 1. A rule creates a new group.
2173 (org-test-with-parsed-data "
2177 (org-element-map tree
'table-row
2179 (if (eq (org-element-property :type row
) 'rule
) 'rule
2180 (org-export-table-row-group row info
)))))))
2181 ;; 2. Special rows are ignored in count.
2185 (org-test-with-parsed-data "
2189 (org-element-map tree
'table-row
2191 (if (eq (org-element-property :type row
) 'rule
) 'rule
2192 (org-export-table-row-group row info
)))
2194 ;; 3. Double rules also are ignored in count.
2196 (equal '(1 rule rule
2)
2197 (org-test-with-parsed-data "
2202 (org-element-map tree
'table-row
2204 (if (eq (org-element-property :type row
) 'rule
) 'rule
2205 (org-export-table-row-group row info
))))))))
2207 (ert-deftest test-org-export
/table-row-number
()
2208 "Test `org-export-table-row-number' specifications."
2209 ;; Standard test. Number is 0-indexed.
2212 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2213 (org-element-map tree
'table-row
2214 (lambda (row) (org-export-table-row-number row info
)) info
))))
2215 ;; Number ignores separators.
2218 (org-test-with-parsed-data "
2222 (org-element-map tree
'table-row
2223 (lambda (row) (org-export-table-row-number row info
)) info
))))
2224 ;; Number ignores special rows.
2227 (org-test-with-parsed-data "
2233 (org-element-map tree
'table-row
2234 (lambda (row) (org-export-table-row-number row info
)) info
)))))
2236 (ert-deftest test-org-export
/table-cell-width
()
2237 "Test `org-export-table-cell-width' specifications."
2238 ;; 1. Width is primarily determined by width cookies. If no cookie
2239 ;; is found, cell's width is nil.
2240 (org-test-with-parsed-data "
2241 | / | <l> | <6> | <l7> |
2246 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2247 (org-element-map tree
'table-cell
'identity info
)))))
2248 ;; 2. The last width cookie has precedence.
2249 (org-test-with-parsed-data "
2256 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2257 (org-element-map tree
'table-cell
'identity info
)))))
2258 ;; 3. Valid width cookies must have a specific row.
2259 (org-test-with-parsed-data "| <6> | cell |"
2263 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2264 (org-element-map tree
'table-cell
'identity
))))))
2266 (ert-deftest test-org-export
/table-cell-alignment
()
2267 "Test `org-export-table-cell-alignment' specifications."
2268 ;; 1. Alignment is primarily determined by alignment cookies.
2270 (equal '(left center right
)
2271 (let ((org-table-number-fraction 0.5)
2272 (org-table-number-regexp "^[0-9]+$"))
2273 (org-test-with-parsed-data "| <l> | <c> | <r> |"
2274 (mapcar (lambda (cell)
2275 (org-export-table-cell-alignment cell info
))
2276 (org-element-map tree
'table-cell
'identity
))))))
2277 ;; 2. The last alignment cookie has precedence.
2279 (equal '(right right right
)
2280 (org-test-with-parsed-data "
2284 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2285 (org-element-map tree
'table-cell
'identity
)))))
2286 ;; 3. If there's no cookie, cell's contents determine alignment.
2287 ;; A column mostly made of cells containing numbers will align
2288 ;; its cells to the right.
2290 (equal '(right right right
)
2291 (let ((org-table-number-fraction 0.5)
2292 (org-table-number-regexp "^[0-9]+$"))
2293 (org-test-with-parsed-data "
2297 (mapcar (lambda (cell)
2298 (org-export-table-cell-alignment cell info
))
2299 (org-element-map tree
'table-cell
'identity
))))))
2300 ;; 4. Otherwise, they will be aligned to the left.
2302 (equal '(left left left
)
2303 (org-test-with-parsed-data "
2307 (mapcar (lambda (cell)
2308 (org-export-table-cell-alignment cell info
))
2309 (org-element-map tree
'table-cell
'identity info
))))))
2311 (ert-deftest test-org-export
/table-cell-borders
()
2312 "Test `org-export-table-cell-borders' specifications."
2313 ;; 1. Recognize various column groups indicators.
2314 (org-test-with-parsed-data "| / | < | > | <> |"
2317 '((right bottom top
) (left bottom top
) (right bottom top
)
2318 (right left bottom top
))
2319 (mapcar (lambda (cell)
2320 (org-export-table-cell-borders cell info
))
2321 (org-element-map tree
'table-cell
'identity
)))))
2322 ;; 2. Accept shortcuts to define column groups.
2323 (org-test-with-parsed-data "| / | < | < |"
2326 '((right bottom top
) (right left bottom top
) (left bottom top
))
2327 (mapcar (lambda (cell)
2328 (org-export-table-cell-borders cell info
))
2329 (org-element-map tree
'table-cell
'identity
)))))
2330 ;; 3. A valid column groups row must start with a "/".
2331 (org-test-with-parsed-data "
2335 (equal '((top) (top) (bottom) (bottom))
2336 (mapcar (lambda (cell)
2337 (org-export-table-cell-borders cell info
))
2338 (org-element-map tree
'table-cell
'identity
)))))
2339 ;; 4. Take table rules into consideration.
2340 (org-test-with-parsed-data "
2345 (equal '((below top
) (bottom above
))
2346 (mapcar (lambda (cell)
2347 (org-export-table-cell-borders cell info
))
2348 (org-element-map tree
'table-cell
'identity
)))))
2349 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2350 ;; (resp. `bottom' and `below') borders. Any special row is
2352 (org-test-with-parsed-data "
2358 (equal '((bottom below top above
))
2360 (mapcar (lambda (cell)
2361 (org-export-table-cell-borders cell info
))
2362 (org-element-map tree
'table-cell
'identity
)))))))
2364 (ert-deftest test-org-export
/table-dimensions
()
2365 "Test `org-export-table-dimensions' specifications."
2366 ;; 1. Standard test.
2367 (org-test-with-parsed-data "
2372 (org-export-table-dimensions
2373 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2374 ;; 2. Ignore horizontal rules and special columns.
2375 (org-test-with-parsed-data "
2382 (org-export-table-dimensions
2383 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2385 (ert-deftest test-org-export
/table-cell-address
()
2386 "Test `org-export-table-cell-address' specifications."
2387 ;; 1. Standard test: index is 0-based.
2388 (org-test-with-parsed-data "| a | b |"
2390 (equal '((0 .
0) (0 .
1))
2391 (org-element-map tree
'table-cell
2392 (lambda (cell) (org-export-table-cell-address cell info
))
2394 ;; 2. Special column isn't counted, nor are special rows.
2395 (org-test-with-parsed-data "
2400 (org-export-table-cell-address
2401 (car (last (org-element-map tree
'table-cell
'identity info
)))
2403 ;; 3. Tables rules do not count either.
2404 (org-test-with-parsed-data "
2412 (org-export-table-cell-address
2413 (car (last (org-element-map tree
'table-cell
'identity info
)))
2415 ;; 4. Return nil for special cells.
2416 (org-test-with-parsed-data "| / | a |"
2418 (org-export-table-cell-address
2419 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2422 (ert-deftest test-org-export
/get-table-cell-at
()
2423 "Test `org-export-get-table-cell-at' specifications."
2424 ;; 1. Address ignores special columns, special rows and rules.
2425 (org-test-with-parsed-data "
2432 (org-element-contents
2433 (org-export-get-table-cell-at
2435 (org-element-map tree
'table
'identity info
'first-match
)
2437 ;; 2. Return value for a non-existent address is nil.
2438 (org-test-with-parsed-data "| a |"
2440 (org-export-get-table-cell-at
2442 (org-element-map tree
'table
'identity info
'first-match
)
2444 (org-test-with-parsed-data "| / |"
2446 (org-export-get-table-cell-at
2448 (org-element-map tree
'table
'identity info
'first-match
)
2451 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2452 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2453 ;; 1. A cell at a beginning of a row always starts a column group.
2454 (org-test-with-parsed-data "| a |"
2456 (org-export-table-cell-starts-colgroup-p
2457 (org-element-map tree
'table-cell
'identity info
'first-match
)
2459 ;; 2. Special column should be ignored when determining the
2460 ;; beginning of the row.
2461 (org-test-with-parsed-data "
2465 (org-export-table-cell-starts-colgroup-p
2466 (org-element-map tree
'table-cell
'identity info
'first-match
)
2468 ;; 2. Explicit column groups.
2469 (org-test-with-parsed-data "
2475 (org-element-map tree
'table-cell
2477 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2480 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2481 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2482 ;; 1. A cell at the end of a row always ends a column group.
2483 (org-test-with-parsed-data "| a |"
2485 (org-export-table-cell-ends-colgroup-p
2486 (org-element-map tree
'table-cell
'identity info
'first-match
)
2488 ;; 2. Special column should be ignored when determining the
2489 ;; beginning of the row.
2490 (org-test-with-parsed-data "
2494 (org-export-table-cell-ends-colgroup-p
2495 (org-element-map tree
'table-cell
'identity info
'first-match
)
2497 ;; 3. Explicit column groups.
2498 (org-test-with-parsed-data "
2504 (org-element-map tree
'table-cell
2506 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2509 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2510 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2511 ;; 1. A row at the beginning of a table always starts a row group.
2512 ;; So does a row following a table rule.
2513 (org-test-with-parsed-data "
2520 (org-element-map tree
'table-row
2522 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2524 ;; 2. Special rows should be ignored when determining the beginning
2526 (org-test-with-parsed-data "
2535 (org-element-map tree
'table-row
2537 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2540 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2541 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2542 ;; 1. A row at the end of a table always ends a row group. So does
2543 ;; a row preceding a table rule.
2544 (org-test-with-parsed-data "
2551 (org-element-map tree
'table-row
2553 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2555 ;; 2. Special rows should be ignored when determining the beginning
2557 (org-test-with-parsed-data "
2566 (org-element-map tree
'table-row
2568 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2571 (ert-deftest test-org-export
/table-row-starts-header-p
()
2572 "Test `org-export-table-row-starts-header-p' specifications."
2573 ;; 1. Only the row starting the first row group starts the table
2575 (org-test-with-parsed-data "
2583 (org-element-map tree
'table-row
2585 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2587 ;; 2. A row cannot start an header if there's no header in the
2589 (org-test-with-parsed-data "
2593 (org-export-table-row-starts-header-p
2594 (org-element-map tree
'table-row
'identity info
'first-match
)
2597 (ert-deftest test-org-export
/table-row-ends-header-p
()
2598 "Test `org-export-table-row-ends-header-p' specifications."
2599 ;; 1. Only the row starting the first row group starts the table
2601 (org-test-with-parsed-data "
2609 (org-element-map tree
'table-row
2611 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2613 ;; 2. A row cannot start an header if there's no header in the
2615 (org-test-with-parsed-data "
2619 (org-export-table-row-ends-header-p
2620 (org-element-map tree
'table-row
'identity info
'first-match
)
2625 ;;; Tables of Contents
2627 (ert-deftest test-org-export
/collect-headlines
()
2628 "Test `org-export-collect-headlines' specifications."
2633 (org-test-with-parsed-data "* H1\n** H2"
2634 (org-export-collect-headlines info
)))))
2635 ;; Do not collect headlines below optional argument.
2639 (org-test-with-parsed-data "* H1\n** H2"
2640 (org-export-collect-headlines info
1)))))
2641 ;; Never collect headlines below maximum headline level.
2645 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
2646 (org-export-collect-headlines info
)))))
2650 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
2651 (org-export-collect-headlines info
2))))))
2657 (ert-deftest test-org-export
/inner-template
()
2658 "Test `inner-template' translator specifications."
2661 (org-test-with-temp-text "* Headline"
2663 (org-export-create-backend
2665 '((inner-template .
(lambda (contents info
) "Success!"))
2666 (headline .
(lambda (h c i
) "Headline"))))))))
2667 ;; Inner template is applied even in a "body-only" export.
2670 (org-test-with-temp-text "* Headline"
2672 (org-export-create-backend
2673 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
2674 (headline .
(lambda (h c i
) "Headline"))))
2675 nil nil
'body-only
)))))
2677 (ert-deftest test-org-export
/template
()
2678 "Test `template' translator specifications."
2681 (org-test-with-temp-text "* Headline"
2683 (org-export-create-backend
2684 :transcoders
'((template .
(lambda (contents info
) "Success!"))
2685 (headline .
(lambda (h c i
) "Headline"))))))))
2686 ;; Template is not applied in a "body-only" export.
2689 (org-test-with-temp-text "* Headline"
2691 (org-export-create-backend
2692 :transcoders
'((template .
(lambda (contents info
) "Success!"))
2693 (headline .
(lambda (h c i
) "Headline"))))
2694 nil nil
'body-only
)))))
2700 (ert-deftest test-org-export
/get-next-element
()
2701 "Test `org-export-get-next-element' specifications."
2705 (org-test-with-parsed-data "* Headline\n*a* b"
2706 (org-export-get-next-element
2707 (org-element-map tree
'bold
'identity info t
) info
))))
2708 ;; Return nil when no previous element.
2710 (org-test-with-parsed-data "* Headline\na *b*"
2711 (org-export-get-next-element
2712 (org-element-map tree
'bold
'identity info t
) info
)))
2713 ;; Non-exportable elements are ignored.
2715 (let ((org-export-with-timestamps nil
))
2716 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2717 (org-export-get-next-element
2718 (org-element-map tree
'entity
'identity info t
) info
))))
2719 ;; Find next element in secondary strings.
2722 (org-test-with-parsed-data "* a =verb="
2724 (org-export-get-next-element
2725 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2728 (org-test-with-parsed-data "* /italic/ =verb="
2730 (org-export-get-next-element
2731 (org-element-map tree
'italic
'identity info t
) info
)))))
2732 ;; Find next element in document keywords.
2735 (org-test-with-parsed-data "#+TITLE: a =verb="
2737 (org-export-get-next-element
2739 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2740 ;; Find next element in parsed affiliated keywords.
2743 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2745 (org-export-get-next-element
2746 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2747 ;; With optional argument N, return a list containing all the
2748 ;; following elements.
2751 '(bold code underline
)
2752 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2754 (org-export-get-next-element
2755 (org-element-map tree
'italic
'identity info t
) info t
)))))
2756 ;; When N is a positive integer, return a list containing up to
2757 ;; N following elements.
2761 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2763 (org-export-get-next-element
2764 (org-element-map tree
'italic
'identity info t
) info
2))))))
2766 (ert-deftest test-org-export
/get-previous-element
()
2767 "Test `org-export-get-previous-element' specifications."
2771 (org-test-with-parsed-data "* Headline\na *b*"
2772 (org-export-get-previous-element
2773 (org-element-map tree
'bold
'identity info t
) info
))))
2774 ;; Return nil when no previous element.
2776 (org-test-with-parsed-data "* Headline\n*a* b"
2777 (org-export-get-previous-element
2778 (org-element-map tree
'bold
'identity info t
) info
)))
2779 ;; Non-exportable elements are ignored.
2781 (let ((org-export-with-timestamps nil
))
2782 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2783 (org-export-get-previous-element
2784 (org-element-map tree
'entity
'identity info t
) info
))))
2785 ;; Find previous element in secondary strings.
2788 (org-test-with-parsed-data "* =verb= a"
2790 (org-export-get-previous-element
2791 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2794 (org-test-with-parsed-data "* =verb= /italic/"
2796 (org-export-get-previous-element
2797 (org-element-map tree
'italic
'identity info t
) info
)))))
2798 ;; Find previous element in document keywords.
2801 (org-test-with-parsed-data "#+TITLE: =verb= a"
2803 (org-export-get-previous-element
2805 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2806 ;; Find previous element in parsed affiliated keywords.
2809 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2811 (org-export-get-previous-element
2812 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2813 ;; With optional argument N, return a list containing up to
2814 ;; N previous elements.
2816 (equal '(underline italic bold
)
2817 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2819 (org-export-get-previous-element
2820 (org-element-map tree
'code
'identity info t
) info t
)))))
2821 ;; When N is a positive integer, return a list containing up to
2822 ;; N previous elements.
2824 (equal '(italic bold
)
2825 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2827 (org-export-get-previous-element
2828 (org-element-map tree
'code
'identity info t
) info
2))))))
2832 ;;; test-org-export.el end here