test-ob-exp.el 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. ;;; test-ob-exp.el
  2. ;; Copyright (c) 2010-2012 Eric Schulte
  3. ;; Authors: Eric Schulte
  4. ;; Released under the GNU General Public License version 3
  5. ;; see: http://www.gnu.org/licenses/gpl-3.0.html
  6. ;;;; Comments:
  7. ;; Template test file for Org-mode tests
  8. ;;; Code:
  9. (let ((load-path (cons (expand-file-name
  10. ".." (file-name-directory
  11. (or load-file-name buffer-file-name)))
  12. load-path)))
  13. (require 'org-test)
  14. (require 'org-test-ob-consts))
  15. ;;; Tests
  16. (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers ()
  17. "Testing export without any headlines in the org-mode file."
  18. (let ((html-file (concat (file-name-sans-extension org-test-no-heading-file)
  19. ".html")))
  20. (when (file-exists-p html-file) (delete-file html-file))
  21. (org-test-in-example-file org-test-no-heading-file
  22. ;; export the file to html
  23. (org-export-as-html nil))
  24. ;; should create a .html file
  25. (should (file-exists-p html-file))
  26. ;; should not create a file with "::" appended to it's name
  27. (should-not (file-exists-p (concat org-test-no-heading-file "::")))
  28. (when (file-exists-p html-file) (delete-file html-file))))
  29. (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-file ()
  30. "Testing export from buffers which are not visiting any file."
  31. (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*"))
  32. (should-not (get-buffer "*Org HTML Export*"))
  33. ;; export the file to HTML in a temporary buffer
  34. (org-test-in-example-file nil (org-export-as-html-to-buffer nil))
  35. ;; should create a .html buffer
  36. (should (buffer-live-p (get-buffer "*Org HTML Export*")))
  37. ;; should contain the content of the buffer
  38. (save-excursion
  39. (set-buffer (get-buffer "*Org HTML Export*"))
  40. (should (string-match (regexp-quote org-test-file-ob-anchor)
  41. (buffer-string))))
  42. (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)
  47. ".html")))
  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))))
  57. (ert-deftest ob-exp/noweb-on-export ()
  58. "Noweb header arguments export correctly.
  59. - yes expand on both export and tangle
  60. - no expand on neither export or tangle
  61. - tangle expand on only tangle not export"
  62. (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
  63. (org-narrow-to-subtree)
  64. (let ((exported-html
  65. (org-export-as-html nil nil nil 'string 'body-only))
  66. (test-point 0))
  67. (org-test-with-temp-text-in-file
  68. exported-html
  69. ;; check following ouput exists and in order
  70. (mapcar (lambda (x)
  71. (should (< test-point
  72. (re-search-forward
  73. x
  74. nil t)))
  75. (setq test-point (point)))
  76. '("<code>:noweb</code> header argument expansion"
  77. "message" "expanded1"
  78. "message" "expanded2"
  79. "noweb-1-yes-start"
  80. "message" "expanded1"
  81. "noweb-no-start"
  82. "&lt;&lt;noweb-example1&gt;&gt;"
  83. "noweb-2-yes-start"
  84. "message" "expanded2"
  85. "noweb-tangle-start"
  86. "&lt;&lt;noweb-example1&gt;&gt;"
  87. "&lt;&lt;noweb-example2&gt;&gt;"))))))
  88. (ert-deftest ob-exp/noweb-on-export-with-exports-results ()
  89. "Noweb header arguments export correctly using :exports results.
  90. - yes expand on both export and tangle
  91. - no expand on neither export or tangle
  92. - tangle expand on only tangle not export"
  93. (org-test-at-id "8701beb4-13d9-468c-997a-8e63e8b66f8d"
  94. (org-narrow-to-subtree)
  95. (let ((exported-html
  96. (org-export-as-html nil nil nil 'string 'body-only))
  97. (test-point 0))
  98. (org-test-with-temp-text-in-file
  99. exported-html
  100. ;; check following ouput exists and in order
  101. (mapcar (lambda (x)
  102. (should (< test-point
  103. (re-search-forward
  104. x
  105. nil t)))
  106. (setq test-point (point)))
  107. '("<code>:noweb</code> header argument expansion using :exports results"
  108. "expanded1"
  109. "expanded2"
  110. "expanded1"
  111. "noweb-no-start"
  112. "&lt;&lt;noweb-example1&gt;&gt;"
  113. "expanded2"
  114. "&lt;&lt;noweb-example1&gt;&gt;"
  115. "&lt;&lt;noweb-example2&gt;&gt;"))))))
  116. (ert-deftest ob-exp/exports-both ()
  117. "Test the :exports both header argument.
  118. The code block should create both <pre></pre> and <table></table>
  119. elements in the final html."
  120. (org-test-at-id "92518f2a-a46a-4205-a3ab-bcce1008a4bb"
  121. (org-narrow-to-subtree)
  122. (let ((exported-html
  123. (org-export-as-html nil nil nil 'string 'body-only))
  124. (test-point 0))
  125. (org-test-with-temp-text-in-file
  126. exported-html
  127. ;; check following ouput exists and in order
  128. (mapcar (lambda (x)
  129. (should (< test-point
  130. (re-search-forward
  131. x
  132. nil t)))
  133. (setq test-point (point)))
  134. '( "Pascal's Triangle &ndash; exports both test"
  135. "<pre"
  136. "defun" "pascals-triangle"
  137. "if""list""list""let*""prev-triangle"
  138. "pascals-triangle""prev-row""car""reverse""prev-triangle"
  139. "append""prev-triangle""list""map""list"
  140. "append""prev-row""append""prev-row""pascals-triangle"
  141. "</pre>"
  142. "<table""<tbody>"
  143. "<tr>"">1<""</tr>"
  144. "<tr>"">1<"">1<""</tr>"
  145. "<tr>"">1<"">2<"">1<""</tr>"
  146. "<tr>"">1<"">3<"">3<"">1<""</tr>"
  147. "<tr>"">1<"">4<"">6<"">4<"">1<""</tr>"
  148. "<tr>"">1<"">5<"">10<"">10<"">5<"">1<""</tr>"
  149. "</tbody>""</table>"))))))
  150. (ert-deftest ob-exp/mixed-blocks-with-exports-both ()
  151. (org-test-at-id "5daa4d03-e3ea-46b7-b093-62c1b7632df3"
  152. (org-narrow-to-subtree)
  153. (let ((exported-html
  154. (org-export-as-html nil nil nil 'string 'body-only))
  155. (test-point 0))
  156. (org-test-with-temp-text-in-file
  157. exported-html
  158. ;; check following ouput exists and in order
  159. (mapcar (lambda (x)
  160. (should (< test-point
  161. (re-search-forward
  162. x
  163. nil t)))
  164. (setq test-point (point)))
  165. '("mixed blocks with exports both"
  166. "<ul>"
  167. "<li>""a""</li>"
  168. "<li>""b""</li>"
  169. "<li>""c""</li>"
  170. "</ul>"
  171. "<pre"
  172. "\"code block results\""
  173. "</pre>"
  174. "<pre class=\"example\">"
  175. "code block results"
  176. "</pre>"))))))
  177. (ert-deftest ob-exp/export-with-name ()
  178. (let ((org-babel-exp-code-template
  179. "=%name=\n#+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
  180. (org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
  181. (org-narrow-to-subtree)
  182. (let ((ascii (org-export-as-ascii nil nil nil 'string 'body-only)))
  183. (should (string-match "qux" ascii))))))
  184. (ert-deftest ob-exp/export-with-header-argument ()
  185. (let ((org-babel-exp-code-template
  186. "
  187. | header | value |
  188. |---------+----------|
  189. | foo | %foo |
  190. | results | %results |
  191. #+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
  192. (org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
  193. (org-narrow-to-subtree)
  194. (let ((ascii (org-export-as-ascii nil nil nil 'string 'body-only)))
  195. (should (string-match "baz" ascii))
  196. (should (string-match "replace" ascii))))))
  197. (ert-deftest ob-exp/noweb-no-export-and-exports-both ()
  198. (org-test-at-id "8a820f6c-7980-43db-8a24-0710d33729c9"
  199. (org-narrow-to-subtree)
  200. (let ((html (org-export-as-html nil nil nil 'string 'body-only)))
  201. (should (string-match (regexp-quote "noweb-no-export-and-exports-both-1")
  202. html)))))
  203. (ert-deftest ob-exp/evaluate-all-executables-in-order ()
  204. (org-test-at-id "96cc7073-97ec-4556-87cf-1f9bffafd317"
  205. (org-narrow-to-subtree)
  206. (let (*evaluation-collector*)
  207. (org-export-as-ascii nil nil nil 'string)
  208. (should (equal '(5 4 3 2 1) *evaluation-collector*)))))
  209. (ert-deftest ob-exp/export-call-line-information ()
  210. (org-test-at-id "bec63a04-491e-4caa-97f5-108f3020365c"
  211. (org-narrow-to-subtree)
  212. (let* ((org-babel-exp-call-line-template "\n: call: %line special-token")
  213. (html (org-export-as-html nil nil nil 'string t)))
  214. (should (string-match "double" html))
  215. (should (string-match "16" html))
  216. (should (string-match "special-token" html)))))
  217. (provide 'test-ob-exp)
  218. ;;; test-ob-exp.el ends here