test-ob-exp.el 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;; test-ob-exp.el
  2. ;; Copyright (c) 2010 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-headers ()
  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. (let (html)
  63. (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
  64. (org-narrow-to-subtree)
  65. (setq html (org-export-as-html nil nil nil 'string)))
  66. (flet ((exp-p (arg)
  67. (and
  68. (string-match
  69. (format "noweb-%s-start\\([^\000]*\\)noweb-%s-end" arg arg)
  70. html)
  71. (string-match "expanded" (match-string 1 html)))))
  72. (should (exp-p "yes"))
  73. (should-not (exp-p "no"))
  74. (should-not (exp-p "tangle")))))
  75. (ert-deftest ob-exp/exports-both ()
  76. "Test the :exports both header argument.
  77. The code block should create both <pre></pre> and <table></table>
  78. elements in the final html."
  79. (let (html)
  80. (org-test-at-id "92518f2a-a46a-4205-a3ab-bcce1008a4bb"
  81. (org-narrow-to-subtree)
  82. (setq html (org-export-as-html nil nil nil 'string))
  83. (should (string-match "<pre.*>[^\000]*</pre>" html))
  84. (should (string-match "<table.*>[^\000]*</table>" html)))))
  85. (provide 'test-ob-exp)
  86. ;;; test-ob-exp.el ends here