test-ob-lob.el 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ;;; test-ob-lob.el --- test for ob-lob.el
  2. ;; Copyright (c) 2010-2015 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. "doc"
  21. (expand-file-name
  22. ".."
  23. (expand-file-name
  24. ".."
  25. (file-name-directory
  26. (or load-file-name buffer-file-name)))))))
  27. (ert-deftest test-ob-lob/ingest ()
  28. "Test the ingestion of an Org file."
  29. (should (< 0 (org-babel-lob-ingest
  30. (expand-file-name "babel.org" org-test-example-dir)))))
  31. (ert-deftest test-ob-lob/call-with-header-arguments ()
  32. "Test the evaluation of a library of babel #+call: line."
  33. (letf (((symbol-function 'org-babel-insert-result)
  34. (symbol-function 'ignore)))
  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-execute-src-block
  40. nil (org-babel-lob-get-info))))
  41. (forward-line 1)
  42. (should (string= "testing" (caar (org-babel-execute-src-block
  43. nil (org-babel-lob-get-info)))))
  44. (forward-line 1)
  45. (should (string= "testing" (org-babel-execute-src-block
  46. nil (org-babel-lob-get-info))))
  47. (forward-line 1)
  48. (should (string= "testing" (caar (org-babel-execute-src-block
  49. nil (org-babel-lob-get-info)))))
  50. (forward-line 1)
  51. (should (string= "testing" (org-babel-execute-src-block
  52. nil (org-babel-lob-get-info))))
  53. (forward-line 1)
  54. (should (string= "testing" (caar (org-babel-execute-src-block
  55. nil (org-babel-lob-get-info)))))
  56. (forward-line 1) (beginning-of-line) (forward-char 27)
  57. (should (string= "testing" (org-babel-execute-src-block
  58. nil (org-babel-lob-get-info))))
  59. (forward-line 1) (beginning-of-line) (forward-char 27)
  60. (should (string= "testing" (caar (org-babel-execute-src-block
  61. nil (org-babel-lob-get-info)))))
  62. (forward-line 1) (beginning-of-line)
  63. (should (= 4 (org-babel-execute-src-block nil (org-babel-lob-get-info))))
  64. (forward-line 1)
  65. (should (string= "testing" (org-babel-execute-src-block
  66. nil (org-babel-lob-get-info))))
  67. (forward-line 1)
  68. (should (string= "123" (org-babel-execute-src-block
  69. nil (org-babel-lob-get-info)))))))
  70. (ert-deftest test-ob-lob/export-lob-lines ()
  71. "Test the export of a variety of library babel call lines."
  72. (let ((org-babel-inline-result-wrap "=%s=")
  73. (org-export-use-babel t))
  74. (org-test-at-id "72ddeed3-2d17-4c7f-8192-a575d535d3fc"
  75. (org-narrow-to-subtree)
  76. (let ((string (org-with-wide-buffer (buffer-string)))
  77. (narrowing (list (point-min) (point-max))))
  78. (with-temp-buffer
  79. (org-mode)
  80. (insert string)
  81. (apply #'narrow-to-region narrowing)
  82. (org-babel-exp-process-buffer)
  83. (message (buffer-string))
  84. (goto-char (point-min))
  85. (should (re-search-forward "^: 0" nil t))
  86. (should (re-search-forward "call {{{results(=2=)}}} stuck" nil t))
  87. (should (re-search-forward
  88. "exported =call_double(it=2)= because" nil t))
  89. (should (re-search-forward "^{{{results(=6=)}}} because" nil t))
  90. (should (re-search-forward "results 8 should" nil t))
  91. (should (re-search-forward "following 2\\*5={{{results(=10=)}}} should" nil t)))))))
  92. (ert-deftest test-ob-lob/do-not-eval-lob-lines-in-example-blocks-on-export ()
  93. (require 'ox)
  94. (org-test-with-temp-text-in-file "
  95. for export
  96. #+begin_example
  97. #+call: rubbish()
  98. #+end_example"
  99. (should (progn (org-babel-exp-process-buffer) t))))
  100. (ert-deftest test-ob-lob/caching-call-line ()
  101. (let ((temporary-value-for-test 0))
  102. (org-test-with-temp-text "
  103. #+name: call-line-caching-example
  104. #+begin_src emacs-lisp :var bar=\"baz\"
  105. (setq temporary-value-for-test (+ 1 temporary-value-for-test))
  106. #+end_src
  107. <point>#+call: call-line-caching-example(\"qux\") :cache yes
  108. "
  109. ;; first execution should flip value to t
  110. (should
  111. (eq (org-babel-execute-src-block nil (org-babel-lob-get-info)) 1))
  112. ;; if cached, second evaluation will retain the t value
  113. (should
  114. (eq (org-babel-execute-src-block nil (org-babel-lob-get-info)) 1)))))
  115. (ert-deftest test-ob-lob/named-caching-call-line ()
  116. (let ((temporary-value-for-test 0))
  117. (org-test-with-temp-text "
  118. #+name: call-line-caching-example
  119. #+begin_src emacs-lisp :var bar=\"baz\"
  120. (setq temporary-value-for-test (+ 1 temporary-value-for-test))
  121. #+end_src
  122. #+name: call-line-caching-called
  123. <point>#+call: call-line-caching-example(\"qux\") :cache yes
  124. "
  125. ;; first execution should flip value to t
  126. (should
  127. (eq (org-babel-execute-src-block nil (org-babel-lob-get-info)) 1))
  128. ;; if cached, second evaluation will retain the t value
  129. (should
  130. (eq (org-babel-execute-src-block nil (org-babel-lob-get-info)) 1)))))
  131. (provide 'test-ob-lob)
  132. ;;; test-ob-lob.el ends here