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.
591 (org-element-map data
'headline
593 (when (string-match "\\<note\\>"
594 (org-element-property :raw-value headline
))
595 (org-export-ignore-element headline info
)))
598 ;; Install function in parse tree filters.
599 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
600 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
601 (should (equal (org-export-as 'test
) "* Head1\n")))))))
603 (ert-deftest test-org-export
/before-processing-hook
()
604 "Test `org-export-before-processing-hook'."
607 "#+MACRO: mac val\nTest\n"
608 (org-test-with-backend test
609 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
610 (let ((org-export-before-processing-hook
612 (while (re-search-forward "{{{" nil t
)
613 (let ((object (org-element-context)))
614 (when (eq (org-element-type object
) 'macro
)
616 (org-element-property :begin object
)
617 (org-element-property :end object
)))))))))
618 (org-export-as 'test
)))))))
620 (ert-deftest test-org-export
/before-parsing-hook
()
621 "Test `org-export-before-parsing-hook'."
623 (equal "Body 1\nBody 2\n"
624 (org-test-with-backend test
625 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
626 (let ((org-export-before-parsing-hook
628 (goto-char (point-min))
629 (while (re-search-forward org-outline-regexp-bol nil t
)
631 (point-at-bol) (progn (forward-line) (point))))))))
632 (org-export-as 'test
)))))))
636 ;;; Affiliated Keywords
638 (ert-deftest test-org-export
/read-attribute
()
639 "Test `org-export-read-attribute' specifications."
643 (org-export-read-attribute
645 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
646 (org-element-at-point)))
648 ;; Return nil on empty attribute.
650 (org-export-read-attribute
652 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
653 ;; Return nil on "nil" string.
655 (equal '(:a nil
:b nil
)
656 (org-export-read-attribute
658 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
659 (org-element-at-point)))))
660 ;; Return nil on empty string.
662 (equal '(:a nil
:b nil
)
663 (org-export-read-attribute
665 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
666 (org-element-at-point)))))
667 ;; Ignore text before first property.
670 (org-export-read-attribute
672 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
673 (org-element-at-point))))))
675 (ert-deftest test-org-export
/get-caption
()
676 "Test `org-export-get-caption' specifications."
677 ;; Without optional argument, return long caption
681 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
682 (org-export-get-caption (org-element-at-point)))))
683 ;; With optional argument, return short caption.
687 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
688 (org-export-get-caption (org-element-at-point) t
))))
689 ;; Multiple lines are separated by white spaces.
693 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
694 (org-export-get-caption (org-element-at-point))))))
700 (ert-deftest test-org-export
/define-backend
()
701 "Test back-end definition and accessors."
704 (equal '((headline . my-headline-test
))
705 (let (org-export-registered-backends)
706 (org-export-define-backend 'test
'((headline . my-headline-test
)))
707 (org-export-backend-translate-table 'test
))))
710 (equal '((:filter-headline . my-filter
))
711 (let (org-export-registered-backends)
712 (org-export-define-backend 'test
713 '((headline . my-headline-test
))
714 :filters-alist
'((:filter-headline . my-filter
)))
715 (org-export-backend-filters 'test
))))
718 (equal '((:prop value
))
719 (let (org-export-registered-backends)
720 (org-export-define-backend 'test
721 '((headline . my-headline-test
))
722 :options-alist
'((:prop value
)))
723 (org-export-backend-options 'test
))))
726 (equal '(?k
"Test Export" test
)
727 (let (org-export-registered-backends)
728 (org-export-define-backend 'test
729 '((headline . my-headline-test
))
730 :menu-entry
'(?k
"Test Export" test
))
731 (org-export-backend-menu 'test
))))
734 (equal '(("TEST" . org-element-export-block-parser
))
735 (let (org-export-registered-backends org-element-block-name-alist
)
736 (org-export-define-backend 'test
737 '((headline . my-headline-test
))
738 :export-block
'("test"))
739 org-element-block-name-alist
))))
741 (ert-deftest test-org-export
/define-derived-backend
()
742 "Test `org-export-define-derived-backend' specifications."
743 ;; Error when parent back-end is not defined.
745 (let (org-export-registered-backends)
746 (org-export-define-derived-backend 'test
'parent
)))
747 ;; Append translation table to parent's.
749 (equal '((:headline . test
) (:headline . parent
))
750 (let (org-export-registered-backends)
751 (org-export-define-backend 'parent
'((:headline . parent
)))
752 (org-export-define-derived-backend 'test
'parent
753 :translate-alist
'((:headline . test
)))
754 (org-export-backend-translate-table 'test
))))
755 ;; Options defined in the new back have priority over those defined
759 (let (org-export-registered-backends)
760 (org-export-define-backend 'parent
761 '((:headline . parent
))
762 :options-alist
'((:a nil nil
'parent
)))
763 (org-export-define-derived-backend 'test
'parent
764 :options-alist
'((:a nil nil
'test
)))
765 (plist-get (org-export--get-global-options 'test
) :a
)))))
767 (ert-deftest test-org-export
/derived-backend-p
()
768 "Test `org-export-derived-backend-p' specifications."
769 ;; Non-nil with direct match.
771 (let (org-export-registered-backends)
772 (org-export-define-backend 'test
'((headline . test
)))
773 (org-export-derived-backend-p 'test
'test
)))
775 (let (org-export-registered-backends)
776 (org-export-define-backend 'test
'((headline . test
)))
777 (org-export-define-derived-backend 'test2
'test
)
778 (org-export-derived-backend-p 'test2
'test2
)))
779 ;; Non-nil with a direct parent.
781 (let (org-export-registered-backends)
782 (org-export-define-backend 'test
'((headline . test
)))
783 (org-export-define-derived-backend 'test2
'test
)
784 (org-export-derived-backend-p 'test2
'test
)))
785 ;; Non-nil with an indirect parent.
787 (let (org-export-registered-backends)
788 (org-export-define-backend 'test
'((headline . test
)))
789 (org-export-define-derived-backend 'test2
'test
)
790 (org-export-define-derived-backend 'test3
'test2
)
791 (org-export-derived-backend-p 'test3
'test
)))
794 (let (org-export-registered-backends)
795 (org-export-define-backend 'test
'((headline . test
)))
796 (org-export-define-backend 'test2
'((headline . test2
)))
797 (org-export-derived-backend-p 'test2
'test
)))
799 (let (org-export-registered-backends)
800 (org-export-define-backend 'test
'((headline . test
)))
801 (org-export-define-backend 'test2
'((headline . test2
)))
802 (org-export-define-derived-backend 'test3
'test2
)
803 (org-export-derived-backend-p 'test3
'test
))))
805 (ert-deftest test-org-export
/with-backend
()
806 "Test `org-export-with-backend' definition."
807 ;; Error when calling an undefined back-end
809 (let (org-export-registered-backends)
810 (org-export-with-backend 'test
"Test")))
811 ;; Error when called back-end doesn't have an appropriate
814 (let (org-export-registered-backends)
815 (org-export-define-backend 'test
((headline . ignore
)))
816 (org-export-with-backend 'test
"Test")))
817 ;; Otherwise, export using correct transcoder
820 (let (org-export-registered-backends)
821 (org-export-define-backend 'test
822 '((plain-text .
(lambda (text contents info
) "Failure"))))
823 (org-export-define-backend 'test2
824 '((plain-text .
(lambda (text contents info
) "Success"))))
825 (org-export-with-backend 'test2
"Test")))))
827 (ert-deftest test-org-export
/data-with-translations
()
828 "Test `org-export-data-with-translations' specifications."
832 (org-export-data-with-translations
834 '((plain-text .
(lambda (text info
) "Success"))
835 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
836 '(:with-emphasize t
)))))
838 (ert-deftest test-org-export
/data-with-backend
()
839 "Test `org-export-data-with-backend' specifications."
840 ;; Error when calling an undefined back-end.
842 (let (org-export-registered-backends)
843 (org-export-data-with-backend 'test
"Test" nil
)))
844 ;; Otherwise, export data recursively, using correct back-end.
848 (let (org-export-registered-backends)
849 (org-export-define-backend 'test
850 '((plain-text .
(lambda (text info
) "Success"))
851 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
852 (org-export-data-with-backend
853 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
859 (ert-deftest test-org-export
/export-snippet
()
860 "Test export snippets transcoding."
861 (org-test-with-temp-text "@@test:A@@@@t:B@@"
862 (org-test-with-backend test
864 (cdr (assq 'test org-export-registered-backends
))
866 (cons (cons 'export-snippet
867 (lambda (snippet contents info
)
868 (when (eq (org-export-snippet-backend snippet
) 'test
)
869 (org-element-property :value snippet
))))
870 (org-export-backend-translate-table 'test
)))
871 (let ((org-export-snippet-translation-alist nil
))
872 (should (equal (org-export-as 'test
) "A\n")))
873 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
874 (should (equal (org-export-as 'test
) "AB\n")))))
875 ;; Ignored export snippets do not remove any blank.
878 (org-test-with-parsed-data "begin @@test:A@@ end"
879 (org-export-data-with-translations
881 '((paragraph .
(lambda (paragraph contents info
) contents
))
882 (section .
(lambda (section contents info
) contents
)))
889 (ert-deftest test-org-export
/footnotes
()
890 "Test footnotes specifications."
891 (let ((org-footnote-section nil
)
892 (org-export-with-footnotes t
))
893 ;; 1. Read every type of footnote.
896 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
897 (org-test-with-parsed-data
898 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
899 (org-element-map tree
'footnote-reference
901 (let ((def (org-export-get-footnote-definition ref info
)))
902 (cons (org-export-get-footnote-number ref info
)
903 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
904 (car (org-element-contents
905 (car (org-element-contents def
))))))))
907 ;; 2. Test nested footnotes order.
908 (org-test-with-parsed-data
909 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
912 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
913 (org-element-map tree
'footnote-reference
915 (when (org-export-footnote-first-reference-p ref info
)
916 (cons (org-export-get-footnote-number ref info
)
917 (org-element-property :label ref
))))
919 ;; 3. Test nested footnote in invisible definitions.
920 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
922 (narrow-to-region (point) (point-at-eol))
923 (let* ((tree (org-element-parse-buffer))
924 (info (org-combine-plists
926 (org-export-collect-tree-properties
927 tree
(org-export-get-environment)))))
928 ;; Both footnotes should be seen.
930 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
931 ;; 4. Test footnotes definitions collection.
932 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
934 \[fn:2] B [fn:3] [fn::D].
937 (should (= (length (org-export-collect-footnote-definitions tree info
))
939 ;; 5. Test export of footnotes defined outside parsing scope.
940 (org-test-with-temp-text "[fn:1] Out of scope
943 (org-test-with-backend test
945 (cdr (assq 'test org-export-registered-backends
))
947 (cons (cons 'footnote-reference
948 (lambda (fn contents info
)
949 (org-element-interpret-data
950 (org-export-get-footnote-definition fn info
))))
951 (org-export-backend-translate-table 'test
)))
953 (should (equal "ParagraphOut of scope\n"
954 (org-export-as 'test
'subtree
)))))
955 ;; 6. Footnotes without a definition should be provided a fallback
958 (org-test-with-parsed-data "[fn:1]"
959 (org-export-get-footnote-definition
960 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
961 ;; 7. Footnote section should be ignored in TOC and in headlines
964 (= 1 (let ((org-footnote-section "Footnotes"))
965 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
966 (org-export-collect-headlines info
))))))
969 (let ((org-footnote-section "Footnotes"))
970 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
971 (org-element-map tree
'headline
973 (when (equal (org-element-property :raw-value hl
) "H2")
974 (org-export-get-headline-number hl info
)))
979 ;;; Headlines and Inlinetasks
981 (ert-deftest test-org-export
/get-relative-level
()
982 "Test `org-export-get-relative-level' specifications."
986 (let ((org-odd-levels-only nil
))
987 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
988 (org-element-map tree
'headline
989 (lambda (h) (org-export-get-relative-level h info
))
994 (let ((org-odd-levels-only nil
))
995 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
996 (org-element-map tree
'headline
997 (lambda (h) (org-export-get-relative-level h info
))
1000 (ert-deftest test-org-export
/low-level-p
()
1001 "Test `org-export-low-level-p' specifications."
1005 (let ((org-odd-levels-only nil
))
1006 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1007 (org-element-map tree
'headline
1008 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1009 (plist-put info
:headline-levels
1)))))))
1011 (ert-deftest test-org-export
/get-headline-number
()
1012 "Test `org-export-get-headline-number' specifications."
1017 (let ((org-odd-levels-only nil
))
1018 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1019 (org-element-map tree
'headline
1020 (lambda (h) (org-export-get-headline-number h info
))
1022 ;; Missing levels are replaced with 0.
1026 (let ((org-odd-levels-only nil
))
1027 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1028 (org-element-map tree
'headline
1029 (lambda (h) (org-export-get-headline-number h info
))
1032 (ert-deftest test-org-export
/numbered-headline-p
()
1033 "Test `org-export-numbered-headline-p' specifications."
1034 ;; If `:section-numbers' is nil, never number headlines.
1036 (org-test-with-parsed-data "* Headline"
1037 (org-element-map tree
'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"
1046 (org-element-map tree
'headline
1047 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1048 (plist-put info
:section-numbers
1)))))
1049 ;; Otherwise, headlines are always numbered.
1051 (org-test-with-parsed-data "* Headline"
1052 (org-element-map tree
'headline
1053 (lambda (h) (org-export-numbered-headline-p h info
))
1054 (plist-put info
:section-numbers t
)))))
1056 (ert-deftest test-org-export
/number-to-roman
()
1057 "Test `org-export-number-to-roman' specifications."
1058 ;; If number is negative, return it as a string.
1059 (should (equal (org-export-number-to-roman -
1) "-1"))
1060 ;; Otherwise, return it as a roman number.
1061 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1063 (ert-deftest test-org-export
/get-optional-title
()
1064 "Test `org-export-get-alt-title' specifications."
1065 ;; If ALT_TITLE property is defined, use it.
1068 (org-test-with-parsed-data
1069 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1070 (org-export-get-alt-title
1071 (org-element-map tree
'headline
'identity info t
)
1073 ;; Otherwise, fall-back to regular title.
1075 (equal '("Headline")
1076 (org-test-with-parsed-data "* Headline"
1077 (org-export-get-alt-title
1078 (org-element-map tree
'headline
'identity info t
)
1081 (ert-deftest test-org-export
/get-tags
()
1082 "Test `org-export-get-tags' specifications."
1083 (let ((org-export-exclude-tags '("noexport"))
1084 (org-export-select-tags '("export")))
1085 ;; Standard test: tags which are not a select tag, an exclude tag,
1086 ;; or specified as optional argument shouldn't be ignored.
1088 (org-test-with-parsed-data "* Headline :tag:"
1089 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1091 ;; Exclude tags are removed.
1093 (org-test-with-parsed-data "* Headline :noexport:"
1094 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1096 ;; Select tags are removed.
1098 (org-test-with-parsed-data "* Headline :export:"
1099 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1104 (org-test-with-parsed-data "* Headline :tag:export:"
1105 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1107 ;; Tags provided in the optional argument are also ignored.
1109 (org-test-with-parsed-data "* Headline :ignore:"
1110 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1112 ;; Allow tag inheritance.
1116 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1117 (org-element-map tree
'headline
1118 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1119 ;; Tag inheritance checks FILETAGS keywords.
1123 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1124 (org-element-map tree
'headline
1125 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1127 (ert-deftest test-org-export
/get-node-property
()
1128 "Test`org-export-get-node-property' specifications."
1132 (org-test-with-parsed-data "* Headline
1136 (org-export-get-node-property
1137 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1138 ;; Test inheritance.
1141 (org-test-with-parsed-data "* Parent
1147 (org-export-get-node-property
1148 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1149 ;; Cannot return a value before the first headline.
1151 (org-test-with-parsed-data "Paragraph
1156 (org-export-get-node-property
1157 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1159 (ert-deftest test-org-export
/get-category
()
1160 "Test `org-export-get-category' specifications."
1164 (org-test-with-parsed-data "* Headline
1168 (org-export-get-category
1169 (org-element-map tree
'headline
'identity nil t
) info
))))
1170 ;; Test inheritance from a parent headline.
1172 (equal '("value" "value")
1173 (org-test-with-parsed-data "* Headline1
1178 (org-element-map tree
'headline
1179 (lambda (hl) (org-export-get-category hl info
)) info
))))
1180 ;; Test inheritance from #+CATEGORY keyword
1183 (org-test-with-parsed-data "#+CATEGORY: value
1185 (org-export-get-category
1186 (org-element-map tree
'headline
'identity nil t
) info
))))
1187 ;; Test inheritance from file name.
1190 (org-test-with-parsed-data "* Headline"
1191 (let ((info (plist-put info
:input-file
"~/test.org")))
1192 (org-export-get-category
1193 (org-element-map tree
'headline
'identity nil t
) info
)))))
1197 (org-test-with-parsed-data "* Headline"
1198 (org-export-get-category
1199 (org-element-map tree
'headline
'identity nil t
) info
)))))
1201 (ert-deftest test-org-export
/first-sibling-p
()
1202 "Test `org-export-first-sibling-p' specifications."
1207 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1208 (org-element-map tree
'headline
1209 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1211 ;; Ignore headlines not exported.
1215 (let ((org-export-exclude-tags '("ignore")))
1216 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1217 (org-element-map tree
'headline
1218 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1221 (ert-deftest test-org-export
/last-sibling-p
()
1222 "Test `org-export-last-sibling-p' specifications."
1227 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1228 (org-element-map tree
'headline
1229 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1231 ;; Ignore headlines not exported.
1235 (let ((org-export-exclude-tags '("ignore")))
1236 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1237 (org-element-map tree
'headline
1238 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1241 (ert-deftest test-org-export
/handle-inlinetasks
()
1242 "Test inlinetask export."
1243 ;; Inlinetask with an exclude tag.
1244 (when (featurep 'org-inlinetask
)
1248 (let ((org-inlinetask-min-level 3))
1249 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1250 (org-test-with-backend test
1251 (org-export-as 'test nil nil nil
'(:exclude-tags
("noexp"))))))))
1252 ;; Inlinetask with an include tag.
1255 "* H2\n*** Inline :exp:\n"
1256 (let ((org-inlinetask-min-level 3)
1257 (org-tags-column 0))
1258 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1259 (org-test-with-backend test
1260 (org-export-as 'test nil nil nil
'(:select-tags
("exp"))))))))
1261 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1264 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1265 (org-inlinetask-min-level 3))
1266 (org-test-with-temp-text "*** TODO Inline"
1267 (org-test-with-backend test
1268 (org-export-as 'test nil nil nil
'(:with-tasks nil
)))))))))
1274 (ert-deftest test-org-export
/get-coderef-format
()
1275 "Test `org-export-get-coderef-format' specifications."
1276 ;; A link without description returns "%s"
1277 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1279 ;; Return "%s" when path is matched within description.
1280 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1282 ;; Otherwise return description.
1283 (should (equal (org-export-get-coderef-format "path" "desc")
1286 (ert-deftest test-org-export
/inline-image-p
()
1287 "Test `org-export-inline-image-p' specifications."
1289 (org-export-inline-image-p
1290 (org-test-with-temp-text "[[#id]]"
1291 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1292 '(("custom-id" .
"id")))))
1294 (ert-deftest test-org-export
/fuzzy-link
()
1295 "Test fuzzy links specifications."
1296 ;; 1. Links to invisible (keyword) targets should be ignored.
1297 (org-test-with-parsed-data
1298 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1300 (org-element-map tree
'link
1302 (org-export-get-ordinal
1303 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1304 ;; 2. Link to an headline should return headline's number.
1305 (org-test-with-parsed-data
1306 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1308 ;; Note: Headline's number is in fact a list of numbers.
1310 (org-element-map tree
'link
1312 (org-export-get-ordinal
1313 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1314 ;; 3. Link to a target in an item should return item's number.
1315 (org-test-with-parsed-data
1316 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1318 ;; Note: Item's number is in fact a list of numbers.
1320 (org-element-map tree
'link
1322 (org-export-get-ordinal
1323 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1324 ;; 4. Link to a target in a footnote should return footnote's
1326 (org-test-with-parsed-data "
1327 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1330 (org-element-map tree
'link
1332 (org-export-get-ordinal
1333 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1334 ;; 5. Link to a named element should return sequence number of that
1336 (org-test-with-parsed-data
1337 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1340 (org-element-map tree
'link
1342 (org-export-get-ordinal
1343 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1344 ;; 6. Link to a target not within an item, a table, a footnote
1345 ;; reference or definition should return section number.
1346 (org-test-with-parsed-data
1347 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1350 (org-element-map tree
'link
1352 (org-export-get-ordinal
1353 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1354 ;; 7. Space are not significant when matching a fuzzy link.
1356 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1357 (org-element-map tree
'link
1358 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1360 ;; 8. Statistics cookies are ignored for headline match.
1362 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1363 (org-element-map tree
'link
1364 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1367 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1368 (org-element-map tree
'link
1369 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1372 (ert-deftest test-org-export
/resolve-coderef
()
1373 "Test `org-export-resolve-coderef' specifications."
1374 (let ((org-coderef-label-format "(ref:%s)"))
1375 ;; 1. A link to a "-n -k -r" block returns line number.
1376 (org-test-with-parsed-data
1377 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1378 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1379 (org-test-with-parsed-data
1380 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1381 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1382 ;; 2. A link to a "-n -r" block returns line number.
1383 (org-test-with-parsed-data
1384 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1385 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1386 (org-test-with-parsed-data
1387 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1388 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1389 ;; 3. A link to a "-n" block returns coderef.
1390 (org-test-with-parsed-data
1391 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1392 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1393 (org-test-with-parsed-data
1394 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1395 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1396 ;; 4. A link to a "-r" block returns line number.
1397 (org-test-with-parsed-data
1398 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1399 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1400 (org-test-with-parsed-data
1401 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1402 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1403 ;; 5. A link to a block without a switch returns coderef.
1404 (org-test-with-parsed-data
1405 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1406 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1407 (org-test-with-parsed-data
1408 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1409 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1410 ;; 6. Correctly handle continued line numbers. A "+n" switch
1411 ;; should resume numbering from previous block with numbered
1412 ;; lines, ignoring blocks not numbering lines in the process.
1413 ;; A "-n" switch resets count.
1414 (org-test-with-parsed-data "
1419 #+BEGIN_SRC emacs-lisp
1423 #+BEGIN_SRC emacs-lisp +n -r
1424 \(+ 1 1) (ref:addition)
1427 #+BEGIN_EXAMPLE -n -r
1428 Another text. (ref:text)
1430 (should (= (org-export-resolve-coderef "addition" info
) 2))
1431 (should (= (org-export-resolve-coderef "text" info
) 1)))
1432 ;; 7. Recognize coderef with user-specified syntax.
1433 (org-test-with-parsed-data
1434 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1435 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1437 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1438 "Test `org-export-resolve-fuzzy-link' specifications."
1439 ;; 1. Match target objects.
1440 (org-test-with-parsed-data "<<target>> [[target]]"
1442 (org-export-resolve-fuzzy-link
1443 (org-element-map tree
'link
'identity info t
) info
)))
1444 ;; 2. Match target elements.
1445 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1447 (org-export-resolve-fuzzy-link
1448 (org-element-map tree
'link
'identity info t
) info
)))
1449 ;; 3. Match named elements.
1450 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1452 (org-export-resolve-fuzzy-link
1453 (org-element-map tree
'link
'identity info t
) info
)))
1454 ;; 4. Match exact headline's name.
1455 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1457 (org-export-resolve-fuzzy-link
1458 (org-element-map tree
'link
'identity info t
) info
)))
1459 ;; 5. Targets objects have priority over named elements and headline
1461 (org-test-with-parsed-data
1462 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1466 (org-export-resolve-fuzzy-link
1467 (org-element-map tree
'link
'identity info t
) info
)))))
1468 ;; 6. Named elements have priority over headline titles.
1469 (org-test-with-parsed-data
1470 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1474 (org-export-resolve-fuzzy-link
1475 (org-element-map tree
'link
'identity info t
) info
)))))
1476 ;; 7. If link's path starts with a "*", only match headline titles,
1478 (org-test-with-parsed-data
1479 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1483 (org-export-resolve-fuzzy-link
1484 (org-element-map tree
'link
'identity info t
) info
)))))
1485 ;; 8. Return nil if no match.
1486 (org-test-with-parsed-data "[[target]]"
1488 (org-export-resolve-fuzzy-link
1489 (org-element-map tree
'link
'identity info t
) info
))))
1491 (ert-deftest test-org-export
/resolve-id-link
()
1492 "Test `org-export-resolve-id-link' specifications."
1493 ;; 1. Regular test for custom-id link.
1494 (org-test-with-parsed-data "* Headline1
1501 (org-export-resolve-id-link
1502 (org-element-map tree
'link
'identity info t
) info
)))
1503 ;; 2. Failing test for custom-id link.
1504 (org-test-with-parsed-data "* Headline1
1511 (org-export-resolve-id-link
1512 (org-element-map tree
'link
'identity info t
) info
)))
1513 ;; 3. Test for internal id target.
1514 (org-test-with-parsed-data "* Headline1
1521 (org-export-resolve-id-link
1522 (org-element-map tree
'link
'identity info t
) info
)))
1523 ;; 4. Test for external id target.
1524 (org-test-with-parsed-data "[[id:aaaa]]"
1526 (org-export-resolve-id-link
1527 (org-element-map tree
'link
'identity info t
)
1528 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1530 (ert-deftest test-org-export
/resolve-radio-link
()
1531 "Test `org-export-resolve-radio-link' specifications."
1534 (org-test-with-temp-text "<<<radio>>> radio"
1535 (org-update-radio-target-regexp)
1536 (let* ((tree (org-element-parse-buffer))
1537 (info `(:parse-tree
,tree
)))
1538 (org-export-resolve-radio-link
1539 (org-element-map tree
'link
'identity info t
)
1541 ;; Radio targets are case-insensitive.
1543 (org-test-with-temp-text "<<<RADIO>>> radio"
1544 (org-update-radio-target-regexp)
1545 (let* ((tree (org-element-parse-buffer))
1546 (info `(:parse-tree
,tree
)))
1547 (org-export-resolve-radio-link
1548 (org-element-map tree
'link
'identity info t
)
1550 ;; Radio target with objects.
1552 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1553 (org-update-radio-target-regexp)
1554 (let* ((tree (org-element-parse-buffer))
1555 (info `(:parse-tree
,tree
)))
1556 (org-export-resolve-radio-link
1557 (org-element-map tree
'link
'identity info t
)
1562 ;;; Src-block and example-block
1564 (ert-deftest test-org-export
/unravel-code
()
1565 "Test `org-export-unravel-code' function."
1566 (let ((org-coderef-label-format "(ref:%s)"))
1567 ;; 1. Code without reference.
1568 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1569 (should (equal (org-export-unravel-code (org-element-at-point))
1571 ;; 2. Code with reference.
1572 (org-test-with-temp-text
1573 "#+BEGIN_EXAMPLE\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 ;; 3. Code with user-defined reference.
1577 (org-test-with-temp-text
1578 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1579 (should (equal (org-export-unravel-code (org-element-at-point))
1580 '("(+ 1 1)\n" (1 .
"test")))))
1581 ;; 4. Code references keys are relative to the current block.
1582 (org-test-with-temp-text "
1591 (should (equal (org-export-unravel-code (org-element-at-point))
1592 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1594 (ert-deftest test-org-export
/format-code-default
()
1595 "Test `org-export-format-code-default' specifications."
1596 ;; Return the empty string when code is empty.
1599 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
1600 (org-export-format-code-default
1601 (org-element-map tree
'src-block
'identity info t
) info
))))
1602 ;; Number lines, two whitespace characters before the actual loc.
1605 (org-test-with-parsed-data
1606 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
1607 (org-export-format-code-default
1608 (org-element-map tree
'src-block
'identity info t
) info
))))
1609 ;; Put references 6 whitespace characters after the widest line,
1610 ;; wrapped within parenthesis.
1612 (equal "123 (a)\n1 (b)\n"
1613 (let ((org-coderef-label-format "(ref:%s)"))
1614 (org-test-with-parsed-data
1615 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
1616 (org-export-format-code-default
1617 (org-element-map tree
'src-block
'identity info t
) info
))))))
1623 (ert-deftest test-org-export
/activate-smart-quotes
()
1624 "Test `org-export-activate-smart-quotes' specifications."
1625 ;; Opening double quotes: standard test.
1628 '("some “paragraph")
1629 (let ((org-export-default-language "en"))
1630 (org-test-with-parsed-data "some \"paragraph"
1631 (org-element-map tree
'plain-text
1632 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1634 ;; Opening quotes: at the beginning of a paragraph.
1638 (let ((org-export-default-language "en"))
1639 (org-test-with-parsed-data "\"begin"
1640 (org-element-map tree
'plain-text
1641 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1643 ;; Opening quotes: after an object.
1647 (let ((org-export-default-language "en"))
1648 (org-test-with-parsed-data "=verb= \"begin"
1649 (org-element-map tree
'plain-text
1650 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1652 ;; Closing quotes: standard test.
1655 '("some” paragraph")
1656 (let ((org-export-default-language "en"))
1657 (org-test-with-parsed-data "some\" paragraph"
1658 (org-element-map tree
'plain-text
1659 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1661 ;; Closing quotes: at the end of a paragraph.
1665 (let ((org-export-default-language "en"))
1666 (org-test-with-parsed-data "end\""
1667 (org-element-map tree
'plain-text
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"
1676 (org-element-map tree
'plain-text
1677 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1679 ;; Apostrophe: before an object.
1683 (let ((org-export-default-language "en"))
1684 (org-test-with-parsed-data "a'=b="
1685 (org-element-map tree
'plain-text
1686 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1688 ;; Apostrophe: after an object.
1692 (let ((org-export-default-language "en"))
1693 (org-test-with-parsed-data "=code='s"
1694 (org-element-map tree
'plain-text
1695 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1697 ;; Special case: isolated quotes.
1699 (equal '("“" "”")
1700 (let ((org-export-default-language "en"))
1701 (org-test-with-parsed-data "\"$x$\""
1702 (org-element-map tree
'plain-text
1703 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1705 ;; Smart quotes in secondary strings.
1707 (equal '("“" "”")
1708 (let ((org-export-default-language "en"))
1709 (org-test-with-parsed-data "* \"$x$\""
1710 (org-element-map tree
'plain-text
1711 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1713 ;; Smart quotes in document keywords.
1715 (equal '("“" "”")
1716 (let ((org-export-default-language "en"))
1717 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1718 (org-element-map (plist-get info
:title
) 'plain-text
1719 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1721 ;; Smart quotes in parsed affiliated keywords.
1723 (equal '("“" "”" "Paragraph")
1724 (let ((org-export-default-language "en"))
1725 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1726 (org-element-map tree
'plain-text
1727 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1728 info nil nil t
))))))
1734 (ert-deftest test-org-export
/special-column
()
1735 "Test if the table's special column is properly recognized."
1736 ;; 1. First column is special if it contains only a special marking
1737 ;; characters or empty cells.
1738 (org-test-with-temp-text "
1742 (org-export-table-has-special-column-p
1744 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1745 ;; 2. If the column contains anything else, it isn't special.
1746 (org-test-with-temp-text "
1750 (org-export-table-has-special-column-p
1752 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1753 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1755 (org-test-with-temp-text "
1764 (org-export-table-has-special-column-p
1766 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1767 ;; 4. A first column with only empty cells isn't considered as
1769 (org-test-with-temp-text "
1773 (org-export-table-has-special-column-p
1775 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1777 (ert-deftest test-org-export
/table-row-is-special-p
()
1778 "Test `org-export-table-row-is-special-p' specifications."
1779 ;; 1. A row is special if it has a special marking character in the
1781 (org-test-with-parsed-data "| ! | 1 |"
1783 (org-export-table-row-is-special-p
1784 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1785 ;; 2. A row is special when its first field is "/"
1786 (org-test-with-parsed-data "
1790 (org-export-table-row-is-special-p
1791 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1792 ;; 3. A row only containing alignment cookies is also considered as
1794 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1796 (org-export-table-row-is-special-p
1797 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1798 ;; 4. Everything else isn't considered as special.
1799 (org-test-with-parsed-data "| \alpha | | c |"
1801 (org-export-table-row-is-special-p
1802 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1803 ;; 5. Table's rules are never considered as special rows.
1804 (org-test-with-parsed-data "|---+---|"
1806 (org-export-table-row-is-special-p
1807 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1809 (ert-deftest test-org-export
/has-header-p
()
1810 "Test `org-export-table-has-header-p' specifications."
1811 ;; 1. With an header.
1812 (org-test-with-parsed-data "
1817 (org-export-table-has-header-p
1818 (org-element-map tree
'table
'identity info
'first-match
)
1820 ;; 2. Without an header.
1821 (org-test-with-parsed-data "
1825 (org-export-table-has-header-p
1826 (org-element-map tree
'table
'identity info
'first-match
)
1828 ;; 3. Don't get fooled with starting and ending rules.
1829 (org-test-with-parsed-data "
1835 (org-export-table-has-header-p
1836 (org-element-map tree
'table
'identity info
'first-match
)
1839 (ert-deftest test-org-export
/table-row-group
()
1840 "Test `org-export-table-row-group' specifications."
1841 ;; 1. A rule creates a new group.
1842 (org-test-with-parsed-data "
1849 (mapcar (lambda (row) (org-export-table-row-group row info
))
1850 (org-element-map tree
'table-row
'identity
)))))
1851 ;; 2. Special rows are ignored in count.
1852 (org-test-with-parsed-data "
1859 (mapcar (lambda (row) (org-export-table-row-group row info
))
1860 (org-element-map tree
'table-row
'identity
)))))
1861 ;; 3. Double rules also are ignored in count.
1862 (org-test-with-parsed-data "
1870 (mapcar (lambda (row) (org-export-table-row-group row info
))
1871 (org-element-map tree
'table-row
'identity
))))))
1873 (ert-deftest test-org-export
/table-cell-width
()
1874 "Test `org-export-table-cell-width' specifications."
1875 ;; 1. Width is primarily determined by width cookies. If no cookie
1876 ;; is found, cell's width is nil.
1877 (org-test-with-parsed-data "
1878 | / | <l> | <6> | <l7> |
1883 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1884 (org-element-map tree
'table-cell
'identity info
)))))
1885 ;; 2. The last width cookie has precedence.
1886 (org-test-with-parsed-data "
1893 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1894 (org-element-map tree
'table-cell
'identity info
)))))
1895 ;; 3. Valid width cookies must have a specific row.
1896 (org-test-with-parsed-data "| <6> | cell |"
1900 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1901 (org-element-map tree
'table-cell
'identity
))))))
1903 (ert-deftest test-org-export
/table-cell-alignment
()
1904 "Test `org-export-table-cell-alignment' specifications."
1905 (let ((org-table-number-fraction 0.5)
1906 (org-table-number-regexp "^[0-9]+$"))
1907 ;; 1. Alignment is primarily determined by alignment cookies.
1908 (org-test-with-temp-text "| <l> | <c> | <r> |"
1909 (let* ((tree (org-element-parse-buffer))
1910 (info `(:parse-tree
,tree
)))
1913 '(left center right
)
1914 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1915 (org-element-map tree
'table-cell
'identity
))))))
1916 ;; 2. The last alignment cookie has precedence.
1917 (org-test-with-parsed-data "
1923 '(right right right
)
1924 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1925 (org-element-map tree
'table-cell
'identity
)))))
1926 ;; 3. If there's no cookie, cell's contents determine alignment.
1927 ;; A column mostly made of cells containing numbers will align
1928 ;; its cells to the right.
1929 (org-test-with-parsed-data "
1935 '(right right right
)
1936 (mapcar (lambda (cell)
1937 (org-export-table-cell-alignment cell info
))
1938 (org-element-map tree
'table-cell
'identity
)))))
1939 ;; 4. Otherwise, they will be aligned to the left.
1940 (org-test-with-parsed-data "
1947 (mapcar (lambda (cell)
1948 (org-export-table-cell-alignment cell info
))
1949 (org-element-map tree
'table-cell
'identity
)))))))
1951 (ert-deftest test-org-export
/table-cell-borders
()
1952 "Test `org-export-table-cell-borders' specifications."
1953 ;; 1. Recognize various column groups indicators.
1954 (org-test-with-parsed-data "| / | < | > | <> |"
1957 '((right bottom top
) (left bottom top
) (right bottom top
)
1958 (right left bottom top
))
1959 (mapcar (lambda (cell)
1960 (org-export-table-cell-borders cell info
))
1961 (org-element-map tree
'table-cell
'identity
)))))
1962 ;; 2. Accept shortcuts to define column groups.
1963 (org-test-with-parsed-data "| / | < | < |"
1966 '((right bottom top
) (right left bottom top
) (left bottom top
))
1967 (mapcar (lambda (cell)
1968 (org-export-table-cell-borders cell info
))
1969 (org-element-map tree
'table-cell
'identity
)))))
1970 ;; 3. A valid column groups row must start with a "/".
1971 (org-test-with-parsed-data "
1975 (equal '((top) (top) (bottom) (bottom))
1976 (mapcar (lambda (cell)
1977 (org-export-table-cell-borders cell info
))
1978 (org-element-map tree
'table-cell
'identity
)))))
1979 ;; 4. Take table rules into consideration.
1980 (org-test-with-parsed-data "
1985 (equal '((below top
) (bottom above
))
1986 (mapcar (lambda (cell)
1987 (org-export-table-cell-borders cell info
))
1988 (org-element-map tree
'table-cell
'identity
)))))
1989 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1990 ;; (resp. `bottom' and `below') borders. Any special row is
1992 (org-test-with-parsed-data "
1998 (equal '((bottom below top above
))
2000 (mapcar (lambda (cell)
2001 (org-export-table-cell-borders cell info
))
2002 (org-element-map tree
'table-cell
'identity
)))))))
2004 (ert-deftest test-org-export
/table-dimensions
()
2005 "Test `org-export-table-dimensions' specifications."
2006 ;; 1. Standard test.
2007 (org-test-with-parsed-data "
2012 (org-export-table-dimensions
2013 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2014 ;; 2. Ignore horizontal rules and special columns.
2015 (org-test-with-parsed-data "
2022 (org-export-table-dimensions
2023 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2025 (ert-deftest test-org-export
/table-cell-address
()
2026 "Test `org-export-table-cell-address' specifications."
2027 ;; 1. Standard test: index is 0-based.
2028 (org-test-with-parsed-data "| a | b |"
2030 (equal '((0 .
0) (0 .
1))
2031 (org-element-map tree
'table-cell
2032 (lambda (cell) (org-export-table-cell-address cell info
))
2034 ;; 2. Special column isn't counted, nor are special rows.
2035 (org-test-with-parsed-data "
2040 (org-export-table-cell-address
2041 (car (last (org-element-map tree
'table-cell
'identity info
)))
2043 ;; 3. Tables rules do not count either.
2044 (org-test-with-parsed-data "
2052 (org-export-table-cell-address
2053 (car (last (org-element-map tree
'table-cell
'identity info
)))
2055 ;; 4. Return nil for special cells.
2056 (org-test-with-parsed-data "| / | a |"
2058 (org-export-table-cell-address
2059 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2062 (ert-deftest test-org-export
/get-table-cell-at
()
2063 "Test `org-export-get-table-cell-at' specifications."
2064 ;; 1. Address ignores special columns, special rows and rules.
2065 (org-test-with-parsed-data "
2072 (org-element-contents
2073 (org-export-get-table-cell-at
2075 (org-element-map tree
'table
'identity info
'first-match
)
2077 ;; 2. Return value for a non-existent address is nil.
2078 (org-test-with-parsed-data "| a |"
2080 (org-export-get-table-cell-at
2082 (org-element-map tree
'table
'identity info
'first-match
)
2084 (org-test-with-parsed-data "| / |"
2086 (org-export-get-table-cell-at
2088 (org-element-map tree
'table
'identity info
'first-match
)
2091 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2092 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2093 ;; 1. A cell at a beginning of a row always starts a column group.
2094 (org-test-with-parsed-data "| a |"
2096 (org-export-table-cell-starts-colgroup-p
2097 (org-element-map tree
'table-cell
'identity info
'first-match
)
2099 ;; 2. Special column should be ignored when determining the
2100 ;; beginning of the row.
2101 (org-test-with-parsed-data "
2105 (org-export-table-cell-starts-colgroup-p
2106 (org-element-map tree
'table-cell
'identity info
'first-match
)
2108 ;; 2. Explicit column groups.
2109 (org-test-with-parsed-data "
2115 (org-element-map tree
'table-cell
2117 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2120 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2121 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2122 ;; 1. A cell at the end of a row always ends a column group.
2123 (org-test-with-parsed-data "| a |"
2125 (org-export-table-cell-ends-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-ends-colgroup-p
2135 (org-element-map tree
'table-cell
'identity info
'first-match
)
2137 ;; 3. Explicit column groups.
2138 (org-test-with-parsed-data "
2144 (org-element-map tree
'table-cell
2146 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2149 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2150 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2151 ;; 1. A row at the beginning of a table always starts a row group.
2152 ;; So does a row following a table rule.
2153 (org-test-with-parsed-data "
2160 (org-element-map tree
'table-row
2162 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2164 ;; 2. Special rows should be ignored when determining the beginning
2166 (org-test-with-parsed-data "
2175 (org-element-map tree
'table-row
2177 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2180 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2181 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2182 ;; 1. A row at the end of a table always ends a row group. So does
2183 ;; a row preceding a table rule.
2184 (org-test-with-parsed-data "
2191 (org-element-map tree
'table-row
2193 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2195 ;; 2. Special rows should be ignored when determining the beginning
2197 (org-test-with-parsed-data "
2206 (org-element-map tree
'table-row
2208 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2211 (ert-deftest test-org-export
/table-row-starts-header-p
()
2212 "Test `org-export-table-row-starts-header-p' specifications."
2213 ;; 1. Only the row starting the first row group starts the table
2215 (org-test-with-parsed-data "
2223 (org-element-map tree
'table-row
2225 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2227 ;; 2. A row cannot start an header if there's no header in the
2229 (org-test-with-parsed-data "
2233 (org-export-table-row-starts-header-p
2234 (org-element-map tree
'table-row
'identity info
'first-match
)
2237 (ert-deftest test-org-export
/table-row-ends-header-p
()
2238 "Test `org-export-table-row-ends-header-p' specifications."
2239 ;; 1. Only the row starting the first row group starts the table
2241 (org-test-with-parsed-data "
2249 (org-element-map tree
'table-row
2251 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2253 ;; 2. A row cannot start an header if there's no header in the
2255 (org-test-with-parsed-data "
2259 (org-export-table-row-ends-header-p
2260 (org-element-map tree
'table-row
'identity info
'first-match
)
2267 (ert-deftest test-org-export
/inner-template
()
2268 "Test `inner-template' translator specifications."
2271 (let (org-export-registered-backends)
2272 (org-export-define-backend 'test
2273 '((inner-template .
(lambda (contents info
) "Success!"))
2274 (headline .
(lambda (h c i
) "Headline"))))
2275 (org-test-with-temp-text "* Headline"
2276 (org-export-as 'test
)))))
2277 ;; Inner template is applied even in a "body-only" export.
2280 (let (org-export-registered-backends)
2281 (org-export-define-backend 'test
2282 '((inner-template .
(lambda (contents info
) "Success!"))
2283 (headline .
(lambda (h c i
) "Headline"))))
2284 (org-test-with-temp-text "* Headline"
2285 (org-export-as 'test nil nil
'body-only
))))))
2287 (ert-deftest test-org-export
/template
()
2288 "Test `template' translator specifications."
2291 (let (org-export-registered-backends)
2292 (org-export-define-backend 'test
2293 '((template .
(lambda (contents info
) "Success!"))
2294 (headline .
(lambda (h c i
) "Headline"))))
2295 (org-test-with-temp-text "* Headline"
2296 (org-export-as 'test
)))))
2297 ;; Template is not applied in a "body-only" export.
2300 (let (org-export-registered-backends)
2301 (org-export-define-backend 'test
2302 '((template .
(lambda (contents info
) "Success!"))
2303 (headline .
(lambda (h c i
) "Headline"))))
2304 (org-test-with-temp-text "* Headline"
2305 (org-export-as 'test nil nil
'body-only
))))))
2311 (ert-deftest test-org-export
/get-next-element
()
2312 "Test `org-export-get-next-element' specifications."
2316 (org-test-with-parsed-data "* Headline\n*a* b"
2317 (org-export-get-next-element
2318 (org-element-map tree
'bold
'identity info t
) info
))))
2319 ;; Return nil when no previous element.
2321 (org-test-with-parsed-data "* Headline\na *b*"
2322 (org-export-get-next-element
2323 (org-element-map tree
'bold
'identity info t
) info
)))
2324 ;; Non-exportable elements are ignored.
2326 (let ((org-export-with-timestamps nil
))
2327 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2328 (org-export-get-next-element
2329 (org-element-map tree
'entity
'identity info t
) info
))))
2330 ;; Find next element in secondary strings.
2333 (org-test-with-parsed-data "* a =verb="
2335 (org-export-get-next-element
2336 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2337 ;; Find next element in document keywords.
2340 (org-test-with-parsed-data "#+TITLE: a =verb="
2342 (org-export-get-next-element
2344 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2345 ;; Find next element in parsed affiliated keywords.
2348 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2350 (org-export-get-next-element
2351 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2352 ;; With optional argument N, return a list containing all the
2353 ;; following elements.
2356 '(bold code underline
)
2357 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2359 (org-export-get-next-element
2360 (org-element-map tree
'italic
'identity info t
) info t
)))))
2361 ;; When N is a positive integer, return a list containing up to
2362 ;; N following elements.
2366 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2368 (org-export-get-next-element
2369 (org-element-map tree
'italic
'identity info t
) info
2))))))
2371 (ert-deftest test-org-export
/get-previous-element
()
2372 "Test `org-export-get-previous-element' specifications."
2376 (org-test-with-parsed-data "* Headline\na *b*"
2377 (org-export-get-previous-element
2378 (org-element-map tree
'bold
'identity info t
) info
))))
2379 ;; Return nil when no previous element.
2381 (org-test-with-parsed-data "* Headline\n*a* b"
2382 (org-export-get-previous-element
2383 (org-element-map tree
'bold
'identity info t
) info
)))
2384 ;; Non-exportable elements are ignored.
2386 (let ((org-export-with-timestamps nil
))
2387 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2388 (org-export-get-previous-element
2389 (org-element-map tree
'entity
'identity info t
) info
))))
2390 ;; Find previous element in secondary strings.
2393 (org-test-with-parsed-data "* =verb= a"
2395 (org-export-get-previous-element
2396 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2397 ;; Find previous element in document keywords.
2400 (org-test-with-parsed-data "#+TITLE: =verb= a"
2402 (org-export-get-previous-element
2404 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2405 ;; Find previous element in parsed affiliated keywords.
2408 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2410 (org-export-get-previous-element
2411 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2412 ;; With optional argument N, return a list containing up to
2413 ;; N previous elements.
2415 (equal '(underline italic bold
)
2416 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2418 (org-export-get-previous-element
2419 (org-element-map tree
'code
'identity info t
) info t
)))))
2420 ;; When N is a positive integer, return a list containing up to
2421 ;; N previous elements.
2423 (equal '(italic bold
)
2424 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2426 (org-export-get-previous-element
2427 (org-element-map tree
'code
'identity info t
) info
2))))))
2431 ;;; test-org-export.el end here