3 ;; Copyright (c) 2010-2013 Eric Schulte
4 ;; Authors: Eric Schulte
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; Template test file for Org-mode tests
26 (ert-deftest test-ob-exp
/org-babel-exp-src-blocks
/w-no-headers
()
27 "Testing export without any headlines in the org-mode file."
28 (let ((html-file (concat (file-name-sans-extension org-test-no-heading-file
)
30 (when (file-exists-p html-file
) (delete-file html-file
))
31 (org-test-in-example-file org-test-no-heading-file
32 ;; export the file to html
33 (org-export-as-html nil
))
34 ;; should create a .html file
35 (should (file-exists-p html-file
))
36 ;; should not create a file with "::" appended to it's name
37 (should-not (file-exists-p (concat org-test-no-heading-file
"::")))
38 (when (file-exists-p html-file
) (delete-file html-file
))))
40 (ert-deftest test-ob-exp
/org-babel-exp-src-blocks
/w-no-file
()
41 "Testing export from buffers which are not visiting any file."
42 (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*"))
43 (should-not (get-buffer "*Org HTML Export*"))
44 ;; export the file to HTML in a temporary buffer
45 (org-test-in-example-file nil
(org-export-as-html-to-buffer nil
))
46 ;; should create a .html buffer
47 (should (buffer-live-p (get-buffer "*Org HTML Export*")))
48 ;; should contain the content of the buffer
50 (set-buffer (get-buffer "*Org HTML Export*"))
51 (should (string-match (regexp-quote org-test-file-ob-anchor
)
53 (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*")))
55 (ert-deftest test-ob-exp
/org-babel-exp-src-blocks
/w-no-headers2
()
56 "Testing export without any headlines in the org-mode file."
57 (let ((html-file (concat (file-name-sans-extension
58 org-test-link-in-heading-file
)
60 (when (file-exists-p html-file
) (delete-file html-file
))
61 (org-test-in-example-file org-test-link-in-heading-file
62 ;; export the file to html
63 (org-export-as-html nil
))
64 ;; should create a .html file
65 (should (file-exists-p html-file
))
66 ;; should not create a file with "::" appended to it's name
67 (should-not (file-exists-p (concat org-test-link-in-heading-file
"::")))
68 (when (file-exists-p html-file
) (delete-file html-file
))))
70 (ert-deftest ob-exp
/noweb-on-export
()
71 "Noweb header arguments export correctly.
72 - yes expand on both export and tangle
73 - no expand on neither export or tangle
74 - tangle expand on only tangle not export"
75 (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
76 (org-narrow-to-subtree)
78 (org-export-as-html nil nil
'string
'body-only
))
81 (org-test-with-temp-text-in-file
84 ;; check following ouput exists and in order
90 (setq test-point
(point)))
91 '("<code>:noweb</code> header argument expansion"
97 "<<noweb-example1>>"
101 "<<noweb-example1>>"
102 "<<noweb-example2>>"))))))
104 (ert-deftest ob-exp
/noweb-on-export-with-exports-results
()
105 "Noweb header arguments export correctly using :exports results.
106 - yes expand on both export and tangle
107 - no expand on neither export or tangle
108 - tangle expand on only tangle not export"
109 (org-test-at-id "8701beb4-13d9-468c-997a-8e63e8b66f8d"
110 (org-narrow-to-subtree)
112 (org-export-as-html nil nil
'string
'body-only
))
115 (org-test-with-temp-text-in-file
118 ;; check following ouput exists and in order
120 (should (< test-point
124 (setq test-point
(point)))
125 '("<code>:noweb</code> header argument expansion using :exports results"
130 "<<noweb-example1>>"
132 "<<noweb-example1>>"
133 "<<noweb-example2>>"))))))
135 (ert-deftest ob-exp
/exports-both
()
136 "Test the :exports both header argument.
137 The code block should create both <pre></pre> and <table></table>
138 elements in the final html."
139 (org-test-at-id "92518f2a-a46a-4205-a3ab-bcce1008a4bb"
140 (org-narrow-to-subtree)
142 (org-export-as-html nil nil
'string
'body-only
))
144 (org-test-with-temp-text-in-file
147 ;; check following ouput exists and in order
149 (should (< test-point
153 (setq test-point
(point)))
154 '( "Pascal's Triangle – exports both test"
156 "defun" "pascals-triangle"
157 "if""list""list""let*""prev-triangle"
158 "pascals-triangle""prev-row""car""reverse""prev-triangle"
159 "append""prev-triangle""list""map""list"
160 "append""prev-row""append""prev-row""pascals-triangle"
164 "<tr>"">1<"">1<""</tr>"
165 "<tr>"">1<"">2<"">1<""</tr>"
166 "<tr>"">1<"">3<"">3<"">1<""</tr>"
167 "<tr>"">1<"">4<"">6<"">4<"">1<""</tr>"
168 "<tr>"">1<"">5<"">10<"">10<"">5<"">1<""</tr>"
169 "</tbody>""</table>"))))))
171 (ert-deftest ob-exp
/mixed-blocks-with-exports-both
()
172 (org-test-at-id "5daa4d03-e3ea-46b7-b093-62c1b7632df3"
173 (org-narrow-to-subtree)
175 (org-export-as-html nil nil
'string
'body-only
))
177 (org-test-with-temp-text-in-file
180 ;; check following ouput exists and in order
182 (should (< test-point
186 (setq test-point
(point)))
187 '("mixed blocks with exports both"
194 "\"code block results\""
196 "<pre class=\"example\">"
200 (ert-deftest ob-exp
/export-with-name
()
201 (let ((org-babel-exp-code-template
202 "=%name=\n#+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
203 (org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
204 (org-narrow-to-subtree)
205 (let ((ascii (org-export-as-ascii nil nil
'string
'body-only
)))
206 (should (string-match "qux" ascii
))))))
208 (ert-deftest ob-exp
/export-with-header-argument
()
209 (let ((org-babel-exp-code-template
212 |---------+----------|
214 | results | %results |
215 #+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
216 (org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
217 (org-narrow-to-subtree)
218 (let ((ascii (org-export-as-ascii nil nil
'string
'body-only
)))
219 (should (string-match "baz" ascii
))
220 (should (string-match "replace" ascii
))))))
222 (ert-deftest ob-exp
/noweb-no-export-and-exports-both
()
223 (org-test-at-id "8a820f6c-7980-43db-8a24-0710d33729c9"
224 (org-narrow-to-subtree)
225 (let ((html (org-export-as-html nil nil
'string
'body-only
)))
226 (should (string-match (regexp-quote "noweb-no-export-and-exports-both-1")
229 (ert-deftest ob-exp
/evaluate-all-executables-in-order
()
230 (org-test-at-id "96cc7073-97ec-4556-87cf-1f9bffafd317"
231 (org-narrow-to-subtree)
232 (let (*evaluation-collector
*)
233 (org-export-as-ascii nil nil
'string
)
234 (should (equal '(5 4 3 2 1) *evaluation-collector
*)))))
236 (ert-deftest ob-exp
/export-call-line-information
()
237 (org-test-at-id "bec63a04-491e-4caa-97f5-108f3020365c"
238 (org-narrow-to-subtree)
239 (let* ((org-babel-exp-call-line-template "\n: call: %line special-token")
240 (html (org-export-as-html nil nil
'string t
)))
241 (should (string-match "double" html
))
242 (should (string-match "16" html
))
243 (should (string-match "special-token" html
)))))
245 (ert-deftest ob-exp
/noweb-strip-export-ensure-strips
()
246 (org-test-at-id "8e7bd234-99b2-4b14-8cd6-53945e409775"
247 (org-narrow-to-subtree)
248 (org-babel-next-src-block 2)
249 (should (= 110 (org-babel-execute-src-block)))
250 (let ((ascii (org-export-as-ascii nil nil
'string t
)))
251 (should-not (string-match (regexp-quote "<<strip-export-1>>") ascii
))
252 (should-not (string-match (regexp-quote "i=\"10\"") ascii
)))))
254 (ert-deftest ob-exp
/export-from-a-temp-buffer
()
255 :expected-result
:failed
256 (org-test-with-temp-text
258 #+Title: exporting from a temporary buffer
261 #+BEGIN_SRC emacs-lisp
266 #+BEGIN_SRC emacs-lisp
270 #+BEGIN_SRC emacs-lisp :var foo=foo :noweb yes :exports results
274 (let* ((org-current-export-file (current-buffer))
275 (ascii (org-export-as-ascii nil nil
'string
)))
276 (should (string-match (regexp-quote (format nil
"%S" '(:foo
:bar
)))
279 (provide 'test-ob-exp
)
281 ;;; test-ob-exp.el ends here