Fix trailing whitespaces.
[org-mode.git] / testing / lisp / test-ob-exp.el
blob85af683560570b05cc6a5c14221b474e2cedc700
1 ;;; test-ob-exp.el
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
9 ;;;; Comments:
11 ;; Template test file for Org-mode tests
14 ;;; Code:
15 (let ((load-path (cons (expand-file-name
16 ".." (file-name-directory
17 (or load-file-name buffer-file-name)))
18 load-path)))
19 (require 'org-test)
20 (require 'org-test-ob-consts))
23 ;;; Tests
24 (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers ()
25 "Testing export without any headlines in the org-mode file."
26 (let ((html-file (concat (file-name-sans-extension org-test-no-heading-file)
27 ".html")))
28 (when (file-exists-p html-file) (delete-file html-file))
29 (org-test-in-example-file org-test-no-heading-file
30 ;; export the file to html
31 (org-export-as-html nil))
32 ;; should create a .html file
33 (should (file-exists-p html-file))
34 ;; should not create a file with "::" appended to it's name
35 (should-not (file-exists-p (concat org-test-no-heading-file "::")))
36 (when (file-exists-p html-file) (delete-file html-file))))
38 (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-file ()
39 "Testing export from buffers which are not visiting any file."
40 (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*"))
41 (should-not (get-buffer "*Org HTML Export*"))
42 ;; export the file to HTML in a temporary buffer
43 (org-test-in-example-file nil (org-export-as-html-to-buffer nil))
44 ;; should create a .html buffer
45 (should (buffer-live-p (get-buffer "*Org HTML Export*")))
46 ;; should contain the content of the buffer
47 (save-excursion
48 (set-buffer (get-buffer "*Org HTML Export*"))
49 (should (string-match (regexp-quote org-test-file-ob-anchor)
50 (buffer-string))))
51 (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*")))
53 (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers2 ()
54 "Testing export without any headlines in the org-mode file."
55 (let ((html-file (concat (file-name-sans-extension
56 org-test-link-in-heading-file)
57 ".html")))
58 (when (file-exists-p html-file) (delete-file html-file))
59 (org-test-in-example-file org-test-link-in-heading-file
60 ;; export the file to html
61 (org-export-as-html nil))
62 ;; should create a .html file
63 (should (file-exists-p html-file))
64 ;; should not create a file with "::" appended to it's name
65 (should-not (file-exists-p (concat org-test-link-in-heading-file "::")))
66 (when (file-exists-p html-file) (delete-file html-file))))
68 (ert-deftest ob-exp/noweb-on-export ()
69 "Noweb header arguments export correctly.
70 - yes expand on both export and tangle
71 - no expand on neither export or tangle
72 - tangle expand on only tangle not export"
73 (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
74 (org-narrow-to-subtree)
75 (let ((exported-html
76 (org-export-as-html nil nil nil 'string))
77 (test-point 0))
79 (org-test-with-temp-text-in-file
80 exported-html
82 ;; check following ouput exists and in order
83 (mapcar (lambda (x)
84 (should (< test-point
85 (re-search-forward
87 nil t)))
88 (setq test-point (point)))
89 '("<head>" "</head>" "<body>"
90 "<code>:noweb</code> header argument expansion"
91 "<code>:noweb</code> header argument expansion"
92 "message" "expanded1"
93 "message" "expanded2"
94 "noweb-1-yes-start"
95 "message" "expanded1"
96 "noweb-no-start"
97 "&lt;&lt;noweb-example1&gt;&gt;"
98 "noweb-2-yes-start"
99 "message" "expanded2"
100 "noweb-tangle-start"
101 "&lt;&lt;noweb-example1&gt;&gt;"
102 "&lt;&lt;noweb-example2&gt;&gt;"
103 "</body>"))))))
105 (ert-deftest ob-exp/noweb-on-export-with-exports-results ()
106 "Noweb header arguments export correctly using :exports results.
107 - yes expand on both export and tangle
108 - no expand on neither export or tangle
109 - tangle expand on only tangle not export"
110 (org-test-at-id "8701beb4-13d9-468c-997a-8e63e8b66f8d"
111 (org-narrow-to-subtree)
112 (let ((exported-html
113 (org-export-as-html nil nil nil 'string))
114 (test-point 0))
116 (org-test-with-temp-text-in-file
117 exported-html
119 ;; check following ouput exists and in order
120 (mapcar (lambda (x)
121 (should (< test-point
122 (re-search-forward
124 nil t)))
125 (setq test-point (point)))
126 '("<head>" "</head>" "<body>"
127 "<code>:noweb</code> header argument expansion using :exports results"
128 "<code>:noweb</code> header argument expansion using :exports results"
129 "expanded1"
130 "expanded2"
131 "expanded1"
132 "noweb-no-start"
133 "&lt;&lt;noweb-example1&gt;&gt;"
134 "expanded2"
135 "&lt;&lt;noweb-example1&gt;&gt;"
136 "&lt;&lt;noweb-example2&gt;&gt;"
137 "</body>"))))))
139 (ert-deftest ob-exp/exports-both ()
140 "Test the :exports both header argument.
141 The code block should create both <pre></pre> and <table></table>
142 elements in the final html."
143 (org-test-at-id "92518f2a-a46a-4205-a3ab-bcce1008a4bb"
144 (org-narrow-to-subtree)
145 (let ((exported-html
146 (org-export-as-html nil nil nil 'string))
147 (test-point 0))
149 (org-test-with-temp-text-in-file
150 exported-html
152 ;; check following ouput exists and in order
153 (mapcar (lambda (x)
154 (should (< test-point
155 (re-search-forward
157 nil t)))
158 (setq test-point (point)))
159 '("<head>" "</head>" "<body>"
160 "Pascal's Triangle &ndash; exports both test"
161 "Pascal's Triangle &ndash; exports both test"
162 "<pre"
163 "defun" "pascals-triangle"
164 "if""list""list""let*""prev-triangle"
165 "pascals-triangle""prev-row""car""reverse""prev-triangle"
166 "append""prev-triangle""list""map""list"
167 "append""prev-row""append""prev-row""pascals-triangle"
168 "</pre>"
169 "<table""<tbody>"
170 "<tr>"">1<""</tr>"
171 "<tr>"">1<"">1<""</tr>"
172 "<tr>"">1<"">2<"">1<""</tr>"
173 "<tr>"">1<"">3<"">3<"">1<""</tr>"
174 "<tr>"">1<"">4<"">6<"">4<"">1<""</tr>"
175 "<tr>"">1<"">5<"">10<"">10<"">5<"">1<""</tr>"
176 "</tbody>""</table>"
177 "</body>"))))))
179 (ert-deftest ob-exp/mixed-blocks-with-exports-both ()
180 (org-test-at-id "5daa4d03-e3ea-46b7-b093-62c1b7632df3"
181 (org-narrow-to-subtree)
182 (let ((exported-html
183 (org-export-as-html nil nil nil 'string))
184 (test-point 0))
185 (org-test-with-temp-text-in-file
186 exported-html
188 ;; check following ouput exists and in order
189 (mapcar (lambda (x)
190 (should (< test-point
191 (re-search-forward
193 nil t)))
194 (setq test-point (point)))
195 '("<head>" "</head>" "<body>"
196 "mixed blocks with exports both"
197 "mixed blocks with exports both"
198 "<ul>"
199 "<li>""a""</li>"
200 "<li>""b""</li>"
201 "<li>""c""</li>"
202 "</ul>"
203 "<pre"
204 "\"code block results\""
205 "</pre>"
206 "<pre class=\"example\">"
207 "code block results"
208 "</pre>"
209 "</body>"))))))
211 (provide 'test-ob-exp)
213 ;;; test-ob-exp.el ends here