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")))))
367 (let ((org-footnote-section nil
))
368 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
369 (org-test-with-backend test
371 (org-export-as 'test nil nil nil
'(:with-footnotes nil
))))))))
373 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
374 (let ((org-footnote-section nil
))
375 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
376 (org-test-with-backend test
378 (org-export-as 'test nil nil nil
'(:with-footnotes t
))))))))
380 (when (featurep 'org-inlinetask
)
383 (let ((org-inlinetask-min-level 15))
384 (org-test-with-temp-text "*************** Task"
385 (org-test-with-backend test
386 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
390 (let ((org-inlinetask-min-level 15))
391 (org-test-with-temp-text
392 "*************** Task\nContents\n*************** END"
393 (org-test-with-backend test
394 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
397 (let ((org-closed-string "CLOSED:"))
398 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
399 (org-test-with-backend test
401 (equal (org-export-as 'test nil nil nil
'(:with-planning t
))
402 "CLOSED: [2012-04-29 sun. 10:45]\n"))
404 (equal (org-export-as 'test nil nil nil
'(:with-planning nil
))
406 ;; Statistics cookies.
409 (org-test-with-temp-text "[0/0]"
410 (org-test-with-backend test
412 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
414 (ert-deftest test-org-export
/with-timestamps
()
415 "Test `org-export-with-timestamps' specifications."
419 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"
420 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
421 (org-test-with-backend test
422 (org-export-as 'test nil nil nil
'(:with-timestamps t
))))))
427 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
428 (org-test-with-backend test
429 (org-export-as 'test nil nil nil
'(:with-timestamps nil
))))))
433 "<2012-03-29 Thu>\n\nParagraph <2012-03-29 Thu>[2012-03-29 Thu]"
434 (org-test-with-temp-text
435 "<2012-03-29 Thu>[2012-03-29 Thu]
437 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
438 (org-test-with-backend test
440 (org-export-as 'test nil nil nil
'(:with-timestamps active
)))))))
444 "[2012-03-29 Thu]\n\nParagraph <2012-03-29 Thu>[2012-03-29 Thu]"
445 (org-test-with-temp-text
446 "<2012-03-29 Thu>[2012-03-29 Thu]
448 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
449 (org-test-with-backend test
451 (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))))))))
453 (ert-deftest test-org-export
/comment-tree
()
454 "Test if export process ignores commented trees."
455 (let ((org-comment-string "COMMENT"))
456 (org-test-with-temp-text "* COMMENT Head1"
457 (org-test-with-backend test
458 (should (equal (org-export-as 'test
) ""))))))
460 (ert-deftest test-org-export
/export-scope
()
461 "Test all export scopes."
462 (org-test-with-temp-text "
467 (org-test-with-backend test
470 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
472 (goto-char (point-min))
475 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
477 (goto-char (point-min))
479 (transient-mark-mode 1)
480 (push-mark (point) t t
)
481 (goto-char (point-at-eol))
482 (should (equal (org-export-as 'test
) "text\n"))))
483 ;; Subtree with a code block calling another block outside.
486 (org-test-with-temp-text "
488 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
493 #+BEGIN_SRC emacs-lisp
496 (org-test-with-backend test
498 (org-export-as 'test
'subtree
)))))
500 (org-test-with-temp-text "Text"
501 (org-test-with-backend test
503 (cdr (assq 'test org-export-registered-backends
))
505 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
506 (org-export-backend-translate-table 'test
)))
507 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
508 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
510 (ert-deftest test-org-export
/output-file-name
()
511 "Test `org-export-output-file-name' specifications."
512 ;; Export from a file: name is built from original file name.
514 (org-test-with-temp-text-in-file "Test"
515 (equal (concat (file-name-as-directory ".")
516 (file-name-nondirectory
517 (file-name-sans-extension (buffer-file-name))))
518 (file-name-sans-extension (org-export-output-file-name ".ext")))))
519 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
521 (org-test-with-temp-text-in-file
522 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
523 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
524 ;; From a buffer not associated to a file, too.
526 (org-test-with-temp-text
527 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
528 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
529 ;; When provided name is absolute, preserve it.
531 (org-test-with-temp-text
532 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
533 (expand-file-name "test"))
534 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
535 ;; When PUB-DIR argument is provided, use it.
537 (org-test-with-temp-text-in-file "Test"
538 (equal (file-name-directory
539 (org-export-output-file-name ".ext" nil
"dir/"))
541 ;; When returned name would overwrite original file, add EXTENSION
544 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
545 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
547 (ert-deftest test-org-export
/expand-include
()
548 "Test file inclusion in an Org buffer."
549 ;; Error when file isn't specified.
551 (org-test-with-temp-text "#+INCLUDE: dummy.org"
552 (org-export-expand-include-keyword)))
553 ;; Full insertion with recursive inclusion.
554 (org-test-with-temp-text
555 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
556 (org-export-expand-include-keyword)
557 (should (equal (buffer-string)
558 "Small Org file with an include keyword.
560 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
566 ;; Localized insertion.
567 (org-test-with-temp-text
568 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
570 (org-export-expand-include-keyword)
571 (should (equal (buffer-string)
572 "Small Org file with an include keyword.\n")))
573 ;; Insertion with constraints on headlines level.
576 "* Top heading\n** Heading\nbody\n"
577 (org-test-with-temp-text
579 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
581 (org-export-expand-include-keyword)
585 "* Top heading\n* Heading\nbody\n"
586 (org-test-with-temp-text
588 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
590 (org-export-expand-include-keyword)
592 ;; Inclusion within an example block.
593 (org-test-with-temp-text
594 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
596 (org-export-expand-include-keyword)
600 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
601 ;; Inclusion within a src-block.
602 (org-test-with-temp-text
604 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
606 (org-export-expand-include-keyword)
607 (should (equal (buffer-string)
608 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
610 (ert-deftest test-org-export
/expand-macro
()
611 "Test macro expansion in an Org buffer."
612 ;; Standard macro expansion.
614 (equal "#+MACRO: macro1 value\nvalue\n"
615 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
616 (org-test-with-backend test
(org-export-as 'test
)))))
617 ;; Expand specific macros.
619 (equal "me 2012-03-29 me@here Title\n"
620 (org-test-with-temp-text
626 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
627 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
628 (substring output
(string-match ".*\n\\'" output
))))))
629 ;; Expand specific macros when property contained a regular macro
633 (org-test-with-temp-text "
634 #+MACRO: macro1 value
635 #+TITLE: {{{macro1}}}
637 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
638 (substring output
(string-match ".*\n\\'" output
))))))
639 ;; Expand macros with templates in included files.
642 (org-test-with-temp-text
643 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
644 {{{included-macro}}}" org-test-dir
)
645 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
646 (substring output
(string-match ".*\n\\'" output
)))))))
648 (ert-deftest test-org-export
/user-ignore-list
()
649 "Test if `:ignore-list' accepts user input."
650 (org-test-with-backend test
651 (flet ((skip-note-head
653 ;; Ignore headlines with the word "note" in their title.
654 (org-element-map data
'headline
656 (when (string-match "\\<note\\>"
657 (org-element-property :raw-value headline
))
658 (org-export-ignore-element headline info
)))
661 ;; Install function in parse tree filters.
662 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
663 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
664 (should (equal (org-export-as 'test
) "* Head1\n")))))))
666 (ert-deftest test-org-export
/before-processing-hook
()
667 "Test `org-export-before-processing-hook'."
670 "#+MACRO: mac val\nTest\n"
671 (org-test-with-backend test
672 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
673 (let ((org-export-before-processing-hook
675 (while (re-search-forward "{{{" nil t
)
676 (let ((object (org-element-context)))
677 (when (eq (org-element-type object
) 'macro
)
679 (org-element-property :begin object
)
680 (org-element-property :end object
)))))))))
681 (org-export-as 'test
)))))))
683 (ert-deftest test-org-export
/before-parsing-hook
()
684 "Test `org-export-before-parsing-hook'."
686 (equal "Body 1\nBody 2\n"
687 (org-test-with-backend test
688 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
689 (let ((org-export-before-parsing-hook
691 (goto-char (point-min))
692 (while (re-search-forward org-outline-regexp-bol nil t
)
694 (point-at-bol) (progn (forward-line) (point))))))))
695 (org-export-as 'test
)))))))
699 ;;; Affiliated Keywords
701 (ert-deftest test-org-export
/read-attribute
()
702 "Test `org-export-read-attribute' specifications."
706 (org-export-read-attribute
708 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
709 (org-element-at-point)))
711 ;; Return nil on empty attribute.
713 (org-export-read-attribute
715 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
716 ;; Return nil on "nil" string.
718 (equal '(:a nil
:b nil
)
719 (org-export-read-attribute
721 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
722 (org-element-at-point)))))
723 ;; Return nil on empty string.
725 (equal '(:a nil
:b nil
)
726 (org-export-read-attribute
728 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
729 (org-element-at-point)))))
730 ;; Return empty string when value is "".
733 (org-export-read-attribute
735 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
736 (org-element-at-point)))))
737 ;; Return \"\" when value is """".
740 (org-export-read-attribute
742 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
743 (org-element-at-point)))))
744 ;; Ignore text before first property.
747 (org-export-read-attribute
749 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
750 (org-element-at-point))))))
752 (ert-deftest test-org-export
/get-caption
()
753 "Test `org-export-get-caption' specifications."
754 ;; Without optional argument, return long caption
758 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
759 (org-export-get-caption (org-element-at-point)))))
760 ;; With optional argument, return short caption.
764 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
765 (org-export-get-caption (org-element-at-point) t
))))
766 ;; Multiple lines are separated by white spaces.
770 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
771 (org-export-get-caption (org-element-at-point))))))
777 (ert-deftest test-org-export
/define-backend
()
778 "Test back-end definition and accessors."
781 (equal '((headline . my-headline-test
))
782 (let (org-export-registered-backends)
783 (org-export-define-backend 'test
'((headline . my-headline-test
)))
784 (org-export-backend-translate-table 'test
))))
787 (equal '((:filter-headline . my-filter
))
788 (let (org-export-registered-backends)
789 (org-export-define-backend 'test
790 '((headline . my-headline-test
))
791 :filters-alist
'((:filter-headline . my-filter
)))
792 (org-export-backend-filters 'test
))))
795 (equal '((:prop value
))
796 (let (org-export-registered-backends)
797 (org-export-define-backend 'test
798 '((headline . my-headline-test
))
799 :options-alist
'((:prop value
)))
800 (org-export-backend-options 'test
))))
803 (equal '(?k
"Test Export" test
)
804 (let (org-export-registered-backends)
805 (org-export-define-backend 'test
806 '((headline . my-headline-test
))
807 :menu-entry
'(?k
"Test Export" test
))
808 (org-export-backend-menu 'test
))))
811 (equal '(("TEST" . org-element-export-block-parser
))
812 (let (org-export-registered-backends org-element-block-name-alist
)
813 (org-export-define-backend 'test
814 '((headline . my-headline-test
))
815 :export-block
'("test"))
816 org-element-block-name-alist
))))
818 (ert-deftest test-org-export
/define-derived-backend
()
819 "Test `org-export-define-derived-backend' specifications."
820 ;; Error when parent back-end is not defined.
822 (let (org-export-registered-backends)
823 (org-export-define-derived-backend 'test
'parent
)))
824 ;; Append translation table to parent's.
826 (equal '((:headline . test
) (:headline . parent
))
827 (let (org-export-registered-backends)
828 (org-export-define-backend 'parent
'((:headline . parent
)))
829 (org-export-define-derived-backend 'test
'parent
830 :translate-alist
'((:headline . test
)))
831 (org-export-backend-translate-table 'test
))))
832 ;; Options defined in the new back have priority over those defined
836 (let (org-export-registered-backends)
837 (org-export-define-backend 'parent
838 '((:headline . parent
))
839 :options-alist
'((:a nil nil
'parent
)))
840 (org-export-define-derived-backend 'test
'parent
841 :options-alist
'((:a nil nil
'test
)))
842 (plist-get (org-export--get-global-options 'test
) :a
)))))
844 (ert-deftest test-org-export
/derived-backend-p
()
845 "Test `org-export-derived-backend-p' specifications."
846 ;; Non-nil with direct match.
848 (let (org-export-registered-backends)
849 (org-export-define-backend 'test
'((headline . test
)))
850 (org-export-derived-backend-p 'test
'test
)))
852 (let (org-export-registered-backends)
853 (org-export-define-backend 'test
'((headline . test
)))
854 (org-export-define-derived-backend 'test2
'test
)
855 (org-export-derived-backend-p 'test2
'test2
)))
856 ;; Non-nil with a direct parent.
858 (let (org-export-registered-backends)
859 (org-export-define-backend 'test
'((headline . test
)))
860 (org-export-define-derived-backend 'test2
'test
)
861 (org-export-derived-backend-p 'test2
'test
)))
862 ;; Non-nil with an indirect parent.
864 (let (org-export-registered-backends)
865 (org-export-define-backend 'test
'((headline . test
)))
866 (org-export-define-derived-backend 'test2
'test
)
867 (org-export-define-derived-backend 'test3
'test2
)
868 (org-export-derived-backend-p 'test3
'test
)))
871 (let (org-export-registered-backends)
872 (org-export-define-backend 'test
'((headline . test
)))
873 (org-export-define-backend 'test2
'((headline . test2
)))
874 (org-export-derived-backend-p 'test2
'test
)))
876 (let (org-export-registered-backends)
877 (org-export-define-backend 'test
'((headline . test
)))
878 (org-export-define-backend 'test2
'((headline . test2
)))
879 (org-export-define-derived-backend 'test3
'test2
)
880 (org-export-derived-backend-p 'test3
'test
))))
882 (ert-deftest test-org-export
/with-backend
()
883 "Test `org-export-with-backend' definition."
884 ;; Error when calling an undefined back-end
886 (let (org-export-registered-backends)
887 (org-export-with-backend 'test
"Test")))
888 ;; Error when called back-end doesn't have an appropriate
891 (let (org-export-registered-backends)
892 (org-export-define-backend 'test
((headline . ignore
)))
893 (org-export-with-backend 'test
"Test")))
894 ;; Otherwise, export using correct transcoder
897 (let (org-export-registered-backends)
898 (org-export-define-backend 'test
899 '((plain-text .
(lambda (text contents info
) "Failure"))))
900 (org-export-define-backend 'test2
901 '((plain-text .
(lambda (text contents info
) "Success"))))
902 (org-export-with-backend 'test2
"Test")))))
904 (ert-deftest test-org-export
/data-with-translations
()
905 "Test `org-export-data-with-translations' specifications."
909 (org-export-data-with-translations
911 '((plain-text .
(lambda (text info
) "Success"))
912 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
913 '(:with-emphasize t
)))))
915 (ert-deftest test-org-export
/data-with-backend
()
916 "Test `org-export-data-with-backend' specifications."
917 ;; Error when calling an undefined back-end.
919 (let (org-export-registered-backends)
920 (org-export-data-with-backend 'test
"Test" nil
)))
921 ;; Otherwise, export data recursively, using correct back-end.
925 (let (org-export-registered-backends)
926 (org-export-define-backend 'test
927 '((plain-text .
(lambda (text info
) "Success"))
928 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
929 (org-export-data-with-backend
930 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
936 (ert-deftest test-org-export
/export-snippet
()
937 "Test export snippets transcoding."
938 (org-test-with-temp-text "@@test:A@@@@t:B@@"
939 (org-test-with-backend test
941 (cdr (assq 'test org-export-registered-backends
))
943 (cons (cons 'export-snippet
944 (lambda (snippet contents info
)
945 (when (eq (org-export-snippet-backend snippet
) 'test
)
946 (org-element-property :value snippet
))))
947 (org-export-backend-translate-table 'test
)))
948 (let ((org-export-snippet-translation-alist nil
))
949 (should (equal (org-export-as 'test
) "A\n")))
950 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
951 (should (equal (org-export-as 'test
) "AB\n")))))
952 ;; Ignored export snippets do not remove any blank.
955 (org-test-with-parsed-data "begin @@test:A@@ end"
956 (org-export-data-with-translations
958 '((paragraph .
(lambda (paragraph contents info
) contents
))
959 (section .
(lambda (section contents info
) contents
)))
966 (ert-deftest test-org-export
/footnotes
()
967 "Test footnotes specifications."
968 (let ((org-footnote-section nil
)
969 (org-export-with-footnotes t
))
970 ;; 1. Read every type of footnote.
973 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
974 (org-test-with-parsed-data
975 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
976 (org-element-map tree
'footnote-reference
978 (let ((def (org-export-get-footnote-definition ref info
)))
979 (cons (org-export-get-footnote-number ref info
)
980 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
981 (car (org-element-contents
982 (car (org-element-contents def
))))))))
984 ;; 2. Test nested footnotes order.
985 (org-test-with-parsed-data
986 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
989 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
990 (org-element-map tree
'footnote-reference
992 (when (org-export-footnote-first-reference-p ref info
)
993 (cons (org-export-get-footnote-number ref info
)
994 (org-element-property :label ref
))))
996 ;; 3. Test nested footnote in invisible definitions.
997 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
999 (narrow-to-region (point) (point-at-eol))
1000 (let* ((tree (org-element-parse-buffer))
1001 (info (org-combine-plists
1002 `(:parse-tree
,tree
)
1003 (org-export-collect-tree-properties
1004 tree
(org-export-get-environment)))))
1005 ;; Both footnotes should be seen.
1007 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
1008 ;; 4. Test footnotes definitions collection.
1009 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1011 \[fn:2] B [fn:3] [fn::D].
1014 (should (= (length (org-export-collect-footnote-definitions tree info
))
1016 ;; 5. Test export of footnotes defined outside parsing scope.
1017 (org-test-with-temp-text "[fn:1] Out of scope
1020 (org-test-with-backend test
1022 (cdr (assq 'test org-export-registered-backends
))
1024 (cons (cons 'footnote-reference
1025 (lambda (fn contents info
)
1026 (org-element-interpret-data
1027 (org-export-get-footnote-definition fn info
))))
1028 (org-export-backend-translate-table 'test
)))
1030 (should (equal "ParagraphOut of scope\n"
1031 (org-export-as 'test
'subtree
)))))
1032 ;; 6. Footnotes without a definition should be provided a fallback
1035 (org-test-with-parsed-data "[fn:1]"
1036 (org-export-get-footnote-definition
1037 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1038 ;; 7. Footnote section should be ignored in TOC and in headlines
1041 (= 1 (let ((org-footnote-section "Footnotes"))
1042 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1043 (org-export-collect-headlines info
))))))
1046 (let ((org-footnote-section "Footnotes"))
1047 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1048 (org-element-map tree
'headline
1050 (when (equal (org-element-property :raw-value hl
) "H2")
1051 (org-export-get-headline-number hl info
)))
1056 ;;; Headlines and Inlinetasks
1058 (ert-deftest test-org-export
/get-relative-level
()
1059 "Test `org-export-get-relative-level' specifications."
1063 (let ((org-odd-levels-only nil
))
1064 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1065 (org-element-map tree
'headline
1066 (lambda (h) (org-export-get-relative-level h info
))
1071 (let ((org-odd-levels-only nil
))
1072 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1073 (org-element-map tree
'headline
1074 (lambda (h) (org-export-get-relative-level h info
))
1077 (ert-deftest test-org-export
/low-level-p
()
1078 "Test `org-export-low-level-p' specifications."
1082 (let ((org-odd-levels-only nil
))
1083 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1084 (org-element-map tree
'headline
1085 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1086 (plist-put info
:headline-levels
1)))))))
1088 (ert-deftest test-org-export
/get-headline-number
()
1089 "Test `org-export-get-headline-number' specifications."
1094 (let ((org-odd-levels-only nil
))
1095 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1096 (org-element-map tree
'headline
1097 (lambda (h) (org-export-get-headline-number h info
))
1099 ;; Missing levels are replaced with 0.
1103 (let ((org-odd-levels-only nil
))
1104 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1105 (org-element-map tree
'headline
1106 (lambda (h) (org-export-get-headline-number h info
))
1109 (ert-deftest test-org-export
/numbered-headline-p
()
1110 "Test `org-export-numbered-headline-p' specifications."
1111 ;; If `:section-numbers' is nil, never number headlines.
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 nil
))))
1117 ;; If `:section-numbers' is a number, only number headlines with
1118 ;; a level greater that it.
1122 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1123 (org-element-map tree
'headline
1124 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1125 (plist-put info
:section-numbers
1)))))
1126 ;; Otherwise, headlines are always numbered.
1128 (org-test-with-parsed-data "* Headline"
1129 (org-element-map tree
'headline
1130 (lambda (h) (org-export-numbered-headline-p h info
))
1131 (plist-put info
:section-numbers t
)))))
1133 (ert-deftest test-org-export
/number-to-roman
()
1134 "Test `org-export-number-to-roman' specifications."
1135 ;; If number is negative, return it as a string.
1136 (should (equal (org-export-number-to-roman -
1) "-1"))
1137 ;; Otherwise, return it as a roman number.
1138 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1140 (ert-deftest test-org-export
/get-optional-title
()
1141 "Test `org-export-get-alt-title' specifications."
1142 ;; If ALT_TITLE property is defined, use it.
1145 (org-test-with-parsed-data
1146 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1147 (org-export-get-alt-title
1148 (org-element-map tree
'headline
'identity info t
)
1150 ;; Otherwise, fall-back to regular title.
1152 (equal '("Headline")
1153 (org-test-with-parsed-data "* Headline"
1154 (org-export-get-alt-title
1155 (org-element-map tree
'headline
'identity info t
)
1158 (ert-deftest test-org-export
/get-tags
()
1159 "Test `org-export-get-tags' specifications."
1160 (let ((org-export-exclude-tags '("noexport"))
1161 (org-export-select-tags '("export")))
1162 ;; Standard test: tags which are not a select tag, an exclude tag,
1163 ;; or specified as optional argument shouldn't be ignored.
1165 (org-test-with-parsed-data "* Headline :tag:"
1166 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1168 ;; Exclude tags are removed.
1170 (org-test-with-parsed-data "* Headline :noexport:"
1171 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1173 ;; Select tags are removed.
1175 (org-test-with-parsed-data "* Headline :export:"
1176 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1181 (org-test-with-parsed-data "* Headline :tag:export:"
1182 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1184 ;; Tags provided in the optional argument are also ignored.
1186 (org-test-with-parsed-data "* Headline :ignore:"
1187 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1189 ;; Allow tag inheritance.
1193 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1194 (org-element-map tree
'headline
1195 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1196 ;; Tag inheritance checks FILETAGS keywords.
1200 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1201 (org-element-map tree
'headline
1202 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1204 (ert-deftest test-org-export
/get-node-property
()
1205 "Test`org-export-get-node-property' specifications."
1209 (org-test-with-parsed-data "* Headline
1213 (org-export-get-node-property
1214 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1215 ;; Test inheritance.
1218 (org-test-with-parsed-data "* Parent
1224 (org-export-get-node-property
1225 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1226 ;; Cannot return a value before the first headline.
1228 (org-test-with-parsed-data "Paragraph
1233 (org-export-get-node-property
1234 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1236 (ert-deftest test-org-export
/get-category
()
1237 "Test `org-export-get-category' specifications."
1241 (org-test-with-parsed-data "* Headline
1245 (org-export-get-category
1246 (org-element-map tree
'headline
'identity nil t
) info
))))
1247 ;; Test inheritance from a parent headline.
1249 (equal '("value" "value")
1250 (org-test-with-parsed-data "* Headline1
1255 (org-element-map tree
'headline
1256 (lambda (hl) (org-export-get-category hl info
)) info
))))
1257 ;; Test inheritance from #+CATEGORY keyword
1260 (org-test-with-parsed-data "#+CATEGORY: value
1262 (org-export-get-category
1263 (org-element-map tree
'headline
'identity nil t
) info
))))
1264 ;; Test inheritance from file name.
1267 (org-test-with-parsed-data "* Headline"
1268 (let ((info (plist-put info
:input-file
"~/test.org")))
1269 (org-export-get-category
1270 (org-element-map tree
'headline
'identity nil t
) info
)))))
1274 (org-test-with-parsed-data "* Headline"
1275 (org-export-get-category
1276 (org-element-map tree
'headline
'identity nil t
) info
)))))
1278 (ert-deftest test-org-export
/first-sibling-p
()
1279 "Test `org-export-first-sibling-p' specifications."
1284 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1285 (org-element-map tree
'headline
1286 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1288 ;; Ignore headlines not exported.
1292 (let ((org-export-exclude-tags '("ignore")))
1293 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1294 (org-element-map tree
'headline
1295 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1298 (ert-deftest test-org-export
/last-sibling-p
()
1299 "Test `org-export-last-sibling-p' specifications."
1304 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1305 (org-element-map tree
'headline
1306 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1308 ;; Ignore headlines not exported.
1312 (let ((org-export-exclude-tags '("ignore")))
1313 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1314 (org-element-map tree
'headline
1315 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1318 (ert-deftest test-org-export
/handle-inlinetasks
()
1319 "Test inlinetask export."
1320 ;; Inlinetask with an exclude tag.
1321 (when (featurep 'org-inlinetask
)
1325 (let ((org-inlinetask-min-level 3))
1326 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1327 (org-test-with-backend test
1328 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp"))))))))
1329 ;; Inlinetask with an include tag.
1332 "* H2\n*** Inline :exp:\n"
1333 (let ((org-inlinetask-min-level 3)
1334 (org-tags-column 0))
1335 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1336 (org-test-with-backend test
1337 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
1338 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1341 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1342 (org-inlinetask-min-level 3))
1343 (org-test-with-temp-text "*** TODO Inline"
1344 (org-test-with-backend test
1345 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))))
1351 (ert-deftest test-org-export
/get-date
()
1352 "Test `org-export-get-date' specifications."
1353 ;; Return a properly formatted string when
1354 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1355 ;; consists in a single timestamp.
1358 (let ((org-export-date-timestamp-format "%d %m %Y"))
1359 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1360 (org-export-get-date info
)))))
1361 ;; Return a secondary string otherwise.
1364 (let ((org-export-date-timestamp-format nil
))
1365 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1366 (org-export-get-date info
)))))
1369 (org-test-with-parsed-data "#+DATE: Date"
1370 (org-export-get-date info
))))
1371 ;; Optional argument has precedence over
1372 ;; `org-export-date-timestamp-format'.
1375 (let ((org-export-date-timestamp-format "%d %m %Y"))
1376 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1377 (org-export-get-date info
"%d %m"))))))
1383 (ert-deftest test-org-export
/get-coderef-format
()
1384 "Test `org-export-get-coderef-format' specifications."
1385 ;; A link without description returns "%s"
1386 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1388 ;; Return "%s" when path is matched within description.
1389 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1391 ;; Otherwise return description.
1392 (should (equal (org-export-get-coderef-format "path" "desc")
1395 (ert-deftest test-org-export
/inline-image-p
()
1396 "Test `org-export-inline-image-p' specifications."
1398 (org-export-inline-image-p
1399 (org-test-with-temp-text "[[#id]]"
1400 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1401 '(("custom-id" .
"id")))))
1403 (ert-deftest test-org-export
/fuzzy-link
()
1404 "Test fuzzy links specifications."
1405 ;; Link to an headline should return headline's number.
1406 (org-test-with-parsed-data
1407 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1409 ;; Note: Headline's number is in fact a list of numbers.
1411 (org-element-map tree
'link
1413 (org-export-get-ordinal
1414 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1415 ;; Link to a target in an item should return item's number.
1416 (org-test-with-parsed-data
1417 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1419 ;; Note: Item's number is in fact a list of numbers.
1421 (org-element-map tree
'link
1423 (org-export-get-ordinal
1424 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1425 ;; Link to a target in a footnote should return footnote's number.
1426 (org-test-with-parsed-data "
1427 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1430 (org-element-map tree
'link
1432 (org-export-get-ordinal
1433 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1434 ;; Link to a named element should return sequence number of that
1436 (org-test-with-parsed-data
1437 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1440 (org-element-map tree
'link
1442 (org-export-get-ordinal
1443 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1444 ;; Link to a target not within an item, a table, a footnote
1445 ;; reference or definition should return section number.
1446 (org-test-with-parsed-data
1447 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1450 (org-element-map tree
'link
1452 (org-export-get-ordinal
1453 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1454 ;; Space are not significant when matching a fuzzy link.
1456 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1457 (org-element-map tree
'link
1458 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1460 ;; Statistics cookies are ignored for headline match.
1462 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1463 (org-element-map tree
'link
1464 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1467 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1468 (org-element-map tree
'link
1469 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1472 (ert-deftest test-org-export
/resolve-coderef
()
1473 "Test `org-export-resolve-coderef' specifications."
1474 (let ((org-coderef-label-format "(ref:%s)"))
1475 ;; 1. A link to a "-n -k -r" block returns line number.
1476 (org-test-with-parsed-data
1477 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1478 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1479 (org-test-with-parsed-data
1480 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1481 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1482 ;; 2. A link to a "-n -r" block returns line number.
1483 (org-test-with-parsed-data
1484 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1485 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1486 (org-test-with-parsed-data
1487 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1488 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1489 ;; 3. A link to a "-n" block returns coderef.
1490 (org-test-with-parsed-data
1491 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1492 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1493 (org-test-with-parsed-data
1494 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1495 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1496 ;; 4. A link to a "-r" block returns line number.
1497 (org-test-with-parsed-data
1498 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1499 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1500 (org-test-with-parsed-data
1501 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1502 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1503 ;; 5. A link to a block without a switch returns coderef.
1504 (org-test-with-parsed-data
1505 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1506 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1507 (org-test-with-parsed-data
1508 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1509 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1510 ;; 6. Correctly handle continued line numbers. A "+n" switch
1511 ;; should resume numbering from previous block with numbered
1512 ;; lines, ignoring blocks not numbering lines in the process.
1513 ;; A "-n" switch resets count.
1514 (org-test-with-parsed-data "
1519 #+BEGIN_SRC emacs-lisp
1523 #+BEGIN_SRC emacs-lisp +n -r
1524 \(+ 1 1) (ref:addition)
1527 #+BEGIN_EXAMPLE -n -r
1528 Another text. (ref:text)
1530 (should (= (org-export-resolve-coderef "addition" info
) 2))
1531 (should (= (org-export-resolve-coderef "text" info
) 1)))
1532 ;; 7. Recognize coderef with user-specified syntax.
1533 (org-test-with-parsed-data
1534 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1535 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1537 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1538 "Test `org-export-resolve-fuzzy-link' specifications."
1539 ;; Match target objects.
1541 (org-test-with-parsed-data "<<target>> [[target]]"
1542 (org-export-resolve-fuzzy-link
1543 (org-element-map tree
'link
'identity info t
) info
)))
1544 ;; Match named elements.
1546 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1547 (org-export-resolve-fuzzy-link
1548 (org-element-map tree
'link
'identity info t
) info
)))
1549 ;; Match exact headline's name.
1551 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1552 (org-export-resolve-fuzzy-link
1553 (org-element-map tree
'link
'identity info t
) info
)))
1554 ;; Targets objects have priority over named elements and headline
1558 (org-test-with-parsed-data
1559 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1561 (org-export-resolve-fuzzy-link
1562 (org-element-map tree
'link
'identity info t
) info
)))))
1563 ;; Named elements have priority over headline titles.
1566 (org-test-with-parsed-data
1567 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1569 (org-export-resolve-fuzzy-link
1570 (org-element-map tree
'link
'identity info t
) info
)))))
1571 ;; If link's path starts with a "*", only match headline titles,
1575 (org-test-with-parsed-data
1576 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1578 (org-export-resolve-fuzzy-link
1579 (org-element-map tree
'link
'identity info t
) info
)))))
1580 ;; Return nil if no match.
1582 (org-test-with-parsed-data "[[target]]"
1583 (org-export-resolve-fuzzy-link
1584 (org-element-map tree
'link
'identity info t
) info
))))
1586 (ert-deftest test-org-export
/resolve-id-link
()
1587 "Test `org-export-resolve-id-link' specifications."
1588 ;; 1. Regular test for custom-id link.
1589 (org-test-with-parsed-data "* Headline1
1596 (org-export-resolve-id-link
1597 (org-element-map tree
'link
'identity info t
) info
)))
1598 ;; 2. Failing test for custom-id link.
1599 (org-test-with-parsed-data "* Headline1
1606 (org-export-resolve-id-link
1607 (org-element-map tree
'link
'identity info t
) info
)))
1608 ;; 3. Test for internal id target.
1609 (org-test-with-parsed-data "* Headline1
1616 (org-export-resolve-id-link
1617 (org-element-map tree
'link
'identity info t
) info
)))
1618 ;; 4. Test for external id target.
1619 (org-test-with-parsed-data "[[id:aaaa]]"
1621 (org-export-resolve-id-link
1622 (org-element-map tree
'link
'identity info t
)
1623 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1625 (ert-deftest test-org-export
/resolve-radio-link
()
1626 "Test `org-export-resolve-radio-link' specifications."
1629 (org-test-with-temp-text "<<<radio>>> radio"
1630 (org-update-radio-target-regexp)
1631 (let* ((tree (org-element-parse-buffer))
1632 (info `(:parse-tree
,tree
)))
1633 (org-export-resolve-radio-link
1634 (org-element-map tree
'link
'identity info t
)
1636 ;; Radio targets are case-insensitive.
1638 (org-test-with-temp-text "<<<RADIO>>> radio"
1639 (org-update-radio-target-regexp)
1640 (let* ((tree (org-element-parse-buffer))
1641 (info `(:parse-tree
,tree
)))
1642 (org-export-resolve-radio-link
1643 (org-element-map tree
'link
'identity info t
)
1645 ;; Radio target with objects.
1647 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1648 (org-update-radio-target-regexp)
1649 (let* ((tree (org-element-parse-buffer))
1650 (info `(:parse-tree
,tree
)))
1651 (org-export-resolve-radio-link
1652 (org-element-map tree
'link
'identity info t
)
1657 ;;; Src-block and example-block
1659 (ert-deftest test-org-export
/unravel-code
()
1660 "Test `org-export-unravel-code' function."
1661 (let ((org-coderef-label-format "(ref:%s)"))
1662 ;; 1. Code without reference.
1663 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1664 (should (equal (org-export-unravel-code (org-element-at-point))
1666 ;; 2. Code with reference.
1667 (org-test-with-temp-text
1668 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1669 (should (equal (org-export-unravel-code (org-element-at-point))
1670 '("(+ 1 1)\n" (1 .
"test")))))
1671 ;; 3. Code with user-defined reference.
1672 (org-test-with-temp-text
1673 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1674 (should (equal (org-export-unravel-code (org-element-at-point))
1675 '("(+ 1 1)\n" (1 .
"test")))))
1676 ;; 4. Code references keys are relative to the current block.
1677 (org-test-with-temp-text "
1686 (should (equal (org-export-unravel-code (org-element-at-point))
1687 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1689 (ert-deftest test-org-export
/format-code-default
()
1690 "Test `org-export-format-code-default' specifications."
1691 ;; Return the empty string when code is empty.
1694 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1695 (org-export-format-code-default
1696 (org-element-map tree
'src-block
'identity info t
) info
))))
1697 ;; Number lines, two whitespace characters before the actual loc.
1700 (org-test-with-parsed-data
1701 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1702 (org-export-format-code-default
1703 (org-element-map tree
'src-block
'identity info t
) info
))))
1704 ;; Put references 6 whitespace characters after the widest line,
1705 ;; wrapped within parenthesis.
1707 (equal "123 (a)\n1 (b)\n"
1708 (let ((org-coderef-label-format "(ref:%s)"))
1709 (org-test-with-parsed-data
1710 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1711 (org-export-format-code-default
1712 (org-element-map tree
'src-block
'identity info t
) info
))))))
1718 (ert-deftest test-org-export
/activate-smart-quotes
()
1719 "Test `org-export-activate-smart-quotes' specifications."
1720 ;; Opening double quotes: standard test.
1723 '("some “paragraph")
1724 (let ((org-export-default-language "en"))
1725 (org-test-with-parsed-data "some \"paragraph"
1726 (org-element-map tree
'plain-text
1727 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1729 ;; Opening quotes: at the beginning of a paragraph.
1733 (let ((org-export-default-language "en"))
1734 (org-test-with-parsed-data "\"begin"
1735 (org-element-map tree
'plain-text
1736 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1738 ;; Opening quotes: after an object.
1742 (let ((org-export-default-language "en"))
1743 (org-test-with-parsed-data "=verb= \"begin"
1744 (org-element-map tree
'plain-text
1745 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1747 ;; Closing quotes: standard test.
1750 '("some” paragraph")
1751 (let ((org-export-default-language "en"))
1752 (org-test-with-parsed-data "some\" paragraph"
1753 (org-element-map tree
'plain-text
1754 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1756 ;; Closing quotes: at the end of a paragraph.
1760 (let ((org-export-default-language "en"))
1761 (org-test-with-parsed-data "end\""
1762 (org-element-map tree
'plain-text
1763 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1765 ;; Apostrophe: standard test.
1768 '("It shouldn’t fail")
1769 (let ((org-export-default-language "en"))
1770 (org-test-with-parsed-data "It shouldn't fail"
1771 (org-element-map tree
'plain-text
1772 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1774 ;; Apostrophe: before an object.
1778 (let ((org-export-default-language "en"))
1779 (org-test-with-parsed-data "a'=b="
1780 (org-element-map tree
'plain-text
1781 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1783 ;; Apostrophe: after an object.
1787 (let ((org-export-default-language "en"))
1788 (org-test-with-parsed-data "=code='s"
1789 (org-element-map tree
'plain-text
1790 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1792 ;; Special case: isolated quotes.
1794 (equal '("“" "”")
1795 (let ((org-export-default-language "en"))
1796 (org-test-with-parsed-data "\"$x$\""
1797 (org-element-map tree
'plain-text
1798 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1800 ;; Smart quotes in secondary strings.
1802 (equal '("“" "”")
1803 (let ((org-export-default-language "en"))
1804 (org-test-with-parsed-data "* \"$x$\""
1805 (org-element-map tree
'plain-text
1806 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1808 ;; Smart quotes in document keywords.
1810 (equal '("“" "”")
1811 (let ((org-export-default-language "en"))
1812 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1813 (org-element-map (plist-get info
:title
) 'plain-text
1814 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1816 ;; Smart quotes in parsed affiliated keywords.
1818 (equal '("“" "”" "Paragraph")
1819 (let ((org-export-default-language "en"))
1820 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1821 (org-element-map tree
'plain-text
1822 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1823 info nil nil t
))))))
1829 (ert-deftest test-org-export
/special-column
()
1830 "Test if the table's special column is properly recognized."
1831 ;; 1. First column is special if it contains only a special marking
1832 ;; characters or empty cells.
1833 (org-test-with-temp-text "
1837 (org-export-table-has-special-column-p
1839 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1840 ;; 2. If the column contains anything else, it isn't special.
1841 (org-test-with-temp-text "
1845 (org-export-table-has-special-column-p
1847 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1848 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1850 (org-test-with-temp-text "
1859 (org-export-table-has-special-column-p
1861 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1862 ;; 4. A first column with only empty cells isn't considered as
1864 (org-test-with-temp-text "
1868 (org-export-table-has-special-column-p
1870 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1872 (ert-deftest test-org-export
/table-row-is-special-p
()
1873 "Test `org-export-table-row-is-special-p' specifications."
1874 ;; 1. A row is special if it has a special marking character in the
1876 (org-test-with-parsed-data "| ! | 1 |"
1878 (org-export-table-row-is-special-p
1879 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1880 ;; 2. A row is special when its first field is "/"
1881 (org-test-with-parsed-data "
1885 (org-export-table-row-is-special-p
1886 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1887 ;; 3. A row only containing alignment cookies is also considered as
1889 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1891 (org-export-table-row-is-special-p
1892 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1893 ;; 4. Everything else isn't considered as special.
1894 (org-test-with-parsed-data "| \alpha | | c |"
1896 (org-export-table-row-is-special-p
1897 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1898 ;; 5. Table's rules are never considered as special rows.
1899 (org-test-with-parsed-data "|---+---|"
1901 (org-export-table-row-is-special-p
1902 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1904 (ert-deftest test-org-export
/has-header-p
()
1905 "Test `org-export-table-has-header-p' specifications."
1906 ;; 1. With an header.
1907 (org-test-with-parsed-data "
1912 (org-export-table-has-header-p
1913 (org-element-map tree
'table
'identity info
'first-match
)
1915 ;; 2. Without an header.
1916 (org-test-with-parsed-data "
1920 (org-export-table-has-header-p
1921 (org-element-map tree
'table
'identity info
'first-match
)
1923 ;; 3. Don't get fooled with starting and ending rules.
1924 (org-test-with-parsed-data "
1930 (org-export-table-has-header-p
1931 (org-element-map tree
'table
'identity info
'first-match
)
1934 (ert-deftest test-org-export
/table-row-group
()
1935 "Test `org-export-table-row-group' specifications."
1936 ;; 1. A rule creates a new group.
1937 (org-test-with-parsed-data "
1944 (mapcar (lambda (row) (org-export-table-row-group row info
))
1945 (org-element-map tree
'table-row
'identity
)))))
1946 ;; 2. Special rows are ignored in count.
1947 (org-test-with-parsed-data "
1954 (mapcar (lambda (row) (org-export-table-row-group row info
))
1955 (org-element-map tree
'table-row
'identity
)))))
1956 ;; 3. Double rules also are ignored in count.
1957 (org-test-with-parsed-data "
1965 (mapcar (lambda (row) (org-export-table-row-group row info
))
1966 (org-element-map tree
'table-row
'identity
))))))
1968 (ert-deftest test-org-export
/table-row-number
()
1969 "Test `org-export-table-row-number' specifications."
1970 ;; Standard test. Number is 0-indexed.
1973 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
1974 (org-element-map tree
'table-row
1975 (lambda (row) (org-export-table-row-number row info
)) info
))))
1976 ;; Number ignores separators.
1979 (org-test-with-parsed-data "
1983 (org-element-map tree
'table-row
1984 (lambda (row) (org-export-table-row-number row info
)) info
))))
1985 ;; Number ignores special rows.
1988 (org-test-with-parsed-data "
1994 (org-element-map tree
'table-row
1995 (lambda (row) (org-export-table-row-number row info
)) info
)))))
1997 (ert-deftest test-org-export
/table-cell-width
()
1998 "Test `org-export-table-cell-width' specifications."
1999 ;; 1. Width is primarily determined by width cookies. If no cookie
2000 ;; is found, cell's width is nil.
2001 (org-test-with-parsed-data "
2002 | / | <l> | <6> | <l7> |
2007 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2008 (org-element-map tree
'table-cell
'identity info
)))))
2009 ;; 2. The last width cookie has precedence.
2010 (org-test-with-parsed-data "
2017 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2018 (org-element-map tree
'table-cell
'identity info
)))))
2019 ;; 3. Valid width cookies must have a specific row.
2020 (org-test-with-parsed-data "| <6> | cell |"
2024 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2025 (org-element-map tree
'table-cell
'identity
))))))
2027 (ert-deftest test-org-export
/table-cell-alignment
()
2028 "Test `org-export-table-cell-alignment' specifications."
2029 (let ((org-table-number-fraction 0.5)
2030 (org-table-number-regexp "^[0-9]+$"))
2031 ;; 1. Alignment is primarily determined by alignment cookies.
2032 (org-test-with-temp-text "| <l> | <c> | <r> |"
2033 (let* ((tree (org-element-parse-buffer))
2034 (info `(:parse-tree
,tree
)))
2037 '(left center right
)
2038 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2039 (org-element-map tree
'table-cell
'identity
))))))
2040 ;; 2. The last alignment cookie has precedence.
2041 (org-test-with-parsed-data "
2047 '(right right right
)
2048 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2049 (org-element-map tree
'table-cell
'identity
)))))
2050 ;; 3. If there's no cookie, cell's contents determine alignment.
2051 ;; A column mostly made of cells containing numbers will align
2052 ;; its cells to the right.
2053 (org-test-with-parsed-data "
2059 '(right right right
)
2060 (mapcar (lambda (cell)
2061 (org-export-table-cell-alignment cell info
))
2062 (org-element-map tree
'table-cell
'identity
)))))
2063 ;; 4. Otherwise, they will be aligned to the left.
2064 (org-test-with-parsed-data "
2071 (mapcar (lambda (cell)
2072 (org-export-table-cell-alignment cell info
))
2073 (org-element-map tree
'table-cell
'identity
)))))))
2075 (ert-deftest test-org-export
/table-cell-borders
()
2076 "Test `org-export-table-cell-borders' specifications."
2077 ;; 1. Recognize various column groups indicators.
2078 (org-test-with-parsed-data "| / | < | > | <> |"
2081 '((right bottom top
) (left bottom top
) (right bottom top
)
2082 (right left bottom top
))
2083 (mapcar (lambda (cell)
2084 (org-export-table-cell-borders cell info
))
2085 (org-element-map tree
'table-cell
'identity
)))))
2086 ;; 2. Accept shortcuts to define column groups.
2087 (org-test-with-parsed-data "| / | < | < |"
2090 '((right bottom top
) (right left bottom top
) (left bottom top
))
2091 (mapcar (lambda (cell)
2092 (org-export-table-cell-borders cell info
))
2093 (org-element-map tree
'table-cell
'identity
)))))
2094 ;; 3. A valid column groups row must start with a "/".
2095 (org-test-with-parsed-data "
2099 (equal '((top) (top) (bottom) (bottom))
2100 (mapcar (lambda (cell)
2101 (org-export-table-cell-borders cell info
))
2102 (org-element-map tree
'table-cell
'identity
)))))
2103 ;; 4. Take table rules into consideration.
2104 (org-test-with-parsed-data "
2109 (equal '((below top
) (bottom above
))
2110 (mapcar (lambda (cell)
2111 (org-export-table-cell-borders cell info
))
2112 (org-element-map tree
'table-cell
'identity
)))))
2113 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2114 ;; (resp. `bottom' and `below') borders. Any special row is
2116 (org-test-with-parsed-data "
2122 (equal '((bottom below top above
))
2124 (mapcar (lambda (cell)
2125 (org-export-table-cell-borders cell info
))
2126 (org-element-map tree
'table-cell
'identity
)))))))
2128 (ert-deftest test-org-export
/table-dimensions
()
2129 "Test `org-export-table-dimensions' specifications."
2130 ;; 1. Standard test.
2131 (org-test-with-parsed-data "
2136 (org-export-table-dimensions
2137 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2138 ;; 2. Ignore horizontal rules and special columns.
2139 (org-test-with-parsed-data "
2146 (org-export-table-dimensions
2147 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2149 (ert-deftest test-org-export
/table-cell-address
()
2150 "Test `org-export-table-cell-address' specifications."
2151 ;; 1. Standard test: index is 0-based.
2152 (org-test-with-parsed-data "| a | b |"
2154 (equal '((0 .
0) (0 .
1))
2155 (org-element-map tree
'table-cell
2156 (lambda (cell) (org-export-table-cell-address cell info
))
2158 ;; 2. Special column isn't counted, nor are special rows.
2159 (org-test-with-parsed-data "
2164 (org-export-table-cell-address
2165 (car (last (org-element-map tree
'table-cell
'identity info
)))
2167 ;; 3. Tables rules do not count either.
2168 (org-test-with-parsed-data "
2176 (org-export-table-cell-address
2177 (car (last (org-element-map tree
'table-cell
'identity info
)))
2179 ;; 4. Return nil for special cells.
2180 (org-test-with-parsed-data "| / | a |"
2182 (org-export-table-cell-address
2183 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2186 (ert-deftest test-org-export
/get-table-cell-at
()
2187 "Test `org-export-get-table-cell-at' specifications."
2188 ;; 1. Address ignores special columns, special rows and rules.
2189 (org-test-with-parsed-data "
2196 (org-element-contents
2197 (org-export-get-table-cell-at
2199 (org-element-map tree
'table
'identity info
'first-match
)
2201 ;; 2. Return value for a non-existent address is nil.
2202 (org-test-with-parsed-data "| a |"
2204 (org-export-get-table-cell-at
2206 (org-element-map tree
'table
'identity info
'first-match
)
2208 (org-test-with-parsed-data "| / |"
2210 (org-export-get-table-cell-at
2212 (org-element-map tree
'table
'identity info
'first-match
)
2215 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2216 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2217 ;; 1. A cell at a beginning of a row always starts a column group.
2218 (org-test-with-parsed-data "| a |"
2220 (org-export-table-cell-starts-colgroup-p
2221 (org-element-map tree
'table-cell
'identity info
'first-match
)
2223 ;; 2. Special column should be ignored when determining the
2224 ;; beginning of the row.
2225 (org-test-with-parsed-data "
2229 (org-export-table-cell-starts-colgroup-p
2230 (org-element-map tree
'table-cell
'identity info
'first-match
)
2232 ;; 2. Explicit column groups.
2233 (org-test-with-parsed-data "
2239 (org-element-map tree
'table-cell
2241 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2244 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2245 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2246 ;; 1. A cell at the end of a row always ends a column group.
2247 (org-test-with-parsed-data "| a |"
2249 (org-export-table-cell-ends-colgroup-p
2250 (org-element-map tree
'table-cell
'identity info
'first-match
)
2252 ;; 2. Special column should be ignored when determining the
2253 ;; beginning of the row.
2254 (org-test-with-parsed-data "
2258 (org-export-table-cell-ends-colgroup-p
2259 (org-element-map tree
'table-cell
'identity info
'first-match
)
2261 ;; 3. Explicit column groups.
2262 (org-test-with-parsed-data "
2268 (org-element-map tree
'table-cell
2270 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2273 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2274 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2275 ;; 1. A row at the beginning of a table always starts a row group.
2276 ;; So does a row following a table rule.
2277 (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
))
2288 ;; 2. Special rows should be ignored when determining the beginning
2290 (org-test-with-parsed-data "
2299 (org-element-map tree
'table-row
2301 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2304 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2305 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2306 ;; 1. A row at the end of a table always ends a row group. So does
2307 ;; a row preceding a table rule.
2308 (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
))
2319 ;; 2. Special rows should be ignored when determining the beginning
2321 (org-test-with-parsed-data "
2330 (org-element-map tree
'table-row
2332 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2335 (ert-deftest test-org-export
/table-row-starts-header-p
()
2336 "Test `org-export-table-row-starts-header-p' specifications."
2337 ;; 1. Only the row starting the first row group starts the table
2339 (org-test-with-parsed-data "
2347 (org-element-map tree
'table-row
2349 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2351 ;; 2. A row cannot start an header if there's no header in the
2353 (org-test-with-parsed-data "
2357 (org-export-table-row-starts-header-p
2358 (org-element-map tree
'table-row
'identity info
'first-match
)
2361 (ert-deftest test-org-export
/table-row-ends-header-p
()
2362 "Test `org-export-table-row-ends-header-p' specifications."
2363 ;; 1. Only the row starting the first row group starts the table
2365 (org-test-with-parsed-data "
2373 (org-element-map tree
'table-row
2375 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2377 ;; 2. A row cannot start an header if there's no header in the
2379 (org-test-with-parsed-data "
2383 (org-export-table-row-ends-header-p
2384 (org-element-map tree
'table-row
'identity info
'first-match
)
2391 (ert-deftest test-org-export
/inner-template
()
2392 "Test `inner-template' translator specifications."
2395 (let (org-export-registered-backends)
2396 (org-export-define-backend 'test
2397 '((inner-template .
(lambda (contents info
) "Success!"))
2398 (headline .
(lambda (h c i
) "Headline"))))
2399 (org-test-with-temp-text "* Headline"
2400 (org-export-as 'test
)))))
2401 ;; Inner template is applied even in a "body-only" export.
2404 (let (org-export-registered-backends)
2405 (org-export-define-backend 'test
2406 '((inner-template .
(lambda (contents info
) "Success!"))
2407 (headline .
(lambda (h c i
) "Headline"))))
2408 (org-test-with-temp-text "* Headline"
2409 (org-export-as 'test nil nil
'body-only
))))))
2411 (ert-deftest test-org-export
/template
()
2412 "Test `template' translator specifications."
2415 (let (org-export-registered-backends)
2416 (org-export-define-backend 'test
2417 '((template .
(lambda (contents info
) "Success!"))
2418 (headline .
(lambda (h c i
) "Headline"))))
2419 (org-test-with-temp-text "* Headline"
2420 (org-export-as 'test
)))))
2421 ;; Template is not applied in a "body-only" export.
2424 (let (org-export-registered-backends)
2425 (org-export-define-backend 'test
2426 '((template .
(lambda (contents info
) "Success!"))
2427 (headline .
(lambda (h c i
) "Headline"))))
2428 (org-test-with-temp-text "* Headline"
2429 (org-export-as 'test nil nil
'body-only
))))))
2435 (ert-deftest test-org-export
/get-next-element
()
2436 "Test `org-export-get-next-element' specifications."
2440 (org-test-with-parsed-data "* Headline\n*a* b"
2441 (org-export-get-next-element
2442 (org-element-map tree
'bold
'identity info t
) info
))))
2443 ;; Return nil when no previous element.
2445 (org-test-with-parsed-data "* Headline\na *b*"
2446 (org-export-get-next-element
2447 (org-element-map tree
'bold
'identity info t
) info
)))
2448 ;; Non-exportable elements are ignored.
2450 (let ((org-export-with-timestamps nil
))
2451 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2452 (org-export-get-next-element
2453 (org-element-map tree
'entity
'identity info t
) info
))))
2454 ;; Find next element in secondary strings.
2457 (org-test-with-parsed-data "* a =verb="
2459 (org-export-get-next-element
2460 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2461 ;; Find next element in document keywords.
2464 (org-test-with-parsed-data "#+TITLE: a =verb="
2466 (org-export-get-next-element
2468 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2469 ;; Find next element in parsed affiliated keywords.
2472 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2474 (org-export-get-next-element
2475 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2476 ;; With optional argument N, return a list containing all the
2477 ;; following elements.
2480 '(bold code underline
)
2481 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2483 (org-export-get-next-element
2484 (org-element-map tree
'italic
'identity info t
) info t
)))))
2485 ;; When N is a positive integer, return a list containing up to
2486 ;; N following elements.
2490 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2492 (org-export-get-next-element
2493 (org-element-map tree
'italic
'identity info t
) info
2))))))
2495 (ert-deftest test-org-export
/get-previous-element
()
2496 "Test `org-export-get-previous-element' specifications."
2500 (org-test-with-parsed-data "* Headline\na *b*"
2501 (org-export-get-previous-element
2502 (org-element-map tree
'bold
'identity info t
) info
))))
2503 ;; Return nil when no previous element.
2505 (org-test-with-parsed-data "* Headline\n*a* b"
2506 (org-export-get-previous-element
2507 (org-element-map tree
'bold
'identity info t
) info
)))
2508 ;; Non-exportable elements are ignored.
2510 (let ((org-export-with-timestamps nil
))
2511 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2512 (org-export-get-previous-element
2513 (org-element-map tree
'entity
'identity info t
) info
))))
2514 ;; Find previous element in secondary strings.
2517 (org-test-with-parsed-data "* =verb= a"
2519 (org-export-get-previous-element
2520 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2521 ;; Find previous element in document keywords.
2524 (org-test-with-parsed-data "#+TITLE: =verb= a"
2526 (org-export-get-previous-element
2528 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2529 ;; Find previous element in parsed affiliated keywords.
2532 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2534 (org-export-get-previous-element
2535 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2536 ;; With optional argument N, return a list containing up to
2537 ;; N previous elements.
2539 (equal '(underline italic bold
)
2540 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2542 (org-export-get-previous-element
2543 (org-element-map tree
'code
'identity info t
) info t
)))))
2544 ;; When N is a positive integer, return a list containing up to
2545 ;; N previous elements.
2547 (equal '(italic bold
)
2548 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2550 (org-export-get-previous-element
2551 (org-element-map tree
'code
'identity info t
) info
2))))))
2555 ;;; test-org-export.el end here