test-ob-lob.el 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;;; test-ob-lob.el --- test for ob-lob.el
  2. ;; Copyright (c) 2010-2012 Eric Schulte
  3. ;; Authors: Eric Schulte
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Tests
  16. (org-babel-lob-ingest
  17. (expand-file-name
  18. "library-of-babel.org"
  19. (expand-file-name
  20. "babel"
  21. (expand-file-name
  22. "contrib"
  23. (expand-file-name
  24. ".."
  25. (expand-file-name
  26. ".."
  27. (file-name-directory
  28. (or load-file-name buffer-file-name))))))))
  29. (ert-deftest test-ob-lob/ingest ()
  30. "Test the ingestion of an org-mode file."
  31. (should (< 0 (org-babel-lob-ingest
  32. (expand-file-name "babel.org" org-test-example-dir)))))
  33. (ert-deftest test-ob-lob/call-with-header-arguments ()
  34. "Test the evaluation of a library of babel #+call: line."
  35. (org-test-at-id "fab7e291-fde6-45fc-bf6e-a485b8bca2f0"
  36. (move-beginning-of-line 1)
  37. (forward-line 6)
  38. (message (buffer-substring (point-at-bol) (point-at-eol)))
  39. (should (string= "testing" (org-babel-lob-execute
  40. (org-babel-lob-get-info))))
  41. (forward-line 1)
  42. (should (string= "testing" (caar (org-babel-lob-execute
  43. (org-babel-lob-get-info)))))
  44. (forward-line 1)
  45. (should (string= "testing" (org-babel-lob-execute
  46. (org-babel-lob-get-info))))
  47. (forward-line 1)
  48. (should (string= "testing" (caar (org-babel-lob-execute
  49. (org-babel-lob-get-info)))))
  50. (forward-line 1)
  51. (should (string= "testing" (org-babel-lob-execute
  52. (org-babel-lob-get-info))))
  53. (forward-line 1)
  54. (should (string= "testing" (caar (org-babel-lob-execute
  55. (org-babel-lob-get-info)))))
  56. (forward-line 1) (beginning-of-line) (forward-char 27)
  57. (should (string= "testing" (org-babel-lob-execute
  58. (org-babel-lob-get-info))))
  59. (forward-line 1) (beginning-of-line) (forward-char 27)
  60. (should (string= "testing" (caar (org-babel-lob-execute
  61. (org-babel-lob-get-info)))))
  62. (forward-line 1) (beginning-of-line)
  63. (should (= 4 (org-babel-lob-execute (org-babel-lob-get-info))))
  64. (forward-line 1)
  65. (should (string= "testing" (org-babel-lob-execute
  66. (org-babel-lob-get-info))))
  67. (forward-line 1)
  68. (should (string= "123" (org-babel-lob-execute (org-babel-lob-get-info))))))
  69. (ert-deftest test-ob-lob/export-lob-lines ()
  70. "Test the export of a variety of library babel call lines."
  71. (org-test-at-id "72ddeed3-2d17-4c7f-8192-a575d535d3fc"
  72. (org-narrow-to-subtree)
  73. (let ((html (org-export-as-html nil nil nil 'string 'body-only)))
  74. ;; check the location of each exported number
  75. (with-temp-buffer
  76. (insert html) (goto-char (point-min))
  77. ;; 0 should be on a line by itself
  78. (should (re-search-forward "0" nil t))
  79. (should (string= "0" (buffer-substring (point-at-bol) (point-at-eol))))
  80. ;; 2 should be in <code> tags
  81. (should (re-search-forward "2" nil t))
  82. (should (re-search-forward (regexp-quote "</code>") (point-at-eol) t))
  83. (should (re-search-backward (regexp-quote "<code>") (point-at-bol) t))
  84. ;; 4 should not be exported
  85. (should (not (re-search-forward "4" nil t)))
  86. ;; 6 should also be inline
  87. (should (re-search-forward "6" nil t))
  88. (should (re-search-forward (regexp-quote "</code>") (point-at-eol) t))
  89. (should (re-search-backward (regexp-quote "<code>") (point-at-bol) t))
  90. ;; 8 should not be quoted
  91. (should (re-search-forward "8" nil t))
  92. (should (not (= ?= (char-after (point)))))
  93. (should (not (= ?= (char-before (- (point) 1)))))
  94. ;; 10 should export
  95. (should (re-search-forward "10" nil t))))))
  96. (ert-deftest test-ob-lob/do-not-eval-lob-lines-in-example-blocks-on-export ()
  97. (org-test-with-temp-text-in-file "
  98. for export
  99. #+begin_example
  100. #+call: rubbish()
  101. #+end_example"
  102. (org-export-as-html nil)))
  103. (provide 'test-ob-lob)
  104. ;;; test-ob-lob.el ends here