test-ob-exp.el 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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))
  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. '("<head>" "</head>" "<body>"
  77. "<code>:noweb</code> header argument expansion"
  78. "<code>:noweb</code> header argument expansion"
  79. "message" "expanded1"
  80. "message" "expanded2"
  81. "noweb-1-yes-start"
  82. "message" "expanded1"
  83. "noweb-no-start"
  84. "&lt;&lt;noweb-example1&gt;&gt;"
  85. "noweb-2-yes-start"
  86. "message" "expanded2"
  87. "noweb-tangle-start"
  88. "&lt;&lt;noweb-example1&gt;&gt;"
  89. "&lt;&lt;noweb-example2&gt;&gt;"
  90. "</body>"))))))
  91. (ert-deftest ob-exp/noweb-on-export-with-exports-results ()
  92. "Noweb header arguments export correctly using :exports results.
  93. - yes expand on both export and tangle
  94. - no expand on neither export or tangle
  95. - tangle expand on only tangle not export"
  96. (org-test-at-id "8701beb4-13d9-468c-997a-8e63e8b66f8d"
  97. (org-narrow-to-subtree)
  98. (let ((exported-html
  99. (org-export-as-html nil nil nil 'string))
  100. (test-point 0))
  101. (org-test-with-temp-text-in-file
  102. exported-html
  103. ;; check following ouput exists and in order
  104. (mapcar (lambda (x)
  105. (should (< test-point
  106. (re-search-forward
  107. x
  108. nil t)))
  109. (setq test-point (point)))
  110. '("<head>" "</head>" "<body>"
  111. "<code>:noweb</code> header argument expansion using :exports results"
  112. "<code>:noweb</code> header argument expansion using :exports results"
  113. "expanded1"
  114. "expanded2"
  115. "expanded1"
  116. "noweb-no-start"
  117. "&lt;&lt;noweb-example1&gt;&gt;"
  118. "expanded2"
  119. "&lt;&lt;noweb-example1&gt;&gt;"
  120. "&lt;&lt;noweb-example2&gt;&gt;"
  121. "</body>"))))))
  122. (ert-deftest ob-exp/exports-both ()
  123. "Test the :exports both header argument.
  124. The code block should create both <pre></pre> and <table></table>
  125. elements in the final html."
  126. (org-test-at-id "92518f2a-a46a-4205-a3ab-bcce1008a4bb"
  127. (org-narrow-to-subtree)
  128. (let ((exported-html
  129. (org-export-as-html nil nil nil 'string))
  130. (test-point 0))
  131. (org-test-with-temp-text-in-file
  132. exported-html
  133. ;; check following ouput exists and in order
  134. (mapcar (lambda (x)
  135. (should (< test-point
  136. (re-search-forward
  137. x
  138. nil t)))
  139. (setq test-point (point)))
  140. '("<head>" "</head>" "<body>"
  141. "Pascal's Triangle &ndash; exports both test"
  142. "Pascal's Triangle &ndash; exports both test"
  143. "<pre"
  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"
  149. "</pre>"
  150. "<table""<tbody>"
  151. "<tr>"">1<""</tr>"
  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>"
  158. "</body>"))))))
  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)
  162. (let ((exported-html
  163. (org-export-as-html nil nil nil 'string))
  164. (test-point 0))
  165. (org-test-with-temp-text-in-file
  166. exported-html
  167. ;; check following ouput exists and in order
  168. (mapcar (lambda (x)
  169. (should (< test-point
  170. (re-search-forward
  171. x
  172. nil t)))
  173. (setq test-point (point)))
  174. '("<head>" "</head>" "<body>"
  175. "mixed blocks with exports both"
  176. "mixed blocks with exports both"
  177. "<ul>"
  178. "<li>""a""</li>"
  179. "<li>""b""</li>"
  180. "<li>""c""</li>"
  181. "</ul>"
  182. "<pre"
  183. "\"code block results\""
  184. "</pre>"
  185. "<pre class=\"example\">"
  186. "code block results"
  187. "</pre>"
  188. "</body>"))))))
  189. (provide 'test-ob-exp)
  190. ;;; test-ob-exp.el ends here