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."
127 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
130 #+DESCRIPTION: Testing
131 #+DESCRIPTION: with two lines
132 #+EMAIL: some@email.org
133 #+EXCLUDE_TAGS: noexport invisible
136 #+SELECT_TAGS: export
138 #+TITLE: with spaces"
139 (org-export--get-inbuffer-options))
141 ("Me, Myself and I") :creator
"Idem" :date
("Today")
142 :description
"Testing\nwith two lines" :email
"some@email.org"
143 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
144 :select-tags
("export") :title
("Some title with spaces")))))
146 (ert-deftest test-org-export
/get-subtree-options
()
147 "Test setting options from headline's properties."
149 (org-test-with-temp-text "#+TITLE: Title
152 :EXPORT_TITLE: Subtree Title
156 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
157 '("Subtree Title"))))
161 (org-test-with-temp-text "#+OPTIONS: H:1
169 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
171 (org-test-with-temp-text "#+DATE: today
174 :EXPORT_DATE: 29-03-2012
178 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
180 ;; Properties with `split' behaviour are stored as a list of
184 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
187 :EXPORT_EXCLUDE_TAGS: a b
192 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
193 ;; Handle :PROPERTY+: syntax.
196 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
199 :EXPORT_EXCLUDE_TAGS: a
200 :EXPORT_EXCLUDE_TAGS+: b
205 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
206 ;; Export properties are case-insensitive.
207 (org-test-with-temp-text "* Headline
209 :EXPORT_Date: 29-03-2012
212 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
214 ;; Still grab correct options when section above is empty.
217 (org-test-with-temp-text "* H1\n** H11\n** H12"
218 (progn (forward-line 2)
219 (plist-get (org-export-get-environment nil t
) :title
))))))
221 (ert-deftest test-org-export
/handle-options
()
222 "Test if export options have an impact on output."
223 ;; Test exclude tags.
224 (org-test-with-temp-text "* Head1 :noexport:"
225 (org-test-with-backend test
227 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
229 ;; Test include tags.
230 (org-test-with-temp-text "
233 ** Sub-Head2.1 :export:
236 (org-test-with-backend test
239 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
240 (let ((org-tags-column 0))
241 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
242 ;; Test mixing include tags and exclude tags.
243 (org-test-with-temp-text "
245 ** Sub-Head1 :noexport:
248 ** Sub-Head1 :export:"
249 (org-test-with-backend test
252 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
255 '(:select-tags
("export") :exclude-tags
("noexport")))))))
257 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
258 (org-test-with-temp-text "* TODO Head1"
259 (org-test-with-backend test
260 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
262 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
263 (org-test-with-temp-text "* TODO Head1"
264 (org-test-with-backend test
265 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
266 "* TODO Head1\n")))))
268 (org-test-with-temp-text "* Head1 :archive:"
269 (let ((org-archive-tag "archive"))
270 (org-test-with-backend test
272 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
274 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
275 (let ((org-archive-tag "archive"))
276 (org-test-with-backend test
279 "\\* Head1[ \t]+:archive:"
280 (org-export-as 'test nil nil nil
281 '(:with-archived-trees headline
)))))))
282 (org-test-with-temp-text "* Head1 :archive:"
283 (let ((org-archive-tag "archive"))
284 (org-test-with-backend test
287 "\\`\\* Head1[ \t]+:archive:\n\\'"
288 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
290 (let ((org-clock-string "CLOCK:"))
291 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
292 (org-test-with-backend test
294 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
295 "CLOCK: [2012-04-29 sun. 10:45]\n"))
297 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
299 (let ((org-drawers '("TEST")))
300 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
301 (org-test-with-backend test
302 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
304 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
305 ":TEST:\ncontents\n:END:\n")))))
306 (let ((org-drawers '("FOO" "BAR")))
307 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
308 (org-test-with-backend test
310 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
311 ":FOO:\nkeep\n:END:\n")))))
312 (let ((org-drawers '("FOO" "BAR")))
313 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
314 (org-test-with-backend test
316 (equal (org-export-as 'test nil nil nil
'(:with-drawers
(not "BAR")))
317 ":FOO:\nkeep\n:END:\n")))))
319 (when (featurep 'org-inlinetask
)
322 (let ((org-inlinetask-min-level 15))
323 (org-test-with-temp-text "*************** Task"
324 (org-test-with-backend test
325 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
329 (let ((org-inlinetask-min-level 15))
330 (org-test-with-temp-text
331 "*************** Task\nContents\n*************** END"
332 (org-test-with-backend test
333 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
336 (let ((org-closed-string "CLOSED:"))
337 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
338 (org-test-with-backend test
340 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
341 "CLOSED: [2012-04-29 sun. 10:45]\n"))
343 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
345 ;; Statistics cookies.
348 (org-test-with-temp-text "[0/0]"
349 (org-test-with-backend test
351 'test nil nil nil
'(:with-statistics-cookies nil
))))))
353 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
354 (org-test-with-backend test
356 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
357 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
359 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
361 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
362 "<2012-04-29 sun. 10:45>\n"))
364 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
365 "[2012-04-29 sun. 10:45]\n")))))
367 (ert-deftest test-org-export
/comment-tree
()
368 "Test if export process ignores commented trees."
369 (let ((org-comment-string "COMMENT"))
370 (org-test-with-temp-text "* COMMENT Head1"
371 (org-test-with-backend test
372 (should (equal (org-export-as 'test
) ""))))))
374 (ert-deftest test-org-export
/export-scope
()
375 "Test all export scopes."
376 (org-test-with-temp-text "
381 (org-test-with-backend test
384 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
386 (goto-char (point-min))
389 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
391 (goto-char (point-min))
393 (transient-mark-mode 1)
394 (push-mark (point) t t
)
395 (goto-char (point-at-eol))
396 (should (equal (org-export-as 'test
) "text\n"))))
397 ;; Subtree with a code block calling another block outside.
400 (org-test-with-temp-text "
402 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
407 #+BEGIN_SRC emacs-lisp
410 (org-test-with-backend test
412 (org-export-as 'test
'subtree
)))))
414 (org-test-with-temp-text "Text"
415 (org-test-with-backend test
417 (cdr (assq 'test org-export-registered-backends
))
419 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
420 (org-export-backend-translate-table 'test
)))
421 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
422 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
424 (ert-deftest test-org-export
/expand-include
()
425 "Test file inclusion in an Org buffer."
426 ;; Error when file isn't specified.
428 (org-test-with-temp-text "#+INCLUDE: dummy.org"
429 (org-export-expand-include-keyword)))
430 ;; Full insertion with recursive inclusion.
431 (org-test-with-temp-text
432 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
433 (org-export-expand-include-keyword)
434 (should (equal (buffer-string)
435 "Small Org file with an include keyword.
437 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
443 ;; Localized insertion.
444 (org-test-with-temp-text
445 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
447 (org-export-expand-include-keyword)
448 (should (equal (buffer-string)
449 "Small Org file with an include keyword.\n")))
450 ;; Insertion with constraints on headlines level.
451 (org-test-with-temp-text
453 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
455 (org-export-expand-include-keyword)
456 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
457 ;; Inclusion within an example block.
458 (org-test-with-temp-text
459 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
461 (org-export-expand-include-keyword)
465 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
466 ;; Inclusion within a src-block.
467 (org-test-with-temp-text
469 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
471 (org-export-expand-include-keyword)
472 (should (equal (buffer-string)
473 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
475 (ert-deftest test-org-export
/expand-macro
()
476 "Test macro expansion in an Org buffer."
477 ;; Standard macro expansion.
479 (equal "#+MACRO: macro1 value\nvalue\n"
480 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
481 (org-test-with-backend test
(org-export-as 'test
)))))
482 ;; Expand specific macros.
484 (equal "me 2012-03-29 me@here Title\n"
485 (org-test-with-temp-text
491 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
492 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
493 (substring output
(string-match ".*\n\\'" output
))))))
494 ;; Expand specific macros when property contained a regular macro
498 (org-test-with-temp-text "
499 #+MACRO: macro1 value
500 #+TITLE: {{{macro1}}}
502 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
503 (substring output
(string-match ".*\n\\'" output
))))))
504 ;; Expand macros with templates in included files.
507 (org-test-with-temp-text
508 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
509 {{{included-macro}}}" org-test-dir
)
510 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
511 (substring output
(string-match ".*\n\\'" output
)))))))
513 (ert-deftest test-org-export
/user-ignore-list
()
514 "Test if `:ignore-list' accepts user input."
515 (org-test-with-backend test
516 (flet ((skip-note-head
518 ;; Ignore headlines with the word "note" in their title.
522 (when (string-match "\\<note\\>"
523 (org-element-property :raw-value headline
))
524 (org-export-ignore-element headline info
)))
527 ;; Install function in parse tree filters.
528 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
529 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
530 (should (equal (org-export-as 'test
) "* Head1\n")))))))
532 (ert-deftest test-org-export
/before-processing-hook
()
533 "Test `org-export-before-processing-hook'."
536 "#+MACRO: mac val\nTest\n"
537 (org-test-with-backend test
538 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
539 (let ((org-export-before-processing-hook
541 (while (re-search-forward "{{{" nil t
)
542 (let ((object (org-element-context)))
543 (when (eq (org-element-type object
) 'macro
)
545 (org-element-property :begin object
)
546 (org-element-property :end object
)))))))))
547 (org-export-as 'test
)))))))
549 (ert-deftest test-org-export
/before-parsing-hook
()
550 "Test `org-export-before-parsing-hook'."
552 (equal "Body 1\nBody 2\n"
553 (org-test-with-backend test
554 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
555 (let ((org-export-before-parsing-hook
557 (goto-char (point-min))
558 (while (re-search-forward org-outline-regexp-bol nil t
)
560 (point-at-bol) (progn (forward-line) (point))))))))
561 (org-export-as 'test
)))))))
565 ;;; Affiliated Keywords
567 (ert-deftest test-org-export
/read-attribute
()
568 "Test `org-export-read-attribute' specifications."
572 (org-export-read-attribute
574 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
575 (org-element-at-point)))
577 ;; Return nil on empty attribute.
579 (org-export-read-attribute
581 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
583 (ert-deftest test-org-export
/get-caption
()
584 "Test `org-export-get-caption' specifications."
585 ;; Without optional argument, return long caption
589 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
590 (org-export-get-caption (org-element-at-point)))))
591 ;; With optional argument, return short caption.
595 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
596 (org-export-get-caption (org-element-at-point) t
))))
597 ;; Multiple lines are separated by white spaces.
601 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
602 (org-export-get-caption (org-element-at-point))))))
608 (ert-deftest test-org-export
/define-backend
()
609 "Test back-end definition and accessors."
612 (equal '((headline . my-headline-test
))
613 (let (org-export-registered-backends)
614 (org-export-define-backend test
((headline . my-headline-test
)))
615 (org-export-backend-translate-table 'test
))))
618 (equal '((:filter-headline . my-filter
))
619 (let (org-export-registered-backends)
620 (org-export-define-backend test
621 ((headline . my-headline-test
))
622 :filters-alist
((:filter-headline . my-filter
)))
623 (org-export-backend-filters 'test
))))
626 (equal '((:prop value
))
627 (let (org-export-registered-backends)
628 (org-export-define-backend test
629 ((headline . my-headline-test
))
630 :options-alist
((:prop value
)))
631 (org-export-backend-options 'test
))))
634 (equal '(?k
"Test Export" test
)
635 (let (org-export-registered-backends)
636 (org-export-define-backend test
637 ((headline . my-headline-test
))
638 :menu-entry
(?k
"Test Export" test
))
639 (org-export-backend-menu 'test
))))
642 (equal '(("TEST" . org-element-export-block-parser
))
643 (let (org-export-registered-backends org-element-block-name-alist
)
644 (org-export-define-backend test
645 ((headline . my-headline-test
))
646 :export-block
("test"))
647 org-element-block-name-alist
))))
649 (ert-deftest test-org-export
/define-derived-backend
()
650 "Test `org-export-define-derived-backend' specifications."
651 ;; Error when parent back-end is not defined.
653 (let (org-export-registered-backends)
654 (org-export-define-derived-backend test parent
)))
655 ;; Append translation table to parent's.
657 (equal '((:headline . test
) (:headline . parent
))
658 (let (org-export-registered-backends)
659 (org-export-define-backend parent
((:headline . parent
)))
660 (org-export-define-derived-backend test parent
661 :translate-alist
((:headline . test
)))
662 (org-export-backend-translate-table 'test
))))
663 ;; Options defined in the new back have priority over those defined
667 (let (org-export-registered-backends)
668 (org-export-define-backend parent
669 ((:headline . parent
))
670 :options-alist
((:a nil nil
'parent
)))
671 (org-export-define-derived-backend test parent
672 :options-alist
((:a nil nil
'test
)))
673 (plist-get (org-export--get-global-options 'test
) :a
)))))
675 (ert-deftest test-org-export
/derived-backend-p
()
676 "Test `org-export-derived-backend-p' specifications."
677 ;; Non-nil with direct match.
679 (let (org-export-registered-backends)
680 (org-export-define-backend test
((headline . test
)))
681 (org-export-derived-backend-p 'test
'test
)))
683 (let (org-export-registered-backends)
684 (org-export-define-backend test
((headline . test
)))
685 (org-export-define-derived-backend test2 test
)
686 (org-export-derived-backend-p 'test2
'test2
)))
687 ;; Non-nil with a direct parent.
689 (let (org-export-registered-backends)
690 (org-export-define-backend test
((headline . test
)))
691 (org-export-define-derived-backend test2 test
)
692 (org-export-derived-backend-p 'test2
'test
)))
693 ;; Non-nil with an indirect parent.
695 (let (org-export-registered-backends)
696 (org-export-define-backend test
((headline . test
)))
697 (org-export-define-derived-backend test2 test
)
698 (org-export-define-derived-backend test3 test2
)
699 (org-export-derived-backend-p 'test3
'test
)))
702 (let (org-export-registered-backends)
703 (org-export-define-backend test
((headline . test
)))
704 (org-export-define-backend test2
((headline . test2
)))
705 (org-export-derived-backend-p 'test2
'test
)))
707 (let (org-export-registered-backends)
708 (org-export-define-backend test
((headline . test
)))
709 (org-export-define-backend test2
((headline . test2
)))
710 (org-export-define-derived-backend test3 test2
)
711 (org-export-derived-backend-p 'test3
'test
))))
713 (ert-deftest test-org-export
/with-backend
()
714 "Test `org-export-with-backend' definition."
715 ;; Error when calling an undefined back-end
717 (let (org-export-registered-backends)
718 (org-export-with-backend 'test
"Test")))
719 ;; Error when called back-end doesn't have an appropriate
722 (let (org-export-registered-backends)
723 (org-export-define-backend test
((headline . ignore
)))
724 (org-export-with-backend 'test
"Test")))
725 ;; Otherwise, export using correct transcoder
728 (let (org-export-registered-backends)
729 (org-export-define-backend test
730 ((plain-text .
(lambda (text contents info
) "Failure"))))
731 (org-export-define-backend test2
732 ((plain-text .
(lambda (text contents info
) "Success"))))
733 (org-export-with-backend 'test2
"Test")))))
735 (ert-deftest test-org-export
/data-with-translations
()
736 "Test `org-export-data-with-translations' specifications."
740 (org-export-data-with-translations
742 '((plain-text .
(lambda (text info
) "Success"))
743 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
744 '(:with-emphasize t
)))))
746 (ert-deftest test-org-export
/data-with-backend
()
747 "Test `org-export-data-with-backend' specifications."
748 ;; Error when calling an undefined back-end.
750 (let (org-export-registered-backends)
751 (org-export-data-with-backend 'test
"Test" nil
)))
752 ;; Otherwise, export data recursively, using correct back-end.
756 (let (org-export-registered-backends)
757 (org-export-define-backend test
758 ((plain-text .
(lambda (text info
) "Success"))
759 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
760 (org-export-data-with-backend
761 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
767 (ert-deftest test-org-export
/export-snippet
()
768 "Test export snippets transcoding."
769 (org-test-with-temp-text "@@test:A@@@@t:B@@"
770 (org-test-with-backend test
772 (cdr (assq 'test org-export-registered-backends
))
774 (cons (cons 'export-snippet
775 (lambda (snippet contents info
)
776 (when (eq (org-export-snippet-backend snippet
) 'test
)
777 (org-element-property :value snippet
))))
778 (org-export-backend-translate-table 'test
)))
779 (let ((org-export-snippet-translation-alist nil
))
780 (should (equal (org-export-as 'test
) "A\n")))
781 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
782 (should (equal (org-export-as 'test
) "AB\n"))))))
788 (ert-deftest test-org-export
/footnotes
()
789 "Test footnotes specifications."
790 (let ((org-footnote-section nil
)
791 (org-export-with-footnotes t
))
792 ;; 1. Read every type of footnote.
795 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
796 (org-test-with-parsed-data
797 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
799 tree
'footnote-reference
801 (let ((def (org-export-get-footnote-definition ref info
)))
802 (cons (org-export-get-footnote-number ref info
)
803 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
804 (car (org-element-contents
805 (car (org-element-contents def
))))))))
807 ;; 2. Test nested footnotes order.
808 (org-test-with-parsed-data
809 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
812 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
814 tree
'footnote-reference
816 (when (org-export-footnote-first-reference-p ref info
)
817 (cons (org-export-get-footnote-number ref info
)
818 (org-element-property :label ref
))))
820 ;; 3. Test nested footnote in invisible definitions.
821 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
823 (narrow-to-region (point) (point-at-eol))
824 (let* ((tree (org-element-parse-buffer))
825 (info (org-combine-plists
827 (org-export-collect-tree-properties
828 tree
(org-export-get-environment)))))
829 ;; Both footnotes should be seen.
831 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
832 ;; 4. Test footnotes definitions collection.
833 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
835 \[fn:2] B [fn:3] [fn::D].
838 (should (= (length (org-export-collect-footnote-definitions tree info
))
840 ;; 5. Test export of footnotes defined outside parsing scope.
841 (org-test-with-temp-text "[fn:1] Out of scope
844 (org-test-with-backend test
846 (cdr (assq 'test org-export-registered-backends
))
848 (cons (cons 'footnote-reference
849 (lambda (fn contents info
)
850 (org-element-interpret-data
851 (org-export-get-footnote-definition fn info
))))
852 (org-export-backend-translate-table 'test
)))
854 (should (equal "ParagraphOut of scope\n"
855 (org-export-as 'test
'subtree
)))))
856 ;; 6. Footnotes without a definition should be provided a fallback
859 (org-test-with-parsed-data "[fn:1]"
860 (org-export-get-footnote-definition
861 (org-element-map tree
'footnote-reference
'identity info t
) info
)))))
865 ;;; Headlines and Inlinetasks
867 (ert-deftest test-org-export
/get-relative-level
()
868 "Test `org-export-get-relative-level' specifications."
872 (let ((org-odd-levels-only nil
))
873 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
876 (lambda (h) (org-export-get-relative-level h info
))
881 (let ((org-odd-levels-only nil
))
882 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
885 (lambda (h) (org-export-get-relative-level h info
))
888 (ert-deftest test-org-export
/low-level-p
()
889 "Test `org-export-low-level-p' specifications."
893 (let ((org-odd-levels-only nil
))
894 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
897 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
898 (plist-put info
:headline-levels
1)))))))
900 (ert-deftest test-org-export
/get-headline-number
()
901 "Test `org-export-get-headline-number' specifications."
906 (let ((org-odd-levels-only nil
))
907 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
910 (lambda (h) (org-export-get-headline-number h info
))
912 ;; Missing levels are replaced with 0.
916 (let ((org-odd-levels-only nil
))
917 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
920 (lambda (h) (org-export-get-headline-number h info
))
923 (ert-deftest test-org-export
/numbered-headline-p
()
924 "Test `org-export-numbered-headline-p' specifications."
925 ;; If `:section-numbers' is nil, never number headlines.
927 (org-test-with-parsed-data "* Headline"
930 (lambda (h) (org-export-numbered-headline-p h info
))
931 (plist-put info
:section-numbers nil
))))
932 ;; If `:section-numbers' is a number, only number headlines with
933 ;; a level greater that it.
937 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
940 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
941 (plist-put info
:section-numbers
1)))))
942 ;; Otherwise, headlines are always numbered.
944 (org-test-with-parsed-data "* Headline"
947 (lambda (h) (org-export-numbered-headline-p h info
))
948 (plist-put info
:section-numbers t
)))))
950 (ert-deftest test-org-export
/number-to-roman
()
951 "Test `org-export-number-to-roman' specifications."
952 ;; If number is negative, return it as a string.
953 (should (equal (org-export-number-to-roman -
1) "-1"))
954 ;; Otherwise, return it as a roman number.
955 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
957 (ert-deftest test-org-export
/get-tags
()
958 "Test `org-export-get-tags' specifications."
959 (let ((org-export-exclude-tags '("noexport"))
960 (org-export-select-tags '("export")))
961 ;; Standard test: tags which are not a select tag, an exclude tag,
962 ;; or specified as optional argument shouldn't be ignored.
964 (org-test-with-parsed-data "* Headline :tag:"
965 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
967 ;; Exclude tags are removed.
969 (org-test-with-parsed-data "* Headline :noexport:"
970 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
972 ;; Select tags are removed.
974 (org-test-with-parsed-data "* Headline :export:"
975 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
980 (org-test-with-parsed-data "* Headline :tag:export:"
981 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
983 ;; Tags provided in the optional argument are also ignored.
985 (org-test-with-parsed-data "* Headline :ignore:"
986 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
988 ;; Allow tag inheritance.
992 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
995 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
996 ;; Tag inheritance checks FILETAGS keywords.
1000 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1003 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1005 (ert-deftest test-org-export
/get-node-property
()
1006 "Test`org-export-get-node-property' specifications."
1010 (org-test-with-parsed-data "* Headline
1014 (org-export-get-node-property
1015 :prop
(org-element-map tree
'headline
'identity nil t
)))))
1016 ;; Test inheritance.
1019 (org-test-with-parsed-data "* Parent
1025 (org-export-get-node-property
1026 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1027 ;; Cannot return a value before the first headline.
1029 (org-test-with-parsed-data "Paragraph
1034 (org-export-get-node-property
1035 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
1037 (ert-deftest test-org-export
/get-category
()
1038 "Test `org-export-get-category' specifications."
1042 (org-test-with-parsed-data "* Headline
1046 (org-export-get-category
1047 (org-element-map tree
'headline
'identity nil t
) info
))))
1048 ;; Test inheritance from a parent headline.
1050 (equal '("value" "value")
1051 (org-test-with-parsed-data "* Headline1
1058 (lambda (hl) (org-export-get-category hl info
)) info
))))
1059 ;; Test inheritance from #+CATEGORY keyword
1062 (org-test-with-parsed-data "#+CATEGORY: value
1064 (org-export-get-category
1065 (org-element-map tree
'headline
'identity nil t
) info
))))
1066 ;; Test inheritance from file name.
1069 (org-test-with-parsed-data "* Headline"
1070 (let ((info (plist-put info
:input-file
"~/test.org")))
1071 (org-export-get-category
1072 (org-element-map tree
'headline
'identity nil t
) info
)))))
1076 (org-test-with-parsed-data "* Headline"
1077 (org-export-get-category
1078 (org-element-map tree
'headline
'identity nil t
) info
)))))
1080 (ert-deftest test-org-export
/first-sibling-p
()
1081 "Test `org-export-first-sibling-p' specifications."
1086 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1089 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1091 ;; Ignore headlines not exported.
1095 (let ((org-export-exclude-tags '("ignore")))
1096 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1099 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1102 (ert-deftest test-org-export
/last-sibling-p
()
1103 "Test `org-export-last-sibling-p' specifications."
1108 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1111 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1113 ;; Ignore headlines not exported.
1117 (let ((org-export-exclude-tags '("ignore")))
1118 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1121 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1128 (ert-deftest test-org-export
/get-coderef-format
()
1129 "Test `org-export-get-coderef-format' specifications."
1130 ;; A link without description returns "%s"
1131 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1133 ;; Return "%s" when path is matched within description.
1134 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1136 ;; Otherwise return description.
1137 (should (equal (org-export-get-coderef-format "path" "desc")
1140 (ert-deftest test-org-export
/inline-image-p
()
1141 "Test `org-export-inline-image-p' specifications."
1143 (org-export-inline-image-p
1144 (org-test-with-temp-text "[[#id]]"
1146 (org-element-parse-buffer) 'link
'identity nil t
))
1147 '(("custom-id" .
"id")))))
1149 (ert-deftest test-org-export
/fuzzy-link
()
1150 "Test fuzzy links specifications."
1151 ;; 1. Links to invisible (keyword) targets should be ignored.
1152 (org-test-with-parsed-data
1153 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1158 (org-export-get-ordinal
1159 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1160 ;; 2. Link to an headline should return headline's number.
1161 (org-test-with-parsed-data
1162 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1164 ;; Note: Headline's number is in fact a list of numbers.
1169 (org-export-get-ordinal
1170 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1171 ;; 3. Link to a target in an item should return item's number.
1172 (org-test-with-parsed-data
1173 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1175 ;; Note: Item's number is in fact a list of numbers.
1180 (org-export-get-ordinal
1181 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1182 ;; 4. Link to a target in a footnote should return footnote's
1184 (org-test-with-parsed-data "
1185 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1191 (org-export-get-ordinal
1192 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1193 ;; 5. Link to a named element should return sequence number of that
1195 (org-test-with-parsed-data
1196 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1202 (org-export-get-ordinal
1203 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1204 ;; 6. Link to a target not within an item, a table, a footnote
1205 ;; reference or definition should return section number.
1206 (org-test-with-parsed-data
1207 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1213 (org-export-get-ordinal
1214 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
1216 (ert-deftest test-org-export
/resolve-coderef
()
1217 "Test `org-export-resolve-coderef' specifications."
1218 (let ((org-coderef-label-format "(ref:%s)"))
1219 ;; 1. A link to a "-n -k -r" block returns line number.
1220 (org-test-with-parsed-data
1221 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1222 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1223 (org-test-with-parsed-data
1224 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1225 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1226 ;; 2. A link to a "-n -r" block returns line number.
1227 (org-test-with-parsed-data
1228 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1229 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1230 (org-test-with-parsed-data
1231 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1232 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1233 ;; 3. A link to a "-n" block returns coderef.
1234 (org-test-with-parsed-data
1235 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1236 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1237 (org-test-with-parsed-data
1238 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1239 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1240 ;; 4. A link to a "-r" block returns line number.
1241 (org-test-with-parsed-data
1242 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1243 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1244 (org-test-with-parsed-data
1245 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1246 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1247 ;; 5. A link to a block without a switch returns coderef.
1248 (org-test-with-parsed-data
1249 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1250 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1251 (org-test-with-parsed-data
1252 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1253 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1254 ;; 6. Correctly handle continued line numbers. A "+n" switch
1255 ;; should resume numbering from previous block with numbered
1256 ;; lines, ignoring blocks not numbering lines in the process.
1257 ;; A "-n" switch resets count.
1258 (org-test-with-parsed-data "
1263 #+BEGIN_SRC emacs-lisp
1267 #+BEGIN_SRC emacs-lisp +n -r
1268 \(+ 1 1) (ref:addition)
1271 #+BEGIN_EXAMPLE -n -r
1272 Another text. (ref:text)
1274 (should (= (org-export-resolve-coderef "addition" info
) 2))
1275 (should (= (org-export-resolve-coderef "text" info
) 1)))
1276 ;; 7. Recognize coderef with user-specified syntax.
1277 (org-test-with-parsed-data
1278 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1279 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1281 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1282 "Test `org-export-resolve-fuzzy-link' specifications."
1283 ;; 1. Match target objects.
1284 (org-test-with-parsed-data "<<target>> [[target]]"
1286 (org-export-resolve-fuzzy-link
1287 (org-element-map tree
'link
'identity info t
) info
)))
1288 ;; 2. Match target elements.
1289 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1291 (org-export-resolve-fuzzy-link
1292 (org-element-map tree
'link
'identity info t
) info
)))
1293 ;; 3. Match named elements.
1294 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1296 (org-export-resolve-fuzzy-link
1297 (org-element-map tree
'link
'identity info t
) info
)))
1298 ;; 4. Match exact headline's name.
1299 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1301 (org-export-resolve-fuzzy-link
1302 (org-element-map tree
'link
'identity info t
) info
)))
1303 ;; 5. Targets objects have priority over named elements and headline
1305 (org-test-with-parsed-data
1306 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1310 (org-export-resolve-fuzzy-link
1311 (org-element-map tree
'link
'identity info t
) info
)))))
1312 ;; 6. Named elements have priority over headline titles.
1313 (org-test-with-parsed-data
1314 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1318 (org-export-resolve-fuzzy-link
1319 (org-element-map tree
'link
'identity info t
) info
)))))
1320 ;; 7. If link's path starts with a "*", only match headline titles,
1322 (org-test-with-parsed-data
1323 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1327 (org-export-resolve-fuzzy-link
1328 (org-element-map tree
'link
'identity info t
) info
)))))
1329 ;; 8. Return nil if no match.
1330 (org-test-with-parsed-data "[[target]]"
1332 (org-export-resolve-fuzzy-link
1333 (org-element-map tree
'link
'identity info t
) info
))))
1335 (ert-deftest test-org-export
/resolve-id-link
()
1336 "Test `org-export-resolve-id-link' specifications."
1337 ;; 1. Regular test for custom-id link.
1338 (org-test-with-parsed-data "* Headline1
1345 (org-export-resolve-id-link
1346 (org-element-map tree
'link
'identity info t
) info
)))
1347 ;; 2. Failing test for custom-id link.
1348 (org-test-with-parsed-data "* Headline1
1355 (org-export-resolve-id-link
1356 (org-element-map tree
'link
'identity info t
) info
)))
1357 ;; 3. Test for internal id target.
1358 (org-test-with-parsed-data "* Headline1
1365 (org-export-resolve-id-link
1366 (org-element-map tree
'link
'identity info t
) info
)))
1367 ;; 4. Test for external id target.
1368 (org-test-with-parsed-data "[[id:aaaa]]"
1370 (org-export-resolve-id-link
1371 (org-element-map tree
'link
'identity info t
)
1372 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1374 (ert-deftest test-org-export
/resolve-radio-link
()
1375 "Test `org-export-resolve-radio-link' specifications."
1377 (org-test-with-temp-text "<<<radio>>> radio"
1378 (org-update-radio-target-regexp)
1380 (let* ((tree (org-element-parse-buffer))
1381 (info `(:parse-tree
,tree
)))
1382 (org-export-resolve-radio-link
1383 (org-element-map tree
'link
'identity info t
)
1385 ;; Radio target with objects.
1386 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1387 (org-update-radio-target-regexp)
1389 (let* ((tree (org-element-parse-buffer))
1390 (info `(:parse-tree
,tree
)))
1391 (org-export-resolve-radio-link
1392 (org-element-map tree
'link
'identity info t
)
1397 ;;; Src-block and example-block
1399 (ert-deftest test-org-export
/unravel-code
()
1400 "Test `org-export-unravel-code' function."
1401 (let ((org-coderef-label-format "(ref:%s)"))
1402 ;; 1. Code without reference.
1403 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1404 (should (equal (org-export-unravel-code (org-element-at-point))
1406 ;; 2. Code with reference.
1407 (org-test-with-temp-text
1408 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1409 (should (equal (org-export-unravel-code (org-element-at-point))
1410 '("(+ 1 1)\n" (1 .
"test")))))
1411 ;; 3. Code with user-defined reference.
1412 (org-test-with-temp-text
1413 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1414 (should (equal (org-export-unravel-code (org-element-at-point))
1415 '("(+ 1 1)\n" (1 .
"test")))))
1416 ;; 4. Code references keys are relative to the current block.
1417 (org-test-with-temp-text "
1426 (should (equal (org-export-unravel-code (org-element-at-point))
1427 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1433 (ert-deftest test-org-export
/activate-smart-quotes
()
1434 "Test `org-export-activate-smart-quotes' specifications."
1435 ;; Opening double quotes: standard test.
1438 '("some “paragraph")
1439 (let ((org-export-default-language "en"))
1440 (org-test-with-parsed-data "some \"paragraph"
1443 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1445 ;; Opening quotes: at the beginning of a paragraph.
1449 (let ((org-export-default-language "en"))
1450 (org-test-with-parsed-data "\"begin"
1453 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1455 ;; Opening quotes: after an object.
1459 (let ((org-export-default-language "en"))
1460 (org-test-with-parsed-data "=verb= \"begin"
1463 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1465 ;; Closing quotes: standard test.
1468 '("some” paragraph")
1469 (let ((org-export-default-language "en"))
1470 (org-test-with-parsed-data "some\" paragraph"
1473 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1475 ;; Closing quotes: at the end of a paragraph.
1479 (let ((org-export-default-language "en"))
1480 (org-test-with-parsed-data "end\""
1483 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1485 ;; Apostrophe: standard test.
1488 '("It shouldn’t fail")
1489 (let ((org-export-default-language "en"))
1490 (org-test-with-parsed-data "It shouldn't fail"
1493 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1495 ;; Apostrophe: before an object.
1499 (let ((org-export-default-language "en"))
1500 (org-test-with-parsed-data "a'=b="
1503 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1505 ;; Apostrophe: after an object.
1509 (let ((org-export-default-language "en"))
1510 (org-test-with-parsed-data "=code='s"
1513 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1515 ;; Special case: isolated quotes.
1517 (equal '("“" "”")
1518 (let ((org-export-default-language "en"))
1519 (org-test-with-parsed-data "\"$x$\""
1522 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1524 ;; Smart quotes in secondary strings.
1526 (equal '("“" "”")
1527 (let ((org-export-default-language "en"))
1528 (org-test-with-parsed-data "* \"$x$\""
1531 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1533 ;; Smart quotes in document keywords.
1535 (equal '("“" "”")
1536 (let ((org-export-default-language "en"))
1537 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1539 (plist-get info
:title
) 'plain-text
1540 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1542 ;; Smart quotes in parsed affiliated keywords.
1544 (equal '("“" "”" "Paragraph")
1545 (let ((org-export-default-language "en"))
1546 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1549 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1550 info nil nil t
))))))
1556 (ert-deftest test-org-export
/special-column
()
1557 "Test if the table's special column is properly recognized."
1558 ;; 1. First column is special if it contains only a special marking
1559 ;; characters or empty cells.
1560 (org-test-with-temp-text "
1564 (org-export-table-has-special-column-p
1566 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1567 ;; 2. If the column contains anything else, it isn't special.
1568 (org-test-with-temp-text "
1572 (org-export-table-has-special-column-p
1574 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1575 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1577 (org-test-with-temp-text "
1586 (org-export-table-has-special-column-p
1588 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1589 ;; 4. A first column with only empty cells isn't considered as
1591 (org-test-with-temp-text "
1595 (org-export-table-has-special-column-p
1597 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1599 (ert-deftest test-org-export
/table-row-is-special-p
()
1600 "Test `org-export-table-row-is-special-p' specifications."
1601 ;; 1. A row is special if it has a special marking character in the
1603 (org-test-with-parsed-data "| ! | 1 |"
1605 (org-export-table-row-is-special-p
1606 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1607 ;; 2. A row is special when its first field is "/"
1608 (org-test-with-parsed-data "
1612 (org-export-table-row-is-special-p
1613 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1614 ;; 3. A row only containing alignment cookies is also considered as
1616 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1618 (org-export-table-row-is-special-p
1619 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1620 ;; 4. Everything else isn't considered as special.
1621 (org-test-with-parsed-data "| \alpha | | c |"
1623 (org-export-table-row-is-special-p
1624 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1625 ;; 5. Table's rules are never considered as special rows.
1626 (org-test-with-parsed-data "|---+---|"
1628 (org-export-table-row-is-special-p
1629 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1631 (ert-deftest test-org-export
/has-header-p
()
1632 "Test `org-export-table-has-header-p' specifications."
1633 ;; 1. With an header.
1634 (org-test-with-parsed-data "
1639 (org-export-table-has-header-p
1640 (org-element-map tree
'table
'identity info
'first-match
)
1642 ;; 2. Without an header.
1643 (org-test-with-parsed-data "
1647 (org-export-table-has-header-p
1648 (org-element-map tree
'table
'identity info
'first-match
)
1650 ;; 3. Don't get fooled with starting and ending rules.
1651 (org-test-with-parsed-data "
1657 (org-export-table-has-header-p
1658 (org-element-map tree
'table
'identity info
'first-match
)
1661 (ert-deftest test-org-export
/table-row-group
()
1662 "Test `org-export-table-row-group' specifications."
1663 ;; 1. A rule creates a new group.
1664 (org-test-with-parsed-data "
1671 (mapcar (lambda (row) (org-export-table-row-group row info
))
1672 (org-element-map tree
'table-row
'identity
)))))
1673 ;; 2. Special rows are ignored in count.
1674 (org-test-with-parsed-data "
1681 (mapcar (lambda (row) (org-export-table-row-group row info
))
1682 (org-element-map tree
'table-row
'identity
)))))
1683 ;; 3. Double rules also are ignored in count.
1684 (org-test-with-parsed-data "
1692 (mapcar (lambda (row) (org-export-table-row-group row info
))
1693 (org-element-map tree
'table-row
'identity
))))))
1695 (ert-deftest test-org-export
/table-cell-width
()
1696 "Test `org-export-table-cell-width' specifications."
1697 ;; 1. Width is primarily determined by width cookies. If no cookie
1698 ;; is found, cell's width is nil.
1699 (org-test-with-parsed-data "
1700 | / | <l> | <6> | <l7> |
1705 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1706 (org-element-map tree
'table-cell
'identity info
)))))
1707 ;; 2. The last width cookie has precedence.
1708 (org-test-with-parsed-data "
1715 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1716 (org-element-map tree
'table-cell
'identity info
)))))
1717 ;; 3. Valid width cookies must have a specific row.
1718 (org-test-with-parsed-data "| <6> | cell |"
1722 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1723 (org-element-map tree
'table-cell
'identity
))))))
1725 (ert-deftest test-org-export
/table-cell-alignment
()
1726 "Test `org-export-table-cell-alignment' specifications."
1727 (let ((org-table-number-fraction 0.5)
1728 (org-table-number-regexp "^[0-9]+$"))
1729 ;; 1. Alignment is primarily determined by alignment cookies.
1730 (org-test-with-temp-text "| <l> | <c> | <r> |"
1731 (let* ((tree (org-element-parse-buffer))
1732 (info `(:parse-tree
,tree
)))
1735 '(left center right
)
1736 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1737 (org-element-map tree
'table-cell
'identity
))))))
1738 ;; 2. The last alignment cookie has precedence.
1739 (org-test-with-parsed-data "
1745 '(right right right
)
1746 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1747 (org-element-map tree
'table-cell
'identity
)))))
1748 ;; 3. If there's no cookie, cell's contents determine alignment.
1749 ;; A column mostly made of cells containing numbers will align
1750 ;; its cells to the right.
1751 (org-test-with-parsed-data "
1757 '(right right right
)
1758 (mapcar (lambda (cell)
1759 (org-export-table-cell-alignment cell info
))
1760 (org-element-map tree
'table-cell
'identity
)))))
1761 ;; 4. Otherwise, they will be aligned to the left.
1762 (org-test-with-parsed-data "
1769 (mapcar (lambda (cell)
1770 (org-export-table-cell-alignment cell info
))
1771 (org-element-map tree
'table-cell
'identity
)))))))
1773 (ert-deftest test-org-export
/table-cell-borders
()
1774 "Test `org-export-table-cell-borders' specifications."
1775 ;; 1. Recognize various column groups indicators.
1776 (org-test-with-parsed-data "| / | < | > | <> |"
1779 '((right bottom top
) (left bottom top
) (right bottom top
)
1780 (right left bottom top
))
1781 (mapcar (lambda (cell)
1782 (org-export-table-cell-borders cell info
))
1783 (org-element-map tree
'table-cell
'identity
)))))
1784 ;; 2. Accept shortcuts to define column groups.
1785 (org-test-with-parsed-data "| / | < | < |"
1788 '((right bottom top
) (right left bottom top
) (left bottom top
))
1789 (mapcar (lambda (cell)
1790 (org-export-table-cell-borders cell info
))
1791 (org-element-map tree
'table-cell
'identity
)))))
1792 ;; 3. A valid column groups row must start with a "/".
1793 (org-test-with-parsed-data "
1797 (equal '((top) (top) (bottom) (bottom))
1798 (mapcar (lambda (cell)
1799 (org-export-table-cell-borders cell info
))
1800 (org-element-map tree
'table-cell
'identity
)))))
1801 ;; 4. Take table rules into consideration.
1802 (org-test-with-parsed-data "
1807 (equal '((below top
) (bottom above
))
1808 (mapcar (lambda (cell)
1809 (org-export-table-cell-borders cell info
))
1810 (org-element-map tree
'table-cell
'identity
)))))
1811 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1812 ;; (resp. `bottom' and `below') borders. Any special row is
1814 (org-test-with-parsed-data "
1820 (equal '((bottom below top above
))
1822 (mapcar (lambda (cell)
1823 (org-export-table-cell-borders cell info
))
1824 (org-element-map tree
'table-cell
'identity
)))))))
1826 (ert-deftest test-org-export
/table-dimensions
()
1827 "Test `org-export-table-dimensions' specifications."
1828 ;; 1. Standard test.
1829 (org-test-with-parsed-data "
1834 (org-export-table-dimensions
1835 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1836 ;; 2. Ignore horizontal rules and special columns.
1837 (org-test-with-parsed-data "
1844 (org-export-table-dimensions
1845 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1847 (ert-deftest test-org-export
/table-cell-address
()
1848 "Test `org-export-table-cell-address' specifications."
1849 ;; 1. Standard test: index is 0-based.
1850 (org-test-with-parsed-data "| a | b |"
1852 (equal '((0 .
0) (0 .
1))
1855 (lambda (cell) (org-export-table-cell-address cell info
))
1857 ;; 2. Special column isn't counted, nor are special rows.
1858 (org-test-with-parsed-data "
1863 (org-export-table-cell-address
1864 (car (last (org-element-map tree
'table-cell
'identity info
)))
1866 ;; 3. Tables rules do not count either.
1867 (org-test-with-parsed-data "
1875 (org-export-table-cell-address
1876 (car (last (org-element-map tree
'table-cell
'identity info
)))
1878 ;; 4. Return nil for special cells.
1879 (org-test-with-parsed-data "| / | a |"
1881 (org-export-table-cell-address
1882 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1885 (ert-deftest test-org-export
/get-table-cell-at
()
1886 "Test `org-export-get-table-cell-at' specifications."
1887 ;; 1. Address ignores special columns, special rows and rules.
1888 (org-test-with-parsed-data "
1895 (org-element-contents
1896 (org-export-get-table-cell-at
1898 (org-element-map tree
'table
'identity info
'first-match
)
1900 ;; 2. Return value for a non-existent address is nil.
1901 (org-test-with-parsed-data "| a |"
1903 (org-export-get-table-cell-at
1905 (org-element-map tree
'table
'identity info
'first-match
)
1907 (org-test-with-parsed-data "| / |"
1909 (org-export-get-table-cell-at
1911 (org-element-map tree
'table
'identity info
'first-match
)
1914 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1915 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1916 ;; 1. A cell at a beginning of a row always starts a column group.
1917 (org-test-with-parsed-data "| a |"
1919 (org-export-table-cell-starts-colgroup-p
1920 (org-element-map tree
'table-cell
'identity info
'first-match
)
1922 ;; 2. Special column should be ignored when determining the
1923 ;; beginning of the row.
1924 (org-test-with-parsed-data "
1928 (org-export-table-cell-starts-colgroup-p
1929 (org-element-map tree
'table-cell
'identity info
'first-match
)
1931 ;; 2. Explicit column groups.
1932 (org-test-with-parsed-data "
1941 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1944 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1945 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1946 ;; 1. A cell at the end of a row always ends a column group.
1947 (org-test-with-parsed-data "| a |"
1949 (org-export-table-cell-ends-colgroup-p
1950 (org-element-map tree
'table-cell
'identity info
'first-match
)
1952 ;; 2. Special column should be ignored when determining the
1953 ;; beginning of the row.
1954 (org-test-with-parsed-data "
1958 (org-export-table-cell-ends-colgroup-p
1959 (org-element-map tree
'table-cell
'identity info
'first-match
)
1961 ;; 3. Explicit column groups.
1962 (org-test-with-parsed-data "
1971 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1974 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1975 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1976 ;; 1. A row at the beginning of a table always starts a row group.
1977 ;; So does a row following a table rule.
1978 (org-test-with-parsed-data "
1988 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1990 ;; 2. Special rows should be ignored when determining the beginning
1992 (org-test-with-parsed-data "
2004 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2007 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2008 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2009 ;; 1. A row at the end of a table always ends a row group. So does
2010 ;; a row preceding a table rule.
2011 (org-test-with-parsed-data "
2021 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2023 ;; 2. Special rows should be ignored when determining the beginning
2025 (org-test-with-parsed-data "
2037 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2040 (ert-deftest test-org-export
/table-row-starts-header-p
()
2041 "Test `org-export-table-row-starts-header-p' specifications."
2042 ;; 1. Only the row starting the first row group starts the table
2044 (org-test-with-parsed-data "
2055 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2057 ;; 2. A row cannot start an header if there's no header in the
2059 (org-test-with-parsed-data "
2063 (org-export-table-row-starts-header-p
2064 (org-element-map tree
'table-row
'identity info
'first-match
)
2067 (ert-deftest test-org-export
/table-row-ends-header-p
()
2068 "Test `org-export-table-row-ends-header-p' specifications."
2069 ;; 1. Only the row starting the first row group starts the table
2071 (org-test-with-parsed-data "
2082 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2084 ;; 2. A row cannot start an header if there's no header in the
2086 (org-test-with-parsed-data "
2090 (org-export-table-row-ends-header-p
2091 (org-element-map tree
'table-row
'identity info
'first-match
)
2098 (ert-deftest test-org-export
/inner-template
()
2099 "Test `inner-template' translator specifications."
2102 (let (org-export-registered-backends)
2103 (org-export-define-backend test
2104 ((inner-template .
(lambda (contents info
) "Success!"))
2105 (headline .
(lambda (h c i
) "Headline"))))
2106 (org-test-with-temp-text "* Headline"
2107 (org-export-as 'test
)))))
2108 ;; Inner template is applied even in a "body-only" export.
2111 (let (org-export-registered-backends)
2112 (org-export-define-backend test
2113 ((inner-template .
(lambda (contents info
) "Success!"))
2114 (headline .
(lambda (h c i
) "Headline"))))
2115 (org-test-with-temp-text "* Headline"
2116 (org-export-as 'test nil nil
'body-only
))))))
2118 (ert-deftest test-org-export
/template
()
2119 "Test `template' translator specifications."
2122 (let (org-export-registered-backends)
2123 (org-export-define-backend test
2124 ((template .
(lambda (contents info
) "Success!"))
2125 (headline .
(lambda (h c i
) "Headline"))))
2126 (org-test-with-temp-text "* Headline"
2127 (org-export-as 'test
)))))
2128 ;; Template is not applied in a "body-only" export.
2131 (let (org-export-registered-backends)
2132 (org-export-define-backend test
2133 ((template .
(lambda (contents info
) "Success!"))
2134 (headline .
(lambda (h c i
) "Headline"))))
2135 (org-test-with-temp-text "* Headline"
2136 (org-export-as 'test nil nil
'body-only
))))))
2142 (ert-deftest test-org-export
/get-next-element
()
2143 "Test `org-export-get-next-element' specifications."
2147 (org-test-with-parsed-data "* Headline\n*a* b"
2148 (org-export-get-next-element
2149 (org-element-map tree
'bold
'identity info t
) info
))))
2150 ;; Return nil when no previous element.
2152 (org-test-with-parsed-data "* Headline\na *b*"
2153 (org-export-get-next-element
2154 (org-element-map tree
'bold
'identity info t
) info
)))
2155 ;; Non-exportable elements are ignored.
2157 (let ((org-export-with-timestamps nil
))
2158 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2159 (org-export-get-next-element
2160 (org-element-map tree
'entity
'identity info t
) info
))))
2161 ;; Find next element in secondary strings.
2164 (org-test-with-parsed-data "* a =verb="
2166 (org-export-get-next-element
2167 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2168 ;; Find next element in document keywords.
2171 (org-test-with-parsed-data "#+TITLE: a =verb="
2173 (org-export-get-next-element
2175 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2176 ;; Find next element in parsed affiliated keywords.
2179 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2181 (org-export-get-next-element
2182 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2183 ;; With optional argument N, return a list containing all the
2184 ;; following elements.
2187 '(bold code underline
)
2188 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2190 (org-export-get-next-element
2191 (org-element-map tree
'italic
'identity info t
) info t
)))))
2192 ;; When N is a positive integer, return a list containing up to
2193 ;; N following elements.
2197 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2199 (org-export-get-next-element
2200 (org-element-map tree
'italic
'identity info t
) info
2))))))
2202 (ert-deftest test-org-export
/get-previous-element
()
2203 "Test `org-export-get-previous-element' specifications."
2207 (org-test-with-parsed-data "* Headline\na *b*"
2208 (org-export-get-previous-element
2209 (org-element-map tree
'bold
'identity info t
) info
))))
2210 ;; Return nil when no previous element.
2212 (org-test-with-parsed-data "* Headline\n*a* b"
2213 (org-export-get-previous-element
2214 (org-element-map tree
'bold
'identity info t
) info
)))
2215 ;; Non-exportable elements are ignored.
2217 (let ((org-export-with-timestamps nil
))
2218 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2219 (org-export-get-previous-element
2220 (org-element-map tree
'entity
'identity info t
) info
))))
2221 ;; Find previous element in secondary strings.
2224 (org-test-with-parsed-data "* =verb= a"
2226 (org-export-get-previous-element
2227 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2228 ;; Find previous element in document keywords.
2231 (org-test-with-parsed-data "#+TITLE: =verb= a"
2233 (org-export-get-previous-element
2235 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2236 ;; Find previous element in parsed affiliated keywords.
2239 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2241 (org-export-get-previous-element
2242 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2243 ;; With optional argument N, return a list containing up to
2244 ;; N previous elements.
2246 (equal '(bold italic underline
)
2247 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2249 (org-export-get-previous-element
2250 (org-element-map tree
'code
'identity info t
) info t
)))))
2251 ;; When N is a positive integer, return a list containing up to
2252 ;; N previous elements.
2254 (equal '(bold italic
)
2255 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2257 (org-export-get-previous-element
2258 (org-element-map tree
'code
'identity info t
) info
2))))))
2262 ;;; test-org-export.el end here