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 (let ((org-babel-library-of-babel
45 (org-test-with-temp-text-in-file
48 #+begin_src emacs-lisp :var input=\"echo'd\"
53 #+begin_src emacs-lisp :var a=0 :var b=0
56 (org-babel-lob-ingest)
57 org-babel-library-of-babel
)))
58 (org-test-at-id "fab7e291-fde6-45fc-bf6e-a485b8bca2f0"
59 (move-beginning-of-line 1)
61 (message (buffer-substring (point-at-bol) (point-at-eol)))
63 (string= "testing" (org-babel-execute-src-block
64 nil
(org-babel-lob-get-info))))
67 (string= "testing" (caar (org-babel-execute-src-block
68 nil
(org-babel-lob-get-info)))))
71 (string= "testing" (org-babel-execute-src-block
72 nil
(org-babel-lob-get-info))))
75 (string= "testing" (caar (org-babel-execute-src-block
76 nil
(org-babel-lob-get-info)))))
79 (string= "testing" (org-babel-execute-src-block
80 nil
(org-babel-lob-get-info))))
83 (string= "testing" (caar (org-babel-execute-src-block
84 nil
(org-babel-lob-get-info)))))
85 (forward-line 1) (beginning-of-line) (forward-char 27)
87 (string= "testing" (org-babel-execute-src-block
88 nil
(org-babel-lob-get-info))))
89 (forward-line 1) (beginning-of-line) (forward-char 27)
91 (string= "testing" (caar (org-babel-execute-src-block
92 nil
(org-babel-lob-get-info)))))
93 (forward-line 1) (beginning-of-line)
95 (= 4 (org-babel-execute-src-block nil
(org-babel-lob-get-info))))
98 (string= "testing" (org-babel-execute-src-block
99 nil
(org-babel-lob-get-info))))
101 (should (string= "123" (org-babel-execute-src-block
102 nil
(org-babel-lob-get-info))))))))
104 (ert-deftest test-ob-lob
/export-lob-lines
()
105 "Test the export of a variety of library babel call lines."
106 (let ((org-babel-inline-result-wrap "=%s=")
107 (org-export-use-babel t
))
108 (org-test-at-id "72ddeed3-2d17-4c7f-8192-a575d535d3fc"
109 (org-narrow-to-subtree)
110 (let ((string (org-with-wide-buffer (buffer-string)))
111 (narrowing (list (point-min) (point-max))))
115 (apply #'narrow-to-region narrowing
)
116 (org-babel-exp-process-buffer)
117 (message (buffer-string))
118 (goto-char (point-min))
119 (should (re-search-forward "^: 0" nil t
))
120 (should (re-search-forward "call {{{results(=2=)}}} stuck" nil t
))
121 (should (re-search-forward
122 "exported =call_double(it=2)= because" nil t
))
123 (should (re-search-forward "^{{{results(=6=)}}} because" nil t
))
124 (should (re-search-forward "results 8 should" nil t
))
125 (should (re-search-forward "following 2\\*5={{{results(=10=)}}} should" nil t
)))))))
127 (ert-deftest test-ob-lob
/do-not-eval-lob-lines-in-example-blocks-on-export
()
129 (org-test-with-temp-text-in-file "
134 (should (progn (org-babel-exp-process-buffer) t
))))
136 (ert-deftest test-ob-lob
/caching-call-line
()
137 (let ((temporary-value-for-test 0))
138 (org-test-with-temp-text "
139 #+name: call-line-caching-example
140 #+begin_src emacs-lisp :var bar=\"baz\"
141 (setq temporary-value-for-test (+ 1 temporary-value-for-test))
144 <point>#+call: call-line-caching-example(\"qux\") :cache yes
146 ;; first execution should flip value to t
148 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1))
149 ;; if cached, second evaluation will retain the t value
151 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1)))))
153 (ert-deftest test-ob-lob
/named-caching-call-line
()
154 (let ((temporary-value-for-test 0))
155 (org-test-with-temp-text "
156 #+name: call-line-caching-example
157 #+begin_src emacs-lisp :var bar=\"baz\"
158 (setq temporary-value-for-test (+ 1 temporary-value-for-test))
161 #+name: call-line-caching-called
162 <point>#+call: call-line-caching-example(\"qux\") :cache yes
164 ;; first execution should flip value to t
166 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1))
167 ;; if cached, second evaluation will retain the t value
169 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1)))))
171 (ert-deftest test-ob-lob
/assignment-with-newline
()
172 "Test call lines with an argument containing a newline character."
175 (org-test-with-temp-text "
177 #+begin_src emacs-lisp :var x=\"a\"
181 call_test-newline[:eval yes :results raw](\"a\nb\")<point>"
182 (org-babel-execute-src-block nil
(org-babel-lob-get-info))
183 (buffer-substring (point) (point-max)))))
186 (org-test-with-temp-text "
188 #+begin_src emacs-lisp :var x=\"a\"
192 call_test-newline[:eval yes :results raw]('(1\n2))<point>"
193 (org-babel-execute-src-block nil
(org-babel-lob-get-info))
194 (buffer-substring (point) (point-max))))))
196 (provide 'test-ob-lob
)
198 ;;; test-ob-lob.el ends here