1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012, 2013 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 (unless (featurep 'ox
)
25 (signal 'missing-test-dependency
"org-export"))
27 (defmacro org-test-with-backend
(backend &rest body
)
28 "Execute body with an export back-end defined.
30 BACKEND is the name of the back-end. BODY is the body to
31 execute. The defined back-end simply returns parsed data as Org
33 (declare (debug (form body
)) (indent 1))
34 `(let ((org-export-registered-backends
38 (let (transcode-table)
39 (dolist (type (append org-element-all-elements
40 org-element-all-objects
)
44 (lambda (obj contents info
)
46 (intern (format "org-element-%s-interpreter"
49 transcode-table
)))))))
52 (defmacro org-test-with-parsed-data
(data &rest body
)
53 "Execute body with parsed data available.
55 DATA is a string containing the data to be parsed. BODY is the
56 body to execute. Parse tree is available under the `tree'
57 variable, and communication channel under `info'.
59 This function calls `org-export-collect-tree-properties'. As
60 such, `:ignore-list' (for `org-element-map') and
61 `:parse-tree' (for `org-export-get-genealogy') properties are
62 already filled in `info'."
63 (declare (debug (form body
)) (indent 1))
64 `(org-test-with-temp-text ,data
65 (let* ((tree (org-element-parse-buffer))
66 (info (org-export-collect-tree-properties
67 tree
(org-export-get-environment))))
74 (ert-deftest test-org-export
/bind-keyword
()
75 "Test reading #+BIND: keywords."
76 ;; Test with `org-export-allow-bind-keywords' set to t.
78 (org-test-with-temp-text "#+BIND: test-ox-var value"
79 (let ((org-export-allow-bind-keywords t
))
80 (org-export-get-environment)
81 (eq test-ox-var
'value
))))
82 ;; Test with `org-export-allow-bind-keywords' set to nil.
84 (org-test-with-temp-text "#+BIND: test-ox-var value"
85 (let ((org-export-allow-bind-keywords nil
))
86 (org-export-get-environment)
87 (boundp 'test-ox-var
))))
88 ;; BIND keywords are case-insensitive.
90 (org-test-with-temp-text "#+bind: test-ox-var value"
91 (let ((org-export-allow-bind-keywords t
))
92 (org-export-get-environment)
93 (eq test-ox-var
'value
))))
94 ;; Preserve order of BIND keywords.
96 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
97 (let ((org-export-allow-bind-keywords t
))
98 (org-export-get-environment)
100 ;; Read BIND keywords in setup files.
102 (org-test-with-temp-text
103 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
104 (let ((org-export-allow-bind-keywords t
))
105 (org-export-get-environment)
106 (eq variable
'value
))))
107 ;; Verify that bound variables are seen during export.
110 (org-test-with-temp-text "#+BIND: test-ox-var value"
111 (let ((org-export-allow-bind-keywords t
)
112 org-export-registered-backends
)
113 (org-export-define-backend 'check
114 '((section .
(lambda (s c i
)
115 (if (eq test-ox-var
'value
) "Yes" "No")))))
116 (org-export-as 'check
))))))
118 (ert-deftest test-org-export
/parse-option-keyword
()
119 "Test reading all standard #+OPTIONS: items."
122 (org-export--parse-option-keyword
123 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
124 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
127 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
128 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
129 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
130 :with-footnotes t
:with-inlinetasks nil
:with-priority t
131 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
132 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
133 :with-todo-keywords t
)))
134 ;; Test some special values.
137 (org-export--parse-option-keyword
138 "arch:headline creator:comment d:(\"TEST\")
139 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
142 :with-archived-trees headline
:with-creator comment
143 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
144 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
146 (ert-deftest test-org-export
/get-inbuffer-options
()
147 "Test reading all standard export keywords."
148 ;; Properties should follow buffer order.
151 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
152 (org-export--get-inbuffer-options))
153 '(:language
"fr" :creator
"Me" :email
"email")))
154 ;; Parse document keywords.
157 (org-test-with-temp-text "#+AUTHOR: Me"
158 (org-export--get-inbuffer-options))
160 ;; Test `space' behaviour.
163 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
164 (org-export--get-inbuffer-options))
165 '(:title
("Some title with spaces"))))
166 ;; Test `newline' behaviour.
169 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
170 (org-export--get-inbuffer-options))
171 '(:description
"With\ntwo lines")))
172 ;; Test `split' behaviour.
175 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
176 (org-export--get-inbuffer-options))
177 '(:select-tags
("a" "b"))))
178 ;; Options set through SETUPFILE.
181 (org-test-with-temp-text
182 (format "#+DESCRIPTION: l1
186 #+SETUPFILE: \"%s/examples/setupfile.org\"
192 (org-export--get-inbuffer-options))
193 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
196 (ert-deftest test-org-export
/get-subtree-options
()
197 "Test setting options from headline's properties."
199 (org-test-with-temp-text "#+TITLE: Title
202 :EXPORT_TITLE: Subtree Title
206 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
207 '("Subtree Title"))))
211 (org-test-with-temp-text "#+OPTIONS: H:1
219 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
221 (org-test-with-temp-text "#+DATE: today
224 :EXPORT_DATE: 29-03-2012
228 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
230 ;; Properties with `split' behaviour are stored as a list of
234 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
237 :EXPORT_EXCLUDE_TAGS: a b
242 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
243 ;; Handle :PROPERTY+: syntax.
246 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
249 :EXPORT_EXCLUDE_TAGS: a
250 :EXPORT_EXCLUDE_TAGS+: b
255 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
256 ;; Export properties are case-insensitive.
257 (org-test-with-temp-text "* Headline
259 :EXPORT_Date: 29-03-2012
262 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
264 ;; Still grab correct options when section above is empty.
267 (org-test-with-temp-text "* H1\n** H11\n** H12"
268 (progn (forward-line 2)
269 (plist-get (org-export-get-environment nil t
) :title
))))))
271 (ert-deftest test-org-export
/handle-options
()
272 "Test if export options have an impact on output."
273 ;; Test exclude tags for headlines and inlinetasks.
276 (org-test-with-temp-text "* Head1 :noexp:"
277 (org-test-with-backend test
278 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp")))))))
279 ;; Test include tags for headlines and inlinetasks.
281 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
282 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
283 (let ((org-tags-column 0))
284 (org-test-with-backend test
285 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
286 ;; Test mixing include tags and exclude tags.
287 (org-test-with-temp-text "
289 ** Sub-Head1 :noexport:
292 ** Sub-Head1 :export:"
293 (org-test-with-backend test
296 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
299 '(:select-tags
("export") :exclude-tags
("noexport")))))))
303 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
304 (org-test-with-temp-text "* TODO Head1"
305 (org-test-with-backend test
306 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))
308 (equal "* TODO Head1\n"
309 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
310 (org-test-with-temp-text "* TODO Head1"
311 (org-test-with-backend test
312 (org-export-as 'test nil nil nil
'(:with-tasks t
)))))))
314 (org-test-with-temp-text "* Head1 :archive:"
315 (let ((org-archive-tag "archive"))
316 (org-test-with-backend test
318 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
320 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
321 (let ((org-archive-tag "archive"))
322 (org-test-with-backend test
325 "\\* Head1[ \t]+:archive:"
326 (org-export-as 'test nil nil nil
327 '(:with-archived-trees headline
)))))))
328 (org-test-with-temp-text "* Head1 :archive:"
329 (let ((org-archive-tag "archive"))
330 (org-test-with-backend test
333 "\\`\\* Head1[ \t]+:archive:\n\\'"
334 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
336 (let ((org-clock-string "CLOCK:"))
337 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
338 (org-test-with-backend test
340 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
341 "CLOCK: [2012-04-29 sun. 10:45]\n"))
343 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
345 (let ((org-drawers '("TEST")))
346 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
347 (org-test-with-backend test
348 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
350 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
351 ":TEST:\ncontents\n:END:\n")))))
352 (let ((org-drawers '("FOO" "BAR")))
353 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
354 (org-test-with-backend test
356 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
357 ":FOO:\nkeep\n:END:\n")))))
358 (let ((org-drawers '("FOO" "BAR")))
359 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
360 (org-test-with-backend test
362 (equal (org-export-as 'test nil nil nil
'(:with-drawers
(not "BAR")))
363 ":FOO:\nkeep\n:END:\n")))))
365 (when (featurep 'org-inlinetask
)
368 (let ((org-inlinetask-min-level 15))
369 (org-test-with-temp-text "*************** Task"
370 (org-test-with-backend test
371 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
375 (let ((org-inlinetask-min-level 15))
376 (org-test-with-temp-text
377 "*************** Task\nContents\n*************** END"
378 (org-test-with-backend test
379 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
382 (let ((org-closed-string "CLOSED:"))
383 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
384 (org-test-with-backend test
386 (equal (org-export-as 'test nil nil nil
'(:with-planning t
))
387 "CLOSED: [2012-04-29 sun. 10:45]\n"))
389 (equal (org-export-as 'test nil nil nil
'(:with-planning nil
))
391 ;; Statistics cookies.
394 (org-test-with-temp-text "[0/0]"
395 (org-test-with-backend test
397 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
399 (ert-deftest test-org-export
/with-timestamps
()
400 "Test `org-export-with-timestamps' specifications."
404 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"
405 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
406 (org-test-with-backend test
407 (org-export-as 'test nil nil nil
'(:with-timestamps t
))))))
412 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
413 (org-test-with-backend test
414 (org-export-as 'test nil nil nil
'(:with-timestamps nil
))))))
418 "<2012-03-29 Thu>\n\nParagraph <2012-03-29 Thu>[2012-03-29 Thu]"
419 (org-test-with-temp-text
420 "<2012-03-29 Thu>[2012-03-29 Thu]
422 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
423 (org-test-with-backend test
425 (org-export-as 'test nil nil nil
'(:with-timestamps active
)))))))
429 "[2012-03-29 Thu]\n\nParagraph <2012-03-29 Thu>[2012-03-29 Thu]"
430 (org-test-with-temp-text
431 "<2012-03-29 Thu>[2012-03-29 Thu]
433 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
434 (org-test-with-backend test
436 (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))))))))
438 (ert-deftest test-org-export
/comment-tree
()
439 "Test if export process ignores commented trees."
440 (let ((org-comment-string "COMMENT"))
441 (org-test-with-temp-text "* COMMENT Head1"
442 (org-test-with-backend test
443 (should (equal (org-export-as 'test
) ""))))))
445 (ert-deftest test-org-export
/export-scope
()
446 "Test all export scopes."
447 (org-test-with-temp-text "
452 (org-test-with-backend test
455 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
457 (goto-char (point-min))
460 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
462 (goto-char (point-min))
464 (transient-mark-mode 1)
465 (push-mark (point) t t
)
466 (goto-char (point-at-eol))
467 (should (equal (org-export-as 'test
) "text\n"))))
468 ;; Subtree with a code block calling another block outside.
471 (org-test-with-temp-text "
473 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
478 #+BEGIN_SRC emacs-lisp
481 (org-test-with-backend test
483 (org-export-as 'test
'subtree
)))))
485 (org-test-with-temp-text "Text"
486 (org-test-with-backend test
488 (cdr (assq 'test org-export-registered-backends
))
490 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
491 (org-export-backend-translate-table 'test
)))
492 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
493 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
495 (ert-deftest test-org-export
/output-file-name
()
496 "Test `org-export-output-file-name' specifications."
497 ;; Export from a file: name is built from original file name.
499 (org-test-with-temp-text-in-file "Test"
500 (equal (concat (file-name-as-directory ".")
501 (file-name-nondirectory
502 (file-name-sans-extension (buffer-file-name))))
503 (file-name-sans-extension (org-export-output-file-name ".ext")))))
504 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
506 (org-test-with-temp-text-in-file
507 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
508 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
509 ;; From a buffer not associated to a file, too.
511 (org-test-with-temp-text
512 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
513 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
514 ;; When provided name is absolute, preserve it.
516 (org-test-with-temp-text
517 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
518 (expand-file-name "test"))
519 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
520 ;; When PUB-DIR argument is provided, use it.
522 (org-test-with-temp-text-in-file "Test"
523 (equal (file-name-directory
524 (org-export-output-file-name ".ext" nil
"dir/"))
526 ;; When returned name would overwrite original file, add EXTENSION
529 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
530 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
532 (ert-deftest test-org-export
/expand-include
()
533 "Test file inclusion in an Org buffer."
534 ;; Error when file isn't specified.
536 (org-test-with-temp-text "#+INCLUDE: dummy.org"
537 (org-export-expand-include-keyword)))
538 ;; Full insertion with recursive inclusion.
539 (org-test-with-temp-text
540 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
541 (org-export-expand-include-keyword)
542 (should (equal (buffer-string)
543 "Small Org file with an include keyword.
545 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
551 ;; Localized insertion.
552 (org-test-with-temp-text
553 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
555 (org-export-expand-include-keyword)
556 (should (equal (buffer-string)
557 "Small Org file with an include keyword.\n")))
558 ;; Insertion with constraints on headlines level.
561 "* Top heading\n** Heading\nbody\n"
562 (org-test-with-temp-text
564 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
566 (org-export-expand-include-keyword)
570 "* Top heading\n* Heading\nbody\n"
571 (org-test-with-temp-text
573 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
575 (org-export-expand-include-keyword)
577 ;; Inclusion within an example block.
578 (org-test-with-temp-text
579 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
581 (org-export-expand-include-keyword)
585 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
586 ;; Inclusion within a src-block.
587 (org-test-with-temp-text
589 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
591 (org-export-expand-include-keyword)
592 (should (equal (buffer-string)
593 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
595 (ert-deftest test-org-export
/expand-macro
()
596 "Test macro expansion in an Org buffer."
597 ;; Standard macro expansion.
599 (equal "#+MACRO: macro1 value\nvalue\n"
600 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
601 (org-test-with-backend test
(org-export-as 'test
)))))
602 ;; Expand specific macros.
604 (equal "me 2012-03-29 me@here Title\n"
605 (org-test-with-temp-text
611 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
612 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
613 (substring output
(string-match ".*\n\\'" output
))))))
614 ;; Expand specific macros when property contained a regular macro
618 (org-test-with-temp-text "
619 #+MACRO: macro1 value
620 #+TITLE: {{{macro1}}}
622 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
623 (substring output
(string-match ".*\n\\'" output
))))))
624 ;; Expand macros with templates in included files.
627 (org-test-with-temp-text
628 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
629 {{{included-macro}}}" org-test-dir
)
630 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
631 (substring output
(string-match ".*\n\\'" output
)))))))
633 (ert-deftest test-org-export
/user-ignore-list
()
634 "Test if `:ignore-list' accepts user input."
635 (org-test-with-backend test
636 (flet ((skip-note-head
638 ;; Ignore headlines with the word "note" in their title.
639 (org-element-map data
'headline
641 (when (string-match "\\<note\\>"
642 (org-element-property :raw-value headline
))
643 (org-export-ignore-element headline info
)))
646 ;; Install function in parse tree filters.
647 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
648 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
649 (should (equal (org-export-as 'test
) "* Head1\n")))))))
651 (ert-deftest test-org-export
/before-processing-hook
()
652 "Test `org-export-before-processing-hook'."
655 "#+MACRO: mac val\nTest\n"
656 (org-test-with-backend test
657 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
658 (let ((org-export-before-processing-hook
660 (while (re-search-forward "{{{" nil t
)
661 (let ((object (org-element-context)))
662 (when (eq (org-element-type object
) 'macro
)
664 (org-element-property :begin object
)
665 (org-element-property :end object
)))))))))
666 (org-export-as 'test
)))))))
668 (ert-deftest test-org-export
/before-parsing-hook
()
669 "Test `org-export-before-parsing-hook'."
671 (equal "Body 1\nBody 2\n"
672 (org-test-with-backend test
673 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
674 (let ((org-export-before-parsing-hook
676 (goto-char (point-min))
677 (while (re-search-forward org-outline-regexp-bol nil t
)
679 (point-at-bol) (progn (forward-line) (point))))))))
680 (org-export-as 'test
)))))))
684 ;;; Affiliated Keywords
686 (ert-deftest test-org-export
/read-attribute
()
687 "Test `org-export-read-attribute' specifications."
691 (org-export-read-attribute
693 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
694 (org-element-at-point)))
696 ;; Return nil on empty attribute.
698 (org-export-read-attribute
700 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
701 ;; Return nil on "nil" string.
703 (equal '(:a nil
:b nil
)
704 (org-export-read-attribute
706 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
707 (org-element-at-point)))))
708 ;; Return nil on empty string.
710 (equal '(:a nil
:b nil
)
711 (org-export-read-attribute
713 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
714 (org-element-at-point)))))
715 ;; Return empty string when value is "".
718 (org-export-read-attribute
720 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
721 (org-element-at-point)))))
722 ;; Return \"\" when value is """".
725 (org-export-read-attribute
727 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
728 (org-element-at-point)))))
729 ;; Ignore text before first property.
732 (org-export-read-attribute
734 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
735 (org-element-at-point))))))
737 (ert-deftest test-org-export
/get-caption
()
738 "Test `org-export-get-caption' specifications."
739 ;; Without optional argument, return long caption
743 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
744 (org-export-get-caption (org-element-at-point)))))
745 ;; With optional argument, return short caption.
749 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
750 (org-export-get-caption (org-element-at-point) t
))))
751 ;; Multiple lines are separated by white spaces.
755 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
756 (org-export-get-caption (org-element-at-point))))))
762 (ert-deftest test-org-export
/define-backend
()
763 "Test back-end definition and accessors."
766 (equal '((headline . my-headline-test
))
767 (let (org-export-registered-backends)
768 (org-export-define-backend 'test
'((headline . my-headline-test
)))
769 (org-export-backend-translate-table 'test
))))
772 (equal '((:filter-headline . my-filter
))
773 (let (org-export-registered-backends)
774 (org-export-define-backend 'test
775 '((headline . my-headline-test
))
776 :filters-alist
'((:filter-headline . my-filter
)))
777 (org-export-backend-filters 'test
))))
780 (equal '((:prop value
))
781 (let (org-export-registered-backends)
782 (org-export-define-backend 'test
783 '((headline . my-headline-test
))
784 :options-alist
'((:prop value
)))
785 (org-export-backend-options 'test
))))
788 (equal '(?k
"Test Export" test
)
789 (let (org-export-registered-backends)
790 (org-export-define-backend 'test
791 '((headline . my-headline-test
))
792 :menu-entry
'(?k
"Test Export" test
))
793 (org-export-backend-menu 'test
))))
796 (equal '(("TEST" . org-element-export-block-parser
))
797 (let (org-export-registered-backends org-element-block-name-alist
)
798 (org-export-define-backend 'test
799 '((headline . my-headline-test
))
800 :export-block
'("test"))
801 org-element-block-name-alist
))))
803 (ert-deftest test-org-export
/define-derived-backend
()
804 "Test `org-export-define-derived-backend' specifications."
805 ;; Error when parent back-end is not defined.
807 (let (org-export-registered-backends)
808 (org-export-define-derived-backend 'test
'parent
)))
809 ;; Append translation table to parent's.
811 (equal '((:headline . test
) (:headline . parent
))
812 (let (org-export-registered-backends)
813 (org-export-define-backend 'parent
'((:headline . parent
)))
814 (org-export-define-derived-backend 'test
'parent
815 :translate-alist
'((:headline . test
)))
816 (org-export-backend-translate-table 'test
))))
817 ;; Options defined in the new back have priority over those defined
821 (let (org-export-registered-backends)
822 (org-export-define-backend 'parent
823 '((:headline . parent
))
824 :options-alist
'((:a nil nil
'parent
)))
825 (org-export-define-derived-backend 'test
'parent
826 :options-alist
'((:a nil nil
'test
)))
827 (plist-get (org-export--get-global-options 'test
) :a
)))))
829 (ert-deftest test-org-export
/derived-backend-p
()
830 "Test `org-export-derived-backend-p' specifications."
831 ;; Non-nil with direct match.
833 (let (org-export-registered-backends)
834 (org-export-define-backend 'test
'((headline . test
)))
835 (org-export-derived-backend-p 'test
'test
)))
837 (let (org-export-registered-backends)
838 (org-export-define-backend 'test
'((headline . test
)))
839 (org-export-define-derived-backend 'test2
'test
)
840 (org-export-derived-backend-p 'test2
'test2
)))
841 ;; Non-nil with a direct parent.
843 (let (org-export-registered-backends)
844 (org-export-define-backend 'test
'((headline . test
)))
845 (org-export-define-derived-backend 'test2
'test
)
846 (org-export-derived-backend-p 'test2
'test
)))
847 ;; Non-nil with an indirect parent.
849 (let (org-export-registered-backends)
850 (org-export-define-backend 'test
'((headline . test
)))
851 (org-export-define-derived-backend 'test2
'test
)
852 (org-export-define-derived-backend 'test3
'test2
)
853 (org-export-derived-backend-p 'test3
'test
)))
856 (let (org-export-registered-backends)
857 (org-export-define-backend 'test
'((headline . test
)))
858 (org-export-define-backend 'test2
'((headline . test2
)))
859 (org-export-derived-backend-p 'test2
'test
)))
861 (let (org-export-registered-backends)
862 (org-export-define-backend 'test
'((headline . test
)))
863 (org-export-define-backend 'test2
'((headline . test2
)))
864 (org-export-define-derived-backend 'test3
'test2
)
865 (org-export-derived-backend-p 'test3
'test
))))
867 (ert-deftest test-org-export
/with-backend
()
868 "Test `org-export-with-backend' definition."
869 ;; Error when calling an undefined back-end
871 (let (org-export-registered-backends)
872 (org-export-with-backend 'test
"Test")))
873 ;; Error when called back-end doesn't have an appropriate
876 (let (org-export-registered-backends)
877 (org-export-define-backend 'test
((headline . ignore
)))
878 (org-export-with-backend 'test
"Test")))
879 ;; Otherwise, export using correct transcoder
882 (let (org-export-registered-backends)
883 (org-export-define-backend 'test
884 '((plain-text .
(lambda (text contents info
) "Failure"))))
885 (org-export-define-backend 'test2
886 '((plain-text .
(lambda (text contents info
) "Success"))))
887 (org-export-with-backend 'test2
"Test")))))
889 (ert-deftest test-org-export
/data-with-translations
()
890 "Test `org-export-data-with-translations' specifications."
894 (org-export-data-with-translations
896 '((plain-text .
(lambda (text info
) "Success"))
897 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
898 '(:with-emphasize t
)))))
900 (ert-deftest test-org-export
/data-with-backend
()
901 "Test `org-export-data-with-backend' specifications."
902 ;; Error when calling an undefined back-end.
904 (let (org-export-registered-backends)
905 (org-export-data-with-backend 'test
"Test" nil
)))
906 ;; Otherwise, export data recursively, using correct back-end.
910 (let (org-export-registered-backends)
911 (org-export-define-backend 'test
912 '((plain-text .
(lambda (text info
) "Success"))
913 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
914 (org-export-data-with-backend
915 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
921 (ert-deftest test-org-export
/export-snippet
()
922 "Test export snippets transcoding."
923 (org-test-with-temp-text "@@test:A@@@@t:B@@"
924 (org-test-with-backend test
926 (cdr (assq 'test org-export-registered-backends
))
928 (cons (cons 'export-snippet
929 (lambda (snippet contents info
)
930 (when (eq (org-export-snippet-backend snippet
) 'test
)
931 (org-element-property :value snippet
))))
932 (org-export-backend-translate-table 'test
)))
933 (let ((org-export-snippet-translation-alist nil
))
934 (should (equal (org-export-as 'test
) "A\n")))
935 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
936 (should (equal (org-export-as 'test
) "AB\n")))))
937 ;; Ignored export snippets do not remove any blank.
940 (org-test-with-parsed-data "begin @@test:A@@ end"
941 (org-export-data-with-translations
943 '((paragraph .
(lambda (paragraph contents info
) contents
))
944 (section .
(lambda (section contents info
) contents
)))
951 (ert-deftest test-org-export
/footnotes
()
952 "Test footnotes specifications."
953 (let ((org-footnote-section nil
)
954 (org-export-with-footnotes t
))
955 ;; 1. Read every type of footnote.
958 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
959 (org-test-with-parsed-data
960 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
961 (org-element-map tree
'footnote-reference
963 (let ((def (org-export-get-footnote-definition ref info
)))
964 (cons (org-export-get-footnote-number ref info
)
965 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
966 (car (org-element-contents
967 (car (org-element-contents def
))))))))
969 ;; 2. Test nested footnotes order.
970 (org-test-with-parsed-data
971 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
974 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
975 (org-element-map tree
'footnote-reference
977 (when (org-export-footnote-first-reference-p ref info
)
978 (cons (org-export-get-footnote-number ref info
)
979 (org-element-property :label ref
))))
981 ;; 3. Test nested footnote in invisible definitions.
982 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
984 (narrow-to-region (point) (point-at-eol))
985 (let* ((tree (org-element-parse-buffer))
986 (info (org-combine-plists
988 (org-export-collect-tree-properties
989 tree
(org-export-get-environment)))))
990 ;; Both footnotes should be seen.
992 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
993 ;; 4. Test footnotes definitions collection.
994 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
996 \[fn:2] B [fn:3] [fn::D].
999 (should (= (length (org-export-collect-footnote-definitions tree info
))
1001 ;; 5. Test export of footnotes defined outside parsing scope.
1002 (org-test-with-temp-text "[fn:1] Out of scope
1005 (org-test-with-backend test
1007 (cdr (assq 'test org-export-registered-backends
))
1009 (cons (cons 'footnote-reference
1010 (lambda (fn contents info
)
1011 (org-element-interpret-data
1012 (org-export-get-footnote-definition fn info
))))
1013 (org-export-backend-translate-table 'test
)))
1015 (should (equal "ParagraphOut of scope\n"
1016 (org-export-as 'test
'subtree
)))))
1017 ;; 6. Footnotes without a definition should be provided a fallback
1020 (org-test-with-parsed-data "[fn:1]"
1021 (org-export-get-footnote-definition
1022 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1023 ;; 7. Footnote section should be ignored in TOC and in headlines
1026 (= 1 (let ((org-footnote-section "Footnotes"))
1027 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1028 (org-export-collect-headlines info
))))))
1031 (let ((org-footnote-section "Footnotes"))
1032 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1033 (org-element-map tree
'headline
1035 (when (equal (org-element-property :raw-value hl
) "H2")
1036 (org-export-get-headline-number hl info
)))
1041 ;;; Headlines and Inlinetasks
1043 (ert-deftest test-org-export
/get-relative-level
()
1044 "Test `org-export-get-relative-level' specifications."
1048 (let ((org-odd-levels-only nil
))
1049 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1050 (org-element-map tree
'headline
1051 (lambda (h) (org-export-get-relative-level h info
))
1056 (let ((org-odd-levels-only nil
))
1057 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1058 (org-element-map tree
'headline
1059 (lambda (h) (org-export-get-relative-level h info
))
1062 (ert-deftest test-org-export
/low-level-p
()
1063 "Test `org-export-low-level-p' specifications."
1067 (let ((org-odd-levels-only nil
))
1068 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1069 (org-element-map tree
'headline
1070 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1071 (plist-put info
:headline-levels
1)))))))
1073 (ert-deftest test-org-export
/get-headline-number
()
1074 "Test `org-export-get-headline-number' specifications."
1079 (let ((org-odd-levels-only nil
))
1080 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1081 (org-element-map tree
'headline
1082 (lambda (h) (org-export-get-headline-number h info
))
1084 ;; Missing levels are replaced with 0.
1088 (let ((org-odd-levels-only nil
))
1089 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1090 (org-element-map tree
'headline
1091 (lambda (h) (org-export-get-headline-number h info
))
1094 (ert-deftest test-org-export
/numbered-headline-p
()
1095 "Test `org-export-numbered-headline-p' specifications."
1096 ;; If `:section-numbers' is nil, never number headlines.
1098 (org-test-with-parsed-data "* Headline"
1099 (org-element-map tree
'headline
1100 (lambda (h) (org-export-numbered-headline-p h info
))
1101 (plist-put info
:section-numbers nil
))))
1102 ;; If `:section-numbers' is a number, only number headlines with
1103 ;; a level greater that it.
1107 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1108 (org-element-map tree
'headline
1109 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1110 (plist-put info
:section-numbers
1)))))
1111 ;; Otherwise, headlines are always numbered.
1113 (org-test-with-parsed-data "* Headline"
1114 (org-element-map tree
'headline
1115 (lambda (h) (org-export-numbered-headline-p h info
))
1116 (plist-put info
:section-numbers t
)))))
1118 (ert-deftest test-org-export
/number-to-roman
()
1119 "Test `org-export-number-to-roman' specifications."
1120 ;; If number is negative, return it as a string.
1121 (should (equal (org-export-number-to-roman -
1) "-1"))
1122 ;; Otherwise, return it as a roman number.
1123 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1125 (ert-deftest test-org-export
/get-optional-title
()
1126 "Test `org-export-get-alt-title' specifications."
1127 ;; If ALT_TITLE property is defined, use it.
1130 (org-test-with-parsed-data
1131 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1132 (org-export-get-alt-title
1133 (org-element-map tree
'headline
'identity info t
)
1135 ;; Otherwise, fall-back to regular title.
1137 (equal '("Headline")
1138 (org-test-with-parsed-data "* Headline"
1139 (org-export-get-alt-title
1140 (org-element-map tree
'headline
'identity info t
)
1143 (ert-deftest test-org-export
/get-tags
()
1144 "Test `org-export-get-tags' specifications."
1145 (let ((org-export-exclude-tags '("noexport"))
1146 (org-export-select-tags '("export")))
1147 ;; Standard test: tags which are not a select tag, an exclude tag,
1148 ;; or specified as optional argument shouldn't be ignored.
1150 (org-test-with-parsed-data "* Headline :tag:"
1151 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1153 ;; Exclude tags are removed.
1155 (org-test-with-parsed-data "* Headline :noexport:"
1156 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1158 ;; Select tags are removed.
1160 (org-test-with-parsed-data "* Headline :export:"
1161 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1166 (org-test-with-parsed-data "* Headline :tag:export:"
1167 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1169 ;; Tags provided in the optional argument are also ignored.
1171 (org-test-with-parsed-data "* Headline :ignore:"
1172 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1174 ;; Allow tag inheritance.
1178 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1179 (org-element-map tree
'headline
1180 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1181 ;; Tag inheritance checks FILETAGS keywords.
1185 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1186 (org-element-map tree
'headline
1187 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1189 (ert-deftest test-org-export
/get-node-property
()
1190 "Test`org-export-get-node-property' specifications."
1194 (org-test-with-parsed-data "* Headline
1198 (org-export-get-node-property
1199 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1200 ;; Test inheritance.
1203 (org-test-with-parsed-data "* Parent
1209 (org-export-get-node-property
1210 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1211 ;; Cannot return a value before the first headline.
1213 (org-test-with-parsed-data "Paragraph
1218 (org-export-get-node-property
1219 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1221 (ert-deftest test-org-export
/get-category
()
1222 "Test `org-export-get-category' specifications."
1226 (org-test-with-parsed-data "* Headline
1230 (org-export-get-category
1231 (org-element-map tree
'headline
'identity nil t
) info
))))
1232 ;; Test inheritance from a parent headline.
1234 (equal '("value" "value")
1235 (org-test-with-parsed-data "* Headline1
1240 (org-element-map tree
'headline
1241 (lambda (hl) (org-export-get-category hl info
)) info
))))
1242 ;; Test inheritance from #+CATEGORY keyword
1245 (org-test-with-parsed-data "#+CATEGORY: value
1247 (org-export-get-category
1248 (org-element-map tree
'headline
'identity nil t
) info
))))
1249 ;; Test inheritance from file name.
1252 (org-test-with-parsed-data "* Headline"
1253 (let ((info (plist-put info
:input-file
"~/test.org")))
1254 (org-export-get-category
1255 (org-element-map tree
'headline
'identity nil t
) info
)))))
1259 (org-test-with-parsed-data "* Headline"
1260 (org-export-get-category
1261 (org-element-map tree
'headline
'identity nil t
) info
)))))
1263 (ert-deftest test-org-export
/first-sibling-p
()
1264 "Test `org-export-first-sibling-p' specifications."
1269 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1270 (org-element-map tree
'headline
1271 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1273 ;; Ignore headlines not exported.
1277 (let ((org-export-exclude-tags '("ignore")))
1278 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1279 (org-element-map tree
'headline
1280 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1283 (ert-deftest test-org-export
/last-sibling-p
()
1284 "Test `org-export-last-sibling-p' specifications."
1289 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1290 (org-element-map tree
'headline
1291 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1293 ;; Ignore headlines not exported.
1297 (let ((org-export-exclude-tags '("ignore")))
1298 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1299 (org-element-map tree
'headline
1300 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1303 (ert-deftest test-org-export
/handle-inlinetasks
()
1304 "Test inlinetask export."
1305 ;; Inlinetask with an exclude tag.
1306 (when (featurep 'org-inlinetask
)
1310 (let ((org-inlinetask-min-level 3))
1311 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1312 (org-test-with-backend test
1313 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp"))))))))
1314 ;; Inlinetask with an include tag.
1317 "* H2\n*** Inline :exp:\n"
1318 (let ((org-inlinetask-min-level 3)
1319 (org-tags-column 0))
1320 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1321 (org-test-with-backend test
1322 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
1323 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1326 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1327 (org-inlinetask-min-level 3))
1328 (org-test-with-temp-text "*** TODO Inline"
1329 (org-test-with-backend test
1330 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))))
1336 (ert-deftest test-org-export
/get-date
()
1337 "Test `org-export-get-date' specifications."
1338 ;; Return a properly formatted string when
1339 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1340 ;; consists in a single timestamp.
1343 (let ((org-export-date-timestamp-format "%d %m %Y"))
1344 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1345 (org-export-get-date info
)))))
1346 ;; Return a secondary string otherwise.
1349 (let ((org-export-date-timestamp-format nil
))
1350 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1351 (org-export-get-date info
)))))
1354 (org-test-with-parsed-data "#+DATE: Date"
1355 (org-export-get-date info
))))
1356 ;; Optional argument has precedence over
1357 ;; `org-export-date-timestamp-format'.
1360 (let ((org-export-date-timestamp-format "%d %m %Y"))
1361 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1362 (org-export-get-date info
"%d %m"))))))
1368 (ert-deftest test-org-export
/get-coderef-format
()
1369 "Test `org-export-get-coderef-format' specifications."
1370 ;; A link without description returns "%s"
1371 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1373 ;; Return "%s" when path is matched within description.
1374 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1376 ;; Otherwise return description.
1377 (should (equal (org-export-get-coderef-format "path" "desc")
1380 (ert-deftest test-org-export
/inline-image-p
()
1381 "Test `org-export-inline-image-p' specifications."
1383 (org-export-inline-image-p
1384 (org-test-with-temp-text "[[#id]]"
1385 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1386 '(("custom-id" .
"id")))))
1388 (ert-deftest test-org-export
/fuzzy-link
()
1389 "Test fuzzy links specifications."
1390 ;; Link to an headline should return headline's number.
1391 (org-test-with-parsed-data
1392 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1394 ;; Note: Headline's number is in fact a list of numbers.
1396 (org-element-map tree
'link
1398 (org-export-get-ordinal
1399 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1400 ;; Link to a target in an item should return item's number.
1401 (org-test-with-parsed-data
1402 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1404 ;; Note: Item's number is in fact a list of numbers.
1406 (org-element-map tree
'link
1408 (org-export-get-ordinal
1409 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1410 ;; Link to a target in a footnote should return footnote's number.
1411 (org-test-with-parsed-data "
1412 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1415 (org-element-map tree
'link
1417 (org-export-get-ordinal
1418 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1419 ;; Link to a named element should return sequence number of that
1421 (org-test-with-parsed-data
1422 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1425 (org-element-map tree
'link
1427 (org-export-get-ordinal
1428 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1429 ;; Link to a target not within an item, a table, a footnote
1430 ;; reference or definition should return section number.
1431 (org-test-with-parsed-data
1432 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1435 (org-element-map tree
'link
1437 (org-export-get-ordinal
1438 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1439 ;; Space are not significant when matching a fuzzy link.
1441 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1442 (org-element-map tree
'link
1443 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1445 ;; Statistics cookies are ignored for headline match.
1447 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1448 (org-element-map tree
'link
1449 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1452 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1453 (org-element-map tree
'link
1454 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1457 (ert-deftest test-org-export
/resolve-coderef
()
1458 "Test `org-export-resolve-coderef' specifications."
1459 (let ((org-coderef-label-format "(ref:%s)"))
1460 ;; 1. A link to a "-n -k -r" block returns line number.
1461 (org-test-with-parsed-data
1462 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1463 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1464 (org-test-with-parsed-data
1465 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1466 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1467 ;; 2. A link to a "-n -r" block returns line number.
1468 (org-test-with-parsed-data
1469 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1470 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1471 (org-test-with-parsed-data
1472 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1473 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1474 ;; 3. A link to a "-n" block returns coderef.
1475 (org-test-with-parsed-data
1476 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1477 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1478 (org-test-with-parsed-data
1479 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1480 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1481 ;; 4. A link to a "-r" block returns line number.
1482 (org-test-with-parsed-data
1483 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1484 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1485 (org-test-with-parsed-data
1486 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1487 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1488 ;; 5. A link to a block without a switch returns coderef.
1489 (org-test-with-parsed-data
1490 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1491 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1492 (org-test-with-parsed-data
1493 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1494 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1495 ;; 6. Correctly handle continued line numbers. A "+n" switch
1496 ;; should resume numbering from previous block with numbered
1497 ;; lines, ignoring blocks not numbering lines in the process.
1498 ;; A "-n" switch resets count.
1499 (org-test-with-parsed-data "
1504 #+BEGIN_SRC emacs-lisp
1508 #+BEGIN_SRC emacs-lisp +n -r
1509 \(+ 1 1) (ref:addition)
1512 #+BEGIN_EXAMPLE -n -r
1513 Another text. (ref:text)
1515 (should (= (org-export-resolve-coderef "addition" info
) 2))
1516 (should (= (org-export-resolve-coderef "text" info
) 1)))
1517 ;; 7. Recognize coderef with user-specified syntax.
1518 (org-test-with-parsed-data
1519 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1520 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1522 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1523 "Test `org-export-resolve-fuzzy-link' specifications."
1524 ;; Match target objects.
1526 (org-test-with-parsed-data "<<target>> [[target]]"
1527 (org-export-resolve-fuzzy-link
1528 (org-element-map tree
'link
'identity info t
) info
)))
1529 ;; Match named elements.
1531 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1532 (org-export-resolve-fuzzy-link
1533 (org-element-map tree
'link
'identity info t
) info
)))
1534 ;; Match exact headline's name.
1536 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1537 (org-export-resolve-fuzzy-link
1538 (org-element-map tree
'link
'identity info t
) info
)))
1539 ;; Targets objects have priority over named elements and headline
1543 (org-test-with-parsed-data
1544 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1546 (org-export-resolve-fuzzy-link
1547 (org-element-map tree
'link
'identity info t
) info
)))))
1548 ;; Named elements have priority over headline titles.
1551 (org-test-with-parsed-data
1552 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1554 (org-export-resolve-fuzzy-link
1555 (org-element-map tree
'link
'identity info t
) info
)))))
1556 ;; If link's path starts with a "*", only match headline titles,
1560 (org-test-with-parsed-data
1561 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1563 (org-export-resolve-fuzzy-link
1564 (org-element-map tree
'link
'identity info t
) info
)))))
1565 ;; Return nil if no match.
1567 (org-test-with-parsed-data "[[target]]"
1568 (org-export-resolve-fuzzy-link
1569 (org-element-map tree
'link
'identity info t
) info
))))
1571 (ert-deftest test-org-export
/resolve-id-link
()
1572 "Test `org-export-resolve-id-link' specifications."
1573 ;; 1. Regular test for custom-id link.
1574 (org-test-with-parsed-data "* Headline1
1581 (org-export-resolve-id-link
1582 (org-element-map tree
'link
'identity info t
) info
)))
1583 ;; 2. Failing test for custom-id link.
1584 (org-test-with-parsed-data "* Headline1
1591 (org-export-resolve-id-link
1592 (org-element-map tree
'link
'identity info t
) info
)))
1593 ;; 3. Test for internal id target.
1594 (org-test-with-parsed-data "* Headline1
1601 (org-export-resolve-id-link
1602 (org-element-map tree
'link
'identity info t
) info
)))
1603 ;; 4. Test for external id target.
1604 (org-test-with-parsed-data "[[id:aaaa]]"
1606 (org-export-resolve-id-link
1607 (org-element-map tree
'link
'identity info t
)
1608 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1610 (ert-deftest test-org-export
/resolve-radio-link
()
1611 "Test `org-export-resolve-radio-link' specifications."
1614 (org-test-with-temp-text "<<<radio>>> radio"
1615 (org-update-radio-target-regexp)
1616 (let* ((tree (org-element-parse-buffer))
1617 (info `(:parse-tree
,tree
)))
1618 (org-export-resolve-radio-link
1619 (org-element-map tree
'link
'identity info t
)
1621 ;; Radio targets are case-insensitive.
1623 (org-test-with-temp-text "<<<RADIO>>> radio"
1624 (org-update-radio-target-regexp)
1625 (let* ((tree (org-element-parse-buffer))
1626 (info `(:parse-tree
,tree
)))
1627 (org-export-resolve-radio-link
1628 (org-element-map tree
'link
'identity info t
)
1630 ;; Radio target with objects.
1632 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1633 (org-update-radio-target-regexp)
1634 (let* ((tree (org-element-parse-buffer))
1635 (info `(:parse-tree
,tree
)))
1636 (org-export-resolve-radio-link
1637 (org-element-map tree
'link
'identity info t
)
1642 ;;; Src-block and example-block
1644 (ert-deftest test-org-export
/unravel-code
()
1645 "Test `org-export-unravel-code' function."
1646 (let ((org-coderef-label-format "(ref:%s)"))
1647 ;; 1. Code without reference.
1648 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1649 (should (equal (org-export-unravel-code (org-element-at-point))
1651 ;; 2. Code with reference.
1652 (org-test-with-temp-text
1653 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1654 (should (equal (org-export-unravel-code (org-element-at-point))
1655 '("(+ 1 1)\n" (1 .
"test")))))
1656 ;; 3. Code with user-defined reference.
1657 (org-test-with-temp-text
1658 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1659 (should (equal (org-export-unravel-code (org-element-at-point))
1660 '("(+ 1 1)\n" (1 .
"test")))))
1661 ;; 4. Code references keys are relative to the current block.
1662 (org-test-with-temp-text "
1671 (should (equal (org-export-unravel-code (org-element-at-point))
1672 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1674 (ert-deftest test-org-export
/format-code-default
()
1675 "Test `org-export-format-code-default' specifications."
1676 ;; Return the empty string when code is empty.
1679 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1680 (org-export-format-code-default
1681 (org-element-map tree
'src-block
'identity info t
) info
))))
1682 ;; Number lines, two whitespace characters before the actual loc.
1685 (org-test-with-parsed-data
1686 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1687 (org-export-format-code-default
1688 (org-element-map tree
'src-block
'identity info t
) info
))))
1689 ;; Put references 6 whitespace characters after the widest line,
1690 ;; wrapped within parenthesis.
1692 (equal "123 (a)\n1 (b)\n"
1693 (let ((org-coderef-label-format "(ref:%s)"))
1694 (org-test-with-parsed-data
1695 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1696 (org-export-format-code-default
1697 (org-element-map tree
'src-block
'identity info t
) info
))))))
1703 (ert-deftest test-org-export
/activate-smart-quotes
()
1704 "Test `org-export-activate-smart-quotes' specifications."
1705 ;; Opening double quotes: standard test.
1708 '("some “paragraph")
1709 (let ((org-export-default-language "en"))
1710 (org-test-with-parsed-data "some \"paragraph"
1711 (org-element-map tree
'plain-text
1712 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1714 ;; Opening quotes: at the beginning of a paragraph.
1718 (let ((org-export-default-language "en"))
1719 (org-test-with-parsed-data "\"begin"
1720 (org-element-map tree
'plain-text
1721 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1723 ;; Opening quotes: after an object.
1727 (let ((org-export-default-language "en"))
1728 (org-test-with-parsed-data "=verb= \"begin"
1729 (org-element-map tree
'plain-text
1730 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1732 ;; Closing quotes: standard test.
1735 '("some” paragraph")
1736 (let ((org-export-default-language "en"))
1737 (org-test-with-parsed-data "some\" paragraph"
1738 (org-element-map tree
'plain-text
1739 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1741 ;; Closing quotes: at the end of a paragraph.
1745 (let ((org-export-default-language "en"))
1746 (org-test-with-parsed-data "end\""
1747 (org-element-map tree
'plain-text
1748 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1750 ;; Apostrophe: standard test.
1753 '("It shouldn’t fail")
1754 (let ((org-export-default-language "en"))
1755 (org-test-with-parsed-data "It shouldn't fail"
1756 (org-element-map tree
'plain-text
1757 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1759 ;; Apostrophe: before an object.
1763 (let ((org-export-default-language "en"))
1764 (org-test-with-parsed-data "a'=b="
1765 (org-element-map tree
'plain-text
1766 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1768 ;; Apostrophe: after an object.
1772 (let ((org-export-default-language "en"))
1773 (org-test-with-parsed-data "=code='s"
1774 (org-element-map tree
'plain-text
1775 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1777 ;; Special case: isolated quotes.
1779 (equal '("“" "”")
1780 (let ((org-export-default-language "en"))
1781 (org-test-with-parsed-data "\"$x$\""
1782 (org-element-map tree
'plain-text
1783 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1785 ;; Smart quotes in secondary strings.
1787 (equal '("“" "”")
1788 (let ((org-export-default-language "en"))
1789 (org-test-with-parsed-data "* \"$x$\""
1790 (org-element-map tree
'plain-text
1791 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1793 ;; Smart quotes in document keywords.
1795 (equal '("“" "”")
1796 (let ((org-export-default-language "en"))
1797 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1798 (org-element-map (plist-get info
:title
) 'plain-text
1799 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1801 ;; Smart quotes in parsed affiliated keywords.
1803 (equal '("“" "”" "Paragraph")
1804 (let ((org-export-default-language "en"))
1805 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1806 (org-element-map tree
'plain-text
1807 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1808 info nil nil t
))))))
1814 (ert-deftest test-org-export
/special-column
()
1815 "Test if the table's special column is properly recognized."
1816 ;; 1. First column is special if it contains only a special marking
1817 ;; characters or empty cells.
1818 (org-test-with-temp-text "
1822 (org-export-table-has-special-column-p
1824 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1825 ;; 2. If the column contains anything else, it isn't special.
1826 (org-test-with-temp-text "
1830 (org-export-table-has-special-column-p
1832 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1833 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1835 (org-test-with-temp-text "
1844 (org-export-table-has-special-column-p
1846 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1847 ;; 4. A first column with only empty cells isn't considered as
1849 (org-test-with-temp-text "
1853 (org-export-table-has-special-column-p
1855 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1857 (ert-deftest test-org-export
/table-row-is-special-p
()
1858 "Test `org-export-table-row-is-special-p' specifications."
1859 ;; 1. A row is special if it has a special marking character in the
1861 (org-test-with-parsed-data "| ! | 1 |"
1863 (org-export-table-row-is-special-p
1864 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1865 ;; 2. A row is special when its first field is "/"
1866 (org-test-with-parsed-data "
1870 (org-export-table-row-is-special-p
1871 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1872 ;; 3. A row only containing alignment cookies is also considered as
1874 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1876 (org-export-table-row-is-special-p
1877 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1878 ;; 4. Everything else isn't considered as special.
1879 (org-test-with-parsed-data "| \alpha | | c |"
1881 (org-export-table-row-is-special-p
1882 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1883 ;; 5. Table's rules are never considered as special rows.
1884 (org-test-with-parsed-data "|---+---|"
1886 (org-export-table-row-is-special-p
1887 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1889 (ert-deftest test-org-export
/has-header-p
()
1890 "Test `org-export-table-has-header-p' specifications."
1891 ;; 1. With an header.
1892 (org-test-with-parsed-data "
1897 (org-export-table-has-header-p
1898 (org-element-map tree
'table
'identity info
'first-match
)
1900 ;; 2. Without an header.
1901 (org-test-with-parsed-data "
1905 (org-export-table-has-header-p
1906 (org-element-map tree
'table
'identity info
'first-match
)
1908 ;; 3. Don't get fooled with starting and ending rules.
1909 (org-test-with-parsed-data "
1915 (org-export-table-has-header-p
1916 (org-element-map tree
'table
'identity info
'first-match
)
1919 (ert-deftest test-org-export
/table-row-group
()
1920 "Test `org-export-table-row-group' specifications."
1921 ;; 1. A rule creates a new group.
1922 (org-test-with-parsed-data "
1929 (mapcar (lambda (row) (org-export-table-row-group row info
))
1930 (org-element-map tree
'table-row
'identity
)))))
1931 ;; 2. Special rows are ignored in count.
1932 (org-test-with-parsed-data "
1939 (mapcar (lambda (row) (org-export-table-row-group row info
))
1940 (org-element-map tree
'table-row
'identity
)))))
1941 ;; 3. Double rules also are ignored in count.
1942 (org-test-with-parsed-data "
1950 (mapcar (lambda (row) (org-export-table-row-group row info
))
1951 (org-element-map tree
'table-row
'identity
))))))
1953 (ert-deftest test-org-export
/table-row-number
()
1954 "Test `org-export-table-row-number' specifications."
1955 ;; Standard test. Number is 0-indexed.
1958 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
1959 (org-element-map tree
'table-row
1960 (lambda (row) (org-export-table-row-number row info
)) info
))))
1961 ;; Number ignores separators.
1964 (org-test-with-parsed-data "
1968 (org-element-map tree
'table-row
1969 (lambda (row) (org-export-table-row-number row info
)) info
))))
1970 ;; Number ignores special rows.
1973 (org-test-with-parsed-data "
1979 (org-element-map tree
'table-row
1980 (lambda (row) (org-export-table-row-number row info
)) info
)))))
1982 (ert-deftest test-org-export
/table-cell-width
()
1983 "Test `org-export-table-cell-width' specifications."
1984 ;; 1. Width is primarily determined by width cookies. If no cookie
1985 ;; is found, cell's width is nil.
1986 (org-test-with-parsed-data "
1987 | / | <l> | <6> | <l7> |
1992 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1993 (org-element-map tree
'table-cell
'identity info
)))))
1994 ;; 2. The last width cookie has precedence.
1995 (org-test-with-parsed-data "
2002 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2003 (org-element-map tree
'table-cell
'identity info
)))))
2004 ;; 3. Valid width cookies must have a specific row.
2005 (org-test-with-parsed-data "| <6> | cell |"
2009 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2010 (org-element-map tree
'table-cell
'identity
))))))
2012 (ert-deftest test-org-export
/table-cell-alignment
()
2013 "Test `org-export-table-cell-alignment' specifications."
2014 (let ((org-table-number-fraction 0.5)
2015 (org-table-number-regexp "^[0-9]+$"))
2016 ;; 1. Alignment is primarily determined by alignment cookies.
2017 (org-test-with-temp-text "| <l> | <c> | <r> |"
2018 (let* ((tree (org-element-parse-buffer))
2019 (info `(:parse-tree
,tree
)))
2022 '(left center right
)
2023 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2024 (org-element-map tree
'table-cell
'identity
))))))
2025 ;; 2. The last alignment cookie has precedence.
2026 (org-test-with-parsed-data "
2032 '(right right right
)
2033 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2034 (org-element-map tree
'table-cell
'identity
)))))
2035 ;; 3. If there's no cookie, cell's contents determine alignment.
2036 ;; A column mostly made of cells containing numbers will align
2037 ;; its cells to the right.
2038 (org-test-with-parsed-data "
2044 '(right right right
)
2045 (mapcar (lambda (cell)
2046 (org-export-table-cell-alignment cell info
))
2047 (org-element-map tree
'table-cell
'identity
)))))
2048 ;; 4. Otherwise, they will be aligned to the left.
2049 (org-test-with-parsed-data "
2056 (mapcar (lambda (cell)
2057 (org-export-table-cell-alignment cell info
))
2058 (org-element-map tree
'table-cell
'identity
)))))))
2060 (ert-deftest test-org-export
/table-cell-borders
()
2061 "Test `org-export-table-cell-borders' specifications."
2062 ;; 1. Recognize various column groups indicators.
2063 (org-test-with-parsed-data "| / | < | > | <> |"
2066 '((right bottom top
) (left bottom top
) (right bottom top
)
2067 (right left bottom top
))
2068 (mapcar (lambda (cell)
2069 (org-export-table-cell-borders cell info
))
2070 (org-element-map tree
'table-cell
'identity
)))))
2071 ;; 2. Accept shortcuts to define column groups.
2072 (org-test-with-parsed-data "| / | < | < |"
2075 '((right bottom top
) (right left bottom top
) (left bottom top
))
2076 (mapcar (lambda (cell)
2077 (org-export-table-cell-borders cell info
))
2078 (org-element-map tree
'table-cell
'identity
)))))
2079 ;; 3. A valid column groups row must start with a "/".
2080 (org-test-with-parsed-data "
2084 (equal '((top) (top) (bottom) (bottom))
2085 (mapcar (lambda (cell)
2086 (org-export-table-cell-borders cell info
))
2087 (org-element-map tree
'table-cell
'identity
)))))
2088 ;; 4. Take table rules into consideration.
2089 (org-test-with-parsed-data "
2094 (equal '((below top
) (bottom above
))
2095 (mapcar (lambda (cell)
2096 (org-export-table-cell-borders cell info
))
2097 (org-element-map tree
'table-cell
'identity
)))))
2098 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2099 ;; (resp. `bottom' and `below') borders. Any special row is
2101 (org-test-with-parsed-data "
2107 (equal '((bottom below top above
))
2109 (mapcar (lambda (cell)
2110 (org-export-table-cell-borders cell info
))
2111 (org-element-map tree
'table-cell
'identity
)))))))
2113 (ert-deftest test-org-export
/table-dimensions
()
2114 "Test `org-export-table-dimensions' specifications."
2115 ;; 1. Standard test.
2116 (org-test-with-parsed-data "
2121 (org-export-table-dimensions
2122 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2123 ;; 2. Ignore horizontal rules and special columns.
2124 (org-test-with-parsed-data "
2131 (org-export-table-dimensions
2132 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2134 (ert-deftest test-org-export
/table-cell-address
()
2135 "Test `org-export-table-cell-address' specifications."
2136 ;; 1. Standard test: index is 0-based.
2137 (org-test-with-parsed-data "| a | b |"
2139 (equal '((0 .
0) (0 .
1))
2140 (org-element-map tree
'table-cell
2141 (lambda (cell) (org-export-table-cell-address cell info
))
2143 ;; 2. Special column isn't counted, nor are special rows.
2144 (org-test-with-parsed-data "
2149 (org-export-table-cell-address
2150 (car (last (org-element-map tree
'table-cell
'identity info
)))
2152 ;; 3. Tables rules do not count either.
2153 (org-test-with-parsed-data "
2161 (org-export-table-cell-address
2162 (car (last (org-element-map tree
'table-cell
'identity info
)))
2164 ;; 4. Return nil for special cells.
2165 (org-test-with-parsed-data "| / | a |"
2167 (org-export-table-cell-address
2168 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2171 (ert-deftest test-org-export
/get-table-cell-at
()
2172 "Test `org-export-get-table-cell-at' specifications."
2173 ;; 1. Address ignores special columns, special rows and rules.
2174 (org-test-with-parsed-data "
2181 (org-element-contents
2182 (org-export-get-table-cell-at
2184 (org-element-map tree
'table
'identity info
'first-match
)
2186 ;; 2. Return value for a non-existent address is nil.
2187 (org-test-with-parsed-data "| a |"
2189 (org-export-get-table-cell-at
2191 (org-element-map tree
'table
'identity info
'first-match
)
2193 (org-test-with-parsed-data "| / |"
2195 (org-export-get-table-cell-at
2197 (org-element-map tree
'table
'identity info
'first-match
)
2200 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2201 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2202 ;; 1. A cell at a beginning of a row always starts a column group.
2203 (org-test-with-parsed-data "| a |"
2205 (org-export-table-cell-starts-colgroup-p
2206 (org-element-map tree
'table-cell
'identity info
'first-match
)
2208 ;; 2. Special column should be ignored when determining the
2209 ;; beginning of the row.
2210 (org-test-with-parsed-data "
2214 (org-export-table-cell-starts-colgroup-p
2215 (org-element-map tree
'table-cell
'identity info
'first-match
)
2217 ;; 2. Explicit column groups.
2218 (org-test-with-parsed-data "
2224 (org-element-map tree
'table-cell
2226 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2229 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2230 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2231 ;; 1. A cell at the end of a row always ends a column group.
2232 (org-test-with-parsed-data "| a |"
2234 (org-export-table-cell-ends-colgroup-p
2235 (org-element-map tree
'table-cell
'identity info
'first-match
)
2237 ;; 2. Special column should be ignored when determining the
2238 ;; beginning of the row.
2239 (org-test-with-parsed-data "
2243 (org-export-table-cell-ends-colgroup-p
2244 (org-element-map tree
'table-cell
'identity info
'first-match
)
2246 ;; 3. Explicit column groups.
2247 (org-test-with-parsed-data "
2253 (org-element-map tree
'table-cell
2255 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2258 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2259 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2260 ;; 1. A row at the beginning of a table always starts a row group.
2261 ;; So does a row following a table rule.
2262 (org-test-with-parsed-data "
2269 (org-element-map tree
'table-row
2271 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2273 ;; 2. Special rows should be ignored when determining the beginning
2275 (org-test-with-parsed-data "
2284 (org-element-map tree
'table-row
2286 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2289 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2290 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2291 ;; 1. A row at the end of a table always ends a row group. So does
2292 ;; a row preceding a table rule.
2293 (org-test-with-parsed-data "
2300 (org-element-map tree
'table-row
2302 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2304 ;; 2. Special rows should be ignored when determining the beginning
2306 (org-test-with-parsed-data "
2315 (org-element-map tree
'table-row
2317 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2320 (ert-deftest test-org-export
/table-row-starts-header-p
()
2321 "Test `org-export-table-row-starts-header-p' specifications."
2322 ;; 1. Only the row starting the first row group starts the table
2324 (org-test-with-parsed-data "
2332 (org-element-map tree
'table-row
2334 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2336 ;; 2. A row cannot start an header if there's no header in the
2338 (org-test-with-parsed-data "
2342 (org-export-table-row-starts-header-p
2343 (org-element-map tree
'table-row
'identity info
'first-match
)
2346 (ert-deftest test-org-export
/table-row-ends-header-p
()
2347 "Test `org-export-table-row-ends-header-p' specifications."
2348 ;; 1. Only the row starting the first row group starts the table
2350 (org-test-with-parsed-data "
2358 (org-element-map tree
'table-row
2360 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2362 ;; 2. A row cannot start an header if there's no header in the
2364 (org-test-with-parsed-data "
2368 (org-export-table-row-ends-header-p
2369 (org-element-map tree
'table-row
'identity info
'first-match
)
2376 (ert-deftest test-org-export
/inner-template
()
2377 "Test `inner-template' translator specifications."
2380 (let (org-export-registered-backends)
2381 (org-export-define-backend 'test
2382 '((inner-template .
(lambda (contents info
) "Success!"))
2383 (headline .
(lambda (h c i
) "Headline"))))
2384 (org-test-with-temp-text "* Headline"
2385 (org-export-as 'test
)))))
2386 ;; Inner template is applied even in a "body-only" export.
2389 (let (org-export-registered-backends)
2390 (org-export-define-backend 'test
2391 '((inner-template .
(lambda (contents info
) "Success!"))
2392 (headline .
(lambda (h c i
) "Headline"))))
2393 (org-test-with-temp-text "* Headline"
2394 (org-export-as 'test nil nil
'body-only
))))))
2396 (ert-deftest test-org-export
/template
()
2397 "Test `template' translator specifications."
2400 (let (org-export-registered-backends)
2401 (org-export-define-backend 'test
2402 '((template .
(lambda (contents info
) "Success!"))
2403 (headline .
(lambda (h c i
) "Headline"))))
2404 (org-test-with-temp-text "* Headline"
2405 (org-export-as 'test
)))))
2406 ;; Template is not applied in a "body-only" export.
2409 (let (org-export-registered-backends)
2410 (org-export-define-backend 'test
2411 '((template .
(lambda (contents info
) "Success!"))
2412 (headline .
(lambda (h c i
) "Headline"))))
2413 (org-test-with-temp-text "* Headline"
2414 (org-export-as 'test nil nil
'body-only
))))))
2420 (ert-deftest test-org-export
/get-next-element
()
2421 "Test `org-export-get-next-element' specifications."
2425 (org-test-with-parsed-data "* Headline\n*a* b"
2426 (org-export-get-next-element
2427 (org-element-map tree
'bold
'identity info t
) info
))))
2428 ;; Return nil when no previous element.
2430 (org-test-with-parsed-data "* Headline\na *b*"
2431 (org-export-get-next-element
2432 (org-element-map tree
'bold
'identity info t
) info
)))
2433 ;; Non-exportable elements are ignored.
2435 (let ((org-export-with-timestamps nil
))
2436 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2437 (org-export-get-next-element
2438 (org-element-map tree
'entity
'identity info t
) info
))))
2439 ;; Find next element in secondary strings.
2442 (org-test-with-parsed-data "* a =verb="
2444 (org-export-get-next-element
2445 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2446 ;; Find next element in document keywords.
2449 (org-test-with-parsed-data "#+TITLE: a =verb="
2451 (org-export-get-next-element
2453 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2454 ;; Find next element in parsed affiliated keywords.
2457 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2459 (org-export-get-next-element
2460 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2461 ;; With optional argument N, return a list containing all the
2462 ;; following elements.
2465 '(bold code underline
)
2466 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2468 (org-export-get-next-element
2469 (org-element-map tree
'italic
'identity info t
) info t
)))))
2470 ;; When N is a positive integer, return a list containing up to
2471 ;; N following elements.
2475 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2477 (org-export-get-next-element
2478 (org-element-map tree
'italic
'identity info t
) info
2))))))
2480 (ert-deftest test-org-export
/get-previous-element
()
2481 "Test `org-export-get-previous-element' specifications."
2485 (org-test-with-parsed-data "* Headline\na *b*"
2486 (org-export-get-previous-element
2487 (org-element-map tree
'bold
'identity info t
) info
))))
2488 ;; Return nil when no previous element.
2490 (org-test-with-parsed-data "* Headline\n*a* b"
2491 (org-export-get-previous-element
2492 (org-element-map tree
'bold
'identity info t
) info
)))
2493 ;; Non-exportable elements are ignored.
2495 (let ((org-export-with-timestamps nil
))
2496 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2497 (org-export-get-previous-element
2498 (org-element-map tree
'entity
'identity info t
) info
))))
2499 ;; Find previous element in secondary strings.
2502 (org-test-with-parsed-data "* =verb= a"
2504 (org-export-get-previous-element
2505 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2506 ;; Find previous element in document keywords.
2509 (org-test-with-parsed-data "#+TITLE: =verb= a"
2511 (org-export-get-previous-element
2513 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2514 ;; Find previous element in parsed affiliated keywords.
2517 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2519 (org-export-get-previous-element
2520 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2521 ;; With optional argument N, return a list containing up to
2522 ;; N previous elements.
2524 (equal '(underline italic bold
)
2525 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2527 (org-export-get-previous-element
2528 (org-element-map tree
'code
'identity info t
) info t
)))))
2529 ;; When N is a positive integer, return a list containing up to
2530 ;; N previous elements.
2532 (equal '(italic bold
)
2533 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2535 (org-export-get-previous-element
2536 (org-element-map tree
'code
'identity info t
) info
2))))))
2540 ;;; test-org-export.el end here