1 ;;; test-org-export.el --- Tests for org-export.el
3 ;; Copyright (C) 2012 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; Released under the GNU General Public License version 3
8 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
15 (let ((load-path (cons (expand-file-name
16 ".." (file-name-directory
17 (or load-file-name buffer-file-name
)))
20 (require 'org-test-ob-consts
)
21 (require 'org-export
))
30 (defmacro org-test-with-backend
(backend &rest body
)
31 "Execute body with an export back-end defined.
33 BACKEND is the name, as a string, of the back-end. BODY is the
34 body to execute. The defined back-end simply returns parsed data
36 (declare (debug (form body
)) (indent 1))
37 `(flet ,(let (transcoders)
38 (dolist (type (append org-element-all-elements
39 org-element-all-objects
)
41 (push `(,(intern (format "org-%s-%s" backend type
))
43 (,(intern (format "org-element-%s-interpreter" type
))
48 (ert-deftest test-org-export
/parse-option-keyword
()
49 "Test reading all standard #+OPTIONS: items."
52 (org-export-parse-option-keyword
53 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
54 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t")
56 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
57 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
58 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
59 :with-footnotes t
:with-priority t
:with-special-strings t
60 :with-sub-superscript t
:with-toc t
:with-tables t
:with-tags t
61 :with-tasks t
:with-timestamps t
:with-todo-keywords t
)))
62 ;; Test some special values.
65 (org-export-parse-option-keyword
66 "arch:headline creator:comment d:(\"TEST\")
67 ^:{} toc:1 tags:not-in-toc tasks:todo")
68 '(:with-archived-trees
69 headline
:with-creator comment
:with-drawers
("TEST")
70 :with-sub-superscript
{} :with-toc
1 :with-tags not-in-toc
73 (ert-deftest test-org-export
/get-inbuffer-options
()
74 "Test reading all standard export keywords."
77 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
80 #+DESCRIPTION: Testing
81 #+DESCRIPTION: with two lines
82 #+EMAIL: some@email.org
83 #+EXPORT_EXCLUDE_TAGS: noexport invisible
86 #+EXPORT_SELECT_TAGS: export
89 (org-export-get-inbuffer-options))
91 "Me, Myself and I" :creator
"Idem" :date
"Today"
92 :description
"Testing\nwith two lines" :email
"some@email.org"
93 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
94 :select-tags
("export") :title
"Some title with spaces"))))
96 (ert-deftest test-org-export
/define-macro
()
97 "Try defining various Org macro using in-buffer #+MACRO: keyword."
99 (should (equal (org-test-with-temp-text "#+MACRO: one 1"
100 (org-export-get-inbuffer-options))
101 '(:macro-one
("1"))))
103 (should (equal (org-test-with-temp-text "#+MACRO: two (eval (+ 1 1))"
104 (org-export-get-inbuffer-options))
105 '(:macro-two
"(eval (+ 1 1))")))
107 (should-not (org-test-with-temp-text "#+MACRO: three"
108 (org-export-get-inbuffer-options)))
109 ;; Macro with newline character.
110 (should (equal (org-test-with-temp-text "#+MACRO: four a\\nb"
111 (org-export-get-inbuffer-options))
112 '(:macro-four
("a\nb"))))
113 ;; Macro with protected newline character.
114 (should (equal (org-test-with-temp-text "#+MACRO: five a\\\\nb"
115 (org-export-get-inbuffer-options))
116 '(:macro-five
("a\\nb"))))
118 (org-test-with-temp-text "#+MACRO: six 6\n#+MACRO: seven 1 + {{{six}}}"
121 (org-export-get-inbuffer-options)
125 ("1 + " (macro (:key
"six" :value
"{{{six}}}" :args nil
:begin
5 :end
14
126 :post-blank
0))))))))
128 (ert-deftest test-org-export
/handle-options
()
129 "Test if export options have an impact on output."
130 ;; Test exclude tags.
131 (org-test-with-temp-text "* Head1 :noexport:"
132 (org-test-with-backend "test"
134 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
136 ;; Test include tags.
137 (org-test-with-temp-text "
139 ** Sub-Head1.1 :export:
142 (org-test-with-backend "test"
145 "\\* Head1\n\\*\\* Sub-Head1.1[ \t]+:export:\n\\*\\*\\* Sub-Head1.1.1\n"
146 (org-export-as 'test nil nil nil
'(:select-tags
("export")))))))
147 ;; Test mixing include tags and exclude tags.
148 (org-test-with-temp-text "
150 ** Sub-Head1 :noexport:
153 ** Sub-Head1 :export:"
154 (org-test-with-backend "test"
157 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
160 '(:select-tags
("export") :exclude-tags
("noexport")))))))
162 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
163 (org-test-with-temp-text "* TODO Head1"
164 (org-test-with-backend "test"
165 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
167 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
168 (org-test-with-temp-text "* TODO Head1"
169 (org-test-with-backend "test"
170 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
171 "* TODO Head1\n")))))
173 (org-test-with-temp-text "* Head1 :archive:"
174 (let ((org-archive-tag "archive"))
175 (org-test-with-backend "test"
177 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
179 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
180 (let ((org-archive-tag "archive"))
181 (org-test-with-backend "test"
184 "\\* Head1[ \t]+:archive:"
185 (org-export-as 'test nil nil nil
186 '(:with-archived-trees headline
)))))))
187 (org-test-with-temp-text "* Head1 :archive:"
188 (let ((org-archive-tag "archive"))
189 (org-test-with-backend "test"
192 "\\`\\* Head1[ \t]+:archive:\n\\'"
193 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
195 (let ((org-drawers '("TEST")))
196 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
197 (org-test-with-backend "test"
198 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
200 (let ((org-drawers '("TEST")))
201 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
202 (org-test-with-backend "test"
203 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
204 ":TEST:\ncontents\n:END:\n"))))))
206 (ert-deftest test-org-export
/comment-tree
()
207 "Test if export process ignores commented trees."
208 (let ((org-comment-string "COMMENT"))
209 (org-test-with-temp-text "* COMMENT Head1"
210 (org-test-with-backend "test"
211 (should (equal (org-export-as 'test
) ""))))))
213 (ert-deftest test-org-export
/export-scope
()
214 "Test all export scopes."
215 (org-test-with-temp-text "
220 (org-test-with-backend "test"
223 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
225 (goto-char (point-min))
228 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
230 (flet ((org-test-template (body info
) (format "BEGIN\n%sEND" body
)))
231 (should (equal (org-export-as 'test nil nil
'body-only
)
232 "* Head1\n** Head2\ntext\n*** Head3\n"))
233 (should (equal (org-export-as 'test
)
234 "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
236 (goto-char (point-min))
239 (should (equal (org-export-as 'test
) "text\n")))))