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: variable value"
79 (let ((org-export-allow-bind-keywords t
))
80 (org-export--install-letbind-maybe)
81 (eq variable
'value
))))
82 ;; Test with `org-export-allow-bind-keywords' set to nil.
84 (org-test-with-temp-text "#+BIND: variable value"
85 (let ((org-export-allow-bind-keywords nil
))
86 (org-export--install-letbind-maybe)
88 ;; BIND keywords are case-insensitive.
90 (org-test-with-temp-text "#+bind: variable value"
91 (let ((org-export-allow-bind-keywords t
))
92 (org-export--install-letbind-maybe)
93 (eq variable
'value
)))))
95 (ert-deftest test-org-export
/parse-option-keyword
()
96 "Test reading all standard #+OPTIONS: items."
99 (org-export--parse-option-keyword
100 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
101 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
104 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
105 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
106 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
107 :with-footnotes t
:with-inlinetasks nil
:with-priority t
108 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
109 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
110 :with-todo-keywords t
)))
111 ;; Test some special values.
114 (org-export--parse-option-keyword
115 "arch:headline creator:comment d:(\"TEST\")
116 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
119 :with-archived-trees headline
:with-creator comment
120 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
121 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
123 (ert-deftest test-org-export
/get-inbuffer-options
()
124 "Test reading all standard export keywords."
125 ;; Properties should follow buffer order.
128 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
129 (org-export--get-inbuffer-options))
130 '(:language
"fr" :creator
"Me" :email
"email")))
131 ;; Parse document keywords.
134 (org-test-with-temp-text "#+AUTHOR: Me"
135 (org-export--get-inbuffer-options))
137 ;; Test `space' behaviour.
140 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
141 (org-export--get-inbuffer-options))
142 '(:title
("Some title with spaces"))))
143 ;; Test `newline' behaviour.
146 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
147 (org-export--get-inbuffer-options))
148 '(:description
"With\ntwo lines")))
149 ;; Test `split' behaviour.
152 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
153 (org-export--get-inbuffer-options))
154 '(:select-tags
("a" "b"))))
155 ;; Options set through SETUPFILE.
158 (org-test-with-temp-text
159 (format "#+DESCRIPTION: l1
163 #+SETUPFILE: \"%s/examples/setupfile.org\"
169 (org-export--get-inbuffer-options))
170 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
173 (ert-deftest test-org-export
/get-subtree-options
()
174 "Test setting options from headline's properties."
176 (org-test-with-temp-text "#+TITLE: Title
179 :EXPORT_TITLE: Subtree Title
183 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
184 '("Subtree Title"))))
188 (org-test-with-temp-text "#+OPTIONS: H:1
196 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
198 (org-test-with-temp-text "#+DATE: today
201 :EXPORT_DATE: 29-03-2012
205 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
207 ;; Properties with `split' behaviour are stored as a list of
211 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
214 :EXPORT_EXCLUDE_TAGS: a b
219 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
220 ;; Handle :PROPERTY+: syntax.
223 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
226 :EXPORT_EXCLUDE_TAGS: a
227 :EXPORT_EXCLUDE_TAGS+: b
232 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
233 ;; Export properties are case-insensitive.
234 (org-test-with-temp-text "* Headline
236 :EXPORT_Date: 29-03-2012
239 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
241 ;; Still grab correct options when section above is empty.
244 (org-test-with-temp-text "* H1\n** H11\n** H12"
245 (progn (forward-line 2)
246 (plist-get (org-export-get-environment nil t
) :title
))))))
248 (ert-deftest test-org-export
/handle-options
()
249 "Test if export options have an impact on output."
250 ;; Test exclude tags for headlines and inlinetasks.
253 (org-test-with-temp-text "* Head1 :noexp:"
254 (org-test-with-backend test
255 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp")))))))
256 ;; Test include tags for headlines and inlinetasks.
258 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
259 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
260 (let ((org-tags-column 0))
261 (org-test-with-backend test
262 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
263 ;; Test mixing include tags and exclude tags.
264 (org-test-with-temp-text "
266 ** Sub-Head1 :noexport:
269 ** Sub-Head1 :export:"
270 (org-test-with-backend test
273 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
276 '(:select-tags
("export") :exclude-tags
("noexport")))))))
280 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
281 (org-test-with-temp-text "* TODO Head1"
282 (org-test-with-backend test
283 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))
285 (equal "* TODO Head1\n"
286 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
287 (org-test-with-temp-text "* TODO Head1"
288 (org-test-with-backend test
289 (org-export-as 'test nil nil nil
'(:with-tasks t
)))))))
291 (org-test-with-temp-text "* Head1 :archive:"
292 (let ((org-archive-tag "archive"))
293 (org-test-with-backend test
295 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
297 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
298 (let ((org-archive-tag "archive"))
299 (org-test-with-backend test
302 "\\* Head1[ \t]+:archive:"
303 (org-export-as 'test nil nil nil
304 '(:with-archived-trees headline
)))))))
305 (org-test-with-temp-text "* Head1 :archive:"
306 (let ((org-archive-tag "archive"))
307 (org-test-with-backend test
310 "\\`\\* Head1[ \t]+:archive:\n\\'"
311 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
313 (let ((org-clock-string "CLOCK:"))
314 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
315 (org-test-with-backend test
317 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
318 "CLOCK: [2012-04-29 sun. 10:45]\n"))
320 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
322 (let ((org-drawers '("TEST")))
323 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
324 (org-test-with-backend test
325 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
327 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
328 ":TEST:\ncontents\n:END:\n")))))
329 (let ((org-drawers '("FOO" "BAR")))
330 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
331 (org-test-with-backend test
333 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
334 ":FOO:\nkeep\n:END:\n")))))
335 (let ((org-drawers '("FOO" "BAR")))
336 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
337 (org-test-with-backend test
339 (equal (org-export-as 'test nil nil nil
'(:with-drawers
(not "BAR")))
340 ":FOO:\nkeep\n:END:\n")))))
342 (when (featurep 'org-inlinetask
)
345 (let ((org-inlinetask-min-level 15))
346 (org-test-with-temp-text "*************** Task"
347 (org-test-with-backend test
348 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
352 (let ((org-inlinetask-min-level 15))
353 (org-test-with-temp-text
354 "*************** Task\nContents\n*************** END"
355 (org-test-with-backend test
356 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
359 (let ((org-closed-string "CLOSED:"))
360 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
361 (org-test-with-backend test
363 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
364 "CLOSED: [2012-04-29 sun. 10:45]\n"))
366 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
368 ;; Statistics cookies.
371 (org-test-with-temp-text "[0/0]"
372 (org-test-with-backend test
374 'test nil nil nil
'(:with-statistics-cookies nil
))))))
376 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
377 (org-test-with-backend test
379 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
380 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
382 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
384 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
385 "<2012-04-29 sun. 10:45>\n"))
387 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
388 "[2012-04-29 sun. 10:45]\n")))))
390 (ert-deftest test-org-export
/comment-tree
()
391 "Test if export process ignores commented trees."
392 (let ((org-comment-string "COMMENT"))
393 (org-test-with-temp-text "* COMMENT Head1"
394 (org-test-with-backend test
395 (should (equal (org-export-as 'test
) ""))))))
397 (ert-deftest test-org-export
/export-scope
()
398 "Test all export scopes."
399 (org-test-with-temp-text "
404 (org-test-with-backend test
407 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
409 (goto-char (point-min))
412 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
414 (goto-char (point-min))
416 (transient-mark-mode 1)
417 (push-mark (point) t t
)
418 (goto-char (point-at-eol))
419 (should (equal (org-export-as 'test
) "text\n"))))
420 ;; Subtree with a code block calling another block outside.
423 (org-test-with-temp-text "
425 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
430 #+BEGIN_SRC emacs-lisp
433 (org-test-with-backend test
435 (org-export-as 'test
'subtree
)))))
437 (org-test-with-temp-text "Text"
438 (org-test-with-backend test
440 (cdr (assq 'test org-export-registered-backends
))
442 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
443 (org-export-backend-translate-table 'test
)))
444 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
445 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
447 (ert-deftest test-org-export
/output-file-name
()
448 "Test `org-export-output-file-name' specifications."
449 ;; Export from a file: name is built from original file name.
451 (org-test-with-temp-text-in-file "Test"
452 (equal (concat (file-name-as-directory ".")
453 (file-name-nondirectory
454 (file-name-sans-extension (buffer-file-name))))
455 (file-name-sans-extension (org-export-output-file-name ".ext")))))
456 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
458 (org-test-with-temp-text-in-file
459 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
460 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
461 ;; From a buffer not associated to a file, too.
463 (org-test-with-temp-text
464 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
465 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
466 ;; When provided name is absolute, preserve it.
468 (org-test-with-temp-text
469 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
470 (expand-file-name "test"))
471 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
472 ;; When PUB-DIR argument is provided, use it.
474 (org-test-with-temp-text-in-file "Test"
475 (equal (file-name-directory
476 (org-export-output-file-name ".ext" nil
"dir/"))
478 ;; When returned name would overwrite original file, add EXTENSION
481 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
482 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
484 (ert-deftest test-org-export
/expand-include
()
485 "Test file inclusion in an Org buffer."
486 ;; Error when file isn't specified.
488 (org-test-with-temp-text "#+INCLUDE: dummy.org"
489 (org-export-expand-include-keyword)))
490 ;; Full insertion with recursive inclusion.
491 (org-test-with-temp-text
492 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
493 (org-export-expand-include-keyword)
494 (should (equal (buffer-string)
495 "Small Org file with an include keyword.
497 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
503 ;; Localized insertion.
504 (org-test-with-temp-text
505 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
507 (org-export-expand-include-keyword)
508 (should (equal (buffer-string)
509 "Small Org file with an include keyword.\n")))
510 ;; Insertion with constraints on headlines level.
513 "* Top heading\n** Heading\nbody\n"
514 (org-test-with-temp-text
516 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
518 (org-export-expand-include-keyword)
522 "* Top heading\n* Heading\nbody\n"
523 (org-test-with-temp-text
525 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
527 (org-export-expand-include-keyword)
529 ;; Inclusion within an example block.
530 (org-test-with-temp-text
531 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
533 (org-export-expand-include-keyword)
537 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
538 ;; Inclusion within a src-block.
539 (org-test-with-temp-text
541 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
543 (org-export-expand-include-keyword)
544 (should (equal (buffer-string)
545 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
547 (ert-deftest test-org-export
/expand-macro
()
548 "Test macro expansion in an Org buffer."
549 ;; Standard macro expansion.
551 (equal "#+MACRO: macro1 value\nvalue\n"
552 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
553 (org-test-with-backend test
(org-export-as 'test
)))))
554 ;; Expand specific macros.
556 (equal "me 2012-03-29 me@here Title\n"
557 (org-test-with-temp-text
563 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
564 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
565 (substring output
(string-match ".*\n\\'" output
))))))
566 ;; Expand specific macros when property contained a regular macro
570 (org-test-with-temp-text "
571 #+MACRO: macro1 value
572 #+TITLE: {{{macro1}}}
574 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
575 (substring output
(string-match ".*\n\\'" output
))))))
576 ;; Expand macros with templates in included files.
579 (org-test-with-temp-text
580 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
581 {{{included-macro}}}" org-test-dir
)
582 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
583 (substring output
(string-match ".*\n\\'" output
)))))))
585 (ert-deftest test-org-export
/user-ignore-list
()
586 "Test if `:ignore-list' accepts user input."
587 (org-test-with-backend test
588 (flet ((skip-note-head
590 ;; Ignore headlines with the word "note" in their title.
594 (when (string-match "\\<note\\>"
595 (org-element-property :raw-value headline
))
596 (org-export-ignore-element headline info
)))
599 ;; Install function in parse tree filters.
600 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
601 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
602 (should (equal (org-export-as 'test
) "* Head1\n")))))))
604 (ert-deftest test-org-export
/before-processing-hook
()
605 "Test `org-export-before-processing-hook'."
608 "#+MACRO: mac val\nTest\n"
609 (org-test-with-backend test
610 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
611 (let ((org-export-before-processing-hook
613 (while (re-search-forward "{{{" nil t
)
614 (let ((object (org-element-context)))
615 (when (eq (org-element-type object
) 'macro
)
617 (org-element-property :begin object
)
618 (org-element-property :end object
)))))))))
619 (org-export-as 'test
)))))))
621 (ert-deftest test-org-export
/before-parsing-hook
()
622 "Test `org-export-before-parsing-hook'."
624 (equal "Body 1\nBody 2\n"
625 (org-test-with-backend test
626 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
627 (let ((org-export-before-parsing-hook
629 (goto-char (point-min))
630 (while (re-search-forward org-outline-regexp-bol nil t
)
632 (point-at-bol) (progn (forward-line) (point))))))))
633 (org-export-as 'test
)))))))
637 ;;; Affiliated Keywords
639 (ert-deftest test-org-export
/read-attribute
()
640 "Test `org-export-read-attribute' specifications."
644 (org-export-read-attribute
646 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
647 (org-element-at-point)))
649 ;; Return nil on empty attribute.
651 (org-export-read-attribute
653 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
655 (ert-deftest test-org-export
/get-caption
()
656 "Test `org-export-get-caption' specifications."
657 ;; Without optional argument, return long caption
661 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
662 (org-export-get-caption (org-element-at-point)))))
663 ;; With optional argument, return short caption.
667 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
668 (org-export-get-caption (org-element-at-point) t
))))
669 ;; Multiple lines are separated by white spaces.
673 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
674 (org-export-get-caption (org-element-at-point))))))
680 (ert-deftest test-org-export
/define-backend
()
681 "Test back-end definition and accessors."
684 (equal '((headline . my-headline-test
))
685 (let (org-export-registered-backends)
686 (org-export-define-backend test
((headline . my-headline-test
)))
687 (org-export-backend-translate-table 'test
))))
690 (equal '((:filter-headline . my-filter
))
691 (let (org-export-registered-backends)
692 (org-export-define-backend test
693 ((headline . my-headline-test
))
694 :filters-alist
((:filter-headline . my-filter
)))
695 (org-export-backend-filters 'test
))))
698 (equal '((:prop value
))
699 (let (org-export-registered-backends)
700 (org-export-define-backend test
701 ((headline . my-headline-test
))
702 :options-alist
((:prop value
)))
703 (org-export-backend-options 'test
))))
706 (equal '(?k
"Test Export" test
)
707 (let (org-export-registered-backends)
708 (org-export-define-backend test
709 ((headline . my-headline-test
))
710 :menu-entry
(?k
"Test Export" test
))
711 (org-export-backend-menu 'test
))))
714 (equal '(("TEST" . org-element-export-block-parser
))
715 (let (org-export-registered-backends org-element-block-name-alist
)
716 (org-export-define-backend test
717 ((headline . my-headline-test
))
718 :export-block
("test"))
719 org-element-block-name-alist
))))
721 (ert-deftest test-org-export
/define-derived-backend
()
722 "Test `org-export-define-derived-backend' specifications."
723 ;; Error when parent back-end is not defined.
725 (let (org-export-registered-backends)
726 (org-export-define-derived-backend test parent
)))
727 ;; Append translation table to parent's.
729 (equal '((:headline . test
) (:headline . parent
))
730 (let (org-export-registered-backends)
731 (org-export-define-backend parent
((:headline . parent
)))
732 (org-export-define-derived-backend test parent
733 :translate-alist
((:headline . test
)))
734 (org-export-backend-translate-table 'test
))))
735 ;; Options defined in the new back have priority over those defined
739 (let (org-export-registered-backends)
740 (org-export-define-backend parent
741 ((:headline . parent
))
742 :options-alist
((:a nil nil
'parent
)))
743 (org-export-define-derived-backend test parent
744 :options-alist
((:a nil nil
'test
)))
745 (plist-get (org-export--get-global-options 'test
) :a
)))))
747 (ert-deftest test-org-export
/derived-backend-p
()
748 "Test `org-export-derived-backend-p' specifications."
749 ;; Non-nil with direct match.
751 (let (org-export-registered-backends)
752 (org-export-define-backend test
((headline . test
)))
753 (org-export-derived-backend-p 'test
'test
)))
755 (let (org-export-registered-backends)
756 (org-export-define-backend test
((headline . test
)))
757 (org-export-define-derived-backend test2 test
)
758 (org-export-derived-backend-p 'test2
'test2
)))
759 ;; Non-nil with a direct parent.
761 (let (org-export-registered-backends)
762 (org-export-define-backend test
((headline . test
)))
763 (org-export-define-derived-backend test2 test
)
764 (org-export-derived-backend-p 'test2
'test
)))
765 ;; Non-nil with an indirect parent.
767 (let (org-export-registered-backends)
768 (org-export-define-backend test
((headline . test
)))
769 (org-export-define-derived-backend test2 test
)
770 (org-export-define-derived-backend test3 test2
)
771 (org-export-derived-backend-p 'test3
'test
)))
774 (let (org-export-registered-backends)
775 (org-export-define-backend test
((headline . test
)))
776 (org-export-define-backend test2
((headline . test2
)))
777 (org-export-derived-backend-p 'test2
'test
)))
779 (let (org-export-registered-backends)
780 (org-export-define-backend test
((headline . test
)))
781 (org-export-define-backend test2
((headline . test2
)))
782 (org-export-define-derived-backend test3 test2
)
783 (org-export-derived-backend-p 'test3
'test
))))
785 (ert-deftest test-org-export
/with-backend
()
786 "Test `org-export-with-backend' definition."
787 ;; Error when calling an undefined back-end
789 (let (org-export-registered-backends)
790 (org-export-with-backend 'test
"Test")))
791 ;; Error when called back-end doesn't have an appropriate
794 (let (org-export-registered-backends)
795 (org-export-define-backend test
((headline . ignore
)))
796 (org-export-with-backend 'test
"Test")))
797 ;; Otherwise, export using correct transcoder
800 (let (org-export-registered-backends)
801 (org-export-define-backend test
802 ((plain-text .
(lambda (text contents info
) "Failure"))))
803 (org-export-define-backend test2
804 ((plain-text .
(lambda (text contents info
) "Success"))))
805 (org-export-with-backend 'test2
"Test")))))
807 (ert-deftest test-org-export
/data-with-translations
()
808 "Test `org-export-data-with-translations' specifications."
812 (org-export-data-with-translations
814 '((plain-text .
(lambda (text info
) "Success"))
815 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
816 '(:with-emphasize t
)))))
818 (ert-deftest test-org-export
/data-with-backend
()
819 "Test `org-export-data-with-backend' specifications."
820 ;; Error when calling an undefined back-end.
822 (let (org-export-registered-backends)
823 (org-export-data-with-backend 'test
"Test" nil
)))
824 ;; Otherwise, export data recursively, using correct back-end.
828 (let (org-export-registered-backends)
829 (org-export-define-backend test
830 ((plain-text .
(lambda (text info
) "Success"))
831 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
832 (org-export-data-with-backend
833 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
839 (ert-deftest test-org-export
/export-snippet
()
840 "Test export snippets transcoding."
841 (org-test-with-temp-text "@@test:A@@@@t:B@@"
842 (org-test-with-backend test
844 (cdr (assq 'test org-export-registered-backends
))
846 (cons (cons 'export-snippet
847 (lambda (snippet contents info
)
848 (when (eq (org-export-snippet-backend snippet
) 'test
)
849 (org-element-property :value snippet
))))
850 (org-export-backend-translate-table 'test
)))
851 (let ((org-export-snippet-translation-alist nil
))
852 (should (equal (org-export-as 'test
) "A\n")))
853 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
854 (should (equal (org-export-as 'test
) "AB\n"))))))
860 (ert-deftest test-org-export
/footnotes
()
861 "Test footnotes specifications."
862 (let ((org-footnote-section nil
)
863 (org-export-with-footnotes t
))
864 ;; 1. Read every type of footnote.
867 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
868 (org-test-with-parsed-data
869 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
871 tree
'footnote-reference
873 (let ((def (org-export-get-footnote-definition ref info
)))
874 (cons (org-export-get-footnote-number ref info
)
875 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
876 (car (org-element-contents
877 (car (org-element-contents def
))))))))
879 ;; 2. Test nested footnotes order.
880 (org-test-with-parsed-data
881 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
884 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
886 tree
'footnote-reference
888 (when (org-export-footnote-first-reference-p ref info
)
889 (cons (org-export-get-footnote-number ref info
)
890 (org-element-property :label ref
))))
892 ;; 3. Test nested footnote in invisible definitions.
893 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
895 (narrow-to-region (point) (point-at-eol))
896 (let* ((tree (org-element-parse-buffer))
897 (info (org-combine-plists
899 (org-export-collect-tree-properties
900 tree
(org-export-get-environment)))))
901 ;; Both footnotes should be seen.
903 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
904 ;; 4. Test footnotes definitions collection.
905 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
907 \[fn:2] B [fn:3] [fn::D].
910 (should (= (length (org-export-collect-footnote-definitions tree info
))
912 ;; 5. Test export of footnotes defined outside parsing scope.
913 (org-test-with-temp-text "[fn:1] Out of scope
916 (org-test-with-backend test
918 (cdr (assq 'test org-export-registered-backends
))
920 (cons (cons 'footnote-reference
921 (lambda (fn contents info
)
922 (org-element-interpret-data
923 (org-export-get-footnote-definition fn info
))))
924 (org-export-backend-translate-table 'test
)))
926 (should (equal "ParagraphOut of scope\n"
927 (org-export-as 'test
'subtree
)))))
928 ;; 6. Footnotes without a definition should be provided a fallback
931 (org-test-with-parsed-data "[fn:1]"
932 (org-export-get-footnote-definition
933 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
934 ;; 7. Footnote section should be ignored in TOC and in headlines
937 (= 1 (let ((org-footnote-section "Footnotes"))
938 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
939 (org-export-collect-headlines info
))))))
942 (let ((org-footnote-section "Footnotes"))
943 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
944 (org-element-map tree
'headline
946 (when (equal (org-element-property :raw-value hl
) "H2")
947 (org-export-get-headline-number hl info
)))
952 ;;; Headlines and Inlinetasks
954 (ert-deftest test-org-export
/get-relative-level
()
955 "Test `org-export-get-relative-level' specifications."
959 (let ((org-odd-levels-only nil
))
960 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
963 (lambda (h) (org-export-get-relative-level h info
))
968 (let ((org-odd-levels-only nil
))
969 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
972 (lambda (h) (org-export-get-relative-level h info
))
975 (ert-deftest test-org-export
/low-level-p
()
976 "Test `org-export-low-level-p' specifications."
980 (let ((org-odd-levels-only nil
))
981 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
984 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
985 (plist-put info
:headline-levels
1)))))))
987 (ert-deftest test-org-export
/get-headline-number
()
988 "Test `org-export-get-headline-number' specifications."
993 (let ((org-odd-levels-only nil
))
994 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
997 (lambda (h) (org-export-get-headline-number h info
))
999 ;; Missing levels are replaced with 0.
1003 (let ((org-odd-levels-only nil
))
1004 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1007 (lambda (h) (org-export-get-headline-number h info
))
1010 (ert-deftest test-org-export
/numbered-headline-p
()
1011 "Test `org-export-numbered-headline-p' specifications."
1012 ;; If `:section-numbers' is nil, never number headlines.
1014 (org-test-with-parsed-data "* Headline"
1017 (lambda (h) (org-export-numbered-headline-p h info
))
1018 (plist-put info
:section-numbers nil
))))
1019 ;; If `:section-numbers' is a number, only number headlines with
1020 ;; a level greater that it.
1024 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1027 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1028 (plist-put info
:section-numbers
1)))))
1029 ;; Otherwise, headlines are always numbered.
1031 (org-test-with-parsed-data "* Headline"
1034 (lambda (h) (org-export-numbered-headline-p h info
))
1035 (plist-put info
:section-numbers t
)))))
1037 (ert-deftest test-org-export
/number-to-roman
()
1038 "Test `org-export-number-to-roman' specifications."
1039 ;; If number is negative, return it as a string.
1040 (should (equal (org-export-number-to-roman -
1) "-1"))
1041 ;; Otherwise, return it as a roman number.
1042 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1044 (ert-deftest test-org-export
/get-optional-title
()
1045 "Test `org-export-get-alt-title' specifications."
1046 ;; If ALT_TITLE property is defined, use it.
1049 (org-test-with-parsed-data
1050 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1051 (org-export-get-alt-title
1052 (org-element-map tree
'headline
'identity info t
)
1054 ;; Otherwise, fall-back to regular title.
1056 (equal '("Headline")
1057 (org-test-with-parsed-data "* Headline"
1058 (org-export-get-alt-title
1059 (org-element-map tree
'headline
'identity info t
)
1062 (ert-deftest test-org-export
/get-tags
()
1063 "Test `org-export-get-tags' specifications."
1064 (let ((org-export-exclude-tags '("noexport"))
1065 (org-export-select-tags '("export")))
1066 ;; Standard test: tags which are not a select tag, an exclude tag,
1067 ;; or specified as optional argument shouldn't be ignored.
1069 (org-test-with-parsed-data "* Headline :tag:"
1070 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1072 ;; Exclude tags are removed.
1074 (org-test-with-parsed-data "* Headline :noexport:"
1075 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1077 ;; Select tags are removed.
1079 (org-test-with-parsed-data "* Headline :export:"
1080 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1085 (org-test-with-parsed-data "* Headline :tag:export:"
1086 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1088 ;; Tags provided in the optional argument are also ignored.
1090 (org-test-with-parsed-data "* Headline :ignore:"
1091 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1093 ;; Allow tag inheritance.
1097 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1100 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1101 ;; Tag inheritance checks FILETAGS keywords.
1105 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1108 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1110 (ert-deftest test-org-export
/get-node-property
()
1111 "Test`org-export-get-node-property' specifications."
1115 (org-test-with-parsed-data "* Headline
1119 (org-export-get-node-property
1120 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1121 ;; Test inheritance.
1124 (org-test-with-parsed-data "* Parent
1130 (org-export-get-node-property
1131 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1132 ;; Cannot return a value before the first headline.
1134 (org-test-with-parsed-data "Paragraph
1139 (org-export-get-node-property
1140 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1142 (ert-deftest test-org-export
/get-category
()
1143 "Test `org-export-get-category' specifications."
1147 (org-test-with-parsed-data "* Headline
1151 (org-export-get-category
1152 (org-element-map tree
'headline
'identity nil t
) info
))))
1153 ;; Test inheritance from a parent headline.
1155 (equal '("value" "value")
1156 (org-test-with-parsed-data "* Headline1
1163 (lambda (hl) (org-export-get-category hl info
)) info
))))
1164 ;; Test inheritance from #+CATEGORY keyword
1167 (org-test-with-parsed-data "#+CATEGORY: value
1169 (org-export-get-category
1170 (org-element-map tree
'headline
'identity nil t
) info
))))
1171 ;; Test inheritance from file name.
1174 (org-test-with-parsed-data "* Headline"
1175 (let ((info (plist-put info
:input-file
"~/test.org")))
1176 (org-export-get-category
1177 (org-element-map tree
'headline
'identity nil t
) info
)))))
1181 (org-test-with-parsed-data "* Headline"
1182 (org-export-get-category
1183 (org-element-map tree
'headline
'identity nil t
) info
)))))
1185 (ert-deftest test-org-export
/first-sibling-p
()
1186 "Test `org-export-first-sibling-p' specifications."
1191 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1194 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1196 ;; Ignore headlines not exported.
1200 (let ((org-export-exclude-tags '("ignore")))
1201 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1204 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1207 (ert-deftest test-org-export
/last-sibling-p
()
1208 "Test `org-export-last-sibling-p' specifications."
1213 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1216 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1218 ;; Ignore headlines not exported.
1222 (let ((org-export-exclude-tags '("ignore")))
1223 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1226 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1229 (ert-deftest test-org-export
/handle-inlinetasks
()
1230 "Test inlinetask export."
1231 ;; Inlinetask with an exclude tag.
1232 (when (featurep 'org-inlinetask
)
1236 (let ((org-inlinetask-min-level 3))
1237 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1238 (org-test-with-backend test
1239 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp"))))))))
1240 ;; Inlinetask with an include tag.
1243 "* H2\n*** Inline :exp:\n"
1244 (let ((org-inlinetask-min-level 3)
1245 (org-tags-column 0))
1246 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1247 (org-test-with-backend test
1248 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
1249 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1252 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1253 (org-inlinetask-min-level 3))
1254 (org-test-with-temp-text "*** TODO Inline"
1255 (org-test-with-backend test
1256 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))))
1262 (ert-deftest test-org-export
/get-coderef-format
()
1263 "Test `org-export-get-coderef-format' specifications."
1264 ;; A link without description returns "%s"
1265 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1267 ;; Return "%s" when path is matched within description.
1268 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1270 ;; Otherwise return description.
1271 (should (equal (org-export-get-coderef-format "path" "desc")
1274 (ert-deftest test-org-export
/inline-image-p
()
1275 "Test `org-export-inline-image-p' specifications."
1277 (org-export-inline-image-p
1278 (org-test-with-temp-text "[[#id]]"
1280 (org-element-parse-buffer) 'link
'identity nil t
))
1281 '(("custom-id" .
"id")))))
1283 (ert-deftest test-org-export
/fuzzy-link
()
1284 "Test fuzzy links specifications."
1285 ;; 1. Links to invisible (keyword) targets should be ignored.
1286 (org-test-with-parsed-data
1287 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1292 (org-export-get-ordinal
1293 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1294 ;; 2. Link to an headline should return headline's number.
1295 (org-test-with-parsed-data
1296 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1298 ;; Note: Headline's number is in fact a list of numbers.
1303 (org-export-get-ordinal
1304 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1305 ;; 3. Link to a target in an item should return item's number.
1306 (org-test-with-parsed-data
1307 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1309 ;; Note: Item's number is in fact a list of numbers.
1314 (org-export-get-ordinal
1315 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1316 ;; 4. Link to a target in a footnote should return footnote's
1318 (org-test-with-parsed-data "
1319 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1325 (org-export-get-ordinal
1326 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1327 ;; 5. Link to a named element should return sequence number of that
1329 (org-test-with-parsed-data
1330 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1336 (org-export-get-ordinal
1337 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1338 ;; 6. Link to a target not within an item, a table, a footnote
1339 ;; reference or definition should return section number.
1340 (org-test-with-parsed-data
1341 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1347 (org-export-get-ordinal
1348 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1349 ;; 7. Space are not significant when matching a fuzzy link.
1351 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1352 (org-element-map tree
'link
1353 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1355 ;; 8. Statistics cookies are ignored for headline match.
1357 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1358 (org-element-map tree
'link
1359 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1362 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1363 (org-element-map tree
'link
1364 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1367 (ert-deftest test-org-export
/resolve-coderef
()
1368 "Test `org-export-resolve-coderef' specifications."
1369 (let ((org-coderef-label-format "(ref:%s)"))
1370 ;; 1. A link to a "-n -k -r" block returns line number.
1371 (org-test-with-parsed-data
1372 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1373 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1374 (org-test-with-parsed-data
1375 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1376 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1377 ;; 2. A link to a "-n -r" block returns line number.
1378 (org-test-with-parsed-data
1379 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1380 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1381 (org-test-with-parsed-data
1382 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1383 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1384 ;; 3. A link to a "-n" block returns coderef.
1385 (org-test-with-parsed-data
1386 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1387 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1388 (org-test-with-parsed-data
1389 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1390 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1391 ;; 4. A link to a "-r" block returns line number.
1392 (org-test-with-parsed-data
1393 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1394 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1395 (org-test-with-parsed-data
1396 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1397 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1398 ;; 5. A link to a block without a switch returns coderef.
1399 (org-test-with-parsed-data
1400 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1401 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1402 (org-test-with-parsed-data
1403 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1404 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1405 ;; 6. Correctly handle continued line numbers. A "+n" switch
1406 ;; should resume numbering from previous block with numbered
1407 ;; lines, ignoring blocks not numbering lines in the process.
1408 ;; A "-n" switch resets count.
1409 (org-test-with-parsed-data "
1414 #+BEGIN_SRC emacs-lisp
1418 #+BEGIN_SRC emacs-lisp +n -r
1419 \(+ 1 1) (ref:addition)
1422 #+BEGIN_EXAMPLE -n -r
1423 Another text. (ref:text)
1425 (should (= (org-export-resolve-coderef "addition" info
) 2))
1426 (should (= (org-export-resolve-coderef "text" info
) 1)))
1427 ;; 7. Recognize coderef with user-specified syntax.
1428 (org-test-with-parsed-data
1429 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1430 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1432 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1433 "Test `org-export-resolve-fuzzy-link' specifications."
1434 ;; 1. Match target objects.
1435 (org-test-with-parsed-data "<<target>> [[target]]"
1437 (org-export-resolve-fuzzy-link
1438 (org-element-map tree
'link
'identity info t
) info
)))
1439 ;; 2. Match target elements.
1440 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1442 (org-export-resolve-fuzzy-link
1443 (org-element-map tree
'link
'identity info t
) info
)))
1444 ;; 3. Match named elements.
1445 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1447 (org-export-resolve-fuzzy-link
1448 (org-element-map tree
'link
'identity info t
) info
)))
1449 ;; 4. Match exact headline's name.
1450 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1452 (org-export-resolve-fuzzy-link
1453 (org-element-map tree
'link
'identity info t
) info
)))
1454 ;; 5. Targets objects have priority over named elements and headline
1456 (org-test-with-parsed-data
1457 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1461 (org-export-resolve-fuzzy-link
1462 (org-element-map tree
'link
'identity info t
) info
)))))
1463 ;; 6. Named elements have priority over headline titles.
1464 (org-test-with-parsed-data
1465 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1469 (org-export-resolve-fuzzy-link
1470 (org-element-map tree
'link
'identity info t
) info
)))))
1471 ;; 7. If link's path starts with a "*", only match headline titles,
1473 (org-test-with-parsed-data
1474 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1478 (org-export-resolve-fuzzy-link
1479 (org-element-map tree
'link
'identity info t
) info
)))))
1480 ;; 8. Return nil if no match.
1481 (org-test-with-parsed-data "[[target]]"
1483 (org-export-resolve-fuzzy-link
1484 (org-element-map tree
'link
'identity info t
) info
))))
1486 (ert-deftest test-org-export
/resolve-id-link
()
1487 "Test `org-export-resolve-id-link' specifications."
1488 ;; 1. Regular test for custom-id link.
1489 (org-test-with-parsed-data "* Headline1
1496 (org-export-resolve-id-link
1497 (org-element-map tree
'link
'identity info t
) info
)))
1498 ;; 2. Failing test for custom-id link.
1499 (org-test-with-parsed-data "* Headline1
1506 (org-export-resolve-id-link
1507 (org-element-map tree
'link
'identity info t
) info
)))
1508 ;; 3. Test for internal id target.
1509 (org-test-with-parsed-data "* Headline1
1516 (org-export-resolve-id-link
1517 (org-element-map tree
'link
'identity info t
) info
)))
1518 ;; 4. Test for external id target.
1519 (org-test-with-parsed-data "[[id:aaaa]]"
1521 (org-export-resolve-id-link
1522 (org-element-map tree
'link
'identity info t
)
1523 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1525 (ert-deftest test-org-export
/resolve-radio-link
()
1526 "Test `org-export-resolve-radio-link' specifications."
1529 (org-test-with-temp-text "<<<radio>>> radio"
1530 (org-update-radio-target-regexp)
1531 (let* ((tree (org-element-parse-buffer))
1532 (info `(:parse-tree
,tree
)))
1533 (org-export-resolve-radio-link
1534 (org-element-map tree
'link
'identity info t
)
1536 ;; Radio targets are case-insensitive.
1538 (org-test-with-temp-text "<<<RADIO>>> radio"
1539 (org-update-radio-target-regexp)
1540 (let* ((tree (org-element-parse-buffer))
1541 (info `(:parse-tree
,tree
)))
1542 (org-export-resolve-radio-link
1543 (org-element-map tree
'link
'identity info t
)
1545 ;; Radio target with objects.
1547 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1548 (org-update-radio-target-regexp)
1549 (let* ((tree (org-element-parse-buffer))
1550 (info `(:parse-tree
,tree
)))
1551 (org-export-resolve-radio-link
1552 (org-element-map tree
'link
'identity info t
)
1557 ;;; Src-block and example-block
1559 (ert-deftest test-org-export
/unravel-code
()
1560 "Test `org-export-unravel-code' function."
1561 (let ((org-coderef-label-format "(ref:%s)"))
1562 ;; 1. Code without reference.
1563 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1564 (should (equal (org-export-unravel-code (org-element-at-point))
1566 ;; 2. Code with reference.
1567 (org-test-with-temp-text
1568 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1569 (should (equal (org-export-unravel-code (org-element-at-point))
1570 '("(+ 1 1)\n" (1 .
"test")))))
1571 ;; 3. Code with user-defined reference.
1572 (org-test-with-temp-text
1573 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1574 (should (equal (org-export-unravel-code (org-element-at-point))
1575 '("(+ 1 1)\n" (1 .
"test")))))
1576 ;; 4. Code references keys are relative to the current block.
1577 (org-test-with-temp-text "
1586 (should (equal (org-export-unravel-code (org-element-at-point))
1587 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1589 (ert-deftest test-org-export
/format-code-default
()
1590 "Test `org-export-format-code-default' specifications."
1591 ;; Return the empty string when code is empty.
1594 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1595 (org-export-format-code-default
1596 (org-element-map tree
'src-block
'identity info t
) info
))))
1597 ;; Number lines, two whitespace characters before the actual loc.
1600 (org-test-with-parsed-data
1601 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1602 (org-export-format-code-default
1603 (org-element-map tree
'src-block
'identity info t
) info
))))
1604 ;; Put references 6 whitespace characters after the widest line,
1605 ;; wrapped within parenthesis.
1607 (equal "123 (a)\n1 (b)\n"
1608 (let ((org-coderef-label-format "(ref:%s)"))
1609 (org-test-with-parsed-data
1610 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1611 (org-export-format-code-default
1612 (org-element-map tree
'src-block
'identity info t
) info
))))))
1618 (ert-deftest test-org-export
/activate-smart-quotes
()
1619 "Test `org-export-activate-smart-quotes' specifications."
1620 ;; Opening double quotes: standard test.
1623 '("some “paragraph")
1624 (let ((org-export-default-language "en"))
1625 (org-test-with-parsed-data "some \"paragraph"
1628 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1630 ;; Opening quotes: at the beginning of a paragraph.
1634 (let ((org-export-default-language "en"))
1635 (org-test-with-parsed-data "\"begin"
1638 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1640 ;; Opening quotes: after an object.
1644 (let ((org-export-default-language "en"))
1645 (org-test-with-parsed-data "=verb= \"begin"
1648 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1650 ;; Closing quotes: standard test.
1653 '("some” paragraph")
1654 (let ((org-export-default-language "en"))
1655 (org-test-with-parsed-data "some\" paragraph"
1658 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1660 ;; Closing quotes: at the end of a paragraph.
1664 (let ((org-export-default-language "en"))
1665 (org-test-with-parsed-data "end\""
1668 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1670 ;; Apostrophe: standard test.
1673 '("It shouldn’t fail")
1674 (let ((org-export-default-language "en"))
1675 (org-test-with-parsed-data "It shouldn't fail"
1678 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1680 ;; Apostrophe: before an object.
1684 (let ((org-export-default-language "en"))
1685 (org-test-with-parsed-data "a'=b="
1688 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1690 ;; Apostrophe: after an object.
1694 (let ((org-export-default-language "en"))
1695 (org-test-with-parsed-data "=code='s"
1698 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1700 ;; Special case: isolated quotes.
1702 (equal '("“" "”")
1703 (let ((org-export-default-language "en"))
1704 (org-test-with-parsed-data "\"$x$\""
1707 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1709 ;; Smart quotes in secondary strings.
1711 (equal '("“" "”")
1712 (let ((org-export-default-language "en"))
1713 (org-test-with-parsed-data "* \"$x$\""
1716 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1718 ;; Smart quotes in document keywords.
1720 (equal '("“" "”")
1721 (let ((org-export-default-language "en"))
1722 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1724 (plist-get info
:title
) 'plain-text
1725 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1727 ;; Smart quotes in parsed affiliated keywords.
1729 (equal '("“" "”" "Paragraph")
1730 (let ((org-export-default-language "en"))
1731 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1734 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1735 info nil nil t
))))))
1741 (ert-deftest test-org-export
/special-column
()
1742 "Test if the table's special column is properly recognized."
1743 ;; 1. First column is special if it contains only a special marking
1744 ;; characters or empty cells.
1745 (org-test-with-temp-text "
1749 (org-export-table-has-special-column-p
1751 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1752 ;; 2. If the column contains anything else, it isn't special.
1753 (org-test-with-temp-text "
1757 (org-export-table-has-special-column-p
1759 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1760 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1762 (org-test-with-temp-text "
1771 (org-export-table-has-special-column-p
1773 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1774 ;; 4. A first column with only empty cells isn't considered as
1776 (org-test-with-temp-text "
1780 (org-export-table-has-special-column-p
1782 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1784 (ert-deftest test-org-export
/table-row-is-special-p
()
1785 "Test `org-export-table-row-is-special-p' specifications."
1786 ;; 1. A row is special if it has a special marking character in the
1788 (org-test-with-parsed-data "| ! | 1 |"
1790 (org-export-table-row-is-special-p
1791 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1792 ;; 2. A row is special when its first field is "/"
1793 (org-test-with-parsed-data "
1797 (org-export-table-row-is-special-p
1798 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1799 ;; 3. A row only containing alignment cookies is also considered as
1801 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1803 (org-export-table-row-is-special-p
1804 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1805 ;; 4. Everything else isn't considered as special.
1806 (org-test-with-parsed-data "| \alpha | | c |"
1808 (org-export-table-row-is-special-p
1809 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1810 ;; 5. Table's rules are never considered as special rows.
1811 (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
))))
1816 (ert-deftest test-org-export
/has-header-p
()
1817 "Test `org-export-table-has-header-p' specifications."
1818 ;; 1. With an header.
1819 (org-test-with-parsed-data "
1824 (org-export-table-has-header-p
1825 (org-element-map tree
'table
'identity info
'first-match
)
1827 ;; 2. Without an header.
1828 (org-test-with-parsed-data "
1832 (org-export-table-has-header-p
1833 (org-element-map tree
'table
'identity info
'first-match
)
1835 ;; 3. Don't get fooled with starting and ending rules.
1836 (org-test-with-parsed-data "
1842 (org-export-table-has-header-p
1843 (org-element-map tree
'table
'identity info
'first-match
)
1846 (ert-deftest test-org-export
/table-row-group
()
1847 "Test `org-export-table-row-group' specifications."
1848 ;; 1. A rule creates a new group.
1849 (org-test-with-parsed-data "
1856 (mapcar (lambda (row) (org-export-table-row-group row info
))
1857 (org-element-map tree
'table-row
'identity
)))))
1858 ;; 2. Special rows are ignored in count.
1859 (org-test-with-parsed-data "
1866 (mapcar (lambda (row) (org-export-table-row-group row info
))
1867 (org-element-map tree
'table-row
'identity
)))))
1868 ;; 3. Double rules also are ignored in count.
1869 (org-test-with-parsed-data "
1877 (mapcar (lambda (row) (org-export-table-row-group row info
))
1878 (org-element-map tree
'table-row
'identity
))))))
1880 (ert-deftest test-org-export
/table-cell-width
()
1881 "Test `org-export-table-cell-width' specifications."
1882 ;; 1. Width is primarily determined by width cookies. If no cookie
1883 ;; is found, cell's width is nil.
1884 (org-test-with-parsed-data "
1885 | / | <l> | <6> | <l7> |
1890 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1891 (org-element-map tree
'table-cell
'identity info
)))))
1892 ;; 2. The last width cookie has precedence.
1893 (org-test-with-parsed-data "
1900 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1901 (org-element-map tree
'table-cell
'identity info
)))))
1902 ;; 3. Valid width cookies must have a specific row.
1903 (org-test-with-parsed-data "| <6> | cell |"
1907 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1908 (org-element-map tree
'table-cell
'identity
))))))
1910 (ert-deftest test-org-export
/table-cell-alignment
()
1911 "Test `org-export-table-cell-alignment' specifications."
1912 (let ((org-table-number-fraction 0.5)
1913 (org-table-number-regexp "^[0-9]+$"))
1914 ;; 1. Alignment is primarily determined by alignment cookies.
1915 (org-test-with-temp-text "| <l> | <c> | <r> |"
1916 (let* ((tree (org-element-parse-buffer))
1917 (info `(:parse-tree
,tree
)))
1920 '(left center right
)
1921 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1922 (org-element-map tree
'table-cell
'identity
))))))
1923 ;; 2. The last alignment cookie has precedence.
1924 (org-test-with-parsed-data "
1930 '(right right right
)
1931 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1932 (org-element-map tree
'table-cell
'identity
)))))
1933 ;; 3. If there's no cookie, cell's contents determine alignment.
1934 ;; A column mostly made of cells containing numbers will align
1935 ;; its cells to the right.
1936 (org-test-with-parsed-data "
1942 '(right right right
)
1943 (mapcar (lambda (cell)
1944 (org-export-table-cell-alignment cell info
))
1945 (org-element-map tree
'table-cell
'identity
)))))
1946 ;; 4. Otherwise, they will be aligned to the left.
1947 (org-test-with-parsed-data "
1954 (mapcar (lambda (cell)
1955 (org-export-table-cell-alignment cell info
))
1956 (org-element-map tree
'table-cell
'identity
)))))))
1958 (ert-deftest test-org-export
/table-cell-borders
()
1959 "Test `org-export-table-cell-borders' specifications."
1960 ;; 1. Recognize various column groups indicators.
1961 (org-test-with-parsed-data "| / | < | > | <> |"
1964 '((right bottom top
) (left bottom top
) (right bottom top
)
1965 (right left bottom top
))
1966 (mapcar (lambda (cell)
1967 (org-export-table-cell-borders cell info
))
1968 (org-element-map tree
'table-cell
'identity
)))))
1969 ;; 2. Accept shortcuts to define column groups.
1970 (org-test-with-parsed-data "| / | < | < |"
1973 '((right bottom top
) (right left bottom top
) (left bottom top
))
1974 (mapcar (lambda (cell)
1975 (org-export-table-cell-borders cell info
))
1976 (org-element-map tree
'table-cell
'identity
)))))
1977 ;; 3. A valid column groups row must start with a "/".
1978 (org-test-with-parsed-data "
1982 (equal '((top) (top) (bottom) (bottom))
1983 (mapcar (lambda (cell)
1984 (org-export-table-cell-borders cell info
))
1985 (org-element-map tree
'table-cell
'identity
)))))
1986 ;; 4. Take table rules into consideration.
1987 (org-test-with-parsed-data "
1992 (equal '((below top
) (bottom above
))
1993 (mapcar (lambda (cell)
1994 (org-export-table-cell-borders cell info
))
1995 (org-element-map tree
'table-cell
'identity
)))))
1996 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1997 ;; (resp. `bottom' and `below') borders. Any special row is
1999 (org-test-with-parsed-data "
2005 (equal '((bottom below top above
))
2007 (mapcar (lambda (cell)
2008 (org-export-table-cell-borders cell info
))
2009 (org-element-map tree
'table-cell
'identity
)))))))
2011 (ert-deftest test-org-export
/table-dimensions
()
2012 "Test `org-export-table-dimensions' specifications."
2013 ;; 1. Standard test.
2014 (org-test-with-parsed-data "
2019 (org-export-table-dimensions
2020 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2021 ;; 2. Ignore horizontal rules and special columns.
2022 (org-test-with-parsed-data "
2029 (org-export-table-dimensions
2030 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2032 (ert-deftest test-org-export
/table-cell-address
()
2033 "Test `org-export-table-cell-address' specifications."
2034 ;; 1. Standard test: index is 0-based.
2035 (org-test-with-parsed-data "| a | b |"
2037 (equal '((0 .
0) (0 .
1))
2040 (lambda (cell) (org-export-table-cell-address cell info
))
2042 ;; 2. Special column isn't counted, nor are special rows.
2043 (org-test-with-parsed-data "
2048 (org-export-table-cell-address
2049 (car (last (org-element-map tree
'table-cell
'identity info
)))
2051 ;; 3. Tables rules do not count either.
2052 (org-test-with-parsed-data "
2060 (org-export-table-cell-address
2061 (car (last (org-element-map tree
'table-cell
'identity info
)))
2063 ;; 4. Return nil for special cells.
2064 (org-test-with-parsed-data "| / | a |"
2066 (org-export-table-cell-address
2067 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2070 (ert-deftest test-org-export
/get-table-cell-at
()
2071 "Test `org-export-get-table-cell-at' specifications."
2072 ;; 1. Address ignores special columns, special rows and rules.
2073 (org-test-with-parsed-data "
2080 (org-element-contents
2081 (org-export-get-table-cell-at
2083 (org-element-map tree
'table
'identity info
'first-match
)
2085 ;; 2. Return value for a non-existent address is nil.
2086 (org-test-with-parsed-data "| a |"
2088 (org-export-get-table-cell-at
2090 (org-element-map tree
'table
'identity info
'first-match
)
2092 (org-test-with-parsed-data "| / |"
2094 (org-export-get-table-cell-at
2096 (org-element-map tree
'table
'identity info
'first-match
)
2099 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2100 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2101 ;; 1. A cell at a beginning of a row always starts a column group.
2102 (org-test-with-parsed-data "| a |"
2104 (org-export-table-cell-starts-colgroup-p
2105 (org-element-map tree
'table-cell
'identity info
'first-match
)
2107 ;; 2. Special column should be ignored when determining the
2108 ;; beginning of the row.
2109 (org-test-with-parsed-data "
2113 (org-export-table-cell-starts-colgroup-p
2114 (org-element-map tree
'table-cell
'identity info
'first-match
)
2116 ;; 2. Explicit column groups.
2117 (org-test-with-parsed-data "
2126 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2129 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2130 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2131 ;; 1. A cell at the end of a row always ends a column group.
2132 (org-test-with-parsed-data "| a |"
2134 (org-export-table-cell-ends-colgroup-p
2135 (org-element-map tree
'table-cell
'identity info
'first-match
)
2137 ;; 2. Special column should be ignored when determining the
2138 ;; beginning of the row.
2139 (org-test-with-parsed-data "
2143 (org-export-table-cell-ends-colgroup-p
2144 (org-element-map tree
'table-cell
'identity info
'first-match
)
2146 ;; 3. Explicit column groups.
2147 (org-test-with-parsed-data "
2156 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2159 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2160 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2161 ;; 1. A row at the beginning of a table always starts a row group.
2162 ;; So does a row following a table rule.
2163 (org-test-with-parsed-data "
2173 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2175 ;; 2. Special rows should be ignored when determining the beginning
2177 (org-test-with-parsed-data "
2189 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2192 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2193 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2194 ;; 1. A row at the end of a table always ends a row group. So does
2195 ;; a row preceding a table rule.
2196 (org-test-with-parsed-data "
2206 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2208 ;; 2. Special rows should be ignored when determining the beginning
2210 (org-test-with-parsed-data "
2222 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2225 (ert-deftest test-org-export
/table-row-starts-header-p
()
2226 "Test `org-export-table-row-starts-header-p' specifications."
2227 ;; 1. Only the row starting the first row group starts the table
2229 (org-test-with-parsed-data "
2240 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2242 ;; 2. A row cannot start an header if there's no header in the
2244 (org-test-with-parsed-data "
2248 (org-export-table-row-starts-header-p
2249 (org-element-map tree
'table-row
'identity info
'first-match
)
2252 (ert-deftest test-org-export
/table-row-ends-header-p
()
2253 "Test `org-export-table-row-ends-header-p' specifications."
2254 ;; 1. Only the row starting the first row group starts the table
2256 (org-test-with-parsed-data "
2267 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2269 ;; 2. A row cannot start an header if there's no header in the
2271 (org-test-with-parsed-data "
2275 (org-export-table-row-ends-header-p
2276 (org-element-map tree
'table-row
'identity info
'first-match
)
2283 (ert-deftest test-org-export
/inner-template
()
2284 "Test `inner-template' translator specifications."
2287 (let (org-export-registered-backends)
2288 (org-export-define-backend test
2289 ((inner-template .
(lambda (contents info
) "Success!"))
2290 (headline .
(lambda (h c i
) "Headline"))))
2291 (org-test-with-temp-text "* Headline"
2292 (org-export-as 'test
)))))
2293 ;; Inner template is applied even in a "body-only" export.
2296 (let (org-export-registered-backends)
2297 (org-export-define-backend test
2298 ((inner-template .
(lambda (contents info
) "Success!"))
2299 (headline .
(lambda (h c i
) "Headline"))))
2300 (org-test-with-temp-text "* Headline"
2301 (org-export-as 'test nil nil
'body-only
))))))
2303 (ert-deftest test-org-export
/template
()
2304 "Test `template' translator specifications."
2307 (let (org-export-registered-backends)
2308 (org-export-define-backend test
2309 ((template .
(lambda (contents info
) "Success!"))
2310 (headline .
(lambda (h c i
) "Headline"))))
2311 (org-test-with-temp-text "* Headline"
2312 (org-export-as 'test
)))))
2313 ;; Template is not applied in a "body-only" export.
2316 (let (org-export-registered-backends)
2317 (org-export-define-backend test
2318 ((template .
(lambda (contents info
) "Success!"))
2319 (headline .
(lambda (h c i
) "Headline"))))
2320 (org-test-with-temp-text "* Headline"
2321 (org-export-as 'test nil nil
'body-only
))))))
2327 (ert-deftest test-org-export
/get-next-element
()
2328 "Test `org-export-get-next-element' specifications."
2332 (org-test-with-parsed-data "* Headline\n*a* b"
2333 (org-export-get-next-element
2334 (org-element-map tree
'bold
'identity info t
) info
))))
2335 ;; Return nil when no previous element.
2337 (org-test-with-parsed-data "* Headline\na *b*"
2338 (org-export-get-next-element
2339 (org-element-map tree
'bold
'identity info t
) info
)))
2340 ;; Non-exportable elements are ignored.
2342 (let ((org-export-with-timestamps nil
))
2343 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2344 (org-export-get-next-element
2345 (org-element-map tree
'entity
'identity info t
) info
))))
2346 ;; Find next element in secondary strings.
2349 (org-test-with-parsed-data "* a =verb="
2351 (org-export-get-next-element
2352 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2353 ;; Find next element in document keywords.
2356 (org-test-with-parsed-data "#+TITLE: a =verb="
2358 (org-export-get-next-element
2360 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2361 ;; Find next element in parsed affiliated keywords.
2364 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2366 (org-export-get-next-element
2367 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2368 ;; With optional argument N, return a list containing all the
2369 ;; following elements.
2372 '(bold code underline
)
2373 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2375 (org-export-get-next-element
2376 (org-element-map tree
'italic
'identity info t
) info t
)))))
2377 ;; When N is a positive integer, return a list containing up to
2378 ;; N following elements.
2382 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2384 (org-export-get-next-element
2385 (org-element-map tree
'italic
'identity info t
) info
2))))))
2387 (ert-deftest test-org-export
/get-previous-element
()
2388 "Test `org-export-get-previous-element' specifications."
2392 (org-test-with-parsed-data "* Headline\na *b*"
2393 (org-export-get-previous-element
2394 (org-element-map tree
'bold
'identity info t
) info
))))
2395 ;; Return nil when no previous element.
2397 (org-test-with-parsed-data "* Headline\n*a* b"
2398 (org-export-get-previous-element
2399 (org-element-map tree
'bold
'identity info t
) info
)))
2400 ;; Non-exportable elements are ignored.
2402 (let ((org-export-with-timestamps nil
))
2403 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2404 (org-export-get-previous-element
2405 (org-element-map tree
'entity
'identity info t
) info
))))
2406 ;; Find previous element in secondary strings.
2409 (org-test-with-parsed-data "* =verb= a"
2411 (org-export-get-previous-element
2412 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2413 ;; Find previous element in document keywords.
2416 (org-test-with-parsed-data "#+TITLE: =verb= a"
2418 (org-export-get-previous-element
2420 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2421 ;; Find previous element in parsed affiliated keywords.
2424 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2426 (org-export-get-previous-element
2427 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2428 ;; With optional argument N, return a list containing up to
2429 ;; N previous elements.
2431 (equal '(underline italic bold
)
2432 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2434 (org-export-get-previous-element
2435 (org-element-map tree
'code
'identity info t
) info t
)))))
2436 ;; When N is a positive integer, return a list containing up to
2437 ;; N previous elements.
2439 (equal '(italic bold
)
2440 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2442 (org-export-get-previous-element
2443 (org-element-map tree
'code
'identity info t
) info
2))))))
2447 ;;; test-org-export.el end here