1 ;;; test-ob-lob.el --- test for ob-lob.el
3 ;; Copyright (c) 2010-2015 Eric Schulte
4 ;; Authors: Eric Schulte
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "library-of-babel.org"
33 (or load-file-name buffer-file-name
)))))))
35 (ert-deftest test-ob-lob
/ingest
()
36 "Test the ingestion of an Org file."
37 (should (< 0 (org-babel-lob-ingest
38 (expand-file-name "babel.org" org-test-example-dir
)))))
40 (ert-deftest test-ob-lob
/call-with-header-arguments
()
41 "Test the evaluation of a library of babel #+call: line."
42 (letf (((symbol-function 'org-babel-insert-result
)
43 (symbol-function 'ignore
)))
44 (org-test-at-id "fab7e291-fde6-45fc-bf6e-a485b8bca2f0"
45 (move-beginning-of-line 1)
47 (message (buffer-substring (point-at-bol) (point-at-eol)))
48 (should (string= "testing" (org-babel-execute-src-block
49 nil
(org-babel-lob-get-info))))
51 (should (string= "testing" (caar (org-babel-execute-src-block
52 nil
(org-babel-lob-get-info)))))
54 (should (string= "testing" (org-babel-execute-src-block
55 nil
(org-babel-lob-get-info))))
57 (should (string= "testing" (caar (org-babel-execute-src-block
58 nil
(org-babel-lob-get-info)))))
60 (should (string= "testing" (org-babel-execute-src-block
61 nil
(org-babel-lob-get-info))))
63 (should (string= "testing" (caar (org-babel-execute-src-block
64 nil
(org-babel-lob-get-info)))))
65 (forward-line 1) (beginning-of-line) (forward-char 27)
66 (should (string= "testing" (org-babel-execute-src-block
67 nil
(org-babel-lob-get-info))))
68 (forward-line 1) (beginning-of-line) (forward-char 27)
69 (should (string= "testing" (caar (org-babel-execute-src-block
70 nil
(org-babel-lob-get-info)))))
71 (forward-line 1) (beginning-of-line)
72 (should (= 4 (org-babel-execute-src-block nil
(org-babel-lob-get-info))))
74 (should (string= "testing" (org-babel-execute-src-block
75 nil
(org-babel-lob-get-info))))
77 (should (string= "123" (org-babel-execute-src-block
78 nil
(org-babel-lob-get-info)))))))
80 (ert-deftest test-ob-lob
/export-lob-lines
()
81 "Test the export of a variety of library babel call lines."
82 (let ((org-babel-inline-result-wrap "=%s=")
83 (org-export-babel-evaluate t
))
84 (org-test-at-id "72ddeed3-2d17-4c7f-8192-a575d535d3fc"
85 (org-narrow-to-subtree)
86 (let ((string (org-with-wide-buffer (buffer-string)))
87 (narrowing (list (point-min) (point-max))))
91 (apply #'narrow-to-region narrowing
)
92 (org-babel-exp-process-buffer)
93 (message (buffer-string))
94 (goto-char (point-min))
95 (should (re-search-forward "^: 0" nil t
))
96 (should (re-search-forward "call {{{results(=2=)}}} stuck" nil t
))
97 (should (re-search-forward
98 "exported =call_double(it=2)= because" nil t
))
99 (should (re-search-forward "^{{{results(=6=)}}} because" nil t
))
100 (should (re-search-forward "results 8 should" nil t
))
101 (should (re-search-forward "following 2\\*5={{{results(=10=)}}} should" nil t
)))))))
103 (ert-deftest test-ob-lob
/do-not-eval-lob-lines-in-example-blocks-on-export
()
105 (org-test-with-temp-text-in-file "
110 (should (progn (org-babel-exp-process-buffer) t
))))
112 (ert-deftest test-ob-lob
/caching-call-line
()
113 (let ((temporary-value-for-test 0))
114 (org-test-with-temp-text "
115 #+name: call-line-caching-example
116 #+begin_src emacs-lisp :var bar=\"baz\"
117 (setq temporary-value-for-test (+ 1 temporary-value-for-test))
120 <point>#+call: call-line-caching-example(\"qux\") :cache yes
122 ;; first execution should flip value to t
124 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1))
125 ;; if cached, second evaluation will retain the t value
127 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1)))))
129 (ert-deftest test-ob-lob
/named-caching-call-line
()
130 (let ((temporary-value-for-test 0))
131 (org-test-with-temp-text "
132 #+name: call-line-caching-example
133 #+begin_src emacs-lisp :var bar=\"baz\"
134 (setq temporary-value-for-test (+ 1 temporary-value-for-test))
137 #+name: call-line-caching-called
138 <point>#+call: call-line-caching-example(\"qux\") :cache yes
140 ;; first execution should flip value to t
142 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1))
143 ;; if cached, second evaluation will retain the t value
145 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1)))))
147 (provide 'test-ob-lob
)
149 ;;; test-ob-lob.el ends here