org-clone-subtree-with-time-shift: Fix SHIFT check
[org-mode.git] / testing / lisp / test-ob-lob.el
blob55a01effebf6368e1644812cc6ef088c1dc2c73c
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/>.
22 ;;; Tests
23 (org-babel-lob-ingest
24 (expand-file-name
25 "library-of-babel.org"
26 (expand-file-name
27 "doc"
28 (expand-file-name
29 ".."
30 (expand-file-name
31 ".."
32 (file-name-directory
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)
46 (forward-line 6)
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))))
50 (forward-line 1)
51 (should (string= "testing" (caar (org-babel-execute-src-block
52 nil (org-babel-lob-get-info)))))
53 (forward-line 1)
54 (should (string= "testing" (org-babel-execute-src-block
55 nil (org-babel-lob-get-info))))
56 (forward-line 1)
57 (should (string= "testing" (caar (org-babel-execute-src-block
58 nil (org-babel-lob-get-info)))))
59 (forward-line 1)
60 (should (string= "testing" (org-babel-execute-src-block
61 nil (org-babel-lob-get-info))))
62 (forward-line 1)
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))))
73 (forward-line 1)
74 (should (string= "testing" (org-babel-execute-src-block
75 nil (org-babel-lob-get-info))))
76 (forward-line 1)
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))))
88 (with-temp-buffer
89 (org-mode)
90 (insert string)
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 ()
104 (require 'ox)
105 (org-test-with-temp-text-in-file "
106 for export
107 #+begin_example
108 #+call: rubbish()
109 #+end_example"
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))
118 #+end_src
120 <point>#+call: call-line-caching-example(\"qux\") :cache yes
122 ;; first execution should flip value to t
123 (should
124 (eq (org-babel-execute-src-block nil (org-babel-lob-get-info)) 1))
125 ;; if cached, second evaluation will retain the t value
126 (should
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))
135 #+end_src
137 #+name: call-line-caching-called
138 <point>#+call: call-line-caching-example(\"qux\") :cache yes
140 ;; first execution should flip value to t
141 (should
142 (eq (org-babel-execute-src-block nil (org-babel-lob-get-info)) 1))
143 ;; if cached, second evaluation will retain the t value
144 (should
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