3 ;; Copyright (c) 2010-2012 Eric Schulte
4 ;; Authors: Eric Schulte
6 ;; Released under the GNU General Public License version 3
7 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
11 ;; Template test file for Org-mode tests
14 (ert-deftest test-ob-exp
/org-babel-exp-src-blocks
/w-no-headers
()
15 "Testing export without any headlines in the org-mode file."
16 (let ((html-file (concat (file-name-sans-extension org-test-no-heading-file
)
18 (when (file-exists-p html-file
) (delete-file html-file
))
19 (org-test-in-example-file org-test-no-heading-file
20 ;; export the file to html
21 (org-export-as-html nil
))
22 ;; should create a .html file
23 (should (file-exists-p html-file
))
24 ;; should not create a file with "::" appended to it's name
25 (should-not (file-exists-p (concat org-test-no-heading-file
"::")))
26 (when (file-exists-p html-file
) (delete-file html-file
))))
28 (ert-deftest test-ob-exp
/org-babel-exp-src-blocks
/w-no-file
()
29 "Testing export from buffers which are not visiting any file."
30 (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*"))
31 (should-not (get-buffer "*Org HTML Export*"))
32 ;; export the file to HTML in a temporary buffer
33 (org-test-in-example-file nil
(org-export-as-html-to-buffer nil
))
34 ;; should create a .html buffer
35 (should (buffer-live-p (get-buffer "*Org HTML Export*")))
36 ;; should contain the content of the buffer
38 (set-buffer (get-buffer "*Org HTML Export*"))
39 (should (string-match (regexp-quote org-test-file-ob-anchor
)
41 (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*")))
43 (ert-deftest test-ob-exp
/org-babel-exp-src-blocks
/w-no-headers2
()
44 "Testing export without any headlines in the org-mode file."
45 (let ((html-file (concat (file-name-sans-extension
46 org-test-link-in-heading-file
)
48 (when (file-exists-p html-file
) (delete-file html-file
))
49 (org-test-in-example-file org-test-link-in-heading-file
50 ;; export the file to html
51 (org-export-as-html nil
))
52 ;; should create a .html file
53 (should (file-exists-p html-file
))
54 ;; should not create a file with "::" appended to it's name
55 (should-not (file-exists-p (concat org-test-link-in-heading-file
"::")))
56 (when (file-exists-p html-file
) (delete-file html-file
))))
58 (ert-deftest ob-exp
/noweb-on-export
()
59 "Noweb header arguments export correctly.
60 - yes expand on both export and tangle
61 - no expand on neither export or tangle
62 - tangle expand on only tangle not export"
63 (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
64 (org-narrow-to-subtree)
66 (org-export-as-html nil nil nil
'string
'body-only
))
69 (org-test-with-temp-text-in-file
72 ;; check following ouput exists and in order
78 (setq test-point
(point)))
79 '("<code>:noweb</code> header argument expansion"
85 "<<noweb-example1>>"
89 "<<noweb-example1>>"
90 "<<noweb-example2>>"))))))
92 (ert-deftest ob-exp
/noweb-on-export-with-exports-results
()
93 "Noweb header arguments export correctly using :exports results.
94 - yes expand on both export and tangle
95 - no expand on neither export or tangle
96 - tangle expand on only tangle not export"
97 (org-test-at-id "8701beb4-13d9-468c-997a-8e63e8b66f8d"
98 (org-narrow-to-subtree)
100 (org-export-as-html nil nil nil
'string
'body-only
))
103 (org-test-with-temp-text-in-file
106 ;; check following ouput exists and in order
108 (should (< test-point
112 (setq test-point
(point)))
113 '("<code>:noweb</code> header argument expansion using :exports results"
118 "<<noweb-example1>>"
120 "<<noweb-example1>>"
121 "<<noweb-example2>>"))))))
123 (ert-deftest ob-exp
/exports-both
()
124 "Test the :exports both header argument.
125 The code block should create both <pre></pre> and <table></table>
126 elements in the final html."
127 (org-test-at-id "92518f2a-a46a-4205-a3ab-bcce1008a4bb"
128 (org-narrow-to-subtree)
130 (org-export-as-html nil nil nil
'string
'body-only
))
132 (org-test-with-temp-text-in-file
135 ;; check following ouput exists and in order
137 (should (< test-point
141 (setq test-point
(point)))
142 '( "Pascal's Triangle – exports both test"
144 "defun" "pascals-triangle"
145 "if""list""list""let*""prev-triangle"
146 "pascals-triangle""prev-row""car""reverse""prev-triangle"
147 "append""prev-triangle""list""map""list"
148 "append""prev-row""append""prev-row""pascals-triangle"
152 "<tr>"">1<"">1<""</tr>"
153 "<tr>"">1<"">2<"">1<""</tr>"
154 "<tr>"">1<"">3<"">3<"">1<""</tr>"
155 "<tr>"">1<"">4<"">6<"">4<"">1<""</tr>"
156 "<tr>"">1<"">5<"">10<"">10<"">5<"">1<""</tr>"
157 "</tbody>""</table>"))))))
159 (ert-deftest ob-exp
/mixed-blocks-with-exports-both
()
160 (org-test-at-id "5daa4d03-e3ea-46b7-b093-62c1b7632df3"
161 (org-narrow-to-subtree)
163 (org-export-as-html nil nil nil
'string
'body-only
))
165 (org-test-with-temp-text-in-file
168 ;; check following ouput exists and in order
170 (should (< test-point
174 (setq test-point
(point)))
175 '("mixed blocks with exports both"
182 "\"code block results\""
184 "<pre class=\"example\">"
188 (ert-deftest ob-exp
/export-with-name
()
189 (let ((org-babel-exp-code-template
190 "=%name=\n#+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
191 (org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
192 (org-narrow-to-subtree)
193 (let ((ascii (org-export-as-ascii nil nil nil
'string
'body-only
)))
194 (should (string-match "qux" ascii
))))))
196 (ert-deftest ob-exp
/export-with-header-argument
()
197 (let ((org-babel-exp-code-template
200 |---------+----------|
202 | results | %results |
203 #+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
204 (org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
205 (org-narrow-to-subtree)
206 (let ((ascii (org-export-as-ascii nil nil nil
'string
'body-only
)))
207 (should (string-match "baz" ascii
))
208 (should (string-match "replace" ascii
))))))
210 (ert-deftest ob-exp
/noweb-no-export-and-exports-both
()
211 (org-test-at-id "8a820f6c-7980-43db-8a24-0710d33729c9"
212 (org-narrow-to-subtree)
213 (let ((html (org-export-as-html nil nil nil
'string
'body-only
)))
214 (should (string-match (regexp-quote "noweb-no-export-and-exports-both-1")
217 (ert-deftest ob-exp
/evaluate-all-executables-in-order
()
218 (org-test-at-id "96cc7073-97ec-4556-87cf-1f9bffafd317"
219 (org-narrow-to-subtree)
220 (let (*evaluation-collector
*)
221 (org-export-as-ascii nil nil nil
'string
)
222 (should (equal '(5 4 3 2 1) *evaluation-collector
*)))))
224 (ert-deftest ob-exp
/export-call-line-information
()
225 (org-test-at-id "bec63a04-491e-4caa-97f5-108f3020365c"
226 (org-narrow-to-subtree)
227 (let* ((org-babel-exp-call-line-template "\n: call: %line special-token")
228 (html (org-export-as-html nil nil nil
'string t
)))
229 (should (string-match "double" html
))
230 (should (string-match "16" html
))
231 (should (string-match "special-token" html
)))))
233 (ert-deftest ob-exp
/noweb-strip-export-ensure-strips
()
234 (org-test-at-id "8e7bd234-99b2-4b14-8cd6-53945e409775"
235 (org-narrow-to-subtree)
236 (org-babel-next-src-block 2)
237 (should (= 110 (org-babel-execute-src-block)))
238 (let ((ascii (org-export-as-ascii nil nil nil
'string t
)))
239 (should-not (string-match (regexp-quote "<<strip-export-1>>") ascii
))
240 (should-not (string-match (regexp-quote "i=\"10\"") ascii
)))))
242 (ert-deftest ob-exp
/export-from-a-temp-buffer
()
243 :expected-result
:failed
244 (org-test-with-temp-text
246 #+Title: exporting from a temporary buffer
249 #+BEGIN_SRC emacs-lisp
254 #+BEGIN_SRC emacs-lisp
258 #+BEGIN_SRC emacs-lisp :var foo=foo :noweb yes :exports results
262 (let* ((org-current-export-file (current-buffer))
263 (ascii (org-export-as-ascii nil nil nil
'string
)))
264 (should (string-match (regexp-quote (format nil
"%S" '(:foo
:bar
)))
267 (provide 'test-ob-exp
)
269 ;;; test-ob-exp.el ends here