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-plannings t
))
387 "CLOSED: [2012-04-29 sun. 10:45]\n"))
389 (equal (org-export-as 'test nil nil nil
'(:with-plannings 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 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
400 (org-test-with-backend test
402 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
403 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
405 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
407 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
408 "<2012-04-29 sun. 10:45>\n"))
410 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
411 "[2012-04-29 sun. 10:45]\n")))))
413 (ert-deftest test-org-export
/comment-tree
()
414 "Test if export process ignores commented trees."
415 (let ((org-comment-string "COMMENT"))
416 (org-test-with-temp-text "* COMMENT Head1"
417 (org-test-with-backend test
418 (should (equal (org-export-as 'test
) ""))))))
420 (ert-deftest test-org-export
/export-scope
()
421 "Test all export scopes."
422 (org-test-with-temp-text "
427 (org-test-with-backend test
430 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
432 (goto-char (point-min))
435 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
437 (goto-char (point-min))
439 (transient-mark-mode 1)
440 (push-mark (point) t t
)
441 (goto-char (point-at-eol))
442 (should (equal (org-export-as 'test
) "text\n"))))
443 ;; Subtree with a code block calling another block outside.
446 (org-test-with-temp-text "
448 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
453 #+BEGIN_SRC emacs-lisp
456 (org-test-with-backend test
458 (org-export-as 'test
'subtree
)))))
460 (org-test-with-temp-text "Text"
461 (org-test-with-backend test
463 (cdr (assq 'test org-export-registered-backends
))
465 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
466 (org-export-backend-translate-table 'test
)))
467 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
468 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
470 (ert-deftest test-org-export
/output-file-name
()
471 "Test `org-export-output-file-name' specifications."
472 ;; Export from a file: name is built from original file name.
474 (org-test-with-temp-text-in-file "Test"
475 (equal (concat (file-name-as-directory ".")
476 (file-name-nondirectory
477 (file-name-sans-extension (buffer-file-name))))
478 (file-name-sans-extension (org-export-output-file-name ".ext")))))
479 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
481 (org-test-with-temp-text-in-file
482 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
483 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
484 ;; From a buffer not associated to a file, too.
486 (org-test-with-temp-text
487 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
488 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
489 ;; When provided name is absolute, preserve it.
491 (org-test-with-temp-text
492 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
493 (expand-file-name "test"))
494 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
495 ;; When PUB-DIR argument is provided, use it.
497 (org-test-with-temp-text-in-file "Test"
498 (equal (file-name-directory
499 (org-export-output-file-name ".ext" nil
"dir/"))
501 ;; When returned name would overwrite original file, add EXTENSION
504 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
505 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
507 (ert-deftest test-org-export
/expand-include
()
508 "Test file inclusion in an Org buffer."
509 ;; Error when file isn't specified.
511 (org-test-with-temp-text "#+INCLUDE: dummy.org"
512 (org-export-expand-include-keyword)))
513 ;; Full insertion with recursive inclusion.
514 (org-test-with-temp-text
515 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
516 (org-export-expand-include-keyword)
517 (should (equal (buffer-string)
518 "Small Org file with an include keyword.
520 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
526 ;; Localized insertion.
527 (org-test-with-temp-text
528 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
530 (org-export-expand-include-keyword)
531 (should (equal (buffer-string)
532 "Small Org file with an include keyword.\n")))
533 ;; Insertion with constraints on headlines level.
536 "* Top heading\n** Heading\nbody\n"
537 (org-test-with-temp-text
539 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
541 (org-export-expand-include-keyword)
545 "* Top heading\n* Heading\nbody\n"
546 (org-test-with-temp-text
548 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
550 (org-export-expand-include-keyword)
552 ;; Inclusion within an example block.
553 (org-test-with-temp-text
554 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
556 (org-export-expand-include-keyword)
560 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
561 ;; Inclusion within a src-block.
562 (org-test-with-temp-text
564 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
566 (org-export-expand-include-keyword)
567 (should (equal (buffer-string)
568 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
570 (ert-deftest test-org-export
/expand-macro
()
571 "Test macro expansion in an Org buffer."
572 ;; Standard macro expansion.
574 (equal "#+MACRO: macro1 value\nvalue\n"
575 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
576 (org-test-with-backend test
(org-export-as 'test
)))))
577 ;; Expand specific macros.
579 (equal "me 2012-03-29 me@here Title\n"
580 (org-test-with-temp-text
586 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
587 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
588 (substring output
(string-match ".*\n\\'" output
))))))
589 ;; Expand specific macros when property contained a regular macro
593 (org-test-with-temp-text "
594 #+MACRO: macro1 value
595 #+TITLE: {{{macro1}}}
597 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
598 (substring output
(string-match ".*\n\\'" output
))))))
599 ;; Expand macros with templates in included files.
602 (org-test-with-temp-text
603 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
604 {{{included-macro}}}" org-test-dir
)
605 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
606 (substring output
(string-match ".*\n\\'" output
)))))))
608 (ert-deftest test-org-export
/user-ignore-list
()
609 "Test if `:ignore-list' accepts user input."
610 (org-test-with-backend test
611 (flet ((skip-note-head
613 ;; Ignore headlines with the word "note" in their title.
614 (org-element-map data
'headline
616 (when (string-match "\\<note\\>"
617 (org-element-property :raw-value headline
))
618 (org-export-ignore-element headline info
)))
621 ;; Install function in parse tree filters.
622 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
623 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
624 (should (equal (org-export-as 'test
) "* Head1\n")))))))
626 (ert-deftest test-org-export
/before-processing-hook
()
627 "Test `org-export-before-processing-hook'."
630 "#+MACRO: mac val\nTest\n"
631 (org-test-with-backend test
632 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
633 (let ((org-export-before-processing-hook
635 (while (re-search-forward "{{{" nil t
)
636 (let ((object (org-element-context)))
637 (when (eq (org-element-type object
) 'macro
)
639 (org-element-property :begin object
)
640 (org-element-property :end object
)))))))))
641 (org-export-as 'test
)))))))
643 (ert-deftest test-org-export
/before-parsing-hook
()
644 "Test `org-export-before-parsing-hook'."
646 (equal "Body 1\nBody 2\n"
647 (org-test-with-backend test
648 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
649 (let ((org-export-before-parsing-hook
651 (goto-char (point-min))
652 (while (re-search-forward org-outline-regexp-bol nil t
)
654 (point-at-bol) (progn (forward-line) (point))))))))
655 (org-export-as 'test
)))))))
659 ;;; Affiliated Keywords
661 (ert-deftest test-org-export
/read-attribute
()
662 "Test `org-export-read-attribute' specifications."
666 (org-export-read-attribute
668 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
669 (org-element-at-point)))
671 ;; Return nil on empty attribute.
673 (org-export-read-attribute
675 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
676 ;; Return nil on "nil" string.
678 (equal '(:a nil
:b nil
)
679 (org-export-read-attribute
681 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
682 (org-element-at-point)))))
683 ;; Return nil on empty string.
685 (equal '(:a nil
:b nil
)
686 (org-export-read-attribute
688 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
689 (org-element-at-point)))))
690 ;; Ignore text before first property.
693 (org-export-read-attribute
695 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
696 (org-element-at-point))))))
698 (ert-deftest test-org-export
/get-caption
()
699 "Test `org-export-get-caption' specifications."
700 ;; Without optional argument, return long caption
704 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
705 (org-export-get-caption (org-element-at-point)))))
706 ;; With optional argument, return short caption.
710 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
711 (org-export-get-caption (org-element-at-point) t
))))
712 ;; Multiple lines are separated by white spaces.
716 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
717 (org-export-get-caption (org-element-at-point))))))
723 (ert-deftest test-org-export
/define-backend
()
724 "Test back-end definition and accessors."
727 (equal '((headline . my-headline-test
))
728 (let (org-export-registered-backends)
729 (org-export-define-backend 'test
'((headline . my-headline-test
)))
730 (org-export-backend-translate-table 'test
))))
733 (equal '((:filter-headline . my-filter
))
734 (let (org-export-registered-backends)
735 (org-export-define-backend 'test
736 '((headline . my-headline-test
))
737 :filters-alist
'((:filter-headline . my-filter
)))
738 (org-export-backend-filters 'test
))))
741 (equal '((:prop value
))
742 (let (org-export-registered-backends)
743 (org-export-define-backend 'test
744 '((headline . my-headline-test
))
745 :options-alist
'((:prop value
)))
746 (org-export-backend-options 'test
))))
749 (equal '(?k
"Test Export" test
)
750 (let (org-export-registered-backends)
751 (org-export-define-backend 'test
752 '((headline . my-headline-test
))
753 :menu-entry
'(?k
"Test Export" test
))
754 (org-export-backend-menu 'test
))))
757 (equal '(("TEST" . org-element-export-block-parser
))
758 (let (org-export-registered-backends org-element-block-name-alist
)
759 (org-export-define-backend 'test
760 '((headline . my-headline-test
))
761 :export-block
'("test"))
762 org-element-block-name-alist
))))
764 (ert-deftest test-org-export
/define-derived-backend
()
765 "Test `org-export-define-derived-backend' specifications."
766 ;; Error when parent back-end is not defined.
768 (let (org-export-registered-backends)
769 (org-export-define-derived-backend 'test
'parent
)))
770 ;; Append translation table to parent's.
772 (equal '((:headline . test
) (:headline . parent
))
773 (let (org-export-registered-backends)
774 (org-export-define-backend 'parent
'((:headline . parent
)))
775 (org-export-define-derived-backend 'test
'parent
776 :translate-alist
'((:headline . test
)))
777 (org-export-backend-translate-table 'test
))))
778 ;; Options defined in the new back have priority over those defined
782 (let (org-export-registered-backends)
783 (org-export-define-backend 'parent
784 '((:headline . parent
))
785 :options-alist
'((:a nil nil
'parent
)))
786 (org-export-define-derived-backend 'test
'parent
787 :options-alist
'((:a nil nil
'test
)))
788 (plist-get (org-export--get-global-options 'test
) :a
)))))
790 (ert-deftest test-org-export
/derived-backend-p
()
791 "Test `org-export-derived-backend-p' specifications."
792 ;; Non-nil with direct match.
794 (let (org-export-registered-backends)
795 (org-export-define-backend 'test
'((headline . test
)))
796 (org-export-derived-backend-p 'test
'test
)))
798 (let (org-export-registered-backends)
799 (org-export-define-backend 'test
'((headline . test
)))
800 (org-export-define-derived-backend 'test2
'test
)
801 (org-export-derived-backend-p 'test2
'test2
)))
802 ;; Non-nil with a direct parent.
804 (let (org-export-registered-backends)
805 (org-export-define-backend 'test
'((headline . test
)))
806 (org-export-define-derived-backend 'test2
'test
)
807 (org-export-derived-backend-p 'test2
'test
)))
808 ;; Non-nil with an indirect parent.
810 (let (org-export-registered-backends)
811 (org-export-define-backend 'test
'((headline . test
)))
812 (org-export-define-derived-backend 'test2
'test
)
813 (org-export-define-derived-backend 'test3
'test2
)
814 (org-export-derived-backend-p 'test3
'test
)))
817 (let (org-export-registered-backends)
818 (org-export-define-backend 'test
'((headline . test
)))
819 (org-export-define-backend 'test2
'((headline . test2
)))
820 (org-export-derived-backend-p 'test2
'test
)))
822 (let (org-export-registered-backends)
823 (org-export-define-backend 'test
'((headline . test
)))
824 (org-export-define-backend 'test2
'((headline . test2
)))
825 (org-export-define-derived-backend 'test3
'test2
)
826 (org-export-derived-backend-p 'test3
'test
))))
828 (ert-deftest test-org-export
/with-backend
()
829 "Test `org-export-with-backend' definition."
830 ;; Error when calling an undefined back-end
832 (let (org-export-registered-backends)
833 (org-export-with-backend 'test
"Test")))
834 ;; Error when called back-end doesn't have an appropriate
837 (let (org-export-registered-backends)
838 (org-export-define-backend 'test
((headline . ignore
)))
839 (org-export-with-backend 'test
"Test")))
840 ;; Otherwise, export using correct transcoder
843 (let (org-export-registered-backends)
844 (org-export-define-backend 'test
845 '((plain-text .
(lambda (text contents info
) "Failure"))))
846 (org-export-define-backend 'test2
847 '((plain-text .
(lambda (text contents info
) "Success"))))
848 (org-export-with-backend 'test2
"Test")))))
850 (ert-deftest test-org-export
/data-with-translations
()
851 "Test `org-export-data-with-translations' specifications."
855 (org-export-data-with-translations
857 '((plain-text .
(lambda (text info
) "Success"))
858 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
859 '(:with-emphasize t
)))))
861 (ert-deftest test-org-export
/data-with-backend
()
862 "Test `org-export-data-with-backend' specifications."
863 ;; Error when calling an undefined back-end.
865 (let (org-export-registered-backends)
866 (org-export-data-with-backend 'test
"Test" nil
)))
867 ;; Otherwise, export data recursively, using correct back-end.
871 (let (org-export-registered-backends)
872 (org-export-define-backend 'test
873 '((plain-text .
(lambda (text info
) "Success"))
874 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
875 (org-export-data-with-backend
876 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
882 (ert-deftest test-org-export
/export-snippet
()
883 "Test export snippets transcoding."
884 (org-test-with-temp-text "@@test:A@@@@t:B@@"
885 (org-test-with-backend test
887 (cdr (assq 'test org-export-registered-backends
))
889 (cons (cons 'export-snippet
890 (lambda (snippet contents info
)
891 (when (eq (org-export-snippet-backend snippet
) 'test
)
892 (org-element-property :value snippet
))))
893 (org-export-backend-translate-table 'test
)))
894 (let ((org-export-snippet-translation-alist nil
))
895 (should (equal (org-export-as 'test
) "A\n")))
896 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
897 (should (equal (org-export-as 'test
) "AB\n")))))
898 ;; Ignored export snippets do not remove any blank.
901 (org-test-with-parsed-data "begin @@test:A@@ end"
902 (org-export-data-with-translations
904 '((paragraph .
(lambda (paragraph contents info
) contents
))
905 (section .
(lambda (section contents info
) contents
)))
912 (ert-deftest test-org-export
/footnotes
()
913 "Test footnotes specifications."
914 (let ((org-footnote-section nil
)
915 (org-export-with-footnotes t
))
916 ;; 1. Read every type of footnote.
919 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
920 (org-test-with-parsed-data
921 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
922 (org-element-map tree
'footnote-reference
924 (let ((def (org-export-get-footnote-definition ref info
)))
925 (cons (org-export-get-footnote-number ref info
)
926 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
927 (car (org-element-contents
928 (car (org-element-contents def
))))))))
930 ;; 2. Test nested footnotes order.
931 (org-test-with-parsed-data
932 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
935 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
936 (org-element-map tree
'footnote-reference
938 (when (org-export-footnote-first-reference-p ref info
)
939 (cons (org-export-get-footnote-number ref info
)
940 (org-element-property :label ref
))))
942 ;; 3. Test nested footnote in invisible definitions.
943 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
945 (narrow-to-region (point) (point-at-eol))
946 (let* ((tree (org-element-parse-buffer))
947 (info (org-combine-plists
949 (org-export-collect-tree-properties
950 tree
(org-export-get-environment)))))
951 ;; Both footnotes should be seen.
953 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
954 ;; 4. Test footnotes definitions collection.
955 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
957 \[fn:2] B [fn:3] [fn::D].
960 (should (= (length (org-export-collect-footnote-definitions tree info
))
962 ;; 5. Test export of footnotes defined outside parsing scope.
963 (org-test-with-temp-text "[fn:1] Out of scope
966 (org-test-with-backend test
968 (cdr (assq 'test org-export-registered-backends
))
970 (cons (cons 'footnote-reference
971 (lambda (fn contents info
)
972 (org-element-interpret-data
973 (org-export-get-footnote-definition fn info
))))
974 (org-export-backend-translate-table 'test
)))
976 (should (equal "ParagraphOut of scope\n"
977 (org-export-as 'test
'subtree
)))))
978 ;; 6. Footnotes without a definition should be provided a fallback
981 (org-test-with-parsed-data "[fn:1]"
982 (org-export-get-footnote-definition
983 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
984 ;; 7. Footnote section should be ignored in TOC and in headlines
987 (= 1 (let ((org-footnote-section "Footnotes"))
988 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
989 (org-export-collect-headlines info
))))))
992 (let ((org-footnote-section "Footnotes"))
993 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
994 (org-element-map tree
'headline
996 (when (equal (org-element-property :raw-value hl
) "H2")
997 (org-export-get-headline-number hl info
)))
1002 ;;; Headlines and Inlinetasks
1004 (ert-deftest test-org-export
/get-relative-level
()
1005 "Test `org-export-get-relative-level' specifications."
1009 (let ((org-odd-levels-only nil
))
1010 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1011 (org-element-map tree
'headline
1012 (lambda (h) (org-export-get-relative-level h info
))
1017 (let ((org-odd-levels-only nil
))
1018 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1019 (org-element-map tree
'headline
1020 (lambda (h) (org-export-get-relative-level h info
))
1023 (ert-deftest test-org-export
/low-level-p
()
1024 "Test `org-export-low-level-p' specifications."
1028 (let ((org-odd-levels-only nil
))
1029 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1030 (org-element-map tree
'headline
1031 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1032 (plist-put info
:headline-levels
1)))))))
1034 (ert-deftest test-org-export
/get-headline-number
()
1035 "Test `org-export-get-headline-number' specifications."
1040 (let ((org-odd-levels-only nil
))
1041 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1042 (org-element-map tree
'headline
1043 (lambda (h) (org-export-get-headline-number h info
))
1045 ;; Missing levels are replaced with 0.
1049 (let ((org-odd-levels-only nil
))
1050 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1051 (org-element-map tree
'headline
1052 (lambda (h) (org-export-get-headline-number h info
))
1055 (ert-deftest test-org-export
/numbered-headline-p
()
1056 "Test `org-export-numbered-headline-p' specifications."
1057 ;; If `:section-numbers' is nil, never number headlines.
1059 (org-test-with-parsed-data "* Headline"
1060 (org-element-map tree
'headline
1061 (lambda (h) (org-export-numbered-headline-p h info
))
1062 (plist-put info
:section-numbers nil
))))
1063 ;; If `:section-numbers' is a number, only number headlines with
1064 ;; a level greater that it.
1068 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1069 (org-element-map tree
'headline
1070 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1071 (plist-put info
:section-numbers
1)))))
1072 ;; Otherwise, headlines are always numbered.
1074 (org-test-with-parsed-data "* Headline"
1075 (org-element-map tree
'headline
1076 (lambda (h) (org-export-numbered-headline-p h info
))
1077 (plist-put info
:section-numbers t
)))))
1079 (ert-deftest test-org-export
/number-to-roman
()
1080 "Test `org-export-number-to-roman' specifications."
1081 ;; If number is negative, return it as a string.
1082 (should (equal (org-export-number-to-roman -
1) "-1"))
1083 ;; Otherwise, return it as a roman number.
1084 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1086 (ert-deftest test-org-export
/get-optional-title
()
1087 "Test `org-export-get-alt-title' specifications."
1088 ;; If ALT_TITLE property is defined, use it.
1091 (org-test-with-parsed-data
1092 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1093 (org-export-get-alt-title
1094 (org-element-map tree
'headline
'identity info t
)
1096 ;; Otherwise, fall-back to regular title.
1098 (equal '("Headline")
1099 (org-test-with-parsed-data "* Headline"
1100 (org-export-get-alt-title
1101 (org-element-map tree
'headline
'identity info t
)
1104 (ert-deftest test-org-export
/get-tags
()
1105 "Test `org-export-get-tags' specifications."
1106 (let ((org-export-exclude-tags '("noexport"))
1107 (org-export-select-tags '("export")))
1108 ;; Standard test: tags which are not a select tag, an exclude tag,
1109 ;; or specified as optional argument shouldn't be ignored.
1111 (org-test-with-parsed-data "* Headline :tag:"
1112 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1114 ;; Exclude tags are removed.
1116 (org-test-with-parsed-data "* Headline :noexport:"
1117 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1119 ;; Select tags are removed.
1121 (org-test-with-parsed-data "* Headline :export:"
1122 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1127 (org-test-with-parsed-data "* Headline :tag:export:"
1128 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1130 ;; Tags provided in the optional argument are also ignored.
1132 (org-test-with-parsed-data "* Headline :ignore:"
1133 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1135 ;; Allow tag inheritance.
1139 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1140 (org-element-map tree
'headline
1141 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1142 ;; Tag inheritance checks FILETAGS keywords.
1146 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1147 (org-element-map tree
'headline
1148 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1150 (ert-deftest test-org-export
/get-node-property
()
1151 "Test`org-export-get-node-property' specifications."
1155 (org-test-with-parsed-data "* Headline
1159 (org-export-get-node-property
1160 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1161 ;; Test inheritance.
1164 (org-test-with-parsed-data "* Parent
1170 (org-export-get-node-property
1171 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1172 ;; Cannot return a value before the first headline.
1174 (org-test-with-parsed-data "Paragraph
1179 (org-export-get-node-property
1180 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1182 (ert-deftest test-org-export
/get-category
()
1183 "Test `org-export-get-category' specifications."
1187 (org-test-with-parsed-data "* Headline
1191 (org-export-get-category
1192 (org-element-map tree
'headline
'identity nil t
) info
))))
1193 ;; Test inheritance from a parent headline.
1195 (equal '("value" "value")
1196 (org-test-with-parsed-data "* Headline1
1201 (org-element-map tree
'headline
1202 (lambda (hl) (org-export-get-category hl info
)) info
))))
1203 ;; Test inheritance from #+CATEGORY keyword
1206 (org-test-with-parsed-data "#+CATEGORY: value
1208 (org-export-get-category
1209 (org-element-map tree
'headline
'identity nil t
) info
))))
1210 ;; Test inheritance from file name.
1213 (org-test-with-parsed-data "* Headline"
1214 (let ((info (plist-put info
:input-file
"~/test.org")))
1215 (org-export-get-category
1216 (org-element-map tree
'headline
'identity nil t
) info
)))))
1220 (org-test-with-parsed-data "* Headline"
1221 (org-export-get-category
1222 (org-element-map tree
'headline
'identity nil t
) info
)))))
1224 (ert-deftest test-org-export
/first-sibling-p
()
1225 "Test `org-export-first-sibling-p' specifications."
1230 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1231 (org-element-map tree
'headline
1232 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1234 ;; Ignore headlines not exported.
1238 (let ((org-export-exclude-tags '("ignore")))
1239 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1240 (org-element-map tree
'headline
1241 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1244 (ert-deftest test-org-export
/last-sibling-p
()
1245 "Test `org-export-last-sibling-p' specifications."
1250 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1251 (org-element-map tree
'headline
1252 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1254 ;; Ignore headlines not exported.
1258 (let ((org-export-exclude-tags '("ignore")))
1259 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1260 (org-element-map tree
'headline
1261 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1264 (ert-deftest test-org-export
/handle-inlinetasks
()
1265 "Test inlinetask export."
1266 ;; Inlinetask with an exclude tag.
1267 (when (featurep 'org-inlinetask
)
1271 (let ((org-inlinetask-min-level 3))
1272 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1273 (org-test-with-backend test
1274 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp"))))))))
1275 ;; Inlinetask with an include tag.
1278 "* H2\n*** Inline :exp:\n"
1279 (let ((org-inlinetask-min-level 3)
1280 (org-tags-column 0))
1281 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1282 (org-test-with-backend test
1283 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
1284 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1287 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1288 (org-inlinetask-min-level 3))
1289 (org-test-with-temp-text "*** TODO Inline"
1290 (org-test-with-backend test
1291 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))))
1297 (ert-deftest test-org-export
/get-coderef-format
()
1298 "Test `org-export-get-coderef-format' specifications."
1299 ;; A link without description returns "%s"
1300 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1302 ;; Return "%s" when path is matched within description.
1303 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1305 ;; Otherwise return description.
1306 (should (equal (org-export-get-coderef-format "path" "desc")
1309 (ert-deftest test-org-export
/inline-image-p
()
1310 "Test `org-export-inline-image-p' specifications."
1312 (org-export-inline-image-p
1313 (org-test-with-temp-text "[[#id]]"
1314 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1315 '(("custom-id" .
"id")))))
1317 (ert-deftest test-org-export
/fuzzy-link
()
1318 "Test fuzzy links specifications."
1319 ;; 1. Links to invisible (keyword) targets should be ignored.
1320 (org-test-with-parsed-data
1321 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1323 (org-element-map tree
'link
1325 (org-export-get-ordinal
1326 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1327 ;; 2. Link to an headline should return headline's number.
1328 (org-test-with-parsed-data
1329 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1331 ;; Note: Headline's number is in fact a list of numbers.
1333 (org-element-map tree
'link
1335 (org-export-get-ordinal
1336 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1337 ;; 3. Link to a target in an item should return item's number.
1338 (org-test-with-parsed-data
1339 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1341 ;; Note: Item's number is in fact a list of numbers.
1343 (org-element-map tree
'link
1345 (org-export-get-ordinal
1346 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1347 ;; 4. Link to a target in a footnote should return footnote's
1349 (org-test-with-parsed-data "
1350 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1353 (org-element-map tree
'link
1355 (org-export-get-ordinal
1356 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1357 ;; 5. Link to a named element should return sequence number of that
1359 (org-test-with-parsed-data
1360 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1363 (org-element-map tree
'link
1365 (org-export-get-ordinal
1366 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1367 ;; 6. Link to a target not within an item, a table, a footnote
1368 ;; reference or definition should return section number.
1369 (org-test-with-parsed-data
1370 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1373 (org-element-map tree
'link
1375 (org-export-get-ordinal
1376 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1377 ;; 7. Space are not significant when matching a fuzzy link.
1379 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1380 (org-element-map tree
'link
1381 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1383 ;; 8. Statistics cookies are ignored for headline match.
1385 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1386 (org-element-map tree
'link
1387 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1390 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1391 (org-element-map tree
'link
1392 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1395 (ert-deftest test-org-export
/resolve-coderef
()
1396 "Test `org-export-resolve-coderef' specifications."
1397 (let ((org-coderef-label-format "(ref:%s)"))
1398 ;; 1. A link to a "-n -k -r" block returns line number.
1399 (org-test-with-parsed-data
1400 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1401 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1402 (org-test-with-parsed-data
1403 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1404 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1405 ;; 2. A link to a "-n -r" block returns line number.
1406 (org-test-with-parsed-data
1407 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1408 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1409 (org-test-with-parsed-data
1410 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1411 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1412 ;; 3. A link to a "-n" block returns coderef.
1413 (org-test-with-parsed-data
1414 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1415 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1416 (org-test-with-parsed-data
1417 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1418 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1419 ;; 4. A link to a "-r" block returns line number.
1420 (org-test-with-parsed-data
1421 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1422 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1423 (org-test-with-parsed-data
1424 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1425 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1426 ;; 5. A link to a block without a switch returns coderef.
1427 (org-test-with-parsed-data
1428 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1429 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1430 (org-test-with-parsed-data
1431 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1432 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1433 ;; 6. Correctly handle continued line numbers. A "+n" switch
1434 ;; should resume numbering from previous block with numbered
1435 ;; lines, ignoring blocks not numbering lines in the process.
1436 ;; A "-n" switch resets count.
1437 (org-test-with-parsed-data "
1442 #+BEGIN_SRC emacs-lisp
1446 #+BEGIN_SRC emacs-lisp +n -r
1447 \(+ 1 1) (ref:addition)
1450 #+BEGIN_EXAMPLE -n -r
1451 Another text. (ref:text)
1453 (should (= (org-export-resolve-coderef "addition" info
) 2))
1454 (should (= (org-export-resolve-coderef "text" info
) 1)))
1455 ;; 7. Recognize coderef with user-specified syntax.
1456 (org-test-with-parsed-data
1457 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1458 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1460 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1461 "Test `org-export-resolve-fuzzy-link' specifications."
1462 ;; 1. Match target objects.
1463 (org-test-with-parsed-data "<<target>> [[target]]"
1465 (org-export-resolve-fuzzy-link
1466 (org-element-map tree
'link
'identity info t
) info
)))
1467 ;; 2. Match target elements.
1468 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1470 (org-export-resolve-fuzzy-link
1471 (org-element-map tree
'link
'identity info t
) info
)))
1472 ;; 3. Match named elements.
1473 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1475 (org-export-resolve-fuzzy-link
1476 (org-element-map tree
'link
'identity info t
) info
)))
1477 ;; 4. Match exact headline's name.
1478 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1480 (org-export-resolve-fuzzy-link
1481 (org-element-map tree
'link
'identity info t
) info
)))
1482 ;; 5. Targets objects have priority over named elements and headline
1484 (org-test-with-parsed-data
1485 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1489 (org-export-resolve-fuzzy-link
1490 (org-element-map tree
'link
'identity info t
) info
)))))
1491 ;; 6. Named elements have priority over headline titles.
1492 (org-test-with-parsed-data
1493 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1497 (org-export-resolve-fuzzy-link
1498 (org-element-map tree
'link
'identity info t
) info
)))))
1499 ;; 7. If link's path starts with a "*", only match headline titles,
1501 (org-test-with-parsed-data
1502 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1506 (org-export-resolve-fuzzy-link
1507 (org-element-map tree
'link
'identity info t
) info
)))))
1508 ;; 8. Return nil if no match.
1509 (org-test-with-parsed-data "[[target]]"
1511 (org-export-resolve-fuzzy-link
1512 (org-element-map tree
'link
'identity info t
) info
))))
1514 (ert-deftest test-org-export
/resolve-id-link
()
1515 "Test `org-export-resolve-id-link' specifications."
1516 ;; 1. Regular test for custom-id link.
1517 (org-test-with-parsed-data "* Headline1
1524 (org-export-resolve-id-link
1525 (org-element-map tree
'link
'identity info t
) info
)))
1526 ;; 2. Failing test for custom-id link.
1527 (org-test-with-parsed-data "* Headline1
1534 (org-export-resolve-id-link
1535 (org-element-map tree
'link
'identity info t
) info
)))
1536 ;; 3. Test for internal id target.
1537 (org-test-with-parsed-data "* Headline1
1544 (org-export-resolve-id-link
1545 (org-element-map tree
'link
'identity info t
) info
)))
1546 ;; 4. Test for external id target.
1547 (org-test-with-parsed-data "[[id:aaaa]]"
1549 (org-export-resolve-id-link
1550 (org-element-map tree
'link
'identity info t
)
1551 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1553 (ert-deftest test-org-export
/resolve-radio-link
()
1554 "Test `org-export-resolve-radio-link' specifications."
1557 (org-test-with-temp-text "<<<radio>>> radio"
1558 (org-update-radio-target-regexp)
1559 (let* ((tree (org-element-parse-buffer))
1560 (info `(:parse-tree
,tree
)))
1561 (org-export-resolve-radio-link
1562 (org-element-map tree
'link
'identity info t
)
1564 ;; Radio targets are case-insensitive.
1566 (org-test-with-temp-text "<<<RADIO>>> radio"
1567 (org-update-radio-target-regexp)
1568 (let* ((tree (org-element-parse-buffer))
1569 (info `(:parse-tree
,tree
)))
1570 (org-export-resolve-radio-link
1571 (org-element-map tree
'link
'identity info t
)
1573 ;; Radio target with objects.
1575 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1576 (org-update-radio-target-regexp)
1577 (let* ((tree (org-element-parse-buffer))
1578 (info `(:parse-tree
,tree
)))
1579 (org-export-resolve-radio-link
1580 (org-element-map tree
'link
'identity info t
)
1585 ;;; Src-block and example-block
1587 (ert-deftest test-org-export
/unravel-code
()
1588 "Test `org-export-unravel-code' function."
1589 (let ((org-coderef-label-format "(ref:%s)"))
1590 ;; 1. Code without reference.
1591 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1592 (should (equal (org-export-unravel-code (org-element-at-point))
1594 ;; 2. Code with reference.
1595 (org-test-with-temp-text
1596 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1597 (should (equal (org-export-unravel-code (org-element-at-point))
1598 '("(+ 1 1)\n" (1 .
"test")))))
1599 ;; 3. Code with user-defined reference.
1600 (org-test-with-temp-text
1601 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1602 (should (equal (org-export-unravel-code (org-element-at-point))
1603 '("(+ 1 1)\n" (1 .
"test")))))
1604 ;; 4. Code references keys are relative to the current block.
1605 (org-test-with-temp-text "
1614 (should (equal (org-export-unravel-code (org-element-at-point))
1615 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1617 (ert-deftest test-org-export
/format-code-default
()
1618 "Test `org-export-format-code-default' specifications."
1619 ;; Return the empty string when code is empty.
1622 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1623 (org-export-format-code-default
1624 (org-element-map tree
'src-block
'identity info t
) info
))))
1625 ;; Number lines, two whitespace characters before the actual loc.
1628 (org-test-with-parsed-data
1629 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1630 (org-export-format-code-default
1631 (org-element-map tree
'src-block
'identity info t
) info
))))
1632 ;; Put references 6 whitespace characters after the widest line,
1633 ;; wrapped within parenthesis.
1635 (equal "123 (a)\n1 (b)\n"
1636 (let ((org-coderef-label-format "(ref:%s)"))
1637 (org-test-with-parsed-data
1638 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1639 (org-export-format-code-default
1640 (org-element-map tree
'src-block
'identity info t
) info
))))))
1646 (ert-deftest test-org-export
/activate-smart-quotes
()
1647 "Test `org-export-activate-smart-quotes' specifications."
1648 ;; Opening double quotes: standard test.
1651 '("some “paragraph")
1652 (let ((org-export-default-language "en"))
1653 (org-test-with-parsed-data "some \"paragraph"
1654 (org-element-map tree
'plain-text
1655 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1657 ;; Opening quotes: at the beginning of a paragraph.
1661 (let ((org-export-default-language "en"))
1662 (org-test-with-parsed-data "\"begin"
1663 (org-element-map tree
'plain-text
1664 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1666 ;; Opening quotes: after an object.
1670 (let ((org-export-default-language "en"))
1671 (org-test-with-parsed-data "=verb= \"begin"
1672 (org-element-map tree
'plain-text
1673 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1675 ;; Closing quotes: standard test.
1678 '("some” paragraph")
1679 (let ((org-export-default-language "en"))
1680 (org-test-with-parsed-data "some\" paragraph"
1681 (org-element-map tree
'plain-text
1682 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1684 ;; Closing quotes: at the end of a paragraph.
1688 (let ((org-export-default-language "en"))
1689 (org-test-with-parsed-data "end\""
1690 (org-element-map tree
'plain-text
1691 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1693 ;; Apostrophe: standard test.
1696 '("It shouldn’t fail")
1697 (let ((org-export-default-language "en"))
1698 (org-test-with-parsed-data "It shouldn't fail"
1699 (org-element-map tree
'plain-text
1700 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1702 ;; Apostrophe: before an object.
1706 (let ((org-export-default-language "en"))
1707 (org-test-with-parsed-data "a'=b="
1708 (org-element-map tree
'plain-text
1709 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1711 ;; Apostrophe: after an object.
1715 (let ((org-export-default-language "en"))
1716 (org-test-with-parsed-data "=code='s"
1717 (org-element-map tree
'plain-text
1718 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1720 ;; Special case: isolated quotes.
1722 (equal '("“" "”")
1723 (let ((org-export-default-language "en"))
1724 (org-test-with-parsed-data "\"$x$\""
1725 (org-element-map tree
'plain-text
1726 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1728 ;; Smart quotes in secondary strings.
1730 (equal '("“" "”")
1731 (let ((org-export-default-language "en"))
1732 (org-test-with-parsed-data "* \"$x$\""
1733 (org-element-map tree
'plain-text
1734 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1736 ;; Smart quotes in document keywords.
1738 (equal '("“" "”")
1739 (let ((org-export-default-language "en"))
1740 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1741 (org-element-map (plist-get info
:title
) 'plain-text
1742 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1744 ;; Smart quotes in parsed affiliated keywords.
1746 (equal '("“" "”" "Paragraph")
1747 (let ((org-export-default-language "en"))
1748 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1749 (org-element-map tree
'plain-text
1750 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1751 info nil nil t
))))))
1757 (ert-deftest test-org-export
/special-column
()
1758 "Test if the table's special column is properly recognized."
1759 ;; 1. First column is special if it contains only a special marking
1760 ;; characters or empty cells.
1761 (org-test-with-temp-text "
1765 (org-export-table-has-special-column-p
1767 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1768 ;; 2. If the column contains anything else, it isn't special.
1769 (org-test-with-temp-text "
1773 (org-export-table-has-special-column-p
1775 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1776 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1778 (org-test-with-temp-text "
1787 (org-export-table-has-special-column-p
1789 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1790 ;; 4. A first column with only empty cells isn't considered as
1792 (org-test-with-temp-text "
1796 (org-export-table-has-special-column-p
1798 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1800 (ert-deftest test-org-export
/table-row-is-special-p
()
1801 "Test `org-export-table-row-is-special-p' specifications."
1802 ;; 1. A row is special if it has a special marking character in the
1804 (org-test-with-parsed-data "| ! | 1 |"
1806 (org-export-table-row-is-special-p
1807 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1808 ;; 2. A row is special when its first field is "/"
1809 (org-test-with-parsed-data "
1813 (org-export-table-row-is-special-p
1814 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1815 ;; 3. A row only containing alignment cookies is also considered as
1817 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1819 (org-export-table-row-is-special-p
1820 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1821 ;; 4. Everything else isn't considered as special.
1822 (org-test-with-parsed-data "| \alpha | | c |"
1824 (org-export-table-row-is-special-p
1825 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1826 ;; 5. Table's rules are never considered as special rows.
1827 (org-test-with-parsed-data "|---+---|"
1829 (org-export-table-row-is-special-p
1830 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1832 (ert-deftest test-org-export
/has-header-p
()
1833 "Test `org-export-table-has-header-p' specifications."
1834 ;; 1. With an header.
1835 (org-test-with-parsed-data "
1840 (org-export-table-has-header-p
1841 (org-element-map tree
'table
'identity info
'first-match
)
1843 ;; 2. Without an header.
1844 (org-test-with-parsed-data "
1848 (org-export-table-has-header-p
1849 (org-element-map tree
'table
'identity info
'first-match
)
1851 ;; 3. Don't get fooled with starting and ending rules.
1852 (org-test-with-parsed-data "
1858 (org-export-table-has-header-p
1859 (org-element-map tree
'table
'identity info
'first-match
)
1862 (ert-deftest test-org-export
/table-row-group
()
1863 "Test `org-export-table-row-group' specifications."
1864 ;; 1. A rule creates a new group.
1865 (org-test-with-parsed-data "
1872 (mapcar (lambda (row) (org-export-table-row-group row info
))
1873 (org-element-map tree
'table-row
'identity
)))))
1874 ;; 2. Special rows are ignored in count.
1875 (org-test-with-parsed-data "
1882 (mapcar (lambda (row) (org-export-table-row-group row info
))
1883 (org-element-map tree
'table-row
'identity
)))))
1884 ;; 3. Double rules also are ignored in count.
1885 (org-test-with-parsed-data "
1893 (mapcar (lambda (row) (org-export-table-row-group row info
))
1894 (org-element-map tree
'table-row
'identity
))))))
1896 (ert-deftest test-org-export
/table-cell-width
()
1897 "Test `org-export-table-cell-width' specifications."
1898 ;; 1. Width is primarily determined by width cookies. If no cookie
1899 ;; is found, cell's width is nil.
1900 (org-test-with-parsed-data "
1901 | / | <l> | <6> | <l7> |
1906 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1907 (org-element-map tree
'table-cell
'identity info
)))))
1908 ;; 2. The last width cookie has precedence.
1909 (org-test-with-parsed-data "
1916 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1917 (org-element-map tree
'table-cell
'identity info
)))))
1918 ;; 3. Valid width cookies must have a specific row.
1919 (org-test-with-parsed-data "| <6> | cell |"
1923 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1924 (org-element-map tree
'table-cell
'identity
))))))
1926 (ert-deftest test-org-export
/table-cell-alignment
()
1927 "Test `org-export-table-cell-alignment' specifications."
1928 (let ((org-table-number-fraction 0.5)
1929 (org-table-number-regexp "^[0-9]+$"))
1930 ;; 1. Alignment is primarily determined by alignment cookies.
1931 (org-test-with-temp-text "| <l> | <c> | <r> |"
1932 (let* ((tree (org-element-parse-buffer))
1933 (info `(:parse-tree
,tree
)))
1936 '(left center right
)
1937 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1938 (org-element-map tree
'table-cell
'identity
))))))
1939 ;; 2. The last alignment cookie has precedence.
1940 (org-test-with-parsed-data "
1946 '(right right right
)
1947 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1948 (org-element-map tree
'table-cell
'identity
)))))
1949 ;; 3. If there's no cookie, cell's contents determine alignment.
1950 ;; A column mostly made of cells containing numbers will align
1951 ;; its cells to the right.
1952 (org-test-with-parsed-data "
1958 '(right right right
)
1959 (mapcar (lambda (cell)
1960 (org-export-table-cell-alignment cell info
))
1961 (org-element-map tree
'table-cell
'identity
)))))
1962 ;; 4. Otherwise, they will be aligned to the left.
1963 (org-test-with-parsed-data "
1970 (mapcar (lambda (cell)
1971 (org-export-table-cell-alignment cell info
))
1972 (org-element-map tree
'table-cell
'identity
)))))))
1974 (ert-deftest test-org-export
/table-cell-borders
()
1975 "Test `org-export-table-cell-borders' specifications."
1976 ;; 1. Recognize various column groups indicators.
1977 (org-test-with-parsed-data "| / | < | > | <> |"
1980 '((right bottom top
) (left bottom top
) (right bottom top
)
1981 (right left bottom top
))
1982 (mapcar (lambda (cell)
1983 (org-export-table-cell-borders cell info
))
1984 (org-element-map tree
'table-cell
'identity
)))))
1985 ;; 2. Accept shortcuts to define column groups.
1986 (org-test-with-parsed-data "| / | < | < |"
1989 '((right bottom top
) (right left bottom top
) (left bottom top
))
1990 (mapcar (lambda (cell)
1991 (org-export-table-cell-borders cell info
))
1992 (org-element-map tree
'table-cell
'identity
)))))
1993 ;; 3. A valid column groups row must start with a "/".
1994 (org-test-with-parsed-data "
1998 (equal '((top) (top) (bottom) (bottom))
1999 (mapcar (lambda (cell)
2000 (org-export-table-cell-borders cell info
))
2001 (org-element-map tree
'table-cell
'identity
)))))
2002 ;; 4. Take table rules into consideration.
2003 (org-test-with-parsed-data "
2008 (equal '((below top
) (bottom above
))
2009 (mapcar (lambda (cell)
2010 (org-export-table-cell-borders cell info
))
2011 (org-element-map tree
'table-cell
'identity
)))))
2012 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2013 ;; (resp. `bottom' and `below') borders. Any special row is
2015 (org-test-with-parsed-data "
2021 (equal '((bottom below top above
))
2023 (mapcar (lambda (cell)
2024 (org-export-table-cell-borders cell info
))
2025 (org-element-map tree
'table-cell
'identity
)))))))
2027 (ert-deftest test-org-export
/table-dimensions
()
2028 "Test `org-export-table-dimensions' specifications."
2029 ;; 1. Standard test.
2030 (org-test-with-parsed-data "
2035 (org-export-table-dimensions
2036 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2037 ;; 2. Ignore horizontal rules and special columns.
2038 (org-test-with-parsed-data "
2045 (org-export-table-dimensions
2046 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2048 (ert-deftest test-org-export
/table-cell-address
()
2049 "Test `org-export-table-cell-address' specifications."
2050 ;; 1. Standard test: index is 0-based.
2051 (org-test-with-parsed-data "| a | b |"
2053 (equal '((0 .
0) (0 .
1))
2054 (org-element-map tree
'table-cell
2055 (lambda (cell) (org-export-table-cell-address cell info
))
2057 ;; 2. Special column isn't counted, nor are special rows.
2058 (org-test-with-parsed-data "
2063 (org-export-table-cell-address
2064 (car (last (org-element-map tree
'table-cell
'identity info
)))
2066 ;; 3. Tables rules do not count either.
2067 (org-test-with-parsed-data "
2075 (org-export-table-cell-address
2076 (car (last (org-element-map tree
'table-cell
'identity info
)))
2078 ;; 4. Return nil for special cells.
2079 (org-test-with-parsed-data "| / | a |"
2081 (org-export-table-cell-address
2082 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2085 (ert-deftest test-org-export
/get-table-cell-at
()
2086 "Test `org-export-get-table-cell-at' specifications."
2087 ;; 1. Address ignores special columns, special rows and rules.
2088 (org-test-with-parsed-data "
2095 (org-element-contents
2096 (org-export-get-table-cell-at
2098 (org-element-map tree
'table
'identity info
'first-match
)
2100 ;; 2. Return value for a non-existent address is nil.
2101 (org-test-with-parsed-data "| a |"
2103 (org-export-get-table-cell-at
2105 (org-element-map tree
'table
'identity info
'first-match
)
2107 (org-test-with-parsed-data "| / |"
2109 (org-export-get-table-cell-at
2111 (org-element-map tree
'table
'identity info
'first-match
)
2114 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2115 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2116 ;; 1. A cell at a beginning of a row always starts a column group.
2117 (org-test-with-parsed-data "| a |"
2119 (org-export-table-cell-starts-colgroup-p
2120 (org-element-map tree
'table-cell
'identity info
'first-match
)
2122 ;; 2. Special column should be ignored when determining the
2123 ;; beginning of the row.
2124 (org-test-with-parsed-data "
2128 (org-export-table-cell-starts-colgroup-p
2129 (org-element-map tree
'table-cell
'identity info
'first-match
)
2131 ;; 2. Explicit column groups.
2132 (org-test-with-parsed-data "
2138 (org-element-map tree
'table-cell
2140 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2143 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2144 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2145 ;; 1. A cell at the end of a row always ends a column group.
2146 (org-test-with-parsed-data "| a |"
2148 (org-export-table-cell-ends-colgroup-p
2149 (org-element-map tree
'table-cell
'identity info
'first-match
)
2151 ;; 2. Special column should be ignored when determining the
2152 ;; beginning of the row.
2153 (org-test-with-parsed-data "
2157 (org-export-table-cell-ends-colgroup-p
2158 (org-element-map tree
'table-cell
'identity info
'first-match
)
2160 ;; 3. Explicit column groups.
2161 (org-test-with-parsed-data "
2167 (org-element-map tree
'table-cell
2169 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2172 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2173 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2174 ;; 1. A row at the beginning of a table always starts a row group.
2175 ;; So does a row following a table rule.
2176 (org-test-with-parsed-data "
2183 (org-element-map tree
'table-row
2185 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2187 ;; 2. Special rows should be ignored when determining the beginning
2189 (org-test-with-parsed-data "
2198 (org-element-map tree
'table-row
2200 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2203 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2204 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2205 ;; 1. A row at the end of a table always ends a row group. So does
2206 ;; a row preceding a table rule.
2207 (org-test-with-parsed-data "
2214 (org-element-map tree
'table-row
2216 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2218 ;; 2. Special rows should be ignored when determining the beginning
2220 (org-test-with-parsed-data "
2229 (org-element-map tree
'table-row
2231 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2234 (ert-deftest test-org-export
/table-row-starts-header-p
()
2235 "Test `org-export-table-row-starts-header-p' specifications."
2236 ;; 1. Only the row starting the first row group starts the table
2238 (org-test-with-parsed-data "
2246 (org-element-map tree
'table-row
2248 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2250 ;; 2. A row cannot start an header if there's no header in the
2252 (org-test-with-parsed-data "
2256 (org-export-table-row-starts-header-p
2257 (org-element-map tree
'table-row
'identity info
'first-match
)
2260 (ert-deftest test-org-export
/table-row-ends-header-p
()
2261 "Test `org-export-table-row-ends-header-p' specifications."
2262 ;; 1. Only the row starting the first row group starts the table
2264 (org-test-with-parsed-data "
2272 (org-element-map tree
'table-row
2274 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2276 ;; 2. A row cannot start an header if there's no header in the
2278 (org-test-with-parsed-data "
2282 (org-export-table-row-ends-header-p
2283 (org-element-map tree
'table-row
'identity info
'first-match
)
2290 (ert-deftest test-org-export
/inner-template
()
2291 "Test `inner-template' translator specifications."
2294 (let (org-export-registered-backends)
2295 (org-export-define-backend 'test
2296 '((inner-template .
(lambda (contents info
) "Success!"))
2297 (headline .
(lambda (h c i
) "Headline"))))
2298 (org-test-with-temp-text "* Headline"
2299 (org-export-as 'test
)))))
2300 ;; Inner template is applied even in a "body-only" export.
2303 (let (org-export-registered-backends)
2304 (org-export-define-backend 'test
2305 '((inner-template .
(lambda (contents info
) "Success!"))
2306 (headline .
(lambda (h c i
) "Headline"))))
2307 (org-test-with-temp-text "* Headline"
2308 (org-export-as 'test nil nil
'body-only
))))))
2310 (ert-deftest test-org-export
/template
()
2311 "Test `template' translator specifications."
2314 (let (org-export-registered-backends)
2315 (org-export-define-backend 'test
2316 '((template .
(lambda (contents info
) "Success!"))
2317 (headline .
(lambda (h c i
) "Headline"))))
2318 (org-test-with-temp-text "* Headline"
2319 (org-export-as 'test
)))))
2320 ;; Template is not applied in a "body-only" export.
2323 (let (org-export-registered-backends)
2324 (org-export-define-backend 'test
2325 '((template .
(lambda (contents info
) "Success!"))
2326 (headline .
(lambda (h c i
) "Headline"))))
2327 (org-test-with-temp-text "* Headline"
2328 (org-export-as 'test nil nil
'body-only
))))))
2334 (ert-deftest test-org-export
/get-next-element
()
2335 "Test `org-export-get-next-element' specifications."
2339 (org-test-with-parsed-data "* Headline\n*a* b"
2340 (org-export-get-next-element
2341 (org-element-map tree
'bold
'identity info t
) info
))))
2342 ;; Return nil when no previous element.
2344 (org-test-with-parsed-data "* Headline\na *b*"
2345 (org-export-get-next-element
2346 (org-element-map tree
'bold
'identity info t
) info
)))
2347 ;; Non-exportable elements are ignored.
2349 (let ((org-export-with-timestamps nil
))
2350 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2351 (org-export-get-next-element
2352 (org-element-map tree
'entity
'identity info t
) info
))))
2353 ;; Find next element in secondary strings.
2356 (org-test-with-parsed-data "* a =verb="
2358 (org-export-get-next-element
2359 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2360 ;; Find next element in document keywords.
2363 (org-test-with-parsed-data "#+TITLE: a =verb="
2365 (org-export-get-next-element
2367 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2368 ;; Find next element in parsed affiliated keywords.
2371 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2373 (org-export-get-next-element
2374 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2375 ;; With optional argument N, return a list containing all the
2376 ;; following elements.
2379 '(bold code underline
)
2380 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2382 (org-export-get-next-element
2383 (org-element-map tree
'italic
'identity info t
) info t
)))))
2384 ;; When N is a positive integer, return a list containing up to
2385 ;; N following elements.
2389 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2391 (org-export-get-next-element
2392 (org-element-map tree
'italic
'identity info t
) info
2))))))
2394 (ert-deftest test-org-export
/get-previous-element
()
2395 "Test `org-export-get-previous-element' specifications."
2399 (org-test-with-parsed-data "* Headline\na *b*"
2400 (org-export-get-previous-element
2401 (org-element-map tree
'bold
'identity info t
) info
))))
2402 ;; Return nil when no previous element.
2404 (org-test-with-parsed-data "* Headline\n*a* b"
2405 (org-export-get-previous-element
2406 (org-element-map tree
'bold
'identity info t
) info
)))
2407 ;; Non-exportable elements are ignored.
2409 (let ((org-export-with-timestamps nil
))
2410 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2411 (org-export-get-previous-element
2412 (org-element-map tree
'entity
'identity info t
) info
))))
2413 ;; Find previous element in secondary strings.
2416 (org-test-with-parsed-data "* =verb= a"
2418 (org-export-get-previous-element
2419 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2420 ;; Find previous element in document keywords.
2423 (org-test-with-parsed-data "#+TITLE: =verb= a"
2425 (org-export-get-previous-element
2427 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2428 ;; Find previous element in parsed affiliated keywords.
2431 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2433 (org-export-get-previous-element
2434 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2435 ;; With optional argument N, return a list containing up to
2436 ;; N previous elements.
2438 (equal '(underline italic bold
)
2439 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2441 (org-export-get-previous-element
2442 (org-element-map tree
'code
'identity info t
) info t
)))))
2443 ;; When N is a positive integer, return a list containing up to
2444 ;; N previous elements.
2446 (equal '(italic bold
)
2447 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2449 (org-export-get-previous-element
2450 (org-element-map tree
'code
'identity info t
) info
2))))))
2454 ;;; test-org-export.el end here