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
/set-title
()
272 "Test title setting."
273 ;; If no title if specified, use file name.
277 (org-test-with-temp-text-in-file "Test"
279 (let (org-export-registered-backends)
280 (org-export-define-backend 'test
281 '((template .
(lambda (text info
)
282 (org-element-interpret-data
283 (plist-get info
:title
) info
)))))
284 (list (org-export-as 'test
)
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"
294 (let (org-export-registered-backends)
295 (org-export-define-backend 'test
296 '((template .
(lambda (text info
)
297 (org-element-interpret-data
298 (plist-get info
:title
) info
)))))
299 (list (org-export-as 'test
) (buffer-name))))))
300 ;; If a title is specified, use it.
304 (org-test-with-temp-text-in-file "#+TITLE: Title\nTest"
306 (let (org-export-registered-backends)
307 (org-export-define-backend 'test
308 '((template .
(lambda (text info
)
309 (org-element-interpret-data
310 (plist-get info
:title
) info
)))))
311 (org-export-as 'test
)))))
312 ;; If an empty title is specified, do not set it.
316 (org-test-with-temp-text-in-file "#+TITLE:\nTest"
318 (let (org-export-registered-backends)
319 (org-export-define-backend 'test
320 '((template .
(lambda (text info
)
321 (org-element-interpret-data
322 (plist-get info
:title
) info
)))))
323 (org-export-as 'test
))))))
325 (ert-deftest test-org-export
/handle-options
()
326 "Test if export options have an impact on output."
327 ;; Test exclude tags for headlines and inlinetasks.
330 (org-test-with-temp-text "* Head1 :noexp:"
331 (org-test-with-backend test
332 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp")))))))
333 ;; Test include tags for headlines and inlinetasks.
335 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
336 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
337 (let ((org-tags-column 0))
338 (org-test-with-backend test
339 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
340 ;; Test mixing include tags and exclude tags.
341 (org-test-with-temp-text "
343 ** Sub-Head1 :noexport:
346 ** Sub-Head1 :export:"
347 (org-test-with-backend test
350 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
353 '(:select-tags
("export") :exclude-tags
("noexport")))))))
357 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
358 (org-test-with-temp-text "* TODO Head1"
359 (org-test-with-backend test
360 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))
362 (equal "* TODO Head1\n"
363 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
364 (org-test-with-temp-text "* TODO Head1"
365 (org-test-with-backend test
366 (org-export-as 'test nil nil nil
'(:with-tasks t
)))))))
368 (org-test-with-temp-text "* Head1 :archive:"
369 (let ((org-archive-tag "archive"))
370 (org-test-with-backend test
372 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
374 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
375 (let ((org-archive-tag "archive"))
376 (org-test-with-backend test
379 "\\* Head1[ \t]+:archive:"
380 (org-export-as 'test nil nil nil
381 '(:with-archived-trees headline
)))))))
382 (org-test-with-temp-text "* Head1 :archive:"
383 (let ((org-archive-tag "archive"))
384 (org-test-with-backend test
387 "\\`\\* Head1[ \t]+:archive:\n\\'"
388 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
390 (let ((org-clock-string "CLOCK:"))
391 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
392 (org-test-with-backend test
394 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
395 "CLOCK: [2012-04-29 sun. 10:45]\n"))
397 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
399 (let ((org-drawers '("TEST")))
400 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
401 (org-test-with-backend test
402 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
404 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
405 ":TEST:\ncontents\n:END:\n")))))
406 (let ((org-drawers '("FOO" "BAR")))
407 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
408 (org-test-with-backend test
410 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
411 ":FOO:\nkeep\n:END:\n")))))
412 (let ((org-drawers '("FOO" "BAR")))
413 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
414 (org-test-with-backend test
416 (equal (org-export-as 'test nil nil nil
'(:with-drawers
(not "BAR")))
417 ":FOO:\nkeep\n:END:\n")))))
421 (let ((org-footnote-section nil
))
422 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
423 (org-test-with-backend test
425 (org-export-as 'test nil nil nil
'(:with-footnotes nil
))))))))
427 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
428 (let ((org-footnote-section nil
))
429 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
430 (org-test-with-backend test
432 (org-export-as 'test nil nil nil
'(:with-footnotes t
))))))))
434 (when (featurep 'org-inlinetask
)
437 (let ((org-inlinetask-min-level 15))
438 (org-test-with-temp-text "*************** Task"
439 (org-test-with-backend test
440 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
444 (let ((org-inlinetask-min-level 15))
445 (org-test-with-temp-text
446 "*************** Task\nContents\n*************** END"
447 (org-test-with-backend test
448 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
451 (let ((org-closed-string "CLOSED:"))
452 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
453 (org-test-with-backend test
455 (equal (org-export-as 'test nil nil nil
'(:with-planning t
))
456 "CLOSED: [2012-04-29 sun. 10:45]\n"))
458 (equal (org-export-as 'test nil nil nil
'(:with-planning nil
))
460 ;; Statistics cookies.
463 (org-test-with-temp-text "[0/0]"
464 (org-test-with-backend test
466 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
468 (ert-deftest test-org-export
/with-timestamps
()
469 "Test `org-export-with-timestamps' specifications."
473 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"
474 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
475 (org-test-with-backend test
476 (org-export-as 'test nil nil nil
'(:with-timestamps t
))))))
481 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
482 (org-test-with-backend test
483 (org-export-as 'test nil nil nil
'(:with-timestamps nil
))))))
487 "<2012-03-29 Thu>\n\nParagraph <2012-03-29 Thu>[2012-03-29 Thu]"
488 (org-test-with-temp-text
489 "<2012-03-29 Thu>[2012-03-29 Thu]
491 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
492 (org-test-with-backend test
494 (org-export-as 'test nil nil nil
'(:with-timestamps active
)))))))
498 "[2012-03-29 Thu]\n\nParagraph <2012-03-29 Thu>[2012-03-29 Thu]"
499 (org-test-with-temp-text
500 "<2012-03-29 Thu>[2012-03-29 Thu]
502 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
503 (org-test-with-backend test
505 (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))))))))
507 (ert-deftest test-org-export
/comment-tree
()
508 "Test if export process ignores commented trees."
509 (let ((org-comment-string "COMMENT"))
510 (org-test-with-temp-text "* COMMENT Head1"
511 (org-test-with-backend test
512 (should (equal (org-export-as 'test
) ""))))))
514 (ert-deftest test-org-export
/export-scope
()
515 "Test all export scopes."
516 (org-test-with-temp-text "
521 (org-test-with-backend test
524 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
526 (goto-char (point-min))
529 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
531 (goto-char (point-min))
533 (transient-mark-mode 1)
534 (push-mark (point) t t
)
535 (goto-char (point-at-eol))
536 (should (equal (org-export-as 'test
) "text\n"))))
537 ;; Subtree with a code block calling another block outside.
540 (org-test-with-temp-text "
542 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
547 #+BEGIN_SRC emacs-lisp
550 (org-test-with-backend test
552 (org-export-as 'test
'subtree
)))))
554 (org-test-with-temp-text "Text"
555 (org-test-with-backend test
557 (cdr (assq 'test org-export-registered-backends
))
559 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
560 (org-export-backend-translate-table 'test
)))
561 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
562 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
564 (ert-deftest test-org-export
/output-file-name
()
565 "Test `org-export-output-file-name' specifications."
566 ;; Export from a file: name is built from original file name.
568 (org-test-with-temp-text-in-file "Test"
569 (equal (concat (file-name-as-directory ".")
570 (file-name-nondirectory
571 (file-name-sans-extension (buffer-file-name))))
572 (file-name-sans-extension (org-export-output-file-name ".ext")))))
573 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
575 (org-test-with-temp-text-in-file
576 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
577 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
578 ;; From a buffer not associated to a file, too.
580 (org-test-with-temp-text
581 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
582 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
583 ;; When provided name is absolute, preserve it.
585 (org-test-with-temp-text
586 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
587 (expand-file-name "test"))
588 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
589 ;; When PUB-DIR argument is provided, use it.
591 (org-test-with-temp-text-in-file "Test"
592 (equal (file-name-directory
593 (org-export-output-file-name ".ext" nil
"dir/"))
595 ;; When returned name would overwrite original file, add EXTENSION
598 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
599 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
601 (ert-deftest test-org-export
/expand-include
()
602 "Test file inclusion in an Org buffer."
603 ;; Error when file isn't specified.
605 (org-test-with-temp-text "#+INCLUDE: dummy.org"
606 (org-export-expand-include-keyword)))
607 ;; Full insertion with recursive inclusion.
608 (org-test-with-temp-text
609 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
610 (org-export-expand-include-keyword)
611 (should (equal (buffer-string)
612 "Small Org file with an include keyword.
614 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
620 ;; Localized insertion.
621 (org-test-with-temp-text
622 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
624 (org-export-expand-include-keyword)
625 (should (equal (buffer-string)
626 "Small Org file with an include keyword.\n")))
627 ;; Insertion with constraints on headlines level.
630 "* Top heading\n** Heading\nbody\n"
631 (org-test-with-temp-text
633 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
635 (org-export-expand-include-keyword)
639 "* Top heading\n* Heading\nbody\n"
640 (org-test-with-temp-text
642 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
644 (org-export-expand-include-keyword)
646 ;; Inclusion within an example block.
647 (org-test-with-temp-text
648 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
650 (org-export-expand-include-keyword)
654 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
655 ;; Inclusion within a src-block.
656 (org-test-with-temp-text
658 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
660 (org-export-expand-include-keyword)
661 (should (equal (buffer-string)
662 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
664 (ert-deftest test-org-export
/expand-macro
()
665 "Test macro expansion in an Org buffer."
666 ;; Standard macro expansion.
668 (equal "#+MACRO: macro1 value\nvalue\n"
669 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
670 (org-test-with-backend test
(org-export-as 'test
)))))
671 ;; Expand specific macros.
673 (equal "me 2012-03-29 me@here Title\n"
674 (org-test-with-temp-text
680 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
681 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
682 (substring output
(string-match ".*\n\\'" output
))))))
683 ;; Expand specific macros when property contained a regular macro
687 (org-test-with-temp-text "
688 #+MACRO: macro1 value
689 #+TITLE: {{{macro1}}}
691 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
692 (substring output
(string-match ".*\n\\'" output
))))))
693 ;; Expand macros with templates in included files.
696 (org-test-with-temp-text
697 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
698 {{{included-macro}}}" org-test-dir
)
699 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
700 (substring output
(string-match ".*\n\\'" output
)))))))
702 (ert-deftest test-org-export
/user-ignore-list
()
703 "Test if `:ignore-list' accepts user input."
704 (org-test-with-backend test
705 (flet ((skip-note-head
707 ;; Ignore headlines with the word "note" in their title.
708 (org-element-map data
'headline
710 (when (string-match "\\<note\\>"
711 (org-element-property :raw-value headline
))
712 (org-export-ignore-element headline info
)))
715 ;; Install function in parse tree filters.
716 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
717 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
718 (should (equal (org-export-as 'test
) "* Head1\n")))))))
720 (ert-deftest test-org-export
/before-processing-hook
()
721 "Test `org-export-before-processing-hook'."
724 "#+MACRO: mac val\nTest\n"
725 (org-test-with-backend test
726 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
727 (let ((org-export-before-processing-hook
729 (while (re-search-forward "{{{" nil t
)
730 (let ((object (org-element-context)))
731 (when (eq (org-element-type object
) 'macro
)
733 (org-element-property :begin object
)
734 (org-element-property :end object
)))))))))
735 (org-export-as 'test
)))))))
737 (ert-deftest test-org-export
/before-parsing-hook
()
738 "Test `org-export-before-parsing-hook'."
740 (equal "Body 1\nBody 2\n"
741 (org-test-with-backend test
742 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
743 (let ((org-export-before-parsing-hook
745 (goto-char (point-min))
746 (while (re-search-forward org-outline-regexp-bol nil t
)
748 (point-at-bol) (progn (forward-line) (point))))))))
749 (org-export-as 'test
)))))))
753 ;;; Affiliated Keywords
755 (ert-deftest test-org-export
/read-attribute
()
756 "Test `org-export-read-attribute' specifications."
760 (org-export-read-attribute
762 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
763 (org-element-at-point)))
765 ;; Return nil on empty attribute.
767 (org-export-read-attribute
769 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
770 ;; Return nil on "nil" string.
772 (equal '(:a nil
:b nil
)
773 (org-export-read-attribute
775 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
776 (org-element-at-point)))))
777 ;; Return nil on empty string.
779 (equal '(:a nil
:b nil
)
780 (org-export-read-attribute
782 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
783 (org-element-at-point)))))
784 ;; Return empty string when value is "".
787 (org-export-read-attribute
789 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
790 (org-element-at-point)))))
791 ;; Return \"\" when value is """".
794 (org-export-read-attribute
796 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
797 (org-element-at-point)))))
798 ;; Ignore text before first property.
801 (org-export-read-attribute
803 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
804 (org-element-at-point))))))
806 (ert-deftest test-org-export
/get-caption
()
807 "Test `org-export-get-caption' specifications."
808 ;; Without optional argument, return long caption
812 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
813 (org-export-get-caption (org-element-at-point)))))
814 ;; With optional argument, return short caption.
818 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
819 (org-export-get-caption (org-element-at-point) t
))))
820 ;; Multiple lines are separated by white spaces.
824 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
825 (org-export-get-caption (org-element-at-point))))))
831 (ert-deftest test-org-export
/define-backend
()
832 "Test back-end definition and accessors."
835 (equal '((headline . my-headline-test
))
836 (let (org-export-registered-backends)
837 (org-export-define-backend 'test
'((headline . my-headline-test
)))
838 (org-export-backend-translate-table 'test
))))
841 (equal '((:filter-headline . my-filter
))
842 (let (org-export-registered-backends)
843 (org-export-define-backend 'test
844 '((headline . my-headline-test
))
845 :filters-alist
'((:filter-headline . my-filter
)))
846 (org-export-backend-filters 'test
))))
849 (equal '((:prop value
))
850 (let (org-export-registered-backends)
851 (org-export-define-backend 'test
852 '((headline . my-headline-test
))
853 :options-alist
'((:prop value
)))
854 (org-export-backend-options 'test
))))
857 (equal '(?k
"Test Export" test
)
858 (let (org-export-registered-backends)
859 (org-export-define-backend 'test
860 '((headline . my-headline-test
))
861 :menu-entry
'(?k
"Test Export" test
))
862 (org-export-backend-menu 'test
))))
865 (equal '(("TEST" . org-element-export-block-parser
))
866 (let (org-export-registered-backends org-element-block-name-alist
)
867 (org-export-define-backend 'test
868 '((headline . my-headline-test
))
869 :export-block
'("test"))
870 org-element-block-name-alist
))))
872 (ert-deftest test-org-export
/define-derived-backend
()
873 "Test `org-export-define-derived-backend' specifications."
874 ;; Error when parent back-end is not defined.
876 (let (org-export-registered-backends)
877 (org-export-define-derived-backend 'test
'parent
)))
878 ;; Append translation table to parent's.
880 (equal '((:headline . test
) (:headline . parent
))
881 (let (org-export-registered-backends)
882 (org-export-define-backend 'parent
'((:headline . parent
)))
883 (org-export-define-derived-backend 'test
'parent
884 :translate-alist
'((:headline . test
)))
885 (org-export-backend-translate-table 'test
))))
886 ;; Options defined in the new back have priority over those defined
890 (let (org-export-registered-backends)
891 (org-export-define-backend 'parent
892 '((:headline . parent
))
893 :options-alist
'((:a nil nil
'parent
)))
894 (org-export-define-derived-backend 'test
'parent
895 :options-alist
'((:a nil nil
'test
)))
896 (plist-get (org-export--get-global-options 'test
) :a
)))))
898 (ert-deftest test-org-export
/derived-backend-p
()
899 "Test `org-export-derived-backend-p' specifications."
900 ;; Non-nil with direct match.
902 (let (org-export-registered-backends)
903 (org-export-define-backend 'test
'((headline . test
)))
904 (org-export-derived-backend-p 'test
'test
)))
906 (let (org-export-registered-backends)
907 (org-export-define-backend 'test
'((headline . test
)))
908 (org-export-define-derived-backend 'test2
'test
)
909 (org-export-derived-backend-p 'test2
'test2
)))
910 ;; Non-nil with a direct parent.
912 (let (org-export-registered-backends)
913 (org-export-define-backend 'test
'((headline . test
)))
914 (org-export-define-derived-backend 'test2
'test
)
915 (org-export-derived-backend-p 'test2
'test
)))
916 ;; Non-nil with an indirect parent.
918 (let (org-export-registered-backends)
919 (org-export-define-backend 'test
'((headline . test
)))
920 (org-export-define-derived-backend 'test2
'test
)
921 (org-export-define-derived-backend 'test3
'test2
)
922 (org-export-derived-backend-p 'test3
'test
)))
925 (let (org-export-registered-backends)
926 (org-export-define-backend 'test
'((headline . test
)))
927 (org-export-define-backend 'test2
'((headline . test2
)))
928 (org-export-derived-backend-p 'test2
'test
)))
930 (let (org-export-registered-backends)
931 (org-export-define-backend 'test
'((headline . test
)))
932 (org-export-define-backend 'test2
'((headline . test2
)))
933 (org-export-define-derived-backend 'test3
'test2
)
934 (org-export-derived-backend-p 'test3
'test
))))
936 (ert-deftest test-org-export
/with-backend
()
937 "Test `org-export-with-backend' definition."
938 ;; Error when calling an undefined back-end
940 (let (org-export-registered-backends)
941 (org-export-with-backend 'test
"Test")))
942 ;; Error when called back-end doesn't have an appropriate
945 (let (org-export-registered-backends)
946 (org-export-define-backend 'test
((headline . ignore
)))
947 (org-export-with-backend 'test
"Test")))
948 ;; Otherwise, export using correct transcoder
951 (let (org-export-registered-backends)
952 (org-export-define-backend 'test
953 '((plain-text .
(lambda (text contents info
) "Failure"))))
954 (org-export-define-backend 'test2
955 '((plain-text .
(lambda (text contents info
) "Success"))))
956 (org-export-with-backend 'test2
"Test")))))
958 (ert-deftest test-org-export
/data-with-translations
()
959 "Test `org-export-data-with-translations' specifications."
963 (org-export-data-with-translations
965 '((plain-text .
(lambda (text info
) "Success"))
966 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
967 '(:with-emphasize t
)))))
969 (ert-deftest test-org-export
/data-with-backend
()
970 "Test `org-export-data-with-backend' specifications."
971 ;; Error when calling an undefined back-end.
973 (let (org-export-registered-backends)
974 (org-export-data-with-backend 'test
"Test" nil
)))
975 ;; Otherwise, export data recursively, using correct back-end.
979 (let (org-export-registered-backends)
980 (org-export-define-backend 'test
981 '((plain-text .
(lambda (text info
) "Success"))
982 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
983 (org-export-data-with-backend
984 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
990 (ert-deftest test-org-export
/export-snippet
()
991 "Test export snippets transcoding."
992 (org-test-with-temp-text "@@test:A@@@@t:B@@"
993 (org-test-with-backend test
995 (cdr (assq 'test org-export-registered-backends
))
997 (cons (cons 'export-snippet
998 (lambda (snippet contents info
)
999 (when (eq (org-export-snippet-backend snippet
) 'test
)
1000 (org-element-property :value snippet
))))
1001 (org-export-backend-translate-table 'test
)))
1002 (let ((org-export-snippet-translation-alist nil
))
1003 (should (equal (org-export-as 'test
) "A\n")))
1004 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1005 (should (equal (org-export-as 'test
) "AB\n")))))
1006 ;; Ignored export snippets do not remove any blank.
1008 (equal "begin end\n"
1009 (org-test-with-parsed-data "begin @@test:A@@ end"
1010 (org-export-data-with-translations
1012 '((paragraph .
(lambda (paragraph contents info
) contents
))
1013 (section .
(lambda (section contents info
) contents
)))
1020 (ert-deftest test-org-export
/footnotes
()
1021 "Test footnotes specifications."
1022 (let ((org-footnote-section nil
)
1023 (org-export-with-footnotes t
))
1024 ;; 1. Read every type of footnote.
1027 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1028 (org-test-with-parsed-data
1029 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1030 (org-element-map tree
'footnote-reference
1032 (let ((def (org-export-get-footnote-definition ref info
)))
1033 (cons (org-export-get-footnote-number ref info
)
1034 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1035 (car (org-element-contents
1036 (car (org-element-contents def
))))))))
1038 ;; 2. Test nested footnotes order.
1039 (org-test-with-parsed-data
1040 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1043 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
1044 (org-element-map tree
'footnote-reference
1046 (when (org-export-footnote-first-reference-p ref info
)
1047 (cons (org-export-get-footnote-number ref info
)
1048 (org-element-property :label ref
))))
1050 ;; 3. Test nested footnote in invisible definitions.
1051 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1052 ;; Hide definitions.
1053 (narrow-to-region (point) (point-at-eol))
1054 (let* ((tree (org-element-parse-buffer))
1055 (info (org-combine-plists
1056 `(:parse-tree
,tree
)
1057 (org-export-collect-tree-properties
1058 tree
(org-export-get-environment)))))
1059 ;; Both footnotes should be seen.
1061 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
1062 ;; 4. Test footnotes definitions collection.
1063 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1065 \[fn:2] B [fn:3] [fn::D].
1068 (should (= (length (org-export-collect-footnote-definitions tree info
))
1070 ;; 5. Test export of footnotes defined outside parsing scope.
1071 (org-test-with-temp-text "[fn:1] Out of scope
1074 (org-test-with-backend test
1076 (cdr (assq 'test org-export-registered-backends
))
1078 (cons (cons 'footnote-reference
1079 (lambda (fn contents info
)
1080 (org-element-interpret-data
1081 (org-export-get-footnote-definition fn info
))))
1082 (org-export-backend-translate-table 'test
)))
1084 (should (equal "ParagraphOut of scope\n"
1085 (org-export-as 'test
'subtree
)))))
1086 ;; 6. Footnotes without a definition should be provided a fallback
1089 (org-test-with-parsed-data "[fn:1]"
1090 (org-export-get-footnote-definition
1091 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1092 ;; 7. Footnote section should be ignored in TOC and in headlines
1095 (= 1 (let ((org-footnote-section "Footnotes"))
1096 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1097 (org-export-collect-headlines info
))))))
1100 (let ((org-footnote-section "Footnotes"))
1101 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1102 (org-element-map tree
'headline
1104 (when (equal (org-element-property :raw-value hl
) "H2")
1105 (org-export-get-headline-number hl info
)))
1110 ;;; Headlines and Inlinetasks
1112 (ert-deftest test-org-export
/get-relative-level
()
1113 "Test `org-export-get-relative-level' specifications."
1117 (let ((org-odd-levels-only nil
))
1118 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1119 (org-element-map tree
'headline
1120 (lambda (h) (org-export-get-relative-level h info
))
1125 (let ((org-odd-levels-only nil
))
1126 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1127 (org-element-map tree
'headline
1128 (lambda (h) (org-export-get-relative-level h info
))
1131 (ert-deftest test-org-export
/low-level-p
()
1132 "Test `org-export-low-level-p' specifications."
1136 (let ((org-odd-levels-only nil
))
1137 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1138 (org-element-map tree
'headline
1139 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1140 (plist-put info
:headline-levels
1)))))))
1142 (ert-deftest test-org-export
/get-headline-number
()
1143 "Test `org-export-get-headline-number' specifications."
1148 (let ((org-odd-levels-only nil
))
1149 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1150 (org-element-map tree
'headline
1151 (lambda (h) (org-export-get-headline-number h info
))
1153 ;; Missing levels are replaced with 0.
1157 (let ((org-odd-levels-only nil
))
1158 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1159 (org-element-map tree
'headline
1160 (lambda (h) (org-export-get-headline-number h info
))
1163 (ert-deftest test-org-export
/numbered-headline-p
()
1164 "Test `org-export-numbered-headline-p' specifications."
1165 ;; If `:section-numbers' is nil, never number headlines.
1167 (org-test-with-parsed-data "* Headline"
1168 (org-element-map tree
'headline
1169 (lambda (h) (org-export-numbered-headline-p h info
))
1170 (plist-put info
:section-numbers nil
))))
1171 ;; If `:section-numbers' is a number, only number headlines with
1172 ;; a level greater that it.
1176 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1177 (org-element-map tree
'headline
1178 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1179 (plist-put info
:section-numbers
1)))))
1180 ;; Otherwise, headlines are always numbered.
1182 (org-test-with-parsed-data "* Headline"
1183 (org-element-map tree
'headline
1184 (lambda (h) (org-export-numbered-headline-p h info
))
1185 (plist-put info
:section-numbers t
)))))
1187 (ert-deftest test-org-export
/number-to-roman
()
1188 "Test `org-export-number-to-roman' specifications."
1189 ;; If number is negative, return it as a string.
1190 (should (equal (org-export-number-to-roman -
1) "-1"))
1191 ;; Otherwise, return it as a roman number.
1192 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1194 (ert-deftest test-org-export
/get-optional-title
()
1195 "Test `org-export-get-alt-title' specifications."
1196 ;; If ALT_TITLE property is defined, use it.
1199 (org-test-with-parsed-data
1200 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1201 (org-export-get-alt-title
1202 (org-element-map tree
'headline
'identity info t
)
1204 ;; Otherwise, fall-back to regular title.
1206 (equal '("Headline")
1207 (org-test-with-parsed-data "* Headline"
1208 (org-export-get-alt-title
1209 (org-element-map tree
'headline
'identity info t
)
1212 (ert-deftest test-org-export
/get-tags
()
1213 "Test `org-export-get-tags' specifications."
1214 (let ((org-export-exclude-tags '("noexport"))
1215 (org-export-select-tags '("export")))
1216 ;; Standard test: tags which are not a select tag, an exclude tag,
1217 ;; or specified as optional argument shouldn't be ignored.
1219 (org-test-with-parsed-data "* Headline :tag:"
1220 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1222 ;; Exclude tags are removed.
1224 (org-test-with-parsed-data "* Headline :noexport:"
1225 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1227 ;; Select tags are removed.
1229 (org-test-with-parsed-data "* Headline :export:"
1230 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1235 (org-test-with-parsed-data "* Headline :tag:export:"
1236 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1238 ;; Tags provided in the optional argument are also ignored.
1240 (org-test-with-parsed-data "* Headline :ignore:"
1241 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1243 ;; Allow tag inheritance.
1247 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1248 (org-element-map tree
'headline
1249 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1250 ;; Tag inheritance checks FILETAGS keywords.
1254 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1255 (org-element-map tree
'headline
1256 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1258 (ert-deftest test-org-export
/get-node-property
()
1259 "Test`org-export-get-node-property' specifications."
1263 (org-test-with-parsed-data "* Headline
1267 (org-export-get-node-property
1268 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1269 ;; Test inheritance.
1272 (org-test-with-parsed-data "* Parent
1278 (org-export-get-node-property
1279 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1280 ;; Cannot return a value before the first headline.
1282 (org-test-with-parsed-data "Paragraph
1287 (org-export-get-node-property
1288 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1290 (ert-deftest test-org-export
/get-category
()
1291 "Test `org-export-get-category' specifications."
1295 (org-test-with-parsed-data "* Headline
1299 (org-export-get-category
1300 (org-element-map tree
'headline
'identity nil t
) info
))))
1301 ;; Test inheritance from a parent headline.
1303 (equal '("value" "value")
1304 (org-test-with-parsed-data "* Headline1
1309 (org-element-map tree
'headline
1310 (lambda (hl) (org-export-get-category hl info
)) info
))))
1311 ;; Test inheritance from #+CATEGORY keyword
1314 (org-test-with-parsed-data "#+CATEGORY: value
1316 (org-export-get-category
1317 (org-element-map tree
'headline
'identity nil t
) info
))))
1318 ;; Test inheritance from file name.
1321 (org-test-with-parsed-data "* Headline"
1322 (let ((info (plist-put info
:input-file
"~/test.org")))
1323 (org-export-get-category
1324 (org-element-map tree
'headline
'identity nil t
) info
)))))
1328 (org-test-with-parsed-data "* Headline"
1329 (org-export-get-category
1330 (org-element-map tree
'headline
'identity nil t
) info
)))))
1332 (ert-deftest test-org-export
/first-sibling-p
()
1333 "Test `org-export-first-sibling-p' specifications."
1338 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1339 (org-element-map tree
'headline
1340 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1342 ;; Ignore headlines not exported.
1346 (let ((org-export-exclude-tags '("ignore")))
1347 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1348 (org-element-map tree
'headline
1349 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1352 (ert-deftest test-org-export
/last-sibling-p
()
1353 "Test `org-export-last-sibling-p' specifications."
1358 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1359 (org-element-map tree
'headline
1360 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1362 ;; Ignore headlines not exported.
1366 (let ((org-export-exclude-tags '("ignore")))
1367 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1368 (org-element-map tree
'headline
1369 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1372 (ert-deftest test-org-export
/handle-inlinetasks
()
1373 "Test inlinetask export."
1374 ;; Inlinetask with an exclude tag.
1375 (when (featurep 'org-inlinetask
)
1379 (let ((org-inlinetask-min-level 3))
1380 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1381 (org-test-with-backend test
1382 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp"))))))))
1383 ;; Inlinetask with an include tag.
1386 "* H2\n*** Inline :exp:\n"
1387 (let ((org-inlinetask-min-level 3)
1388 (org-tags-column 0))
1389 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1390 (org-test-with-backend test
1391 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
1392 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1395 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1396 (org-inlinetask-min-level 3))
1397 (org-test-with-temp-text "*** TODO Inline"
1398 (org-test-with-backend test
1399 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))))
1405 (ert-deftest test-org-export
/get-date
()
1406 "Test `org-export-get-date' specifications."
1407 ;; Return a properly formatted string when
1408 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1409 ;; consists in a single timestamp.
1412 (let ((org-export-date-timestamp-format "%d %m %Y"))
1413 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1414 (org-export-get-date info
)))))
1415 ;; Return a secondary string otherwise.
1418 (let ((org-export-date-timestamp-format nil
))
1419 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1420 (org-export-get-date info
)))))
1423 (org-test-with-parsed-data "#+DATE: Date"
1424 (org-export-get-date info
))))
1425 ;; Optional argument has precedence over
1426 ;; `org-export-date-timestamp-format'.
1429 (let ((org-export-date-timestamp-format "%d %m %Y"))
1430 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1431 (org-export-get-date info
"%d %m"))))))
1437 (ert-deftest test-org-export
/get-coderef-format
()
1438 "Test `org-export-get-coderef-format' specifications."
1439 ;; A link without description returns "%s"
1440 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1442 ;; Return "%s" when path is matched within description.
1443 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1445 ;; Otherwise return description.
1446 (should (equal (org-export-get-coderef-format "path" "desc")
1449 (ert-deftest test-org-export
/inline-image-p
()
1450 "Test `org-export-inline-image-p' specifications."
1452 (org-export-inline-image-p
1453 (org-test-with-temp-text "[[#id]]"
1454 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1455 '(("custom-id" .
"id")))))
1457 (ert-deftest test-org-export
/fuzzy-link
()
1458 "Test fuzzy links specifications."
1459 ;; Link to an headline should return headline's number.
1460 (org-test-with-parsed-data
1461 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1463 ;; Note: Headline's number is in fact a list of numbers.
1465 (org-element-map tree
'link
1467 (org-export-get-ordinal
1468 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1469 ;; Link to a target in an item should return item's number.
1470 (org-test-with-parsed-data
1471 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1473 ;; Note: Item's number is in fact a list of numbers.
1475 (org-element-map tree
'link
1477 (org-export-get-ordinal
1478 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1479 ;; Link to a target in a footnote should return footnote's number.
1480 (org-test-with-parsed-data "
1481 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1484 (org-element-map tree
'link
1486 (org-export-get-ordinal
1487 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1488 ;; Link to a named element should return sequence number of that
1490 (org-test-with-parsed-data
1491 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1494 (org-element-map tree
'link
1496 (org-export-get-ordinal
1497 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1498 ;; Link to a target not within an item, a table, a footnote
1499 ;; reference or definition should return section number.
1500 (org-test-with-parsed-data
1501 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1504 (org-element-map tree
'link
1506 (org-export-get-ordinal
1507 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1508 ;; Space are not significant when matching a fuzzy link.
1510 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1511 (org-element-map tree
'link
1512 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1514 ;; Statistics cookies are ignored for headline match.
1516 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1517 (org-element-map tree
'link
1518 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1521 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1522 (org-element-map tree
'link
1523 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1525 ;; Headline match is position dependent.
1529 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
1530 (org-element-map tree
'link
1531 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
1533 (ert-deftest test-org-export
/resolve-coderef
()
1534 "Test `org-export-resolve-coderef' specifications."
1535 (let ((org-coderef-label-format "(ref:%s)"))
1536 ;; 1. A link to a "-n -k -r" block returns line number.
1537 (org-test-with-parsed-data
1538 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1539 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1540 (org-test-with-parsed-data
1541 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1542 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1543 ;; 2. A link to a "-n -r" block returns line number.
1544 (org-test-with-parsed-data
1545 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1546 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1547 (org-test-with-parsed-data
1548 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1549 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1550 ;; 3. A link to a "-n" block returns coderef.
1551 (org-test-with-parsed-data
1552 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1553 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1554 (org-test-with-parsed-data
1555 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1556 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1557 ;; 4. A link to a "-r" block returns line number.
1558 (org-test-with-parsed-data
1559 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1560 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1561 (org-test-with-parsed-data
1562 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1563 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1564 ;; 5. A link to a block without a switch returns coderef.
1565 (org-test-with-parsed-data
1566 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1567 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1568 (org-test-with-parsed-data
1569 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1570 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1571 ;; 6. Correctly handle continued line numbers. A "+n" switch
1572 ;; should resume numbering from previous block with numbered
1573 ;; lines, ignoring blocks not numbering lines in the process.
1574 ;; A "-n" switch resets count.
1575 (org-test-with-parsed-data "
1580 #+BEGIN_SRC emacs-lisp
1584 #+BEGIN_SRC emacs-lisp +n -r
1585 \(+ 1 1) (ref:addition)
1588 #+BEGIN_EXAMPLE -n -r
1589 Another text. (ref:text)
1591 (should (= (org-export-resolve-coderef "addition" info
) 2))
1592 (should (= (org-export-resolve-coderef "text" info
) 1)))
1593 ;; 7. Recognize coderef with user-specified syntax.
1594 (org-test-with-parsed-data
1595 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1596 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1598 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1599 "Test `org-export-resolve-fuzzy-link' specifications."
1600 ;; Match target objects.
1602 (org-test-with-parsed-data "<<target>> [[target]]"
1603 (org-export-resolve-fuzzy-link
1604 (org-element-map tree
'link
'identity info t
) info
)))
1605 ;; Match named elements.
1607 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1608 (org-export-resolve-fuzzy-link
1609 (org-element-map tree
'link
'identity info t
) info
)))
1610 ;; Match exact headline's name.
1612 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1613 (org-export-resolve-fuzzy-link
1614 (org-element-map tree
'link
'identity info t
) info
)))
1615 ;; Targets objects have priority over named elements and headline
1619 (org-test-with-parsed-data
1620 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1622 (org-export-resolve-fuzzy-link
1623 (org-element-map tree
'link
'identity info t
) info
)))))
1624 ;; Named elements have priority over headline titles.
1627 (org-test-with-parsed-data
1628 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1630 (org-export-resolve-fuzzy-link
1631 (org-element-map tree
'link
'identity info t
) info
)))))
1632 ;; If link's path starts with a "*", only match headline titles,
1636 (org-test-with-parsed-data
1637 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1639 (org-export-resolve-fuzzy-link
1640 (org-element-map tree
'link
'identity info t
) info
)))))
1641 ;; Return nil if no match.
1643 (org-test-with-parsed-data "[[target]]"
1644 (org-export-resolve-fuzzy-link
1645 (org-element-map tree
'link
'identity info t
) info
))))
1647 (ert-deftest test-org-export
/resolve-id-link
()
1648 "Test `org-export-resolve-id-link' specifications."
1649 ;; 1. Regular test for custom-id link.
1650 (org-test-with-parsed-data "* Headline1
1657 (org-export-resolve-id-link
1658 (org-element-map tree
'link
'identity info t
) info
)))
1659 ;; 2. Failing test for custom-id link.
1660 (org-test-with-parsed-data "* Headline1
1667 (org-export-resolve-id-link
1668 (org-element-map tree
'link
'identity info t
) info
)))
1669 ;; 3. Test for internal id target.
1670 (org-test-with-parsed-data "* Headline1
1677 (org-export-resolve-id-link
1678 (org-element-map tree
'link
'identity info t
) info
)))
1679 ;; 4. Test for external id target.
1680 (org-test-with-parsed-data "[[id:aaaa]]"
1682 (org-export-resolve-id-link
1683 (org-element-map tree
'link
'identity info t
)
1684 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1686 (ert-deftest test-org-export
/resolve-radio-link
()
1687 "Test `org-export-resolve-radio-link' specifications."
1690 (org-test-with-temp-text "<<<radio>>> radio"
1691 (org-update-radio-target-regexp)
1692 (let* ((tree (org-element-parse-buffer))
1693 (info `(:parse-tree
,tree
)))
1694 (org-export-resolve-radio-link
1695 (org-element-map tree
'link
'identity info t
)
1697 ;; Radio targets are case-insensitive.
1699 (org-test-with-temp-text "<<<RADIO>>> radio"
1700 (org-update-radio-target-regexp)
1701 (let* ((tree (org-element-parse-buffer))
1702 (info `(:parse-tree
,tree
)))
1703 (org-export-resolve-radio-link
1704 (org-element-map tree
'link
'identity info t
)
1706 ;; Radio target with objects.
1708 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1709 (org-update-radio-target-regexp)
1710 (let* ((tree (org-element-parse-buffer))
1711 (info `(:parse-tree
,tree
)))
1712 (org-export-resolve-radio-link
1713 (org-element-map tree
'link
'identity info t
)
1715 ;; Multiple radio targets.
1717 (equal '("radio1" "radio2")
1718 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
1719 (org-update-radio-target-regexp)
1720 (let* ((tree (org-element-parse-buffer))
1721 (info `(:parse-tree
,tree
)))
1722 (org-element-map tree
'link
1724 (org-element-property
1725 :value
(org-export-resolve-radio-link link info
)))
1727 ;; Radio target is whitespace insensitive.
1729 (org-test-with-temp-text "<<<a radio>>> a\n radio"
1730 (org-update-radio-target-regexp)
1731 (let* ((tree (org-element-parse-buffer))
1732 (info `(:parse-tree
,tree
)))
1733 (org-element-map tree
'link
1734 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
1738 ;;; Src-block and example-block
1740 (ert-deftest test-org-export
/unravel-code
()
1741 "Test `org-export-unravel-code' function."
1742 (let ((org-coderef-label-format "(ref:%s)"))
1743 ;; 1. Code without reference.
1744 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1745 (should (equal (org-export-unravel-code (org-element-at-point))
1747 ;; 2. Code with reference.
1748 (org-test-with-temp-text
1749 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1750 (should (equal (org-export-unravel-code (org-element-at-point))
1751 '("(+ 1 1)\n" (1 .
"test")))))
1752 ;; 3. Code with user-defined reference.
1753 (org-test-with-temp-text
1754 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1755 (should (equal (org-export-unravel-code (org-element-at-point))
1756 '("(+ 1 1)\n" (1 .
"test")))))
1757 ;; 4. Code references keys are relative to the current block.
1758 (org-test-with-temp-text "
1767 (should (equal (org-export-unravel-code (org-element-at-point))
1768 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1770 (ert-deftest test-org-export
/format-code-default
()
1771 "Test `org-export-format-code-default' specifications."
1772 ;; Return the empty string when code is empty.
1775 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1776 (org-export-format-code-default
1777 (org-element-map tree
'src-block
'identity info t
) info
))))
1778 ;; Number lines, two whitespace characters before the actual loc.
1781 (org-test-with-parsed-data
1782 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1783 (org-export-format-code-default
1784 (org-element-map tree
'src-block
'identity info t
) info
))))
1785 ;; Put references 6 whitespace characters after the widest line,
1786 ;; wrapped within parenthesis.
1788 (equal "123 (a)\n1 (b)\n"
1789 (let ((org-coderef-label-format "(ref:%s)"))
1790 (org-test-with-parsed-data
1791 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1792 (org-export-format-code-default
1793 (org-element-map tree
'src-block
'identity info t
) info
))))))
1799 (ert-deftest test-org-export
/activate-smart-quotes
()
1800 "Test `org-export-activate-smart-quotes' specifications."
1801 ;; Opening double quotes: standard test.
1804 '("some “paragraph")
1805 (let ((org-export-default-language "en"))
1806 (org-test-with-parsed-data "some \"paragraph"
1807 (org-element-map tree
'plain-text
1808 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1810 ;; Opening quotes: at the beginning of a paragraph.
1814 (let ((org-export-default-language "en"))
1815 (org-test-with-parsed-data "\"begin"
1816 (org-element-map tree
'plain-text
1817 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1819 ;; Opening quotes: after an object.
1823 (let ((org-export-default-language "en"))
1824 (org-test-with-parsed-data "=verb= \"begin"
1825 (org-element-map tree
'plain-text
1826 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1828 ;; Closing quotes: standard test.
1831 '("some” paragraph")
1832 (let ((org-export-default-language "en"))
1833 (org-test-with-parsed-data "some\" paragraph"
1834 (org-element-map tree
'plain-text
1835 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1837 ;; Closing quotes: at the end of a paragraph.
1841 (let ((org-export-default-language "en"))
1842 (org-test-with-parsed-data "end\""
1843 (org-element-map tree
'plain-text
1844 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1846 ;; Apostrophe: standard test.
1849 '("It shouldn’t fail")
1850 (let ((org-export-default-language "en"))
1851 (org-test-with-parsed-data "It shouldn't fail"
1852 (org-element-map tree
'plain-text
1853 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1855 ;; Apostrophe: before an object.
1859 (let ((org-export-default-language "en"))
1860 (org-test-with-parsed-data "a'=b="
1861 (org-element-map tree
'plain-text
1862 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1864 ;; Apostrophe: after an object.
1868 (let ((org-export-default-language "en"))
1869 (org-test-with-parsed-data "=code='s"
1870 (org-element-map tree
'plain-text
1871 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1873 ;; Special case: isolated quotes.
1875 (equal '("“" "”")
1876 (let ((org-export-default-language "en"))
1877 (org-test-with-parsed-data "\"$x$\""
1878 (org-element-map tree
'plain-text
1879 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1881 ;; Smart quotes in secondary strings.
1883 (equal '("“" "”")
1884 (let ((org-export-default-language "en"))
1885 (org-test-with-parsed-data "* \"$x$\""
1886 (org-element-map tree
'plain-text
1887 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1889 ;; Smart quotes in document keywords.
1891 (equal '("“" "”")
1892 (let ((org-export-default-language "en"))
1893 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1894 (org-element-map (plist-get info
:title
) 'plain-text
1895 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1897 ;; Smart quotes in parsed affiliated keywords.
1899 (equal '("“" "”" "Paragraph")
1900 (let ((org-export-default-language "en"))
1901 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1902 (org-element-map tree
'plain-text
1903 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1904 info nil nil t
))))))
1910 (ert-deftest test-org-export
/special-column
()
1911 "Test if the table's special column is properly recognized."
1912 ;; 1. First column is special if it contains only a special marking
1913 ;; characters or empty cells.
1914 (org-test-with-temp-text "
1918 (org-export-table-has-special-column-p
1920 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1921 ;; 2. If the column contains anything else, it isn't special.
1922 (org-test-with-temp-text "
1926 (org-export-table-has-special-column-p
1928 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1929 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1931 (org-test-with-temp-text "
1940 (org-export-table-has-special-column-p
1942 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1943 ;; 4. A first column with only empty cells isn't considered as
1945 (org-test-with-temp-text "
1949 (org-export-table-has-special-column-p
1951 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1953 (ert-deftest test-org-export
/table-row-is-special-p
()
1954 "Test `org-export-table-row-is-special-p' specifications."
1955 ;; 1. A row is special if it has a special marking character in the
1957 (org-test-with-parsed-data "| ! | 1 |"
1959 (org-export-table-row-is-special-p
1960 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1961 ;; 2. A row is special when its first field is "/"
1962 (org-test-with-parsed-data "
1966 (org-export-table-row-is-special-p
1967 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1968 ;; 3. A row only containing alignment cookies is also considered as
1970 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1972 (org-export-table-row-is-special-p
1973 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1974 ;; 4. Everything else isn't considered as special.
1975 (org-test-with-parsed-data "| \alpha | | c |"
1977 (org-export-table-row-is-special-p
1978 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1979 ;; 5. Table's rules are never considered as special rows.
1980 (org-test-with-parsed-data "|---+---|"
1982 (org-export-table-row-is-special-p
1983 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1985 (ert-deftest test-org-export
/has-header-p
()
1986 "Test `org-export-table-has-header-p' specifications."
1987 ;; 1. With an header.
1988 (org-test-with-parsed-data "
1993 (org-export-table-has-header-p
1994 (org-element-map tree
'table
'identity info
'first-match
)
1996 ;; 2. Without an header.
1997 (org-test-with-parsed-data "
2001 (org-export-table-has-header-p
2002 (org-element-map tree
'table
'identity info
'first-match
)
2004 ;; 3. Don't get fooled with starting and ending rules.
2005 (org-test-with-parsed-data "
2011 (org-export-table-has-header-p
2012 (org-element-map tree
'table
'identity info
'first-match
)
2015 (ert-deftest test-org-export
/table-row-group
()
2016 "Test `org-export-table-row-group' specifications."
2017 ;; 1. A rule creates a new group.
2018 (org-test-with-parsed-data "
2025 (mapcar (lambda (row) (org-export-table-row-group row info
))
2026 (org-element-map tree
'table-row
'identity
)))))
2027 ;; 2. Special rows are ignored in count.
2028 (org-test-with-parsed-data "
2035 (mapcar (lambda (row) (org-export-table-row-group row info
))
2036 (org-element-map tree
'table-row
'identity
)))))
2037 ;; 3. Double rules also are ignored in count.
2038 (org-test-with-parsed-data "
2046 (mapcar (lambda (row) (org-export-table-row-group row info
))
2047 (org-element-map tree
'table-row
'identity
))))))
2049 (ert-deftest test-org-export
/table-row-number
()
2050 "Test `org-export-table-row-number' specifications."
2051 ;; Standard test. Number is 0-indexed.
2054 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2055 (org-element-map tree
'table-row
2056 (lambda (row) (org-export-table-row-number row info
)) info
))))
2057 ;; Number ignores separators.
2060 (org-test-with-parsed-data "
2064 (org-element-map tree
'table-row
2065 (lambda (row) (org-export-table-row-number row info
)) info
))))
2066 ;; Number ignores special rows.
2069 (org-test-with-parsed-data "
2075 (org-element-map tree
'table-row
2076 (lambda (row) (org-export-table-row-number row info
)) info
)))))
2078 (ert-deftest test-org-export
/table-cell-width
()
2079 "Test `org-export-table-cell-width' specifications."
2080 ;; 1. Width is primarily determined by width cookies. If no cookie
2081 ;; is found, cell's width is nil.
2082 (org-test-with-parsed-data "
2083 | / | <l> | <6> | <l7> |
2088 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2089 (org-element-map tree
'table-cell
'identity info
)))))
2090 ;; 2. The last width cookie has precedence.
2091 (org-test-with-parsed-data "
2098 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2099 (org-element-map tree
'table-cell
'identity info
)))))
2100 ;; 3. Valid width cookies must have a specific row.
2101 (org-test-with-parsed-data "| <6> | cell |"
2105 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2106 (org-element-map tree
'table-cell
'identity
))))))
2108 (ert-deftest test-org-export
/table-cell-alignment
()
2109 "Test `org-export-table-cell-alignment' specifications."
2110 (let ((org-table-number-fraction 0.5)
2111 (org-table-number-regexp "^[0-9]+$"))
2112 ;; 1. Alignment is primarily determined by alignment cookies.
2113 (org-test-with-temp-text "| <l> | <c> | <r> |"
2114 (let* ((tree (org-element-parse-buffer))
2115 (info `(:parse-tree
,tree
)))
2118 '(left center right
)
2119 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2120 (org-element-map tree
'table-cell
'identity
))))))
2121 ;; 2. The last alignment cookie has precedence.
2122 (org-test-with-parsed-data "
2128 '(right right right
)
2129 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2130 (org-element-map tree
'table-cell
'identity
)))))
2131 ;; 3. If there's no cookie, cell's contents determine alignment.
2132 ;; A column mostly made of cells containing numbers will align
2133 ;; its cells to the right.
2134 (org-test-with-parsed-data "
2140 '(right right right
)
2141 (mapcar (lambda (cell)
2142 (org-export-table-cell-alignment cell info
))
2143 (org-element-map tree
'table-cell
'identity
)))))
2144 ;; 4. Otherwise, they will be aligned to the left.
2145 (org-test-with-parsed-data "
2152 (mapcar (lambda (cell)
2153 (org-export-table-cell-alignment cell info
))
2154 (org-element-map tree
'table-cell
'identity
)))))))
2156 (ert-deftest test-org-export
/table-cell-borders
()
2157 "Test `org-export-table-cell-borders' specifications."
2158 ;; 1. Recognize various column groups indicators.
2159 (org-test-with-parsed-data "| / | < | > | <> |"
2162 '((right bottom top
) (left bottom top
) (right bottom top
)
2163 (right left bottom top
))
2164 (mapcar (lambda (cell)
2165 (org-export-table-cell-borders cell info
))
2166 (org-element-map tree
'table-cell
'identity
)))))
2167 ;; 2. Accept shortcuts to define column groups.
2168 (org-test-with-parsed-data "| / | < | < |"
2171 '((right bottom top
) (right left bottom top
) (left bottom top
))
2172 (mapcar (lambda (cell)
2173 (org-export-table-cell-borders cell info
))
2174 (org-element-map tree
'table-cell
'identity
)))))
2175 ;; 3. A valid column groups row must start with a "/".
2176 (org-test-with-parsed-data "
2180 (equal '((top) (top) (bottom) (bottom))
2181 (mapcar (lambda (cell)
2182 (org-export-table-cell-borders cell info
))
2183 (org-element-map tree
'table-cell
'identity
)))))
2184 ;; 4. Take table rules into consideration.
2185 (org-test-with-parsed-data "
2190 (equal '((below top
) (bottom above
))
2191 (mapcar (lambda (cell)
2192 (org-export-table-cell-borders cell info
))
2193 (org-element-map tree
'table-cell
'identity
)))))
2194 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2195 ;; (resp. `bottom' and `below') borders. Any special row is
2197 (org-test-with-parsed-data "
2203 (equal '((bottom below top above
))
2205 (mapcar (lambda (cell)
2206 (org-export-table-cell-borders cell info
))
2207 (org-element-map tree
'table-cell
'identity
)))))))
2209 (ert-deftest test-org-export
/table-dimensions
()
2210 "Test `org-export-table-dimensions' specifications."
2211 ;; 1. Standard test.
2212 (org-test-with-parsed-data "
2217 (org-export-table-dimensions
2218 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2219 ;; 2. Ignore horizontal rules and special columns.
2220 (org-test-with-parsed-data "
2227 (org-export-table-dimensions
2228 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2230 (ert-deftest test-org-export
/table-cell-address
()
2231 "Test `org-export-table-cell-address' specifications."
2232 ;; 1. Standard test: index is 0-based.
2233 (org-test-with-parsed-data "| a | b |"
2235 (equal '((0 .
0) (0 .
1))
2236 (org-element-map tree
'table-cell
2237 (lambda (cell) (org-export-table-cell-address cell info
))
2239 ;; 2. Special column isn't counted, nor are special rows.
2240 (org-test-with-parsed-data "
2245 (org-export-table-cell-address
2246 (car (last (org-element-map tree
'table-cell
'identity info
)))
2248 ;; 3. Tables rules do not count either.
2249 (org-test-with-parsed-data "
2257 (org-export-table-cell-address
2258 (car (last (org-element-map tree
'table-cell
'identity info
)))
2260 ;; 4. Return nil for special cells.
2261 (org-test-with-parsed-data "| / | a |"
2263 (org-export-table-cell-address
2264 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2267 (ert-deftest test-org-export
/get-table-cell-at
()
2268 "Test `org-export-get-table-cell-at' specifications."
2269 ;; 1. Address ignores special columns, special rows and rules.
2270 (org-test-with-parsed-data "
2277 (org-element-contents
2278 (org-export-get-table-cell-at
2280 (org-element-map tree
'table
'identity info
'first-match
)
2282 ;; 2. Return value for a non-existent address is nil.
2283 (org-test-with-parsed-data "| a |"
2285 (org-export-get-table-cell-at
2287 (org-element-map tree
'table
'identity info
'first-match
)
2289 (org-test-with-parsed-data "| / |"
2291 (org-export-get-table-cell-at
2293 (org-element-map tree
'table
'identity info
'first-match
)
2296 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2297 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2298 ;; 1. A cell at a beginning of a row always starts a column group.
2299 (org-test-with-parsed-data "| a |"
2301 (org-export-table-cell-starts-colgroup-p
2302 (org-element-map tree
'table-cell
'identity info
'first-match
)
2304 ;; 2. Special column should be ignored when determining the
2305 ;; beginning of the row.
2306 (org-test-with-parsed-data "
2310 (org-export-table-cell-starts-colgroup-p
2311 (org-element-map tree
'table-cell
'identity info
'first-match
)
2313 ;; 2. Explicit column groups.
2314 (org-test-with-parsed-data "
2320 (org-element-map tree
'table-cell
2322 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2325 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2326 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2327 ;; 1. A cell at the end of a row always ends a column group.
2328 (org-test-with-parsed-data "| a |"
2330 (org-export-table-cell-ends-colgroup-p
2331 (org-element-map tree
'table-cell
'identity info
'first-match
)
2333 ;; 2. Special column should be ignored when determining the
2334 ;; beginning of the row.
2335 (org-test-with-parsed-data "
2339 (org-export-table-cell-ends-colgroup-p
2340 (org-element-map tree
'table-cell
'identity info
'first-match
)
2342 ;; 3. Explicit column groups.
2343 (org-test-with-parsed-data "
2349 (org-element-map tree
'table-cell
2351 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2354 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2355 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2356 ;; 1. A row at the beginning of a table always starts a row group.
2357 ;; So does a row following a table rule.
2358 (org-test-with-parsed-data "
2365 (org-element-map tree
'table-row
2367 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2369 ;; 2. Special rows should be ignored when determining the beginning
2371 (org-test-with-parsed-data "
2380 (org-element-map tree
'table-row
2382 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2385 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2386 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2387 ;; 1. A row at the end of a table always ends a row group. So does
2388 ;; a row preceding a table rule.
2389 (org-test-with-parsed-data "
2396 (org-element-map tree
'table-row
2398 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2400 ;; 2. Special rows should be ignored when determining the beginning
2402 (org-test-with-parsed-data "
2411 (org-element-map tree
'table-row
2413 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2416 (ert-deftest test-org-export
/table-row-starts-header-p
()
2417 "Test `org-export-table-row-starts-header-p' specifications."
2418 ;; 1. Only the row starting the first row group starts the table
2420 (org-test-with-parsed-data "
2428 (org-element-map tree
'table-row
2430 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2432 ;; 2. A row cannot start an header if there's no header in the
2434 (org-test-with-parsed-data "
2438 (org-export-table-row-starts-header-p
2439 (org-element-map tree
'table-row
'identity info
'first-match
)
2442 (ert-deftest test-org-export
/table-row-ends-header-p
()
2443 "Test `org-export-table-row-ends-header-p' specifications."
2444 ;; 1. Only the row starting the first row group starts the table
2446 (org-test-with-parsed-data "
2454 (org-element-map tree
'table-row
2456 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2458 ;; 2. A row cannot start an header if there's no header in the
2460 (org-test-with-parsed-data "
2464 (org-export-table-row-ends-header-p
2465 (org-element-map tree
'table-row
'identity info
'first-match
)
2472 (ert-deftest test-org-export
/inner-template
()
2473 "Test `inner-template' translator specifications."
2476 (let (org-export-registered-backends)
2477 (org-export-define-backend 'test
2478 '((inner-template .
(lambda (contents info
) "Success!"))
2479 (headline .
(lambda (h c i
) "Headline"))))
2480 (org-test-with-temp-text "* Headline"
2481 (org-export-as 'test
)))))
2482 ;; Inner template is applied even in a "body-only" export.
2485 (let (org-export-registered-backends)
2486 (org-export-define-backend 'test
2487 '((inner-template .
(lambda (contents info
) "Success!"))
2488 (headline .
(lambda (h c i
) "Headline"))))
2489 (org-test-with-temp-text "* Headline"
2490 (org-export-as 'test nil nil
'body-only
))))))
2492 (ert-deftest test-org-export
/template
()
2493 "Test `template' translator specifications."
2496 (let (org-export-registered-backends)
2497 (org-export-define-backend 'test
2498 '((template .
(lambda (contents info
) "Success!"))
2499 (headline .
(lambda (h c i
) "Headline"))))
2500 (org-test-with-temp-text "* Headline"
2501 (org-export-as 'test
)))))
2502 ;; Template is not applied in a "body-only" export.
2505 (let (org-export-registered-backends)
2506 (org-export-define-backend 'test
2507 '((template .
(lambda (contents info
) "Success!"))
2508 (headline .
(lambda (h c i
) "Headline"))))
2509 (org-test-with-temp-text "* Headline"
2510 (org-export-as 'test nil nil
'body-only
))))))
2516 (ert-deftest test-org-export
/get-next-element
()
2517 "Test `org-export-get-next-element' specifications."
2521 (org-test-with-parsed-data "* Headline\n*a* b"
2522 (org-export-get-next-element
2523 (org-element-map tree
'bold
'identity info t
) info
))))
2524 ;; Return nil when no previous element.
2526 (org-test-with-parsed-data "* Headline\na *b*"
2527 (org-export-get-next-element
2528 (org-element-map tree
'bold
'identity info t
) info
)))
2529 ;; Non-exportable elements are ignored.
2531 (let ((org-export-with-timestamps nil
))
2532 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2533 (org-export-get-next-element
2534 (org-element-map tree
'entity
'identity info t
) info
))))
2535 ;; Find next element in secondary strings.
2538 (org-test-with-parsed-data "* a =verb="
2540 (org-export-get-next-element
2541 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2542 ;; Find next element in document keywords.
2545 (org-test-with-parsed-data "#+TITLE: a =verb="
2547 (org-export-get-next-element
2549 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2550 ;; Find next element in parsed affiliated keywords.
2553 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2555 (org-export-get-next-element
2556 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2557 ;; With optional argument N, return a list containing all the
2558 ;; following elements.
2561 '(bold code underline
)
2562 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2564 (org-export-get-next-element
2565 (org-element-map tree
'italic
'identity info t
) info t
)))))
2566 ;; When N is a positive integer, return a list containing up to
2567 ;; N following elements.
2571 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2573 (org-export-get-next-element
2574 (org-element-map tree
'italic
'identity info t
) info
2))))))
2576 (ert-deftest test-org-export
/get-previous-element
()
2577 "Test `org-export-get-previous-element' specifications."
2581 (org-test-with-parsed-data "* Headline\na *b*"
2582 (org-export-get-previous-element
2583 (org-element-map tree
'bold
'identity info t
) info
))))
2584 ;; Return nil when no previous element.
2586 (org-test-with-parsed-data "* Headline\n*a* b"
2587 (org-export-get-previous-element
2588 (org-element-map tree
'bold
'identity info t
) info
)))
2589 ;; Non-exportable elements are ignored.
2591 (let ((org-export-with-timestamps nil
))
2592 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2593 (org-export-get-previous-element
2594 (org-element-map tree
'entity
'identity info t
) info
))))
2595 ;; Find previous element in secondary strings.
2598 (org-test-with-parsed-data "* =verb= a"
2600 (org-export-get-previous-element
2601 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2602 ;; Find previous element in document keywords.
2605 (org-test-with-parsed-data "#+TITLE: =verb= a"
2607 (org-export-get-previous-element
2609 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2610 ;; Find previous element in parsed affiliated keywords.
2613 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2615 (org-export-get-previous-element
2616 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2617 ;; With optional argument N, return a list containing up to
2618 ;; N previous elements.
2620 (equal '(underline italic bold
)
2621 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2623 (org-export-get-previous-element
2624 (org-element-map tree
'code
'identity info t
) info t
)))))
2625 ;; When N is a positive integer, return a list containing up to
2626 ;; N previous elements.
2628 (equal '(italic bold
)
2629 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2631 (org-export-get-previous-element
2632 (org-element-map tree
'code
'identity info t
) info
2))))))
2636 ;;; test-org-export.el end here