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))))
654 ;; Return nil on "nil" string.
656 (equal '(:a nil
:b nil
)
657 (org-export-read-attribute
659 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
660 (org-element-at-point)))))
661 ;; Return nil on empty string.
663 (equal '(:a nil
:b nil
)
664 (org-export-read-attribute
666 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
667 (org-element-at-point)))))
668 ;; Ignore text before first property.
671 (org-export-read-attribute
673 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
674 (org-element-at-point))))))
676 (ert-deftest test-org-export
/get-caption
()
677 "Test `org-export-get-caption' specifications."
678 ;; Without optional argument, return long caption
682 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
683 (org-export-get-caption (org-element-at-point)))))
684 ;; With optional argument, return short caption.
688 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
689 (org-export-get-caption (org-element-at-point) t
))))
690 ;; Multiple lines are separated by white spaces.
694 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
695 (org-export-get-caption (org-element-at-point))))))
701 (ert-deftest test-org-export
/define-backend
()
702 "Test back-end definition and accessors."
705 (equal '((headline . my-headline-test
))
706 (let (org-export-registered-backends)
707 (org-export-define-backend test
((headline . my-headline-test
)))
708 (org-export-backend-translate-table 'test
))))
711 (equal '((:filter-headline . my-filter
))
712 (let (org-export-registered-backends)
713 (org-export-define-backend test
714 ((headline . my-headline-test
))
715 :filters-alist
((:filter-headline . my-filter
)))
716 (org-export-backend-filters 'test
))))
719 (equal '((:prop value
))
720 (let (org-export-registered-backends)
721 (org-export-define-backend test
722 ((headline . my-headline-test
))
723 :options-alist
((:prop value
)))
724 (org-export-backend-options 'test
))))
727 (equal '(?k
"Test Export" test
)
728 (let (org-export-registered-backends)
729 (org-export-define-backend test
730 ((headline . my-headline-test
))
731 :menu-entry
(?k
"Test Export" test
))
732 (org-export-backend-menu 'test
))))
735 (equal '(("TEST" . org-element-export-block-parser
))
736 (let (org-export-registered-backends org-element-block-name-alist
)
737 (org-export-define-backend test
738 ((headline . my-headline-test
))
739 :export-block
("test"))
740 org-element-block-name-alist
))))
742 (ert-deftest test-org-export
/define-derived-backend
()
743 "Test `org-export-define-derived-backend' specifications."
744 ;; Error when parent back-end is not defined.
746 (let (org-export-registered-backends)
747 (org-export-define-derived-backend test parent
)))
748 ;; Append translation table to parent's.
750 (equal '((:headline . test
) (:headline . parent
))
751 (let (org-export-registered-backends)
752 (org-export-define-backend parent
((:headline . parent
)))
753 (org-export-define-derived-backend test parent
754 :translate-alist
((:headline . test
)))
755 (org-export-backend-translate-table 'test
))))
756 ;; Options defined in the new back have priority over those defined
760 (let (org-export-registered-backends)
761 (org-export-define-backend parent
762 ((:headline . parent
))
763 :options-alist
((:a nil nil
'parent
)))
764 (org-export-define-derived-backend test parent
765 :options-alist
((:a nil nil
'test
)))
766 (plist-get (org-export--get-global-options 'test
) :a
)))))
768 (ert-deftest test-org-export
/derived-backend-p
()
769 "Test `org-export-derived-backend-p' specifications."
770 ;; Non-nil with direct match.
772 (let (org-export-registered-backends)
773 (org-export-define-backend test
((headline . test
)))
774 (org-export-derived-backend-p 'test
'test
)))
776 (let (org-export-registered-backends)
777 (org-export-define-backend test
((headline . test
)))
778 (org-export-define-derived-backend test2 test
)
779 (org-export-derived-backend-p 'test2
'test2
)))
780 ;; Non-nil with a direct parent.
782 (let (org-export-registered-backends)
783 (org-export-define-backend test
((headline . test
)))
784 (org-export-define-derived-backend test2 test
)
785 (org-export-derived-backend-p 'test2
'test
)))
786 ;; Non-nil with an indirect parent.
788 (let (org-export-registered-backends)
789 (org-export-define-backend test
((headline . test
)))
790 (org-export-define-derived-backend test2 test
)
791 (org-export-define-derived-backend test3 test2
)
792 (org-export-derived-backend-p 'test3
'test
)))
795 (let (org-export-registered-backends)
796 (org-export-define-backend test
((headline . test
)))
797 (org-export-define-backend test2
((headline . test2
)))
798 (org-export-derived-backend-p 'test2
'test
)))
800 (let (org-export-registered-backends)
801 (org-export-define-backend test
((headline . test
)))
802 (org-export-define-backend test2
((headline . test2
)))
803 (org-export-define-derived-backend test3 test2
)
804 (org-export-derived-backend-p 'test3
'test
))))
806 (ert-deftest test-org-export
/with-backend
()
807 "Test `org-export-with-backend' definition."
808 ;; Error when calling an undefined back-end
810 (let (org-export-registered-backends)
811 (org-export-with-backend 'test
"Test")))
812 ;; Error when called back-end doesn't have an appropriate
815 (let (org-export-registered-backends)
816 (org-export-define-backend test
((headline . ignore
)))
817 (org-export-with-backend 'test
"Test")))
818 ;; Otherwise, export using correct transcoder
821 (let (org-export-registered-backends)
822 (org-export-define-backend test
823 ((plain-text .
(lambda (text contents info
) "Failure"))))
824 (org-export-define-backend test2
825 ((plain-text .
(lambda (text contents info
) "Success"))))
826 (org-export-with-backend 'test2
"Test")))))
828 (ert-deftest test-org-export
/data-with-translations
()
829 "Test `org-export-data-with-translations' specifications."
833 (org-export-data-with-translations
835 '((plain-text .
(lambda (text info
) "Success"))
836 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
837 '(:with-emphasize t
)))))
839 (ert-deftest test-org-export
/data-with-backend
()
840 "Test `org-export-data-with-backend' specifications."
841 ;; Error when calling an undefined back-end.
843 (let (org-export-registered-backends)
844 (org-export-data-with-backend 'test
"Test" nil
)))
845 ;; Otherwise, export data recursively, using correct back-end.
849 (let (org-export-registered-backends)
850 (org-export-define-backend test
851 ((plain-text .
(lambda (text info
) "Success"))
852 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
853 (org-export-data-with-backend
854 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
860 (ert-deftest test-org-export
/export-snippet
()
861 "Test export snippets transcoding."
862 (org-test-with-temp-text "@@test:A@@@@t:B@@"
863 (org-test-with-backend test
865 (cdr (assq 'test org-export-registered-backends
))
867 (cons (cons 'export-snippet
868 (lambda (snippet contents info
)
869 (when (eq (org-export-snippet-backend snippet
) 'test
)
870 (org-element-property :value snippet
))))
871 (org-export-backend-translate-table 'test
)))
872 (let ((org-export-snippet-translation-alist nil
))
873 (should (equal (org-export-as 'test
) "A\n")))
874 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
875 (should (equal (org-export-as 'test
) "AB\n"))))))
881 (ert-deftest test-org-export
/footnotes
()
882 "Test footnotes specifications."
883 (let ((org-footnote-section nil
)
884 (org-export-with-footnotes t
))
885 ;; 1. Read every type of footnote.
888 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
889 (org-test-with-parsed-data
890 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
892 tree
'footnote-reference
894 (let ((def (org-export-get-footnote-definition ref info
)))
895 (cons (org-export-get-footnote-number ref info
)
896 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
897 (car (org-element-contents
898 (car (org-element-contents def
))))))))
900 ;; 2. Test nested footnotes order.
901 (org-test-with-parsed-data
902 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
905 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
907 tree
'footnote-reference
909 (when (org-export-footnote-first-reference-p ref info
)
910 (cons (org-export-get-footnote-number ref info
)
911 (org-element-property :label ref
))))
913 ;; 3. Test nested footnote in invisible definitions.
914 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
916 (narrow-to-region (point) (point-at-eol))
917 (let* ((tree (org-element-parse-buffer))
918 (info (org-combine-plists
920 (org-export-collect-tree-properties
921 tree
(org-export-get-environment)))))
922 ;; Both footnotes should be seen.
924 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
925 ;; 4. Test footnotes definitions collection.
926 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
928 \[fn:2] B [fn:3] [fn::D].
931 (should (= (length (org-export-collect-footnote-definitions tree info
))
933 ;; 5. Test export of footnotes defined outside parsing scope.
934 (org-test-with-temp-text "[fn:1] Out of scope
937 (org-test-with-backend test
939 (cdr (assq 'test org-export-registered-backends
))
941 (cons (cons 'footnote-reference
942 (lambda (fn contents info
)
943 (org-element-interpret-data
944 (org-export-get-footnote-definition fn info
))))
945 (org-export-backend-translate-table 'test
)))
947 (should (equal "ParagraphOut of scope\n"
948 (org-export-as 'test
'subtree
)))))
949 ;; 6. Footnotes without a definition should be provided a fallback
952 (org-test-with-parsed-data "[fn:1]"
953 (org-export-get-footnote-definition
954 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
955 ;; 7. Footnote section should be ignored in TOC and in headlines
958 (= 1 (let ((org-footnote-section "Footnotes"))
959 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
960 (org-export-collect-headlines info
))))))
963 (let ((org-footnote-section "Footnotes"))
964 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
965 (org-element-map tree
'headline
967 (when (equal (org-element-property :raw-value hl
) "H2")
968 (org-export-get-headline-number hl info
)))
973 ;;; Headlines and Inlinetasks
975 (ert-deftest test-org-export
/get-relative-level
()
976 "Test `org-export-get-relative-level' specifications."
980 (let ((org-odd-levels-only nil
))
981 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
984 (lambda (h) (org-export-get-relative-level h info
))
989 (let ((org-odd-levels-only nil
))
990 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
993 (lambda (h) (org-export-get-relative-level h info
))
996 (ert-deftest test-org-export
/low-level-p
()
997 "Test `org-export-low-level-p' specifications."
1001 (let ((org-odd-levels-only nil
))
1002 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1005 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1006 (plist-put info
:headline-levels
1)))))))
1008 (ert-deftest test-org-export
/get-headline-number
()
1009 "Test `org-export-get-headline-number' specifications."
1014 (let ((org-odd-levels-only nil
))
1015 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1018 (lambda (h) (org-export-get-headline-number h info
))
1020 ;; Missing levels are replaced with 0.
1024 (let ((org-odd-levels-only nil
))
1025 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1028 (lambda (h) (org-export-get-headline-number h info
))
1031 (ert-deftest test-org-export
/numbered-headline-p
()
1032 "Test `org-export-numbered-headline-p' specifications."
1033 ;; If `:section-numbers' is nil, never number headlines.
1035 (org-test-with-parsed-data "* Headline"
1038 (lambda (h) (org-export-numbered-headline-p h info
))
1039 (plist-put info
:section-numbers nil
))))
1040 ;; If `:section-numbers' is a number, only number headlines with
1041 ;; a level greater that it.
1045 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1048 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1049 (plist-put info
:section-numbers
1)))))
1050 ;; Otherwise, headlines are always numbered.
1052 (org-test-with-parsed-data "* Headline"
1055 (lambda (h) (org-export-numbered-headline-p h info
))
1056 (plist-put info
:section-numbers t
)))))
1058 (ert-deftest test-org-export
/number-to-roman
()
1059 "Test `org-export-number-to-roman' specifications."
1060 ;; If number is negative, return it as a string.
1061 (should (equal (org-export-number-to-roman -
1) "-1"))
1062 ;; Otherwise, return it as a roman number.
1063 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1065 (ert-deftest test-org-export
/get-optional-title
()
1066 "Test `org-export-get-alt-title' specifications."
1067 ;; If ALT_TITLE property is defined, use it.
1070 (org-test-with-parsed-data
1071 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1072 (org-export-get-alt-title
1073 (org-element-map tree
'headline
'identity info t
)
1075 ;; Otherwise, fall-back to regular title.
1077 (equal '("Headline")
1078 (org-test-with-parsed-data "* Headline"
1079 (org-export-get-alt-title
1080 (org-element-map tree
'headline
'identity info t
)
1083 (ert-deftest test-org-export
/get-tags
()
1084 "Test `org-export-get-tags' specifications."
1085 (let ((org-export-exclude-tags '("noexport"))
1086 (org-export-select-tags '("export")))
1087 ;; Standard test: tags which are not a select tag, an exclude tag,
1088 ;; or specified as optional argument shouldn't be ignored.
1090 (org-test-with-parsed-data "* Headline :tag:"
1091 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1093 ;; Exclude tags are removed.
1095 (org-test-with-parsed-data "* Headline :noexport:"
1096 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1098 ;; Select tags are removed.
1100 (org-test-with-parsed-data "* Headline :export:"
1101 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1106 (org-test-with-parsed-data "* Headline :tag:export:"
1107 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1109 ;; Tags provided in the optional argument are also ignored.
1111 (org-test-with-parsed-data "* Headline :ignore:"
1112 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1114 ;; Allow tag inheritance.
1118 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1121 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1122 ;; Tag inheritance checks FILETAGS keywords.
1126 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1129 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1131 (ert-deftest test-org-export
/get-node-property
()
1132 "Test`org-export-get-node-property' specifications."
1136 (org-test-with-parsed-data "* Headline
1140 (org-export-get-node-property
1141 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1142 ;; Test inheritance.
1145 (org-test-with-parsed-data "* Parent
1151 (org-export-get-node-property
1152 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1153 ;; Cannot return a value before the first headline.
1155 (org-test-with-parsed-data "Paragraph
1160 (org-export-get-node-property
1161 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1163 (ert-deftest test-org-export
/get-category
()
1164 "Test `org-export-get-category' specifications."
1168 (org-test-with-parsed-data "* Headline
1172 (org-export-get-category
1173 (org-element-map tree
'headline
'identity nil t
) info
))))
1174 ;; Test inheritance from a parent headline.
1176 (equal '("value" "value")
1177 (org-test-with-parsed-data "* Headline1
1184 (lambda (hl) (org-export-get-category hl info
)) info
))))
1185 ;; Test inheritance from #+CATEGORY keyword
1188 (org-test-with-parsed-data "#+CATEGORY: value
1190 (org-export-get-category
1191 (org-element-map tree
'headline
'identity nil t
) info
))))
1192 ;; Test inheritance from file name.
1195 (org-test-with-parsed-data "* Headline"
1196 (let ((info (plist-put info
:input-file
"~/test.org")))
1197 (org-export-get-category
1198 (org-element-map tree
'headline
'identity nil t
) info
)))))
1202 (org-test-with-parsed-data "* Headline"
1203 (org-export-get-category
1204 (org-element-map tree
'headline
'identity nil t
) info
)))))
1206 (ert-deftest test-org-export
/first-sibling-p
()
1207 "Test `org-export-first-sibling-p' specifications."
1212 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1215 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1217 ;; Ignore headlines not exported.
1221 (let ((org-export-exclude-tags '("ignore")))
1222 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1225 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1228 (ert-deftest test-org-export
/last-sibling-p
()
1229 "Test `org-export-last-sibling-p' specifications."
1234 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1237 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1239 ;; Ignore headlines not exported.
1243 (let ((org-export-exclude-tags '("ignore")))
1244 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1247 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1250 (ert-deftest test-org-export
/handle-inlinetasks
()
1251 "Test inlinetask export."
1252 ;; Inlinetask with an exclude tag.
1253 (when (featurep 'org-inlinetask
)
1257 (let ((org-inlinetask-min-level 3))
1258 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1259 (org-test-with-backend test
1260 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp"))))))))
1261 ;; Inlinetask with an include tag.
1264 "* H2\n*** Inline :exp:\n"
1265 (let ((org-inlinetask-min-level 3)
1266 (org-tags-column 0))
1267 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1268 (org-test-with-backend test
1269 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
1270 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1273 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1274 (org-inlinetask-min-level 3))
1275 (org-test-with-temp-text "*** TODO Inline"
1276 (org-test-with-backend test
1277 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))))
1283 (ert-deftest test-org-export
/get-coderef-format
()
1284 "Test `org-export-get-coderef-format' specifications."
1285 ;; A link without description returns "%s"
1286 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1288 ;; Return "%s" when path is matched within description.
1289 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1291 ;; Otherwise return description.
1292 (should (equal (org-export-get-coderef-format "path" "desc")
1295 (ert-deftest test-org-export
/inline-image-p
()
1296 "Test `org-export-inline-image-p' specifications."
1298 (org-export-inline-image-p
1299 (org-test-with-temp-text "[[#id]]"
1301 (org-element-parse-buffer) 'link
'identity nil t
))
1302 '(("custom-id" .
"id")))))
1304 (ert-deftest test-org-export
/fuzzy-link
()
1305 "Test fuzzy links specifications."
1306 ;; 1. Links to invisible (keyword) targets should be ignored.
1307 (org-test-with-parsed-data
1308 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1313 (org-export-get-ordinal
1314 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1315 ;; 2. Link to an headline should return headline's number.
1316 (org-test-with-parsed-data
1317 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1319 ;; Note: Headline's number is in fact a list of numbers.
1324 (org-export-get-ordinal
1325 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1326 ;; 3. Link to a target in an item should return item's number.
1327 (org-test-with-parsed-data
1328 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1330 ;; Note: Item's number is in fact a list of numbers.
1335 (org-export-get-ordinal
1336 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1337 ;; 4. Link to a target in a footnote should return footnote's
1339 (org-test-with-parsed-data "
1340 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1346 (org-export-get-ordinal
1347 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1348 ;; 5. Link to a named element should return sequence number of that
1350 (org-test-with-parsed-data
1351 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1357 (org-export-get-ordinal
1358 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1359 ;; 6. Link to a target not within an item, a table, a footnote
1360 ;; reference or definition should return section number.
1361 (org-test-with-parsed-data
1362 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1368 (org-export-get-ordinal
1369 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1370 ;; 7. Space are not significant when matching a fuzzy link.
1372 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1373 (org-element-map tree
'link
1374 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1376 ;; 8. Statistics cookies are ignored for headline match.
1378 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1379 (org-element-map tree
'link
1380 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1383 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1384 (org-element-map tree
'link
1385 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1388 (ert-deftest test-org-export
/resolve-coderef
()
1389 "Test `org-export-resolve-coderef' specifications."
1390 (let ((org-coderef-label-format "(ref:%s)"))
1391 ;; 1. A link to a "-n -k -r" block returns line number.
1392 (org-test-with-parsed-data
1393 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1394 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1395 (org-test-with-parsed-data
1396 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1397 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1398 ;; 2. A link to a "-n -r" block returns line number.
1399 (org-test-with-parsed-data
1400 "#+BEGIN_EXAMPLE -n -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 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1404 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1405 ;; 3. A link to a "-n" block returns coderef.
1406 (org-test-with-parsed-data
1407 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1408 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1409 (org-test-with-parsed-data
1410 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1411 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1412 ;; 4. A link to a "-r" block returns line number.
1413 (org-test-with-parsed-data
1414 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1415 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1416 (org-test-with-parsed-data
1417 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1418 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1419 ;; 5. A link to a block without a switch returns coderef.
1420 (org-test-with-parsed-data
1421 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1422 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1423 (org-test-with-parsed-data
1424 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1425 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1426 ;; 6. Correctly handle continued line numbers. A "+n" switch
1427 ;; should resume numbering from previous block with numbered
1428 ;; lines, ignoring blocks not numbering lines in the process.
1429 ;; A "-n" switch resets count.
1430 (org-test-with-parsed-data "
1435 #+BEGIN_SRC emacs-lisp
1439 #+BEGIN_SRC emacs-lisp +n -r
1440 \(+ 1 1) (ref:addition)
1443 #+BEGIN_EXAMPLE -n -r
1444 Another text. (ref:text)
1446 (should (= (org-export-resolve-coderef "addition" info
) 2))
1447 (should (= (org-export-resolve-coderef "text" info
) 1)))
1448 ;; 7. Recognize coderef with user-specified syntax.
1449 (org-test-with-parsed-data
1450 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1451 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1453 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1454 "Test `org-export-resolve-fuzzy-link' specifications."
1455 ;; 1. Match target objects.
1456 (org-test-with-parsed-data "<<target>> [[target]]"
1458 (org-export-resolve-fuzzy-link
1459 (org-element-map tree
'link
'identity info t
) info
)))
1460 ;; 2. Match target elements.
1461 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1463 (org-export-resolve-fuzzy-link
1464 (org-element-map tree
'link
'identity info t
) info
)))
1465 ;; 3. Match named elements.
1466 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1468 (org-export-resolve-fuzzy-link
1469 (org-element-map tree
'link
'identity info t
) info
)))
1470 ;; 4. Match exact headline's name.
1471 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1473 (org-export-resolve-fuzzy-link
1474 (org-element-map tree
'link
'identity info t
) info
)))
1475 ;; 5. Targets objects have priority over named elements and headline
1477 (org-test-with-parsed-data
1478 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1482 (org-export-resolve-fuzzy-link
1483 (org-element-map tree
'link
'identity info t
) info
)))))
1484 ;; 6. Named elements have priority over headline titles.
1485 (org-test-with-parsed-data
1486 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1490 (org-export-resolve-fuzzy-link
1491 (org-element-map tree
'link
'identity info t
) info
)))))
1492 ;; 7. If link's path starts with a "*", only match headline titles,
1494 (org-test-with-parsed-data
1495 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1499 (org-export-resolve-fuzzy-link
1500 (org-element-map tree
'link
'identity info t
) info
)))))
1501 ;; 8. Return nil if no match.
1502 (org-test-with-parsed-data "[[target]]"
1504 (org-export-resolve-fuzzy-link
1505 (org-element-map tree
'link
'identity info t
) info
))))
1507 (ert-deftest test-org-export
/resolve-id-link
()
1508 "Test `org-export-resolve-id-link' specifications."
1509 ;; 1. Regular test for custom-id link.
1510 (org-test-with-parsed-data "* Headline1
1517 (org-export-resolve-id-link
1518 (org-element-map tree
'link
'identity info t
) info
)))
1519 ;; 2. Failing test for custom-id link.
1520 (org-test-with-parsed-data "* Headline1
1527 (org-export-resolve-id-link
1528 (org-element-map tree
'link
'identity info t
) info
)))
1529 ;; 3. Test for internal id target.
1530 (org-test-with-parsed-data "* Headline1
1537 (org-export-resolve-id-link
1538 (org-element-map tree
'link
'identity info t
) info
)))
1539 ;; 4. Test for external id target.
1540 (org-test-with-parsed-data "[[id:aaaa]]"
1542 (org-export-resolve-id-link
1543 (org-element-map tree
'link
'identity info t
)
1544 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1546 (ert-deftest test-org-export
/resolve-radio-link
()
1547 "Test `org-export-resolve-radio-link' specifications."
1550 (org-test-with-temp-text "<<<radio>>> radio"
1551 (org-update-radio-target-regexp)
1552 (let* ((tree (org-element-parse-buffer))
1553 (info `(:parse-tree
,tree
)))
1554 (org-export-resolve-radio-link
1555 (org-element-map tree
'link
'identity info t
)
1557 ;; Radio targets are case-insensitive.
1559 (org-test-with-temp-text "<<<RADIO>>> radio"
1560 (org-update-radio-target-regexp)
1561 (let* ((tree (org-element-parse-buffer))
1562 (info `(:parse-tree
,tree
)))
1563 (org-export-resolve-radio-link
1564 (org-element-map tree
'link
'identity info t
)
1566 ;; Radio target with objects.
1568 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1569 (org-update-radio-target-regexp)
1570 (let* ((tree (org-element-parse-buffer))
1571 (info `(:parse-tree
,tree
)))
1572 (org-export-resolve-radio-link
1573 (org-element-map tree
'link
'identity info t
)
1578 ;;; Src-block and example-block
1580 (ert-deftest test-org-export
/unravel-code
()
1581 "Test `org-export-unravel-code' function."
1582 (let ((org-coderef-label-format "(ref:%s)"))
1583 ;; 1. Code without reference.
1584 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1585 (should (equal (org-export-unravel-code (org-element-at-point))
1587 ;; 2. Code with reference.
1588 (org-test-with-temp-text
1589 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1590 (should (equal (org-export-unravel-code (org-element-at-point))
1591 '("(+ 1 1)\n" (1 .
"test")))))
1592 ;; 3. Code with user-defined reference.
1593 (org-test-with-temp-text
1594 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1595 (should (equal (org-export-unravel-code (org-element-at-point))
1596 '("(+ 1 1)\n" (1 .
"test")))))
1597 ;; 4. Code references keys are relative to the current block.
1598 (org-test-with-temp-text "
1607 (should (equal (org-export-unravel-code (org-element-at-point))
1608 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1610 (ert-deftest test-org-export
/format-code-default
()
1611 "Test `org-export-format-code-default' specifications."
1612 ;; Return the empty string when code is empty.
1615 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1616 (org-export-format-code-default
1617 (org-element-map tree
'src-block
'identity info t
) info
))))
1618 ;; Number lines, two whitespace characters before the actual loc.
1621 (org-test-with-parsed-data
1622 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1623 (org-export-format-code-default
1624 (org-element-map tree
'src-block
'identity info t
) info
))))
1625 ;; Put references 6 whitespace characters after the widest line,
1626 ;; wrapped within parenthesis.
1628 (equal "123 (a)\n1 (b)\n"
1629 (let ((org-coderef-label-format "(ref:%s)"))
1630 (org-test-with-parsed-data
1631 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1632 (org-export-format-code-default
1633 (org-element-map tree
'src-block
'identity info t
) info
))))))
1639 (ert-deftest test-org-export
/activate-smart-quotes
()
1640 "Test `org-export-activate-smart-quotes' specifications."
1641 ;; Opening double quotes: standard test.
1644 '("some “paragraph")
1645 (let ((org-export-default-language "en"))
1646 (org-test-with-parsed-data "some \"paragraph"
1649 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1651 ;; Opening quotes: at the beginning of a paragraph.
1655 (let ((org-export-default-language "en"))
1656 (org-test-with-parsed-data "\"begin"
1659 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1661 ;; Opening quotes: after an object.
1665 (let ((org-export-default-language "en"))
1666 (org-test-with-parsed-data "=verb= \"begin"
1669 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1671 ;; Closing quotes: standard test.
1674 '("some” paragraph")
1675 (let ((org-export-default-language "en"))
1676 (org-test-with-parsed-data "some\" paragraph"
1679 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1681 ;; Closing quotes: at the end of a paragraph.
1685 (let ((org-export-default-language "en"))
1686 (org-test-with-parsed-data "end\""
1689 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1691 ;; Apostrophe: standard test.
1694 '("It shouldn’t fail")
1695 (let ((org-export-default-language "en"))
1696 (org-test-with-parsed-data "It shouldn't fail"
1699 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1701 ;; Apostrophe: before an object.
1705 (let ((org-export-default-language "en"))
1706 (org-test-with-parsed-data "a'=b="
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"
1719 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1721 ;; Special case: isolated quotes.
1723 (equal '("“" "”")
1724 (let ((org-export-default-language "en"))
1725 (org-test-with-parsed-data "\"$x$\""
1728 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1730 ;; Smart quotes in secondary strings.
1732 (equal '("“" "”")
1733 (let ((org-export-default-language "en"))
1734 (org-test-with-parsed-data "* \"$x$\""
1737 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1739 ;; Smart quotes in document keywords.
1741 (equal '("“" "”")
1742 (let ((org-export-default-language "en"))
1743 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1745 (plist-get info
:title
) 'plain-text
1746 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1748 ;; Smart quotes in parsed affiliated keywords.
1750 (equal '("“" "”" "Paragraph")
1751 (let ((org-export-default-language "en"))
1752 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1755 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1756 info nil nil t
))))))
1762 (ert-deftest test-org-export
/special-column
()
1763 "Test if the table's special column is properly recognized."
1764 ;; 1. First column is special if it contains only a special marking
1765 ;; characters or empty cells.
1766 (org-test-with-temp-text "
1770 (org-export-table-has-special-column-p
1772 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1773 ;; 2. If the column contains anything else, it isn't special.
1774 (org-test-with-temp-text "
1778 (org-export-table-has-special-column-p
1780 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1781 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1783 (org-test-with-temp-text "
1792 (org-export-table-has-special-column-p
1794 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1795 ;; 4. A first column with only empty cells isn't considered as
1797 (org-test-with-temp-text "
1801 (org-export-table-has-special-column-p
1803 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1805 (ert-deftest test-org-export
/table-row-is-special-p
()
1806 "Test `org-export-table-row-is-special-p' specifications."
1807 ;; 1. A row is special if it has a special marking character in the
1809 (org-test-with-parsed-data "| ! | 1 |"
1811 (org-export-table-row-is-special-p
1812 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1813 ;; 2. A row is special when its first field is "/"
1814 (org-test-with-parsed-data "
1818 (org-export-table-row-is-special-p
1819 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1820 ;; 3. A row only containing alignment cookies is also considered as
1822 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1824 (org-export-table-row-is-special-p
1825 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1826 ;; 4. Everything else isn't considered as special.
1827 (org-test-with-parsed-data "| \alpha | | c |"
1829 (org-export-table-row-is-special-p
1830 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1831 ;; 5. Table's rules are never considered as special rows.
1832 (org-test-with-parsed-data "|---+---|"
1834 (org-export-table-row-is-special-p
1835 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1837 (ert-deftest test-org-export
/has-header-p
()
1838 "Test `org-export-table-has-header-p' specifications."
1839 ;; 1. With an header.
1840 (org-test-with-parsed-data "
1845 (org-export-table-has-header-p
1846 (org-element-map tree
'table
'identity info
'first-match
)
1848 ;; 2. Without an header.
1849 (org-test-with-parsed-data "
1853 (org-export-table-has-header-p
1854 (org-element-map tree
'table
'identity info
'first-match
)
1856 ;; 3. Don't get fooled with starting and ending rules.
1857 (org-test-with-parsed-data "
1863 (org-export-table-has-header-p
1864 (org-element-map tree
'table
'identity info
'first-match
)
1867 (ert-deftest test-org-export
/table-row-group
()
1868 "Test `org-export-table-row-group' specifications."
1869 ;; 1. A rule creates a new group.
1870 (org-test-with-parsed-data "
1877 (mapcar (lambda (row) (org-export-table-row-group row info
))
1878 (org-element-map tree
'table-row
'identity
)))))
1879 ;; 2. Special rows are ignored in count.
1880 (org-test-with-parsed-data "
1887 (mapcar (lambda (row) (org-export-table-row-group row info
))
1888 (org-element-map tree
'table-row
'identity
)))))
1889 ;; 3. Double rules also are ignored in count.
1890 (org-test-with-parsed-data "
1898 (mapcar (lambda (row) (org-export-table-row-group row info
))
1899 (org-element-map tree
'table-row
'identity
))))))
1901 (ert-deftest test-org-export
/table-cell-width
()
1902 "Test `org-export-table-cell-width' specifications."
1903 ;; 1. Width is primarily determined by width cookies. If no cookie
1904 ;; is found, cell's width is nil.
1905 (org-test-with-parsed-data "
1906 | / | <l> | <6> | <l7> |
1911 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1912 (org-element-map tree
'table-cell
'identity info
)))))
1913 ;; 2. The last width cookie has precedence.
1914 (org-test-with-parsed-data "
1921 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1922 (org-element-map tree
'table-cell
'identity info
)))))
1923 ;; 3. Valid width cookies must have a specific row.
1924 (org-test-with-parsed-data "| <6> | cell |"
1928 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1929 (org-element-map tree
'table-cell
'identity
))))))
1931 (ert-deftest test-org-export
/table-cell-alignment
()
1932 "Test `org-export-table-cell-alignment' specifications."
1933 (let ((org-table-number-fraction 0.5)
1934 (org-table-number-regexp "^[0-9]+$"))
1935 ;; 1. Alignment is primarily determined by alignment cookies.
1936 (org-test-with-temp-text "| <l> | <c> | <r> |"
1937 (let* ((tree (org-element-parse-buffer))
1938 (info `(:parse-tree
,tree
)))
1941 '(left center right
)
1942 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1943 (org-element-map tree
'table-cell
'identity
))))))
1944 ;; 2. The last alignment cookie has precedence.
1945 (org-test-with-parsed-data "
1951 '(right right right
)
1952 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1953 (org-element-map tree
'table-cell
'identity
)))))
1954 ;; 3. If there's no cookie, cell's contents determine alignment.
1955 ;; A column mostly made of cells containing numbers will align
1956 ;; its cells to the right.
1957 (org-test-with-parsed-data "
1963 '(right right right
)
1964 (mapcar (lambda (cell)
1965 (org-export-table-cell-alignment cell info
))
1966 (org-element-map tree
'table-cell
'identity
)))))
1967 ;; 4. Otherwise, they will be aligned to the left.
1968 (org-test-with-parsed-data "
1975 (mapcar (lambda (cell)
1976 (org-export-table-cell-alignment cell info
))
1977 (org-element-map tree
'table-cell
'identity
)))))))
1979 (ert-deftest test-org-export
/table-cell-borders
()
1980 "Test `org-export-table-cell-borders' specifications."
1981 ;; 1. Recognize various column groups indicators.
1982 (org-test-with-parsed-data "| / | < | > | <> |"
1985 '((right bottom top
) (left bottom top
) (right bottom top
)
1986 (right left bottom top
))
1987 (mapcar (lambda (cell)
1988 (org-export-table-cell-borders cell info
))
1989 (org-element-map tree
'table-cell
'identity
)))))
1990 ;; 2. Accept shortcuts to define column groups.
1991 (org-test-with-parsed-data "| / | < | < |"
1994 '((right bottom top
) (right left bottom top
) (left bottom top
))
1995 (mapcar (lambda (cell)
1996 (org-export-table-cell-borders cell info
))
1997 (org-element-map tree
'table-cell
'identity
)))))
1998 ;; 3. A valid column groups row must start with a "/".
1999 (org-test-with-parsed-data "
2003 (equal '((top) (top) (bottom) (bottom))
2004 (mapcar (lambda (cell)
2005 (org-export-table-cell-borders cell info
))
2006 (org-element-map tree
'table-cell
'identity
)))))
2007 ;; 4. Take table rules into consideration.
2008 (org-test-with-parsed-data "
2013 (equal '((below top
) (bottom above
))
2014 (mapcar (lambda (cell)
2015 (org-export-table-cell-borders cell info
))
2016 (org-element-map tree
'table-cell
'identity
)))))
2017 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2018 ;; (resp. `bottom' and `below') borders. Any special row is
2020 (org-test-with-parsed-data "
2026 (equal '((bottom below top above
))
2028 (mapcar (lambda (cell)
2029 (org-export-table-cell-borders cell info
))
2030 (org-element-map tree
'table-cell
'identity
)))))))
2032 (ert-deftest test-org-export
/table-dimensions
()
2033 "Test `org-export-table-dimensions' specifications."
2034 ;; 1. Standard test.
2035 (org-test-with-parsed-data "
2040 (org-export-table-dimensions
2041 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2042 ;; 2. Ignore horizontal rules and special columns.
2043 (org-test-with-parsed-data "
2050 (org-export-table-dimensions
2051 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2053 (ert-deftest test-org-export
/table-cell-address
()
2054 "Test `org-export-table-cell-address' specifications."
2055 ;; 1. Standard test: index is 0-based.
2056 (org-test-with-parsed-data "| a | b |"
2058 (equal '((0 .
0) (0 .
1))
2061 (lambda (cell) (org-export-table-cell-address cell info
))
2063 ;; 2. Special column isn't counted, nor are special rows.
2064 (org-test-with-parsed-data "
2069 (org-export-table-cell-address
2070 (car (last (org-element-map tree
'table-cell
'identity info
)))
2072 ;; 3. Tables rules do not count either.
2073 (org-test-with-parsed-data "
2081 (org-export-table-cell-address
2082 (car (last (org-element-map tree
'table-cell
'identity info
)))
2084 ;; 4. Return nil for special cells.
2085 (org-test-with-parsed-data "| / | a |"
2087 (org-export-table-cell-address
2088 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2091 (ert-deftest test-org-export
/get-table-cell-at
()
2092 "Test `org-export-get-table-cell-at' specifications."
2093 ;; 1. Address ignores special columns, special rows and rules.
2094 (org-test-with-parsed-data "
2101 (org-element-contents
2102 (org-export-get-table-cell-at
2104 (org-element-map tree
'table
'identity info
'first-match
)
2106 ;; 2. Return value for a non-existent address is nil.
2107 (org-test-with-parsed-data "| a |"
2109 (org-export-get-table-cell-at
2111 (org-element-map tree
'table
'identity info
'first-match
)
2113 (org-test-with-parsed-data "| / |"
2115 (org-export-get-table-cell-at
2117 (org-element-map tree
'table
'identity info
'first-match
)
2120 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2121 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2122 ;; 1. A cell at a beginning of a row always starts a column group.
2123 (org-test-with-parsed-data "| a |"
2125 (org-export-table-cell-starts-colgroup-p
2126 (org-element-map tree
'table-cell
'identity info
'first-match
)
2128 ;; 2. Special column should be ignored when determining the
2129 ;; beginning of the row.
2130 (org-test-with-parsed-data "
2134 (org-export-table-cell-starts-colgroup-p
2135 (org-element-map tree
'table-cell
'identity info
'first-match
)
2137 ;; 2. Explicit column groups.
2138 (org-test-with-parsed-data "
2147 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2150 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2151 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2152 ;; 1. A cell at the end of a row always ends a column group.
2153 (org-test-with-parsed-data "| a |"
2155 (org-export-table-cell-ends-colgroup-p
2156 (org-element-map tree
'table-cell
'identity info
'first-match
)
2158 ;; 2. Special column should be ignored when determining the
2159 ;; beginning of the row.
2160 (org-test-with-parsed-data "
2164 (org-export-table-cell-ends-colgroup-p
2165 (org-element-map tree
'table-cell
'identity info
'first-match
)
2167 ;; 3. Explicit column groups.
2168 (org-test-with-parsed-data "
2177 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2180 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2181 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2182 ;; 1. A row at the beginning of a table always starts a row group.
2183 ;; So does a row following a table rule.
2184 (org-test-with-parsed-data "
2194 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2196 ;; 2. Special rows should be ignored when determining the beginning
2198 (org-test-with-parsed-data "
2210 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2213 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2214 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2215 ;; 1. A row at the end of a table always ends a row group. So does
2216 ;; a row preceding a table rule.
2217 (org-test-with-parsed-data "
2227 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2229 ;; 2. Special rows should be ignored when determining the beginning
2231 (org-test-with-parsed-data "
2243 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2246 (ert-deftest test-org-export
/table-row-starts-header-p
()
2247 "Test `org-export-table-row-starts-header-p' specifications."
2248 ;; 1. Only the row starting the first row group starts the table
2250 (org-test-with-parsed-data "
2261 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2263 ;; 2. A row cannot start an header if there's no header in the
2265 (org-test-with-parsed-data "
2269 (org-export-table-row-starts-header-p
2270 (org-element-map tree
'table-row
'identity info
'first-match
)
2273 (ert-deftest test-org-export
/table-row-ends-header-p
()
2274 "Test `org-export-table-row-ends-header-p' specifications."
2275 ;; 1. Only the row starting the first row group starts the table
2277 (org-test-with-parsed-data "
2288 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2290 ;; 2. A row cannot start an header if there's no header in the
2292 (org-test-with-parsed-data "
2296 (org-export-table-row-ends-header-p
2297 (org-element-map tree
'table-row
'identity info
'first-match
)
2304 (ert-deftest test-org-export
/inner-template
()
2305 "Test `inner-template' translator specifications."
2308 (let (org-export-registered-backends)
2309 (org-export-define-backend test
2310 ((inner-template .
(lambda (contents info
) "Success!"))
2311 (headline .
(lambda (h c i
) "Headline"))))
2312 (org-test-with-temp-text "* Headline"
2313 (org-export-as 'test
)))))
2314 ;; Inner template is applied even in a "body-only" export.
2317 (let (org-export-registered-backends)
2318 (org-export-define-backend test
2319 ((inner-template .
(lambda (contents info
) "Success!"))
2320 (headline .
(lambda (h c i
) "Headline"))))
2321 (org-test-with-temp-text "* Headline"
2322 (org-export-as 'test nil nil
'body-only
))))))
2324 (ert-deftest test-org-export
/template
()
2325 "Test `template' translator specifications."
2328 (let (org-export-registered-backends)
2329 (org-export-define-backend test
2330 ((template .
(lambda (contents info
) "Success!"))
2331 (headline .
(lambda (h c i
) "Headline"))))
2332 (org-test-with-temp-text "* Headline"
2333 (org-export-as 'test
)))))
2334 ;; Template is not applied in a "body-only" export.
2337 (let (org-export-registered-backends)
2338 (org-export-define-backend test
2339 ((template .
(lambda (contents info
) "Success!"))
2340 (headline .
(lambda (h c i
) "Headline"))))
2341 (org-test-with-temp-text "* Headline"
2342 (org-export-as 'test nil nil
'body-only
))))))
2348 (ert-deftest test-org-export
/get-next-element
()
2349 "Test `org-export-get-next-element' specifications."
2353 (org-test-with-parsed-data "* Headline\n*a* b"
2354 (org-export-get-next-element
2355 (org-element-map tree
'bold
'identity info t
) info
))))
2356 ;; Return nil when no previous element.
2358 (org-test-with-parsed-data "* Headline\na *b*"
2359 (org-export-get-next-element
2360 (org-element-map tree
'bold
'identity info t
) info
)))
2361 ;; Non-exportable elements are ignored.
2363 (let ((org-export-with-timestamps nil
))
2364 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2365 (org-export-get-next-element
2366 (org-element-map tree
'entity
'identity info t
) info
))))
2367 ;; Find next element in secondary strings.
2370 (org-test-with-parsed-data "* a =verb="
2372 (org-export-get-next-element
2373 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2374 ;; Find next element in document keywords.
2377 (org-test-with-parsed-data "#+TITLE: a =verb="
2379 (org-export-get-next-element
2381 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2382 ;; Find next element in parsed affiliated keywords.
2385 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2387 (org-export-get-next-element
2388 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2389 ;; With optional argument N, return a list containing all the
2390 ;; following elements.
2393 '(bold code underline
)
2394 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2396 (org-export-get-next-element
2397 (org-element-map tree
'italic
'identity info t
) info t
)))))
2398 ;; When N is a positive integer, return a list containing up to
2399 ;; N following elements.
2403 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2405 (org-export-get-next-element
2406 (org-element-map tree
'italic
'identity info t
) info
2))))))
2408 (ert-deftest test-org-export
/get-previous-element
()
2409 "Test `org-export-get-previous-element' specifications."
2413 (org-test-with-parsed-data "* Headline\na *b*"
2414 (org-export-get-previous-element
2415 (org-element-map tree
'bold
'identity info t
) info
))))
2416 ;; Return nil when no previous element.
2418 (org-test-with-parsed-data "* Headline\n*a* b"
2419 (org-export-get-previous-element
2420 (org-element-map tree
'bold
'identity info t
) info
)))
2421 ;; Non-exportable elements are ignored.
2423 (let ((org-export-with-timestamps nil
))
2424 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2425 (org-export-get-previous-element
2426 (org-element-map tree
'entity
'identity info t
) info
))))
2427 ;; Find previous element in secondary strings.
2430 (org-test-with-parsed-data "* =verb= a"
2432 (org-export-get-previous-element
2433 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2434 ;; Find previous element in document keywords.
2437 (org-test-with-parsed-data "#+TITLE: =verb= a"
2439 (org-export-get-previous-element
2441 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2442 ;; Find previous element in parsed affiliated keywords.
2445 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2447 (org-export-get-previous-element
2448 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2449 ;; With optional argument N, return a list containing up to
2450 ;; N previous elements.
2452 (equal '(underline italic bold
)
2453 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2455 (org-export-get-previous-element
2456 (org-element-map tree
'code
'identity info t
) info t
)))))
2457 ;; When N is a positive integer, return a list containing up to
2458 ;; N previous elements.
2460 (equal '(italic bold
)
2461 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2463 (org-export-get-previous-element
2464 (org-element-map tree
'code
'identity info t
) info
2))))))
2468 ;;; test-org-export.el end here