1 ;;; test-org-export.el --- Tests for org-export.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 'org-export
)
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-all-BIND' set to t.
78 (org-test-with-temp-text "#+BIND: variable value"
79 (let ((org-export-allow-BIND t
))
80 (org-export--install-letbind-maybe)
81 (eq variable
'value
))))
82 ;; Test with `org-export-all-BIND' set to nil.
84 (org-test-with-temp-text "#+BIND: variable value"
85 (let ((org-export-allow-BIND nil
))
86 (org-export--install-letbind-maybe)
88 ;; Test with `org-export-all-BIND' set to 'confirm and
89 ;; `org-export--allow-BIND-local' to t .
91 (org-test-with-temp-text "#+BIND: variable value"
92 (let ((org-export-allow-BIND 'confirm
))
93 (org-set-local 'org-export--allow-BIND-local t
)
94 (org-export--install-letbind-maybe)
95 (eq variable
'value
))))
96 ;; Test with `org-export-all-BIND' set to 'confirm and
97 ;; `org-export--allow-BIND-local' to nil.
99 (org-test-with-temp-text "#+BIND: variable value"
100 (let ((org-export-allow-BIND 'confirm
))
101 (org-set-local 'org-export--allow-BIND-local nil
)
102 (org-export--install-letbind-maybe)
103 (boundp 'variable
))))
104 ;; BIND keywords are case-insensitive.
106 (org-test-with-temp-text "#+bind: variable value"
107 (let ((org-export-allow-BIND t
))
108 (org-export--install-letbind-maybe)
109 (eq variable
'value
)))))
111 (ert-deftest test-org-export
/parse-option-keyword
()
112 "Test reading all standard #+OPTIONS: items."
115 (org-export--parse-option-keyword
116 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
117 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
120 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
121 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
122 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
123 :with-footnotes t
:with-inlinetasks nil
:with-priority t
124 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
125 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
126 :with-todo-keywords t
)))
127 ;; Test some special values.
130 (org-export--parse-option-keyword
131 "arch:headline creator:comment d:(\"TEST\")
132 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
135 :with-archived-trees headline
:with-creator comment
136 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
137 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
139 (ert-deftest test-org-export
/get-inbuffer-options
()
140 "Test reading all standard export keywords."
143 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
146 #+DESCRIPTION: Testing
147 #+DESCRIPTION: with two lines
148 #+EMAIL: some@email.org
149 #+EXCLUDE_TAGS: noexport invisible
152 #+SELECT_TAGS: export
154 #+TITLE: with spaces"
155 (org-export--get-inbuffer-options))
157 ("Me, Myself and I") :creator
"Idem" :date
("Today")
158 :description
"Testing\nwith two lines" :email
"some@email.org"
159 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
160 :select-tags
("export") :title
("Some title with spaces")))))
162 (ert-deftest test-org-export
/get-subtree-options
()
163 "Test setting options from headline's properties."
165 (org-test-with-temp-text "#+TITLE: Title
168 :EXPORT_TITLE: Subtree Title
172 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
173 '("Subtree Title"))))
177 (org-test-with-temp-text "#+OPTIONS: H:1
185 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
187 (org-test-with-temp-text "#+DATE: today
190 :EXPORT_DATE: 29-03-2012
194 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
196 ;; Properties with `split' behaviour are stored as a list of
200 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
203 :EXPORT_EXCLUDE_TAGS: a b
208 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
209 ;; Handle :PROPERTY+: syntax.
212 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
215 :EXPORT_EXCLUDE_TAGS: a
216 :EXPORT_EXCLUDE_TAGS+: b
221 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
222 ;; Export properties are case-insensitive.
223 (org-test-with-temp-text "* Headline
225 :EXPORT_Date: 29-03-2012
228 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
230 ;; Still grab correct options when section above is empty.
233 (org-test-with-temp-text "* H1\n** H11\n** H12"
234 (progn (forward-line 2)
235 (plist-get (org-export-get-environment nil t
) :title
))))))
237 (ert-deftest test-org-export
/handle-options
()
238 "Test if export options have an impact on output."
239 ;; Test exclude tags.
240 (org-test-with-temp-text "* Head1 :noexport:"
241 (org-test-with-backend test
243 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
245 ;; Test include tags.
246 (org-test-with-temp-text "
249 ** Sub-Head2.1 :export:
252 (org-test-with-backend test
255 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
256 (let ((org-tags-column 0))
257 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
258 ;; Test mixing include tags and exclude tags.
259 (org-test-with-temp-text "
261 ** Sub-Head1 :noexport:
264 ** Sub-Head1 :export:"
265 (org-test-with-backend test
268 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
271 '(:select-tags
("export") :exclude-tags
("noexport")))))))
273 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
274 (org-test-with-temp-text "* TODO Head1"
275 (org-test-with-backend test
276 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
278 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
279 (org-test-with-temp-text "* TODO Head1"
280 (org-test-with-backend test
281 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
282 "* TODO Head1\n")))))
284 (org-test-with-temp-text "* Head1 :archive:"
285 (let ((org-archive-tag "archive"))
286 (org-test-with-backend test
288 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
290 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
291 (let ((org-archive-tag "archive"))
292 (org-test-with-backend test
295 "\\* Head1[ \t]+:archive:"
296 (org-export-as 'test nil nil nil
297 '(:with-archived-trees headline
)))))))
298 (org-test-with-temp-text "* Head1 :archive:"
299 (let ((org-archive-tag "archive"))
300 (org-test-with-backend test
303 "\\`\\* Head1[ \t]+:archive:\n\\'"
304 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
306 (let ((org-drawers '("TEST")))
307 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
308 (org-test-with-backend test
309 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
311 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
312 ":TEST:\ncontents\n:END:\n")))))
313 (let ((org-drawers '("FOO" "BAR")))
314 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
315 (org-test-with-backend test
317 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
318 ":FOO:\nkeep\n:END:\n")))))
320 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
321 (org-test-with-backend test
323 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
324 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
326 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
328 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
329 "<2012-04-29 sun. 10:45>\n"))
331 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
332 "[2012-04-29 sun. 10:45]\n"))))
334 (let ((org-clock-string "CLOCK:"))
335 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
336 (org-test-with-backend test
338 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
339 "CLOCK: [2012-04-29 sun. 10:45]\n"))
341 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
343 (let ((org-closed-string "CLOSED:"))
344 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
345 (org-test-with-backend test
347 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
348 "CLOSED: [2012-04-29 sun. 10:45]\n"))
350 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
353 (when (featurep 'org-inlinetask
)
356 (let ((org-inlinetask-min-level 15))
357 (org-test-with-temp-text "*************** Task"
358 (org-test-with-backend test
359 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
363 (let ((org-inlinetask-min-level 15))
364 (org-test-with-temp-text
365 "*************** Task\nContents\n*************** END"
366 (org-test-with-backend test
367 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
369 ;; Statistics cookies.
372 (org-test-with-temp-text "[0/0]"
373 (org-test-with-backend test
375 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
377 (ert-deftest test-org-export
/comment-tree
()
378 "Test if export process ignores commented trees."
379 (let ((org-comment-string "COMMENT"))
380 (org-test-with-temp-text "* COMMENT Head1"
381 (org-test-with-backend test
382 (should (equal (org-export-as 'test
) ""))))))
384 (ert-deftest test-org-export
/export-scope
()
385 "Test all export scopes."
386 (org-test-with-temp-text "
391 (org-test-with-backend test
394 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
396 (goto-char (point-min))
399 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
401 (goto-char (point-min))
403 (transient-mark-mode 1)
404 (push-mark (point) t t
)
405 (goto-char (point-at-eol))
406 (should (equal (org-export-as 'test
) "text\n"))))
407 ;; Subtree with a code block calling another block outside.
410 (org-test-with-temp-text "
412 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
417 #+BEGIN_SRC emacs-lisp
420 (org-test-with-backend test
422 (org-export-as 'test
'subtree
)))))
424 (org-test-with-temp-text "Text"
425 (org-test-with-backend test
427 (cdr (assq 'test org-export-registered-backends
))
429 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
430 (org-export-backend-translate-table 'test
)))
431 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
432 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
434 (ert-deftest test-org-export
/expand-include
()
435 "Test file inclusion in an Org buffer."
436 ;; Error when file isn't specified.
438 (org-test-with-temp-text "#+INCLUDE: dummy.org"
439 (org-export-expand-include-keyword)))
440 ;; Full insertion with recursive inclusion.
441 (org-test-with-temp-text
442 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
443 (org-export-expand-include-keyword)
444 (should (equal (buffer-string)
445 "Small Org file with an include keyword.
447 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
453 ;; Localized insertion.
454 (org-test-with-temp-text
455 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
457 (org-export-expand-include-keyword)
458 (should (equal (buffer-string)
459 "Small Org file with an include keyword.\n")))
460 ;; Insertion with constraints on headlines level.
461 (org-test-with-temp-text
463 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
465 (org-export-expand-include-keyword)
466 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
467 ;; Inclusion within an example block.
468 (org-test-with-temp-text
469 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
471 (org-export-expand-include-keyword)
475 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
476 ;; Inclusion within a src-block.
477 (org-test-with-temp-text
479 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
481 (org-export-expand-include-keyword)
482 (should (equal (buffer-string)
483 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
485 (ert-deftest test-org-export
/expand-macro
()
486 "Test macro expansion in an Org buffer."
487 ;; Standard macro expansion.
489 (equal "#+MACRO: macro1 value\nvalue\n"
490 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
491 (org-test-with-backend test
(org-export-as 'test
)))))
492 ;; Expand specific macros.
494 (equal "me 2012-03-29 me@here Title\n"
495 (org-test-with-temp-text
501 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
502 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
503 (substring output
(string-match ".*\n\\'" output
))))))
504 ;; Expand specific macros when property contained a regular macro
508 (org-test-with-temp-text "
509 #+MACRO: macro1 value
510 #+TITLE: {{{macro1}}}
512 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
513 (substring output
(string-match ".*\n\\'" output
))))))
514 ;; Expand macros with templates in included files.
517 (org-test-with-temp-text
518 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
519 {{{included-macro}}}" org-test-dir
)
520 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
521 (substring output
(string-match ".*\n\\'" output
)))))))
523 (ert-deftest test-org-export
/user-ignore-list
()
524 "Test if `:ignore-list' accepts user input."
525 (org-test-with-backend test
526 (flet ((skip-note-head
528 ;; Ignore headlines with the word "note" in their title.
532 (when (string-match "\\<note\\>"
533 (org-element-property :raw-value headline
))
534 (org-export-ignore-element headline info
)))
537 ;; Install function in parse tree filters.
538 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
539 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
540 (should (equal (org-export-as 'test
) "* Head1\n")))))))
542 (ert-deftest test-org-export
/before-processing-hook
()
543 "Test `org-export-before-processing-hook'."
546 "#+MACRO: mac val\nTest\n"
547 (org-test-with-backend test
548 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
549 (let ((org-export-before-processing-hook
551 (while (re-search-forward "{{{" nil t
)
552 (let ((object (org-element-context)))
553 (when (eq (org-element-type object
) 'macro
)
555 (org-element-property :begin object
)
556 (org-element-property :end object
)))))))))
557 (org-export-as 'test
)))))))
559 (ert-deftest test-org-export
/before-parsing-hook
()
560 "Test `org-export-before-parsing-hook'."
562 (equal "Body 1\nBody 2\n"
563 (org-test-with-backend test
564 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
565 (let ((org-export-before-parsing-hook
567 (goto-char (point-min))
568 (while (re-search-forward org-outline-regexp-bol nil t
)
570 (point-at-bol) (progn (forward-line) (point))))))))
571 (org-export-as 'test
)))))))
575 ;;; Affiliated Keywords
577 (ert-deftest test-org-export
/read-attribute
()
578 "Test `org-export-read-attribute' specifications."
582 (org-export-read-attribute
584 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
585 (org-element-at-point)))
587 ;; Return nil on empty attribute.
589 (org-export-read-attribute
591 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
593 (ert-deftest test-org-export
/get-caption
()
594 "Test `org-export-get-caption' specifications."
595 ;; Without optional argument, return long caption
599 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
600 (org-export-get-caption (org-element-at-point)))))
601 ;; With optional argument, return short caption.
605 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
606 (org-export-get-caption (org-element-at-point) t
))))
607 ;; Multiple lines are separated by white spaces.
611 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
612 (org-export-get-caption (org-element-at-point))))))
618 (ert-deftest test-org-export
/define-backend
()
619 "Test back-end definition and accessors."
622 (equal '((headline . my-headline-test
))
623 (let (org-export-registered-backends)
624 (org-export-define-backend test
((headline . my-headline-test
)))
625 (org-export-backend-translate-table 'test
))))
628 (equal '((:filter-headline . my-filter
))
629 (let (org-export-registered-backends)
630 (org-export-define-backend test
631 ((headline . my-headline-test
))
632 :filters-alist
((:filter-headline . my-filter
)))
633 (org-export-backend-filters 'test
))))
636 (equal '((:prop value
))
637 (let (org-export-registered-backends)
638 (org-export-define-backend test
639 ((headline . my-headline-test
))
640 :options-alist
((:prop value
)))
641 (org-export-backend-options 'test
))))
644 (equal '(?k
"Test Export" test
)
645 (let (org-export-registered-backends)
646 (org-export-define-backend test
647 ((headline . my-headline-test
))
648 :menu-entry
(?k
"Test Export" test
))
649 (org-export-backend-menu 'test
))))
652 (equal '(("TEST" . org-element-export-block-parser
))
653 (let (org-export-registered-backends org-element-block-name-alist
)
654 (org-export-define-backend test
655 ((headline . my-headline-test
))
656 :export-block
("test"))
657 org-element-block-name-alist
))))
659 (ert-deftest test-org-export
/define-derived-backend
()
660 "Test `org-export-define-derived-backend' specifications."
661 ;; Error when parent back-end is not defined.
663 (let (org-export-registered-backends)
664 (org-export-define-derived-backend test parent
)))
665 ;; Append translation table to parent's.
667 (equal '((:headline . test
) (:headline . parent
))
668 (let (org-export-registered-backends)
669 (org-export-define-backend parent
((:headline . parent
)))
670 (org-export-define-derived-backend test parent
671 :translate-alist
((:headline . test
)))
672 (org-export-backend-translate-table 'test
)))))
674 (ert-deftest test-org-export
/derived-backend-p
()
675 "Test `org-export-derived-backend-p' specifications."
676 ;; Non-nil with direct match.
678 (let (org-export-registered-backends)
679 (org-export-define-backend test
((headline . test
)))
680 (org-export-derived-backend-p 'test
'test
)))
682 (let (org-export-registered-backends)
683 (org-export-define-backend test
((headline . test
)))
684 (org-export-define-derived-backend test2 test
)
685 (org-export-derived-backend-p 'test2
'test2
)))
686 ;; Non-nil with a direct parent.
688 (let (org-export-registered-backends)
689 (org-export-define-backend test
((headline . test
)))
690 (org-export-define-derived-backend test2 test
)
691 (org-export-derived-backend-p 'test2
'test
)))
692 ;; Non-nil with an indirect parent.
694 (let (org-export-registered-backends)
695 (org-export-define-backend test
((headline . test
)))
696 (org-export-define-derived-backend test2 test
)
697 (org-export-define-derived-backend test3 test2
)
698 (org-export-derived-backend-p 'test3
'test
)))
701 (let (org-export-registered-backends)
702 (org-export-define-backend test
((headline . test
)))
703 (org-export-define-backend test2
((headline . test2
)))
704 (org-export-derived-backend-p 'test2
'test
)))
706 (let (org-export-registered-backends)
707 (org-export-define-backend test
((headline . test
)))
708 (org-export-define-backend test2
((headline . test2
)))
709 (org-export-define-derived-backend test3 test2
)
710 (org-export-derived-backend-p 'test3
'test
))))
712 (ert-deftest test-org-export
/with-backend
()
713 "Test `org-export-with-backend' definition."
714 ;; Error when calling an undefined back-end
716 (let (org-export-registered-backends)
717 (org-export-with-backend 'test
"Test")))
718 ;; Error when called back-end doesn't have an appropriate
721 (let (org-export-registered-backends)
722 (org-export-define-backend test
((headline . ignore
)))
723 (org-export-with-backend 'test
"Test")))
724 ;; Otherwise, export using correct transcoder
727 (let (org-export-registered-backends)
728 (org-export-define-backend test
729 ((plain-text .
(lambda (text contents info
) "Failure"))))
730 (org-export-define-backend test2
731 ((plain-text .
(lambda (text contents info
) "Success"))))
732 (org-export-with-backend 'test2
"Test")))))
734 (ert-deftest test-org-export
/data-with-translations
()
735 "Test `org-export-data-with-translations' specifications."
739 (org-export-data-with-translations
741 '((plain-text .
(lambda (text info
) "Success"))
742 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
743 '(:with-emphasize t
)))))
745 (ert-deftest test-org-export
/data-with-backend
()
746 "Test `org-export-data-with-backend' specifications."
747 ;; Error when calling an undefined back-end.
749 (let (org-export-registered-backends)
750 (org-export-data-with-backend 'test
"Test" nil
)))
751 ;; Otherwise, export data recursively, using correct back-end.
755 (let (org-export-registered-backends)
756 (org-export-define-backend test
757 ((plain-text .
(lambda (text info
) "Success"))
758 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
759 (org-export-data-with-backend
760 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
766 (ert-deftest test-org-export
/export-snippet
()
767 "Test export snippets transcoding."
768 (org-test-with-temp-text "@@test:A@@@@t:B@@"
769 (org-test-with-backend test
771 (cdr (assq 'test org-export-registered-backends
))
773 (cons (cons 'export-snippet
774 (lambda (snippet contents info
)
775 (when (eq (org-export-snippet-backend snippet
) 'test
)
776 (org-element-property :value snippet
))))
777 (org-export-backend-translate-table 'test
)))
778 (let ((org-export-snippet-translation-alist nil
))
779 (should (equal (org-export-as 'test
) "A\n")))
780 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
781 (should (equal (org-export-as 'test
) "AB\n"))))))
787 (ert-deftest test-org-export
/footnotes
()
788 "Test footnotes specifications."
789 (let ((org-footnote-section nil
)
790 (org-export-with-footnotes t
))
791 ;; 1. Read every type of footnote.
794 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
795 (org-test-with-parsed-data
796 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
798 tree
'footnote-reference
800 (let ((def (org-export-get-footnote-definition ref info
)))
801 (cons (org-export-get-footnote-number ref info
)
802 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
803 (car (org-element-contents
804 (car (org-element-contents def
))))))))
806 ;; 2. Test nested footnotes order.
807 (org-test-with-parsed-data
808 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
811 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
813 tree
'footnote-reference
815 (when (org-export-footnote-first-reference-p ref info
)
816 (cons (org-export-get-footnote-number ref info
)
817 (org-element-property :label ref
))))
819 ;; 3. Test nested footnote in invisible definitions.
820 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
822 (narrow-to-region (point) (point-at-eol))
823 (let* ((tree (org-element-parse-buffer))
824 (info (org-combine-plists
826 (org-export-collect-tree-properties
827 tree
(org-export-get-environment)))))
828 ;; Both footnotes should be seen.
830 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
831 ;; 4. Test footnotes definitions collection.
832 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
834 \[fn:2] B [fn:3] [fn::D].
837 (should (= (length (org-export-collect-footnote-definitions tree info
))
839 ;; 5. Test export of footnotes defined outside parsing scope.
840 (org-test-with-temp-text "[fn:1] Out of scope
843 (org-test-with-backend test
845 (cdr (assq 'test org-export-registered-backends
))
847 (cons (cons 'footnote-reference
848 (lambda (fn contents info
)
849 (org-element-interpret-data
850 (org-export-get-footnote-definition fn info
))))
851 (org-export-backend-translate-table 'test
)))
853 (should (equal "ParagraphOut of scope\n"
854 (org-export-as 'test
'subtree
)))))
855 ;; 6. Footnotes without a definition should be provided a fallback
858 (org-test-with-parsed-data "[fn:1]"
859 (org-export-get-footnote-definition
860 (org-element-map tree
'footnote-reference
'identity info t
) info
)))))
864 ;;; Headlines and Inlinetasks
866 (ert-deftest test-org-export
/get-relative-level
()
867 "Test `org-export-get-relative-level' specifications."
871 (let ((org-odd-levels-only nil
))
872 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
875 (lambda (h) (org-export-get-relative-level h info
))
880 (let ((org-odd-levels-only nil
))
881 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
884 (lambda (h) (org-export-get-relative-level h info
))
887 (ert-deftest test-org-export
/low-level-p
()
888 "Test `org-export-low-level-p' specifications."
892 (let ((org-odd-levels-only nil
))
893 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
896 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
897 (plist-put info
:headline-levels
1)))))))
899 (ert-deftest test-org-export
/get-headline-number
()
900 "Test `org-export-get-headline-number' specifications."
905 (let ((org-odd-levels-only nil
))
906 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
909 (lambda (h) (org-export-get-headline-number h info
))
911 ;; Missing levels are replaced with 0.
915 (let ((org-odd-levels-only nil
))
916 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
919 (lambda (h) (org-export-get-headline-number h info
))
922 (ert-deftest test-org-export
/numbered-headline-p
()
923 "Test `org-export-numbered-headline-p' specifications."
924 ;; If `:section-numbers' is nil, never number headlines.
926 (org-test-with-parsed-data "* Headline"
929 (lambda (h) (org-export-numbered-headline-p h info
))
930 (plist-put info
:section-numbers nil
))))
931 ;; If `:section-numbers' is a number, only number headlines with
932 ;; a level greater that it.
936 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
939 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
940 (plist-put info
:section-numbers
1)))))
941 ;; Otherwise, headlines are always numbered.
943 (org-test-with-parsed-data "* Headline"
946 (lambda (h) (org-export-numbered-headline-p h info
))
947 (plist-put info
:section-numbers t
)))))
949 (ert-deftest test-org-export
/number-to-roman
()
950 "Test `org-export-number-to-roman' specifications."
951 ;; If number is negative, return it as a string.
952 (should (equal (org-export-number-to-roman -
1) "-1"))
953 ;; Otherwise, return it as a roman number.
954 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
956 (ert-deftest test-org-export
/get-tags
()
957 "Test `org-export-get-tags' specifications."
958 (let ((org-export-exclude-tags '("noexport"))
959 (org-export-select-tags '("export")))
960 ;; Standard test: tags which are not a select tag, an exclude tag,
961 ;; or specified as optional argument shouldn't be ignored.
963 (org-test-with-parsed-data "* Headline :tag:"
964 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
966 ;; Exclude tags are removed.
968 (org-test-with-parsed-data "* Headline :noexport:"
969 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
971 ;; Select tags are removed.
973 (org-test-with-parsed-data "* Headline :export:"
974 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
979 (org-test-with-parsed-data "* Headline :tag:export:"
980 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
982 ;; Tags provided in the optional argument are also ignored.
984 (org-test-with-parsed-data "* Headline :ignore:"
985 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
987 ;; Allow tag inheritance.
991 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
994 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
995 ;; Tag inheritance checks FILETAGS keywords.
999 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1002 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1004 (ert-deftest test-org-export
/get-node-property
()
1005 "Test`org-export-get-node-property' specifications."
1009 (org-test-with-parsed-data "* Headline
1013 (org-export-get-node-property
1014 :prop
(org-element-map tree
'headline
'identity nil t
)))))
1015 ;; Test inheritance.
1018 (org-test-with-parsed-data "* Parent
1024 (org-export-get-node-property
1025 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1026 ;; Cannot return a value before the first headline.
1028 (org-test-with-parsed-data "Paragraph
1033 (org-export-get-node-property
1034 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
1036 (ert-deftest test-org-export
/get-category
()
1037 "Test `org-export-get-category' specifications."
1041 (org-test-with-parsed-data "* Headline
1045 (org-export-get-category
1046 (org-element-map tree
'headline
'identity nil t
) info
))))
1047 ;; Test inheritance from a parent headline.
1049 (equal '("value" "value")
1050 (org-test-with-parsed-data "* Headline1
1057 (lambda (hl) (org-export-get-category hl info
)) info
))))
1058 ;; Test inheritance from #+CATEGORY keyword
1061 (org-test-with-parsed-data "#+CATEGORY: value
1063 (org-export-get-category
1064 (org-element-map tree
'headline
'identity nil t
) info
))))
1065 ;; Test inheritance from file name.
1068 (org-test-with-parsed-data "* Headline"
1069 (let ((info (plist-put info
:input-file
"~/test.org")))
1070 (org-export-get-category
1071 (org-element-map tree
'headline
'identity nil t
) info
)))))
1075 (org-test-with-parsed-data "* Headline"
1076 (org-export-get-category
1077 (org-element-map tree
'headline
'identity nil t
) info
)))))
1079 (ert-deftest test-org-export
/first-sibling-p
()
1080 "Test `org-export-first-sibling-p' specifications."
1085 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1088 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1090 ;; Ignore headlines not exported.
1094 (let ((org-export-exclude-tags '("ignore")))
1095 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1098 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1101 (ert-deftest test-org-export
/last-sibling-p
()
1102 "Test `org-export-last-sibling-p' specifications."
1107 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1110 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1112 ;; Ignore headlines not exported.
1116 (let ((org-export-exclude-tags '("ignore")))
1117 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1120 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1127 (ert-deftest test-org-export
/get-coderef-format
()
1128 "Test `org-export-get-coderef-format' specifications."
1129 ;; A link without description returns "%s"
1130 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1132 ;; Return "%s" when path is matched within description.
1133 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1135 ;; Otherwise return description.
1136 (should (equal (org-export-get-coderef-format "path" "desc")
1139 (ert-deftest test-org-export
/inline-image-p
()
1140 "Test `org-export-inline-image-p' specifications."
1142 (org-export-inline-image-p
1143 (org-test-with-temp-text "[[#id]]"
1145 (org-element-parse-buffer) 'link
'identity nil t
))
1146 '(("custom-id" .
"id")))))
1148 (ert-deftest test-org-export
/fuzzy-link
()
1149 "Test fuzzy links specifications."
1150 ;; 1. Links to invisible (keyword) targets should be ignored.
1151 (org-test-with-parsed-data
1152 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1157 (org-export-get-ordinal
1158 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1159 ;; 2. Link to an headline should return headline's number.
1160 (org-test-with-parsed-data
1161 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1163 ;; Note: Headline's number is in fact a list of numbers.
1168 (org-export-get-ordinal
1169 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1170 ;; 3. Link to a target in an item should return item's number.
1171 (org-test-with-parsed-data
1172 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1174 ;; Note: Item's number is in fact a list of numbers.
1179 (org-export-get-ordinal
1180 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1181 ;; 4. Link to a target in a footnote should return footnote's
1183 (org-test-with-parsed-data "
1184 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1190 (org-export-get-ordinal
1191 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1192 ;; 5. Link to a named element should return sequence number of that
1194 (org-test-with-parsed-data
1195 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1201 (org-export-get-ordinal
1202 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1203 ;; 6. Link to a target not within an item, a table, a footnote
1204 ;; reference or definition should return section number.
1205 (org-test-with-parsed-data
1206 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1212 (org-export-get-ordinal
1213 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
1215 (ert-deftest test-org-export
/resolve-coderef
()
1216 "Test `org-export-resolve-coderef' specifications."
1217 (let ((org-coderef-label-format "(ref:%s)"))
1218 ;; 1. A link to a "-n -k -r" block returns line number.
1219 (org-test-with-parsed-data
1220 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1221 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1222 (org-test-with-parsed-data
1223 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1224 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1225 ;; 2. A link to a "-n -r" block returns line number.
1226 (org-test-with-parsed-data
1227 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1228 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1229 (org-test-with-parsed-data
1230 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1231 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1232 ;; 3. A link to a "-n" block returns coderef.
1233 (org-test-with-parsed-data
1234 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1235 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1236 (org-test-with-parsed-data
1237 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1238 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1239 ;; 4. A link to a "-r" block returns line number.
1240 (org-test-with-parsed-data
1241 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1242 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1243 (org-test-with-parsed-data
1244 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1245 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1246 ;; 5. A link to a block without a switch returns coderef.
1247 (org-test-with-parsed-data
1248 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1249 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1250 (org-test-with-parsed-data
1251 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1252 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1253 ;; 6. Correctly handle continued line numbers. A "+n" switch
1254 ;; should resume numbering from previous block with numbered
1255 ;; lines, ignoring blocks not numbering lines in the process.
1256 ;; A "-n" switch resets count.
1257 (org-test-with-parsed-data "
1262 #+BEGIN_SRC emacs-lisp
1266 #+BEGIN_SRC emacs-lisp +n -r
1267 \(+ 1 1) (ref:addition)
1270 #+BEGIN_EXAMPLE -n -r
1271 Another text. (ref:text)
1273 (should (= (org-export-resolve-coderef "addition" info
) 2))
1274 (should (= (org-export-resolve-coderef "text" info
) 1)))
1275 ;; 7. Recognize coderef with user-specified syntax.
1276 (org-test-with-parsed-data
1277 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1278 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1280 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1281 "Test `org-export-resolve-fuzzy-link' specifications."
1282 ;; 1. Match target objects.
1283 (org-test-with-parsed-data "<<target>> [[target]]"
1285 (org-export-resolve-fuzzy-link
1286 (org-element-map tree
'link
'identity info t
) info
)))
1287 ;; 2. Match target elements.
1288 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1290 (org-export-resolve-fuzzy-link
1291 (org-element-map tree
'link
'identity info t
) info
)))
1292 ;; 3. Match named elements.
1293 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1295 (org-export-resolve-fuzzy-link
1296 (org-element-map tree
'link
'identity info t
) info
)))
1297 ;; 4. Match exact headline's name.
1298 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1300 (org-export-resolve-fuzzy-link
1301 (org-element-map tree
'link
'identity info t
) info
)))
1302 ;; 5. Targets objects have priority over named elements and headline
1304 (org-test-with-parsed-data
1305 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1309 (org-export-resolve-fuzzy-link
1310 (org-element-map tree
'link
'identity info t
) info
)))))
1311 ;; 6. Named elements have priority over headline titles.
1312 (org-test-with-parsed-data
1313 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1317 (org-export-resolve-fuzzy-link
1318 (org-element-map tree
'link
'identity info t
) info
)))))
1319 ;; 7. If link's path starts with a "*", only match headline titles,
1321 (org-test-with-parsed-data
1322 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1326 (org-export-resolve-fuzzy-link
1327 (org-element-map tree
'link
'identity info t
) info
)))))
1328 ;; 8. Return nil if no match.
1329 (org-test-with-parsed-data "[[target]]"
1331 (org-export-resolve-fuzzy-link
1332 (org-element-map tree
'link
'identity info t
) info
))))
1334 (ert-deftest test-org-export
/resolve-id-link
()
1335 "Test `org-export-resolve-id-link' specifications."
1336 ;; 1. Regular test for custom-id link.
1337 (org-test-with-parsed-data "* Headline1
1344 (org-export-resolve-id-link
1345 (org-element-map tree
'link
'identity info t
) info
)))
1346 ;; 2. Failing test for custom-id link.
1347 (org-test-with-parsed-data "* Headline1
1354 (org-export-resolve-id-link
1355 (org-element-map tree
'link
'identity info t
) info
)))
1356 ;; 3. Test for internal id target.
1357 (org-test-with-parsed-data "* Headline1
1364 (org-export-resolve-id-link
1365 (org-element-map tree
'link
'identity info t
) info
)))
1366 ;; 4. Test for external id target.
1367 (org-test-with-parsed-data "[[id:aaaa]]"
1369 (org-export-resolve-id-link
1370 (org-element-map tree
'link
'identity info t
)
1371 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1373 (ert-deftest test-org-export
/resolve-radio-link
()
1374 "Test `org-export-resolve-radio-link' specifications."
1376 (org-test-with-temp-text "<<<radio>>> radio"
1377 (org-update-radio-target-regexp)
1379 (let* ((tree (org-element-parse-buffer))
1380 (info `(:parse-tree
,tree
)))
1381 (org-export-resolve-radio-link
1382 (org-element-map tree
'link
'identity info t
)
1384 ;; Radio target with objects.
1385 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1386 (org-update-radio-target-regexp)
1388 (let* ((tree (org-element-parse-buffer))
1389 (info `(:parse-tree
,tree
)))
1390 (org-export-resolve-radio-link
1391 (org-element-map tree
'link
'identity info t
)
1396 ;;; Src-block and example-block
1398 (ert-deftest test-org-export
/unravel-code
()
1399 "Test `org-export-unravel-code' function."
1400 (let ((org-coderef-label-format "(ref:%s)"))
1401 ;; 1. Code without reference.
1402 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1403 (should (equal (org-export-unravel-code (org-element-at-point))
1405 ;; 2. Code with reference.
1406 (org-test-with-temp-text
1407 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1408 (should (equal (org-export-unravel-code (org-element-at-point))
1409 '("(+ 1 1)\n" (1 .
"test")))))
1410 ;; 3. Code with user-defined reference.
1411 (org-test-with-temp-text
1412 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1413 (should (equal (org-export-unravel-code (org-element-at-point))
1414 '("(+ 1 1)\n" (1 .
"test")))))
1415 ;; 4. Code references keys are relative to the current block.
1416 (org-test-with-temp-text "
1425 (should (equal (org-export-unravel-code (org-element-at-point))
1426 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1432 (ert-deftest test-org-export
/activate-smart-quotes
()
1433 "Test `org-export-activate-smart-quotes' specifications."
1434 ;; Opening double quotes: standard test.
1437 '("some “paragraph")
1438 (let ((org-export-default-language "en"))
1439 (org-test-with-parsed-data "some \"paragraph"
1442 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1444 ;; Opening quotes: at the beginning of a paragraph.
1448 (let ((org-export-default-language "en"))
1449 (org-test-with-parsed-data "\"begin"
1452 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1454 ;; Opening quotes: after an object.
1458 (let ((org-export-default-language "en"))
1459 (org-test-with-parsed-data "=verb= \"begin"
1462 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1464 ;; Closing quotes: standard test.
1467 '("some” paragraph")
1468 (let ((org-export-default-language "en"))
1469 (org-test-with-parsed-data "some\" paragraph"
1472 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1474 ;; Closing quotes: at the end of a paragraph.
1478 (let ((org-export-default-language "en"))
1479 (org-test-with-parsed-data "end\""
1482 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1484 ;; Apostrophe: standard test.
1487 '("It shouldn’t fail")
1488 (let ((org-export-default-language "en"))
1489 (org-test-with-parsed-data "It shouldn't fail"
1492 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1494 ;; Apostrophe: before an object.
1498 (let ((org-export-default-language "en"))
1499 (org-test-with-parsed-data "a'=b="
1502 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1504 ;; Apostrophe: after an object.
1508 (let ((org-export-default-language "en"))
1509 (org-test-with-parsed-data "=code='s"
1512 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1514 ;; Special case: isolated quotes.
1516 (equal '("“" "”")
1517 (let ((org-export-default-language "en"))
1518 (org-test-with-parsed-data "\"$x$\""
1521 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1523 ;; Smart quotes in secondary strings.
1525 (equal '("“" "”")
1526 (let ((org-export-default-language "en"))
1527 (org-test-with-parsed-data "* \"$x$\""
1530 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1532 ;; Smart quotes in document keywords.
1534 (equal '("“" "”")
1535 (let ((org-export-default-language "en"))
1536 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1538 (plist-get info
:title
) 'plain-text
1539 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1541 ;; Smart quotes in parsed affiliated keywords.
1543 (equal '("“" "”" "Paragraph")
1544 (let ((org-export-default-language "en"))
1545 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1548 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1549 info nil nil t
))))))
1555 (ert-deftest test-org-export
/special-column
()
1556 "Test if the table's special column is properly recognized."
1557 ;; 1. First column is special if it contains only a special marking
1558 ;; characters or empty cells.
1559 (org-test-with-temp-text "
1563 (org-export-table-has-special-column-p
1565 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1566 ;; 2. If the column contains anything else, it isn't special.
1567 (org-test-with-temp-text "
1571 (org-export-table-has-special-column-p
1573 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1574 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1576 (org-test-with-temp-text "
1585 (org-export-table-has-special-column-p
1587 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1588 ;; 4. A first column with only empty cells isn't considered as
1590 (org-test-with-temp-text "
1594 (org-export-table-has-special-column-p
1596 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1598 (ert-deftest test-org-export
/table-row-is-special-p
()
1599 "Test `org-export-table-row-is-special-p' specifications."
1600 ;; 1. A row is special if it has a special marking character in the
1602 (org-test-with-parsed-data "| ! | 1 |"
1604 (org-export-table-row-is-special-p
1605 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1606 ;; 2. A row is special when its first field is "/"
1607 (org-test-with-parsed-data "
1611 (org-export-table-row-is-special-p
1612 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1613 ;; 3. A row only containing alignment cookies is also considered as
1615 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1617 (org-export-table-row-is-special-p
1618 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1619 ;; 4. Everything else isn't considered as special.
1620 (org-test-with-parsed-data "| \alpha | | c |"
1622 (org-export-table-row-is-special-p
1623 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1624 ;; 5. Table's rules are never considered as special rows.
1625 (org-test-with-parsed-data "|---+---|"
1627 (org-export-table-row-is-special-p
1628 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1630 (ert-deftest test-org-export
/has-header-p
()
1631 "Test `org-export-table-has-header-p' specifications."
1632 ;; 1. With an header.
1633 (org-test-with-parsed-data "
1638 (org-export-table-has-header-p
1639 (org-element-map tree
'table
'identity info
'first-match
)
1641 ;; 2. Without an header.
1642 (org-test-with-parsed-data "
1646 (org-export-table-has-header-p
1647 (org-element-map tree
'table
'identity info
'first-match
)
1649 ;; 3. Don't get fooled with starting and ending rules.
1650 (org-test-with-parsed-data "
1656 (org-export-table-has-header-p
1657 (org-element-map tree
'table
'identity info
'first-match
)
1660 (ert-deftest test-org-export
/table-row-group
()
1661 "Test `org-export-table-row-group' specifications."
1662 ;; 1. A rule creates a new group.
1663 (org-test-with-parsed-data "
1670 (mapcar (lambda (row) (org-export-table-row-group row info
))
1671 (org-element-map tree
'table-row
'identity
)))))
1672 ;; 2. Special rows are ignored in count.
1673 (org-test-with-parsed-data "
1680 (mapcar (lambda (row) (org-export-table-row-group row info
))
1681 (org-element-map tree
'table-row
'identity
)))))
1682 ;; 3. Double rules also are ignored in count.
1683 (org-test-with-parsed-data "
1691 (mapcar (lambda (row) (org-export-table-row-group row info
))
1692 (org-element-map tree
'table-row
'identity
))))))
1694 (ert-deftest test-org-export
/table-cell-width
()
1695 "Test `org-export-table-cell-width' specifications."
1696 ;; 1. Width is primarily determined by width cookies. If no cookie
1697 ;; is found, cell's width is nil.
1698 (org-test-with-parsed-data "
1699 | / | <l> | <6> | <l7> |
1704 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1705 (org-element-map tree
'table-cell
'identity info
)))))
1706 ;; 2. The last width cookie has precedence.
1707 (org-test-with-parsed-data "
1714 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1715 (org-element-map tree
'table-cell
'identity info
)))))
1716 ;; 3. Valid width cookies must have a specific row.
1717 (org-test-with-parsed-data "| <6> | cell |"
1721 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1722 (org-element-map tree
'table-cell
'identity
))))))
1724 (ert-deftest test-org-export
/table-cell-alignment
()
1725 "Test `org-export-table-cell-alignment' specifications."
1726 (let ((org-table-number-fraction 0.5)
1727 (org-table-number-regexp "^[0-9]+$"))
1728 ;; 1. Alignment is primarily determined by alignment cookies.
1729 (org-test-with-temp-text "| <l> | <c> | <r> |"
1730 (let* ((tree (org-element-parse-buffer))
1731 (info `(:parse-tree
,tree
)))
1734 '(left center right
)
1735 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1736 (org-element-map tree
'table-cell
'identity
))))))
1737 ;; 2. The last alignment cookie has precedence.
1738 (org-test-with-parsed-data "
1744 '(right right right
)
1745 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1746 (org-element-map tree
'table-cell
'identity
)))))
1747 ;; 3. If there's no cookie, cell's contents determine alignment.
1748 ;; A column mostly made of cells containing numbers will align
1749 ;; its cells to the right.
1750 (org-test-with-parsed-data "
1756 '(right right right
)
1757 (mapcar (lambda (cell)
1758 (org-export-table-cell-alignment cell info
))
1759 (org-element-map tree
'table-cell
'identity
)))))
1760 ;; 4. Otherwise, they will be aligned to the left.
1761 (org-test-with-parsed-data "
1768 (mapcar (lambda (cell)
1769 (org-export-table-cell-alignment cell info
))
1770 (org-element-map tree
'table-cell
'identity
)))))))
1772 (ert-deftest test-org-export
/table-cell-borders
()
1773 "Test `org-export-table-cell-borders' specifications."
1774 ;; 1. Recognize various column groups indicators.
1775 (org-test-with-parsed-data "| / | < | > | <> |"
1778 '((right bottom top
) (left bottom top
) (right bottom top
)
1779 (right left bottom top
))
1780 (mapcar (lambda (cell)
1781 (org-export-table-cell-borders cell info
))
1782 (org-element-map tree
'table-cell
'identity
)))))
1783 ;; 2. Accept shortcuts to define column groups.
1784 (org-test-with-parsed-data "| / | < | < |"
1787 '((right bottom top
) (right left bottom top
) (left bottom top
))
1788 (mapcar (lambda (cell)
1789 (org-export-table-cell-borders cell info
))
1790 (org-element-map tree
'table-cell
'identity
)))))
1791 ;; 3. A valid column groups row must start with a "/".
1792 (org-test-with-parsed-data "
1796 (equal '((top) (top) (bottom) (bottom))
1797 (mapcar (lambda (cell)
1798 (org-export-table-cell-borders cell info
))
1799 (org-element-map tree
'table-cell
'identity
)))))
1800 ;; 4. Take table rules into consideration.
1801 (org-test-with-parsed-data "
1806 (equal '((below top
) (bottom above
))
1807 (mapcar (lambda (cell)
1808 (org-export-table-cell-borders cell info
))
1809 (org-element-map tree
'table-cell
'identity
)))))
1810 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1811 ;; (resp. `bottom' and `below') borders. Any special row is
1813 (org-test-with-parsed-data "
1819 (equal '((bottom below top above
))
1821 (mapcar (lambda (cell)
1822 (org-export-table-cell-borders cell info
))
1823 (org-element-map tree
'table-cell
'identity
)))))))
1825 (ert-deftest test-org-export
/table-dimensions
()
1826 "Test `org-export-table-dimensions' specifications."
1827 ;; 1. Standard test.
1828 (org-test-with-parsed-data "
1833 (org-export-table-dimensions
1834 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1835 ;; 2. Ignore horizontal rules and special columns.
1836 (org-test-with-parsed-data "
1843 (org-export-table-dimensions
1844 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1846 (ert-deftest test-org-export
/table-cell-address
()
1847 "Test `org-export-table-cell-address' specifications."
1848 ;; 1. Standard test: index is 0-based.
1849 (org-test-with-parsed-data "| a | b |"
1851 (equal '((0 .
0) (0 .
1))
1854 (lambda (cell) (org-export-table-cell-address cell info
))
1856 ;; 2. Special column isn't counted, nor are special rows.
1857 (org-test-with-parsed-data "
1862 (org-export-table-cell-address
1863 (car (last (org-element-map tree
'table-cell
'identity info
)))
1865 ;; 3. Tables rules do not count either.
1866 (org-test-with-parsed-data "
1874 (org-export-table-cell-address
1875 (car (last (org-element-map tree
'table-cell
'identity info
)))
1877 ;; 4. Return nil for special cells.
1878 (org-test-with-parsed-data "| / | a |"
1880 (org-export-table-cell-address
1881 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1884 (ert-deftest test-org-export
/get-table-cell-at
()
1885 "Test `org-export-get-table-cell-at' specifications."
1886 ;; 1. Address ignores special columns, special rows and rules.
1887 (org-test-with-parsed-data "
1894 (org-element-contents
1895 (org-export-get-table-cell-at
1897 (org-element-map tree
'table
'identity info
'first-match
)
1899 ;; 2. Return value for a non-existent address is nil.
1900 (org-test-with-parsed-data "| a |"
1902 (org-export-get-table-cell-at
1904 (org-element-map tree
'table
'identity info
'first-match
)
1906 (org-test-with-parsed-data "| / |"
1908 (org-export-get-table-cell-at
1910 (org-element-map tree
'table
'identity info
'first-match
)
1913 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1914 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1915 ;; 1. A cell at a beginning of a row always starts a column group.
1916 (org-test-with-parsed-data "| a |"
1918 (org-export-table-cell-starts-colgroup-p
1919 (org-element-map tree
'table-cell
'identity info
'first-match
)
1921 ;; 2. Special column should be ignored when determining the
1922 ;; beginning of the row.
1923 (org-test-with-parsed-data "
1927 (org-export-table-cell-starts-colgroup-p
1928 (org-element-map tree
'table-cell
'identity info
'first-match
)
1930 ;; 2. Explicit column groups.
1931 (org-test-with-parsed-data "
1940 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1943 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1944 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1945 ;; 1. A cell at the end of a row always ends a column group.
1946 (org-test-with-parsed-data "| a |"
1948 (org-export-table-cell-ends-colgroup-p
1949 (org-element-map tree
'table-cell
'identity info
'first-match
)
1951 ;; 2. Special column should be ignored when determining the
1952 ;; beginning of the row.
1953 (org-test-with-parsed-data "
1957 (org-export-table-cell-ends-colgroup-p
1958 (org-element-map tree
'table-cell
'identity info
'first-match
)
1960 ;; 3. Explicit column groups.
1961 (org-test-with-parsed-data "
1970 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1973 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1974 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1975 ;; 1. A row at the beginning of a table always starts a row group.
1976 ;; So does a row following a table rule.
1977 (org-test-with-parsed-data "
1987 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1989 ;; 2. Special rows should be ignored when determining the beginning
1991 (org-test-with-parsed-data "
2003 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2006 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2007 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2008 ;; 1. A row at the end of a table always ends a row group. So does
2009 ;; a row preceding a table rule.
2010 (org-test-with-parsed-data "
2020 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2022 ;; 2. Special rows should be ignored when determining the beginning
2024 (org-test-with-parsed-data "
2036 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2039 (ert-deftest test-org-export
/table-row-starts-header-p
()
2040 "Test `org-export-table-row-starts-header-p' specifications."
2041 ;; 1. Only the row starting the first row group starts the table
2043 (org-test-with-parsed-data "
2054 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2056 ;; 2. A row cannot start an header if there's no header in the
2058 (org-test-with-parsed-data "
2062 (org-export-table-row-starts-header-p
2063 (org-element-map tree
'table-row
'identity info
'first-match
)
2066 (ert-deftest test-org-export
/table-row-ends-header-p
()
2067 "Test `org-export-table-row-ends-header-p' specifications."
2068 ;; 1. Only the row starting the first row group starts the table
2070 (org-test-with-parsed-data "
2081 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2083 ;; 2. A row cannot start an header if there's no header in the
2085 (org-test-with-parsed-data "
2089 (org-export-table-row-ends-header-p
2090 (org-element-map tree
'table-row
'identity info
'first-match
)
2097 (ert-deftest test-org-export
/get-next-element
()
2098 "Test `org-export-get-next-element' specifications."
2102 (org-test-with-parsed-data "* Headline\n*a* b"
2103 (org-export-get-next-element
2104 (org-element-map tree
'bold
'identity info t
) info
))))
2105 ;; Return nil when no previous element.
2107 (org-test-with-parsed-data "* Headline\na *b*"
2108 (org-export-get-next-element
2109 (org-element-map tree
'bold
'identity info t
) info
)))
2110 ;; Non-exportable elements are ignored.
2112 (let ((org-export-with-timestamps nil
))
2113 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2114 (org-export-get-next-element
2115 (org-element-map tree
'entity
'identity info t
) info
))))
2116 ;; Find next element in secondary strings.
2119 (org-test-with-parsed-data "* a =verb="
2121 (org-export-get-next-element
2122 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2123 ;; Find next element in document keywords.
2126 (org-test-with-parsed-data "#+TITLE: a =verb="
2128 (org-export-get-next-element
2130 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2131 ;; Find next element in parsed affiliated keywords.
2134 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2136 (org-export-get-next-element
2137 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2138 ;; With optional argument N, return a list containing all the
2139 ;; following elements.
2142 '(bold code underline
)
2143 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2145 (org-export-get-next-element
2146 (org-element-map tree
'italic
'identity info t
) info t
)))))
2147 ;; When N is a positive integer, return a list containing up to
2148 ;; N following elements.
2152 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2154 (org-export-get-next-element
2155 (org-element-map tree
'italic
'identity info t
) info
2))))))
2157 (ert-deftest test-org-export
/get-previous-element
()
2158 "Test `org-export-get-previous-element' specifications."
2162 (org-test-with-parsed-data "* Headline\na *b*"
2163 (org-export-get-previous-element
2164 (org-element-map tree
'bold
'identity info t
) info
))))
2165 ;; Return nil when no previous element.
2167 (org-test-with-parsed-data "* Headline\n*a* b"
2168 (org-export-get-previous-element
2169 (org-element-map tree
'bold
'identity info t
) info
)))
2170 ;; Non-exportable elements are ignored.
2172 (let ((org-export-with-timestamps nil
))
2173 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2174 (org-export-get-previous-element
2175 (org-element-map tree
'entity
'identity info t
) info
))))
2176 ;; Find previous element in secondary strings.
2179 (org-test-with-parsed-data "* =verb= a"
2181 (org-export-get-previous-element
2182 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2183 ;; Find previous element in document keywords.
2186 (org-test-with-parsed-data "#+TITLE: =verb= a"
2188 (org-export-get-previous-element
2190 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2191 ;; Find previous element in parsed affiliated keywords.
2194 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2196 (org-export-get-previous-element
2197 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2198 ;; With optional argument N, return a list containing up to
2199 ;; N previous elements.
2201 (equal '(bold italic underline
)
2202 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2204 (org-export-get-previous-element
2205 (org-element-map tree
'code
'identity info t
) info t
)))))
2206 ;; When N is a positive integer, return a list containing up to
2207 ;; N previous elements.
2209 (equal '(bold italic
)
2210 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2212 (org-export-get-previous-element
2213 (org-element-map tree
'code
'identity info t
) info
2))))))
2216 (provide 'test-org-export
)
2217 ;;; test-org-export.el end here