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
)))
1646 ;; Match fuzzy link even when before first headline.
1649 (org-test-with-parsed-data "[[hl]]\n* hl"
1651 (org-export-resolve-fuzzy-link
1652 (org-element-map tree
'link
'identity info t
) info
))))))
1654 (ert-deftest test-org-export
/resolve-id-link
()
1655 "Test `org-export-resolve-id-link' specifications."
1656 ;; 1. Regular test for custom-id link.
1657 (org-test-with-parsed-data "* Headline1
1664 (org-export-resolve-id-link
1665 (org-element-map tree
'link
'identity info t
) info
)))
1666 ;; 2. Failing test for custom-id link.
1667 (org-test-with-parsed-data "* Headline1
1674 (org-export-resolve-id-link
1675 (org-element-map tree
'link
'identity info t
) info
)))
1676 ;; 3. Test for internal id target.
1677 (org-test-with-parsed-data "* Headline1
1684 (org-export-resolve-id-link
1685 (org-element-map tree
'link
'identity info t
) info
)))
1686 ;; 4. Test for external id target.
1687 (org-test-with-parsed-data "[[id:aaaa]]"
1689 (org-export-resolve-id-link
1690 (org-element-map tree
'link
'identity info t
)
1691 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1693 (ert-deftest test-org-export
/resolve-radio-link
()
1694 "Test `org-export-resolve-radio-link' specifications."
1697 (org-test-with-temp-text "<<<radio>>> radio"
1698 (org-update-radio-target-regexp)
1699 (let* ((tree (org-element-parse-buffer))
1700 (info `(:parse-tree
,tree
)))
1701 (org-export-resolve-radio-link
1702 (org-element-map tree
'link
'identity info t
)
1704 ;; Radio targets are case-insensitive.
1706 (org-test-with-temp-text "<<<RADIO>>> radio"
1707 (org-update-radio-target-regexp)
1708 (let* ((tree (org-element-parse-buffer))
1709 (info `(:parse-tree
,tree
)))
1710 (org-export-resolve-radio-link
1711 (org-element-map tree
'link
'identity info t
)
1713 ;; Radio target with objects.
1715 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1716 (org-update-radio-target-regexp)
1717 (let* ((tree (org-element-parse-buffer))
1718 (info `(:parse-tree
,tree
)))
1719 (org-export-resolve-radio-link
1720 (org-element-map tree
'link
'identity info t
)
1722 ;; Multiple radio targets.
1724 (equal '("radio1" "radio2")
1725 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
1726 (org-update-radio-target-regexp)
1727 (let* ((tree (org-element-parse-buffer))
1728 (info `(:parse-tree
,tree
)))
1729 (org-element-map tree
'link
1731 (org-element-property
1732 :value
(org-export-resolve-radio-link link info
)))
1734 ;; Radio target is whitespace insensitive.
1736 (org-test-with-temp-text "<<<a radio>>> a\n radio"
1737 (org-update-radio-target-regexp)
1738 (let* ((tree (org-element-parse-buffer))
1739 (info `(:parse-tree
,tree
)))
1740 (org-element-map tree
'link
1741 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
1745 ;;; Src-block and example-block
1747 (ert-deftest test-org-export
/unravel-code
()
1748 "Test `org-export-unravel-code' function."
1749 ;; Code without reference.
1751 (equal '("(+ 1 1)\n")
1752 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1753 (org-export-unravel-code (org-element-at-point)))))
1754 ;; Code with reference.
1756 (equal '("(+ 1 1)\n" (1 .
"test"))
1757 (org-test-with-temp-text
1758 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1759 (let ((org-coderef-label-format "(ref:%s)"))
1760 (org-export-unravel-code (org-element-at-point))))))
1761 ;; Code with user-defined reference.
1764 '("(+ 1 1)\n" (1 .
"test"))
1765 (org-test-with-temp-text
1766 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1767 (let ((org-coderef-label-format "(ref:%s)"))
1768 (org-export-unravel-code (org-element-at-point))))))
1769 ;; Code references keys are relative to the current block.
1771 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
1772 (org-test-with-temp-text "
1781 (let ((org-coderef-label-format "(ref:%s)"))
1782 (org-export-unravel-code (org-element-at-point)))))))
1784 (ert-deftest test-org-export
/format-code-default
()
1785 "Test `org-export-format-code-default' specifications."
1786 ;; Return the empty string when code is empty.
1789 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1790 (org-export-format-code-default
1791 (org-element-map tree
'src-block
'identity info t
) info
))))
1792 ;; Number lines, two whitespace characters before the actual loc.
1795 (org-test-with-parsed-data
1796 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1797 (org-export-format-code-default
1798 (org-element-map tree
'src-block
'identity info t
) info
))))
1799 ;; Put references 6 whitespace characters after the widest line,
1800 ;; wrapped within parenthesis.
1802 (equal "123 (a)\n1 (b)\n"
1803 (let ((org-coderef-label-format "(ref:%s)"))
1804 (org-test-with-parsed-data
1805 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1806 (org-export-format-code-default
1807 (org-element-map tree
'src-block
'identity info t
) info
))))))
1813 (ert-deftest test-org-export
/activate-smart-quotes
()
1814 "Test `org-export-activate-smart-quotes' specifications."
1815 ;; Opening double quotes: standard test.
1818 '("some “paragraph")
1819 (let ((org-export-default-language "en"))
1820 (org-test-with-parsed-data "some \"paragraph"
1821 (org-element-map tree
'plain-text
1822 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1824 ;; Opening quotes: at the beginning of a paragraph.
1828 (let ((org-export-default-language "en"))
1829 (org-test-with-parsed-data "\"begin"
1830 (org-element-map tree
'plain-text
1831 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1833 ;; Opening quotes: after an object.
1837 (let ((org-export-default-language "en"))
1838 (org-test-with-parsed-data "=verb= \"begin"
1839 (org-element-map tree
'plain-text
1840 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1842 ;; Closing quotes: standard test.
1845 '("some” paragraph")
1846 (let ((org-export-default-language "en"))
1847 (org-test-with-parsed-data "some\" paragraph"
1848 (org-element-map tree
'plain-text
1849 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1851 ;; Closing quotes: at the end of a paragraph.
1855 (let ((org-export-default-language "en"))
1856 (org-test-with-parsed-data "end\""
1857 (org-element-map tree
'plain-text
1858 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1860 ;; Apostrophe: standard test.
1863 '("It shouldn’t fail")
1864 (let ((org-export-default-language "en"))
1865 (org-test-with-parsed-data "It shouldn't fail"
1866 (org-element-map tree
'plain-text
1867 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1869 ;; Apostrophe: before an object.
1873 (let ((org-export-default-language "en"))
1874 (org-test-with-parsed-data "a'=b="
1875 (org-element-map tree
'plain-text
1876 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1878 ;; Apostrophe: after an object.
1882 (let ((org-export-default-language "en"))
1883 (org-test-with-parsed-data "=code='s"
1884 (org-element-map tree
'plain-text
1885 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1887 ;; Special case: isolated quotes.
1889 (equal '("“" "”")
1890 (let ((org-export-default-language "en"))
1891 (org-test-with-parsed-data "\"$x$\""
1892 (org-element-map tree
'plain-text
1893 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1895 ;; Smart quotes in secondary strings.
1897 (equal '("“" "”")
1898 (let ((org-export-default-language "en"))
1899 (org-test-with-parsed-data "* \"$x$\""
1900 (org-element-map tree
'plain-text
1901 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1903 ;; Smart quotes in document keywords.
1905 (equal '("“" "”")
1906 (let ((org-export-default-language "en"))
1907 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1908 (org-element-map (plist-get info
:title
) 'plain-text
1909 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1911 ;; Smart quotes in parsed affiliated keywords.
1913 (equal '("“" "”" "Paragraph")
1914 (let ((org-export-default-language "en"))
1915 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1916 (org-element-map tree
'plain-text
1917 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1918 info nil nil t
))))))
1924 (ert-deftest test-org-export
/special-column
()
1925 "Test if the table's special column is properly recognized."
1926 ;; 1. First column is special if it contains only a special marking
1927 ;; characters or empty cells.
1928 (org-test-with-temp-text "
1932 (org-export-table-has-special-column-p
1934 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1935 ;; 2. If the column contains anything else, it isn't special.
1936 (org-test-with-temp-text "
1940 (org-export-table-has-special-column-p
1942 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1943 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1945 (org-test-with-temp-text "
1954 (org-export-table-has-special-column-p
1956 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1957 ;; 4. A first column with only empty cells isn't considered as
1959 (org-test-with-temp-text "
1963 (org-export-table-has-special-column-p
1965 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1967 (ert-deftest test-org-export
/table-row-is-special-p
()
1968 "Test `org-export-table-row-is-special-p' specifications."
1969 ;; 1. A row is special if it has a special marking character in the
1971 (org-test-with-parsed-data "| ! | 1 |"
1973 (org-export-table-row-is-special-p
1974 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1975 ;; 2. A row is special when its first field is "/"
1976 (org-test-with-parsed-data "
1980 (org-export-table-row-is-special-p
1981 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1982 ;; 3. A row only containing alignment cookies is also considered as
1984 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1986 (org-export-table-row-is-special-p
1987 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1988 ;; 4. Everything else isn't considered as special.
1989 (org-test-with-parsed-data "| \alpha | | c |"
1991 (org-export-table-row-is-special-p
1992 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1993 ;; 5. Table's rules are never considered as special rows.
1994 (org-test-with-parsed-data "|---+---|"
1996 (org-export-table-row-is-special-p
1997 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1999 (ert-deftest test-org-export
/has-header-p
()
2000 "Test `org-export-table-has-header-p' specifications."
2001 ;; 1. With an header.
2002 (org-test-with-parsed-data "
2007 (org-export-table-has-header-p
2008 (org-element-map tree
'table
'identity info
'first-match
)
2010 ;; 2. Without an header.
2011 (org-test-with-parsed-data "
2015 (org-export-table-has-header-p
2016 (org-element-map tree
'table
'identity info
'first-match
)
2018 ;; 3. Don't get fooled with starting and ending rules.
2019 (org-test-with-parsed-data "
2025 (org-export-table-has-header-p
2026 (org-element-map tree
'table
'identity info
'first-match
)
2029 (ert-deftest test-org-export
/table-row-group
()
2030 "Test `org-export-table-row-group' specifications."
2031 ;; 1. A rule creates a new group.
2034 (org-test-with-parsed-data "
2038 (org-element-map tree
'table-row
2040 (if (eq (org-element-property :type row
) 'rule
) 'rule
2041 (org-export-table-row-group row info
)))))))
2042 ;; 2. Special rows are ignored in count.
2046 (org-test-with-parsed-data "
2050 (org-element-map tree
'table-row
2052 (if (eq (org-element-property :type row
) 'rule
) 'rule
2053 (org-export-table-row-group row info
)))
2055 ;; 3. Double rules also are ignored in count.
2057 (equal '(1 rule rule
2)
2058 (org-test-with-parsed-data "
2063 (org-element-map tree
'table-row
2065 (if (eq (org-element-property :type row
) 'rule
) 'rule
2066 (org-export-table-row-group row info
))))))))
2068 (ert-deftest test-org-export
/table-row-number
()
2069 "Test `org-export-table-row-number' specifications."
2070 ;; Standard test. Number is 0-indexed.
2073 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2074 (org-element-map tree
'table-row
2075 (lambda (row) (org-export-table-row-number row info
)) info
))))
2076 ;; Number ignores separators.
2079 (org-test-with-parsed-data "
2083 (org-element-map tree
'table-row
2084 (lambda (row) (org-export-table-row-number row info
)) info
))))
2085 ;; Number ignores special rows.
2088 (org-test-with-parsed-data "
2094 (org-element-map tree
'table-row
2095 (lambda (row) (org-export-table-row-number row info
)) info
)))))
2097 (ert-deftest test-org-export
/table-cell-width
()
2098 "Test `org-export-table-cell-width' specifications."
2099 ;; 1. Width is primarily determined by width cookies. If no cookie
2100 ;; is found, cell's width is nil.
2101 (org-test-with-parsed-data "
2102 | / | <l> | <6> | <l7> |
2107 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2108 (org-element-map tree
'table-cell
'identity info
)))))
2109 ;; 2. The last width cookie has precedence.
2110 (org-test-with-parsed-data "
2117 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2118 (org-element-map tree
'table-cell
'identity info
)))))
2119 ;; 3. Valid width cookies must have a specific row.
2120 (org-test-with-parsed-data "| <6> | cell |"
2124 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2125 (org-element-map tree
'table-cell
'identity
))))))
2127 (ert-deftest test-org-export
/table-cell-alignment
()
2128 "Test `org-export-table-cell-alignment' specifications."
2129 (let ((org-table-number-fraction 0.5)
2130 (org-table-number-regexp "^[0-9]+$"))
2131 ;; 1. Alignment is primarily determined by alignment cookies.
2132 (org-test-with-temp-text "| <l> | <c> | <r> |"
2133 (let* ((tree (org-element-parse-buffer))
2134 (info `(:parse-tree
,tree
)))
2137 '(left center right
)
2138 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2139 (org-element-map tree
'table-cell
'identity
))))))
2140 ;; 2. The last alignment cookie has precedence.
2141 (org-test-with-parsed-data "
2147 '(right right right
)
2148 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2149 (org-element-map tree
'table-cell
'identity
)))))
2150 ;; 3. If there's no cookie, cell's contents determine alignment.
2151 ;; A column mostly made of cells containing numbers will align
2152 ;; its cells to the right.
2153 (org-test-with-parsed-data "
2159 '(right right right
)
2160 (mapcar (lambda (cell)
2161 (org-export-table-cell-alignment cell info
))
2162 (org-element-map tree
'table-cell
'identity
)))))
2163 ;; 4. Otherwise, they will be aligned to the left.
2164 (org-test-with-parsed-data "
2171 (mapcar (lambda (cell)
2172 (org-export-table-cell-alignment cell info
))
2173 (org-element-map tree
'table-cell
'identity
)))))))
2175 (ert-deftest test-org-export
/table-cell-borders
()
2176 "Test `org-export-table-cell-borders' specifications."
2177 ;; 1. Recognize various column groups indicators.
2178 (org-test-with-parsed-data "| / | < | > | <> |"
2181 '((right bottom top
) (left bottom top
) (right bottom top
)
2182 (right left bottom top
))
2183 (mapcar (lambda (cell)
2184 (org-export-table-cell-borders cell info
))
2185 (org-element-map tree
'table-cell
'identity
)))))
2186 ;; 2. Accept shortcuts to define column groups.
2187 (org-test-with-parsed-data "| / | < | < |"
2190 '((right bottom top
) (right left bottom top
) (left bottom top
))
2191 (mapcar (lambda (cell)
2192 (org-export-table-cell-borders cell info
))
2193 (org-element-map tree
'table-cell
'identity
)))))
2194 ;; 3. A valid column groups row must start with a "/".
2195 (org-test-with-parsed-data "
2199 (equal '((top) (top) (bottom) (bottom))
2200 (mapcar (lambda (cell)
2201 (org-export-table-cell-borders cell info
))
2202 (org-element-map tree
'table-cell
'identity
)))))
2203 ;; 4. Take table rules into consideration.
2204 (org-test-with-parsed-data "
2209 (equal '((below top
) (bottom above
))
2210 (mapcar (lambda (cell)
2211 (org-export-table-cell-borders cell info
))
2212 (org-element-map tree
'table-cell
'identity
)))))
2213 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2214 ;; (resp. `bottom' and `below') borders. Any special row is
2216 (org-test-with-parsed-data "
2222 (equal '((bottom below top above
))
2224 (mapcar (lambda (cell)
2225 (org-export-table-cell-borders cell info
))
2226 (org-element-map tree
'table-cell
'identity
)))))))
2228 (ert-deftest test-org-export
/table-dimensions
()
2229 "Test `org-export-table-dimensions' specifications."
2230 ;; 1. Standard test.
2231 (org-test-with-parsed-data "
2236 (org-export-table-dimensions
2237 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2238 ;; 2. Ignore horizontal rules and special columns.
2239 (org-test-with-parsed-data "
2246 (org-export-table-dimensions
2247 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2249 (ert-deftest test-org-export
/table-cell-address
()
2250 "Test `org-export-table-cell-address' specifications."
2251 ;; 1. Standard test: index is 0-based.
2252 (org-test-with-parsed-data "| a | b |"
2254 (equal '((0 .
0) (0 .
1))
2255 (org-element-map tree
'table-cell
2256 (lambda (cell) (org-export-table-cell-address cell info
))
2258 ;; 2. Special column isn't counted, nor are special rows.
2259 (org-test-with-parsed-data "
2264 (org-export-table-cell-address
2265 (car (last (org-element-map tree
'table-cell
'identity info
)))
2267 ;; 3. Tables rules do not count either.
2268 (org-test-with-parsed-data "
2276 (org-export-table-cell-address
2277 (car (last (org-element-map tree
'table-cell
'identity info
)))
2279 ;; 4. Return nil for special cells.
2280 (org-test-with-parsed-data "| / | a |"
2282 (org-export-table-cell-address
2283 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2286 (ert-deftest test-org-export
/get-table-cell-at
()
2287 "Test `org-export-get-table-cell-at' specifications."
2288 ;; 1. Address ignores special columns, special rows and rules.
2289 (org-test-with-parsed-data "
2296 (org-element-contents
2297 (org-export-get-table-cell-at
2299 (org-element-map tree
'table
'identity info
'first-match
)
2301 ;; 2. Return value for a non-existent address is nil.
2302 (org-test-with-parsed-data "| a |"
2304 (org-export-get-table-cell-at
2306 (org-element-map tree
'table
'identity info
'first-match
)
2308 (org-test-with-parsed-data "| / |"
2310 (org-export-get-table-cell-at
2312 (org-element-map tree
'table
'identity info
'first-match
)
2315 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2316 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2317 ;; 1. A cell at a beginning of a row always starts a column group.
2318 (org-test-with-parsed-data "| a |"
2320 (org-export-table-cell-starts-colgroup-p
2321 (org-element-map tree
'table-cell
'identity info
'first-match
)
2323 ;; 2. Special column should be ignored when determining the
2324 ;; beginning of the row.
2325 (org-test-with-parsed-data "
2329 (org-export-table-cell-starts-colgroup-p
2330 (org-element-map tree
'table-cell
'identity info
'first-match
)
2332 ;; 2. Explicit column groups.
2333 (org-test-with-parsed-data "
2339 (org-element-map tree
'table-cell
2341 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2344 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2345 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2346 ;; 1. A cell at the end of a row always ends a column group.
2347 (org-test-with-parsed-data "| a |"
2349 (org-export-table-cell-ends-colgroup-p
2350 (org-element-map tree
'table-cell
'identity info
'first-match
)
2352 ;; 2. Special column should be ignored when determining the
2353 ;; beginning of the row.
2354 (org-test-with-parsed-data "
2358 (org-export-table-cell-ends-colgroup-p
2359 (org-element-map tree
'table-cell
'identity info
'first-match
)
2361 ;; 3. Explicit column groups.
2362 (org-test-with-parsed-data "
2368 (org-element-map tree
'table-cell
2370 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2373 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2374 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2375 ;; 1. A row at the beginning of a table always starts a row group.
2376 ;; So does a row following a table rule.
2377 (org-test-with-parsed-data "
2384 (org-element-map tree
'table-row
2386 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2388 ;; 2. Special rows should be ignored when determining the beginning
2390 (org-test-with-parsed-data "
2399 (org-element-map tree
'table-row
2401 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2404 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2405 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2406 ;; 1. A row at the end of a table always ends a row group. So does
2407 ;; a row preceding a table rule.
2408 (org-test-with-parsed-data "
2415 (org-element-map tree
'table-row
2417 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2419 ;; 2. Special rows should be ignored when determining the beginning
2421 (org-test-with-parsed-data "
2430 (org-element-map tree
'table-row
2432 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2435 (ert-deftest test-org-export
/table-row-starts-header-p
()
2436 "Test `org-export-table-row-starts-header-p' specifications."
2437 ;; 1. Only the row starting the first row group starts the table
2439 (org-test-with-parsed-data "
2447 (org-element-map tree
'table-row
2449 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2451 ;; 2. A row cannot start an header if there's no header in the
2453 (org-test-with-parsed-data "
2457 (org-export-table-row-starts-header-p
2458 (org-element-map tree
'table-row
'identity info
'first-match
)
2461 (ert-deftest test-org-export
/table-row-ends-header-p
()
2462 "Test `org-export-table-row-ends-header-p' specifications."
2463 ;; 1. Only the row starting the first row group starts the table
2465 (org-test-with-parsed-data "
2473 (org-element-map tree
'table-row
2475 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2477 ;; 2. A row cannot start an header if there's no header in the
2479 (org-test-with-parsed-data "
2483 (org-export-table-row-ends-header-p
2484 (org-element-map tree
'table-row
'identity info
'first-match
)
2491 (ert-deftest test-org-export
/inner-template
()
2492 "Test `inner-template' translator specifications."
2495 (let (org-export-registered-backends)
2496 (org-export-define-backend 'test
2497 '((inner-template .
(lambda (contents info
) "Success!"))
2498 (headline .
(lambda (h c i
) "Headline"))))
2499 (org-test-with-temp-text "* Headline"
2500 (org-export-as 'test
)))))
2501 ;; Inner template is applied even in a "body-only" export.
2504 (let (org-export-registered-backends)
2505 (org-export-define-backend 'test
2506 '((inner-template .
(lambda (contents info
) "Success!"))
2507 (headline .
(lambda (h c i
) "Headline"))))
2508 (org-test-with-temp-text "* Headline"
2509 (org-export-as 'test nil nil
'body-only
))))))
2511 (ert-deftest test-org-export
/template
()
2512 "Test `template' translator specifications."
2515 (let (org-export-registered-backends)
2516 (org-export-define-backend 'test
2517 '((template .
(lambda (contents info
) "Success!"))
2518 (headline .
(lambda (h c i
) "Headline"))))
2519 (org-test-with-temp-text "* Headline"
2520 (org-export-as 'test
)))))
2521 ;; Template is not applied in a "body-only" export.
2524 (let (org-export-registered-backends)
2525 (org-export-define-backend 'test
2526 '((template .
(lambda (contents info
) "Success!"))
2527 (headline .
(lambda (h c i
) "Headline"))))
2528 (org-test-with-temp-text "* Headline"
2529 (org-export-as 'test nil nil
'body-only
))))))
2535 (ert-deftest test-org-export
/get-next-element
()
2536 "Test `org-export-get-next-element' specifications."
2540 (org-test-with-parsed-data "* Headline\n*a* b"
2541 (org-export-get-next-element
2542 (org-element-map tree
'bold
'identity info t
) info
))))
2543 ;; Return nil when no previous element.
2545 (org-test-with-parsed-data "* Headline\na *b*"
2546 (org-export-get-next-element
2547 (org-element-map tree
'bold
'identity info t
) info
)))
2548 ;; Non-exportable elements are ignored.
2550 (let ((org-export-with-timestamps nil
))
2551 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2552 (org-export-get-next-element
2553 (org-element-map tree
'entity
'identity info t
) info
))))
2554 ;; Find next element in secondary strings.
2557 (org-test-with-parsed-data "* a =verb="
2559 (org-export-get-next-element
2560 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2561 ;; Find next element in document keywords.
2564 (org-test-with-parsed-data "#+TITLE: a =verb="
2566 (org-export-get-next-element
2568 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2569 ;; Find next element in parsed affiliated keywords.
2572 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2574 (org-export-get-next-element
2575 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2576 ;; With optional argument N, return a list containing all the
2577 ;; following elements.
2580 '(bold code underline
)
2581 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2583 (org-export-get-next-element
2584 (org-element-map tree
'italic
'identity info t
) info t
)))))
2585 ;; When N is a positive integer, return a list containing up to
2586 ;; N following elements.
2590 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2592 (org-export-get-next-element
2593 (org-element-map tree
'italic
'identity info t
) info
2))))))
2595 (ert-deftest test-org-export
/get-previous-element
()
2596 "Test `org-export-get-previous-element' specifications."
2600 (org-test-with-parsed-data "* Headline\na *b*"
2601 (org-export-get-previous-element
2602 (org-element-map tree
'bold
'identity info t
) info
))))
2603 ;; Return nil when no previous element.
2605 (org-test-with-parsed-data "* Headline\n*a* b"
2606 (org-export-get-previous-element
2607 (org-element-map tree
'bold
'identity info t
) info
)))
2608 ;; Non-exportable elements are ignored.
2610 (let ((org-export-with-timestamps nil
))
2611 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2612 (org-export-get-previous-element
2613 (org-element-map tree
'entity
'identity info t
) info
))))
2614 ;; Find previous element in secondary strings.
2617 (org-test-with-parsed-data "* =verb= a"
2619 (org-export-get-previous-element
2620 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2621 ;; Find previous element in document keywords.
2624 (org-test-with-parsed-data "#+TITLE: =verb= a"
2626 (org-export-get-previous-element
2628 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2629 ;; Find previous element in parsed affiliated keywords.
2632 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2634 (org-export-get-previous-element
2635 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2636 ;; With optional argument N, return a list containing up to
2637 ;; N previous elements.
2639 (equal '(underline italic bold
)
2640 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2642 (org-export-get-previous-element
2643 (org-element-map tree
'code
'identity info t
) info t
)))))
2644 ;; When N is a positive integer, return a list containing up to
2645 ;; N previous elements.
2647 (equal '(italic bold
)
2648 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2650 (org-export-get-previous-element
2651 (org-element-map tree
'code
'identity info t
) info
2))))))
2655 ;;; test-org-export.el end here