ob-core: Fix `org-babel-balanced-split'
[org-mode/org-tableheadings.git] / testing / lisp / test-ob.el
blobfe4ecb85e3b4b06dbd2a31a72347e5b77d1e8e4b
1 ;;; test-ob.el --- tests for ob.el
3 ;; Copyright (c) 2010-2015 Eric Schulte
4 ;; Authors: Eric Schulte, Martyn Jago
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/>.
21 ;;; Code:
23 (ert-deftest test-ob/indented-cached-org-bracket-link ()
24 "When the result of a source block is a cached indented link it
25 should still return the link."
26 (should
27 (let ((default-directory temporary-file-directory))
28 (org-test-with-temp-text
30 * Test
31 #+<point>BEGIN_SRC emacs-lisp :file test.txt :cache yes
32 (message \"test\")
33 #+END_SRC"
34 ;; Execute twice as the first time creates the cache.
35 (org-babel-execute-src-block)
36 (string= (expand-file-name "test.txt")
37 (org-babel-execute-src-block))))))
39 (ert-deftest test-ob/multi-line-header-regexp ()
40 (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
41 org-babel-multi-line-header-regexp))
42 ;;TODO can be optimised - and what about blah4 blah5 blah6?
43 (should (string-match
44 org-babel-multi-line-header-regexp
45 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))
46 (should
47 (equal
48 "blah1 blah2 blah3 \t"
49 (match-string
51 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n")))
53 ;;TODO Check - should this fail?
54 (should
55 (not (org-test-string-exact-match
56 org-babel-multi-line-header-regexp
57 " \t #+headers : blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))))
59 (ert-deftest test-ob/src-block-regexp ()
60 (let ((test-block
61 (concat
62 "#+begin_src language -n-r-a-b -c :argument-1 yes :argument-2 no\n"
63 "echo this is a test\n"
64 "echo Currently in ' $PWD\n"
65 "#+end_src"))
66 (language "language")
67 (flags "-n-r-a-b -c ")
68 (arguments ":argument-1 yes :argument-2 no")
69 (body "echo this is a test\necho Currently in ' $PWD\n"))
70 (should (string-match org-babel-src-block-regexp test-block))
71 (should (string-match org-babel-src-block-regexp (upcase test-block)))
72 (should (equal language (match-string 2 test-block)))
73 ;;TODO Consider refactoring
74 (should (equal flags (match-string 3 test-block)))
75 (should (equal arguments (match-string 4 test-block)))
76 (should (equal body (match-string 5 test-block)))
77 ;;no switches
78 (should (org-test-string-exact-match
79 org-babel-src-block-regexp
80 (replace-regexp-in-string flags "" test-block)))
81 ;;no header arguments
82 (should (org-test-string-exact-match
83 org-babel-src-block-regexp
84 (replace-regexp-in-string arguments "" test-block)))
85 ;; should be valid with no body
86 (should (org-test-string-exact-match
87 org-babel-src-block-regexp
88 (replace-regexp-in-string body "" test-block)))))
90 (ert-deftest test-ob/default-inline-header-args ()
91 (should(equal
92 '((:session . "none")
93 (:results . "replace")
94 (:exports . "results")
95 (:hlines . "yes"))
96 org-babel-default-inline-header-args)))
98 (ert-deftest ob-test/org-babel-combine-header-arg-lists ()
99 (let ((results (org-babel-combine-header-arg-lists
100 '((foo . :any)
101 (bar)
102 (baz . ((foo bar) (baz)))
103 (qux . ((foo bar baz qux)))
104 (quux . ((foo bar))))
105 '((bar)
106 (baz . ((baz)))
107 (quux . :any)))))
108 (dolist (pair '((foo . :any)
109 (bar)
110 (baz . ((baz)))
111 (quux . :any)
112 (qux . ((foo bar baz qux)))))
113 (should (equal (cdr pair)
114 (cdr (assoc (car pair) results)))))))
116 ;;; ob-get-src-block-info
117 (ert-deftest test-ob/get-src-block-info-language ()
118 (org-test-at-marker nil org-test-file-ob-anchor
119 (let ((info (org-babel-get-src-block-info)))
120 (should (string= "emacs-lisp" (nth 0 info))))))
122 (ert-deftest test-ob/get-src-block-info-body ()
123 (org-test-at-marker nil org-test-file-ob-anchor
124 (let ((info (org-babel-get-src-block-info)))
125 (should (string-match (regexp-quote org-test-file-ob-anchor)
126 (nth 1 info))))))
128 (ert-deftest test-ob/get-src-block-info-tangle ()
129 (org-test-at-marker nil org-test-file-ob-anchor
130 (let ((info (org-babel-get-src-block-info)))
131 (should (string= "no" (cdr (assq :tangle (nth 2 info))))))))
133 (ert-deftest test-ob/elisp-in-header-arguments ()
134 "Test execution of elisp forms in header arguments."
135 (org-test-with-temp-text-in-file "
137 * elisp forms in header arguments
138 :PROPERTIES:
139 :header-args: :var prop = (* 7 6)
140 :END:
141 #+begin_src emacs-lisp
142 prop
143 #+end_src"
144 (goto-char (point-min))
145 (org-babel-next-src-block)
146 (should (= 42 (org-babel-execute-src-block)))))
148 (ert-deftest test-ob/simple-named-code-block ()
149 "Test that simple named code blocks can be evaluated."
150 (org-test-with-temp-text-in-file "
152 #+name: i-have-a-name
153 #+begin_src emacs-lisp
155 #+end_src"
156 (org-babel-next-src-block 1)
157 (should (= 42 (org-babel-execute-src-block)))))
159 (ert-deftest test-ob/simple-variable-resolution ()
160 "Test that simple variable resolution is working."
161 (org-test-with-temp-text-in-file "
163 #+name: four
164 #+begin_src emacs-lisp
165 (list 1 2 3 4)
166 #+end_src
168 #+begin_src emacs-lisp :var four=four
169 (length four)
170 #+end_src"
172 (org-babel-next-src-block 2)
173 (should (= 4 (org-babel-execute-src-block)))
174 (forward-line 5)
175 (should (string= ": 4" (buffer-substring
176 (point-at-bol)
177 (point-at-eol))))))
179 (ert-deftest test-ob/multi-line-header-arguments ()
180 "Test that multi-line header arguments and can be read."
181 (org-test-with-temp-text-in-file "
183 #+headers: :var letters='(a b c d e f g)
184 #+begin_src emacs-lisp :var numbers='(1 2 3 4 5 6 7)
185 (require 'cl-lib)
186 (cl-map 'list #'list numbers letters)
187 #+end_src"
188 (org-babel-next-src-block)
189 (let ((results (org-babel-execute-src-block)))
190 (should (eq 'a (cadr (assoc 1 results))))
191 (should (eq 'd (cadr (assoc 4 results)))))))
193 (ert-deftest test-ob/parse-header-args ()
194 (org-test-with-temp-text-in-file "
196 #+begin_src example-lang :session :results output :var num=9
197 the body
198 #+end_src"
200 (org-babel-next-src-block)
201 (let* ((info (org-babel-get-src-block-info))
202 (params (nth 2 info)))
203 (message "%S" params)
204 (should (equal "example-lang" (nth 0 info)))
205 (should (string= "the body" (org-trim (nth 1 info))))
206 (should-not (member '(:session\ \ \ \ ) params))
207 (should (equal '(:session) (assq :session params)))
208 (should (equal '(:result-type . output) (assq :result-type params)))
209 (should (equal '(num . 9) (cdr (assq :var params)))))))
211 (ert-deftest test-ob/parse-header-args2 ()
212 (org-test-with-temp-text-in-file "
214 * resolving sub-trees as references
216 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
217 (length text)
218 #+end_src
220 #+begin_src org :noweb yes
221 <<simple-subtree>>
222 <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
223 #+end_src
225 ** simple subtree with custom ID
226 :PROPERTIES:
227 :CUSTOM_ID: simple-subtree
228 :END:
229 this is simple"
231 (should (string-match (regexp-quote "this is simple")
232 (org-babel-ref-resolve "simple-subtree")))
233 (org-babel-next-src-block)
234 (should (= 14 (org-babel-execute-src-block)))))
236 (ert-deftest test-ob/inline-src-blocks ()
237 (should
238 (= 1
239 (org-test-with-temp-text
240 "In the middle <point>src_emacs-lisp{(+ 0 1)} of a line"
241 (org-babel-execute-src-block))))
242 (should
243 (= 2
244 (org-test-with-temp-text
245 "One at the end of a line: <point>src_emacs-lisp{(+ 1 1)}"
246 (org-babel-execute-src-block))))
247 (should
248 (= 3
249 (org-test-with-temp-text
250 "src_emacs-lisp{(+ 2 1)} at the beginning of a line."
251 (org-babel-execute-src-block))))
252 (should
253 (= 4
254 (org-test-with-temp-text
255 "In the middle <point>src_emacs-lisp[:results silent\
256 :exports code]{(+ 3 1)} of a line"
257 (org-babel-execute-src-block))))
258 (should
259 (= 5
260 (org-test-with-temp-text
261 "One at the end of a line: <point>src_emacs-lisp[:results silent\
262 :exports code]{(+ 4 1)}"
263 (org-babel-execute-src-block))))
264 (should
265 (= 6
266 (org-test-with-temp-text
267 "src_emacs-lisp[:results silent :exports code]{(+ 5 1)}\
268 at the beginning of a line."
269 (org-babel-execute-src-block))))
270 (should
271 (= 7
272 (org-test-with-temp-text
273 "One also evaluated: <point>src_emacs-lisp[:exports both\
274 :results silent]{(+ 6 1)}"
275 (org-babel-execute-src-block)))))
277 (ert-deftest test-ob/inline-src_blk-default-results-replace-line-1 ()
278 (let ((test-line "src_sh{echo 1}")
279 (org-babel-inline-result-wrap "=%s="))
280 ;; src_ at bol line 1...
281 (org-test-with-temp-text
282 test-line
283 (goto-char (point-min)) (org-babel-execute-maybe)
284 (should (string=
285 (concat test-line " {{{results(=1=)}}}")
286 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
287 (forward-char) (org-babel-execute-maybe)
288 (should (string=
289 (concat test-line " {{{results(=1=)}}}")
290 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
291 (re-search-forward "{{{")
292 ;;(should-error (org-ctrl-c-ctrl-c))
293 (backward-char 4) ;; last char of block body
294 (org-babel-execute-maybe)
295 (should (string=
296 (concat test-line " {{{results(=1=)}}}")
297 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
298 ;; src_ follows space line 1...
299 (let ((test-line " src_emacs-lisp{ 1 }"))
300 (org-test-with-temp-text
301 test-line
302 (should-error (org-ctrl-c-ctrl-c))
303 (forward-char) (org-babel-execute-maybe)
304 (should (string=
305 (concat test-line " {{{results(=1=)}}}")
306 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
307 (re-search-forward "{ 1 ") (org-babel-execute-maybe)
308 (should (string=
309 (concat test-line " {{{results(=1=)}}}")
310 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
311 (forward-char 6)
312 (should-error (org-ctrl-c-ctrl-c))))
313 ;; Results on a subsequent line are replaced.
314 (should
315 (equal
316 "src_emacs-lisp{(+ 1 2)}\n {{{results(=3=)}}}"
317 (org-test-with-temp-text "src_emacs-lisp{(+ 1 2)}\n {{{results(=2=)}}}"
318 (let ((org-babel-inline-result-wrap "=%s=")) (org-babel-execute-maybe))
319 (buffer-string))))
320 ;; Also handle results at the beginning of a line.
321 (should
322 (equal
323 "src_emacs-lisp{(+ 1 2)}\n{{{results(=3=)}}}"
324 (org-test-with-temp-text "src_emacs-lisp{(+ 1 2)}\n{{{results(=2=)}}}"
325 (let ((org-babel-inline-result-wrap "=%s=")) (org-babel-execute-maybe))
326 (buffer-string))))))
328 (ert-deftest test-ob/inline-src_blk-default-results-replace-line-2 ()
329 ;; src_ at bol line 2...
330 (let ((test-line " src_emacs-lisp{ \"x\" }")
331 (org-babel-inline-result-wrap "=%s="))
332 (org-test-with-temp-text
333 (concat "\n" test-line)
334 (should-error (org-ctrl-c-ctrl-c))
335 (goto-char (point-min))
336 (should-error (org-ctrl-c-ctrl-c))
337 (forward-line)
338 (should-error (org-ctrl-c-ctrl-c))
339 (forward-char) (org-babel-execute-maybe)
340 (should (string=
341 (concat test-line " {{{results(=x=)}}}")
342 (buffer-substring-no-properties
343 (point-at-bol) (point-at-eol))))))
344 (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }")
345 (org-babel-inline-result-wrap "=%s="))
346 (org-test-with-temp-text
347 test-line
348 (goto-char (point-max))
349 (insert (concat "\n" test-line " end"))
350 (re-search-backward "src") (org-babel-execute-maybe)
351 (should (string=
352 (concat test-line " {{{results(=y=)}}} end")
353 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
354 (re-search-forward "\" ") (org-babel-execute-maybe)
355 (should (string=
356 (concat test-line " {{{results(=y=)}}} end")
357 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
358 (forward-char 3)
359 (should-error (org-ctrl-c-ctrl-c)))))
361 (ert-deftest test-ob/inline-src_blk-manual-results-replace ()
362 (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }")
363 (org-babel-inline-result-wrap "=%s="))
364 (org-test-with-temp-text
365 (concat "\n" test-line)
366 (should-error (org-ctrl-c-ctrl-c))
367 (goto-char (point-max))
368 (org-babel-execute-maybe)
369 (beginning-of-line)
370 (should-error (org-ctrl-c-ctrl-c))
371 (forward-char) (org-babel-execute-maybe)
372 (should (string=
373 (concat test-line " {{{results(=x=)}}}")
374 (buffer-substring-no-properties
375 (point-at-bol) (point-at-eol))))))
376 (let ((test-line (concat " Some text prior to block "
377 "src_emacs-lisp[:results replace]{ \"y\" }"))
378 (org-babel-inline-result-wrap "=%s="))
379 (org-test-with-temp-text test-line
380 (goto-char (point-max))
381 (insert (concat "\n" test-line " end"))
382 (re-search-backward "src") (org-babel-execute-maybe)
383 (should (string=
384 (concat test-line " {{{results(=y=)}}} end")
385 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
386 (re-search-forward "\" ") (org-babel-execute-maybe)
387 (should (string=
388 (concat test-line " {{{results(=y=)}}} end")
389 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
390 (forward-char 3)
391 (should-error (org-ctrl-c-ctrl-c)))))
393 (ert-deftest test-ob/inline-src_blk-results-silent ()
394 (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
395 (org-test-with-temp-text test-line
396 (org-babel-execute-maybe)
397 (should (string= test-line
398 (buffer-substring-no-properties
399 (point-at-bol) (point-at-eol))))))
400 (let ((test-line (concat " Some text prior to block src_emacs-lisp"
401 "[ :results silent ]{ \"y\" }")))
402 (org-test-with-temp-text
403 test-line
404 (goto-char (point-max))
405 (insert (concat "\n" test-line " end"))
406 (re-search-backward "src_") (org-babel-execute-maybe)
407 (should (string= (concat test-line " end")
408 (buffer-substring-no-properties
409 (point-at-bol) (point-at-eol))))
410 (re-search-forward "\" ") (org-babel-execute-maybe)
411 (should (string= (concat test-line " end")
412 (buffer-substring-no-properties
413 (point-at-bol) (point-at-eol))))
414 (forward-char 2)
415 (should-error (org-ctrl-c-ctrl-c)))))
417 (ert-deftest test-ob/inline-src_blk-results-raw ()
418 (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
419 (org-test-with-temp-text test-line
420 (org-babel-execute-maybe)
421 (should (string= (concat test-line " x")
422 (buffer-string)))))
423 (let ((test-line (concat " Some text prior to block "
424 "src_emacs-lisp[ :results raw ]{ \"the\" }")))
425 (org-test-with-temp-text (concat test-line " end")
426 (re-search-forward "src_") (org-babel-execute-maybe)
427 (should (string= (concat test-line " the end")
428 (buffer-substring-no-properties
429 (point-at-bol) (point-at-eol))))
430 (re-search-forward "\" ") (org-babel-execute-maybe)
431 (should (string= (concat test-line " the the end")
432 (buffer-substring-no-properties
433 (point-at-bol) (point-at-eol))))
434 (forward-char 2)
435 (should-error (org-ctrl-c-ctrl-c)))))
437 (ert-deftest test-ob/inline-src_blk-results-file ()
438 (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\" }"))
439 (org-test-with-temp-text
440 test-line
441 (org-babel-execute-maybe)
442 (should (string= (concat test-line " {{{results([[file:~/test-file]])}}}")
443 (buffer-substring-no-properties
444 (point-min) (point-max)))))))
446 (ert-deftest test-ob/inline-src_blk-results-scalar ()
447 (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\" }")
448 (org-babel-inline-result-wrap "=%s="))
449 (org-test-with-temp-text
450 test-line
451 (org-babel-execute-maybe)
452 (should (string= (concat test-line " {{{results(=\"x\"=)}}}")
453 (buffer-substring-no-properties
454 (point-min) (point-max)))))))
456 (ert-deftest test-ob/inline-src_blk-results-verbatim ()
457 (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\" }")
458 (org-babel-inline-result-wrap "=%s="))
459 (org-test-with-temp-text
460 test-line
461 (org-babel-execute-maybe)
462 (should (string= (concat test-line " {{{results(=\"x\"=)}}}")
463 (buffer-substring-no-properties
464 (point-min) (point-max)))))))
466 (ert-deftest test-ob/combining-scalar-and-raw-result-types ()
467 (org-test-with-temp-text-in-file "
469 #+begin_src sh :results scalar
470 echo \"[[file:./cv.cls]]\"
471 #+end_src
473 #+name:
474 : [[file:./cv.cls]]
476 #+begin_src sh :results raw scalar
477 echo \"[[file:./cv.cls]]\"
478 #+end_src
480 (cl-flet ((next-result ()
481 (org-babel-next-src-block)
482 (org-babel-execute-src-block)
483 (goto-char (org-babel-where-is-src-block-result))
484 (forward-line 1)))
485 (goto-char (point-min))
486 (next-result)
487 (should (eq (org-element-type (org-element-at-point)) 'fixed-width))
488 (next-result)
489 (should-not
490 (eq (org-element-type (org-element-at-point)) 'fixed-width)))))
492 (ert-deftest test-ob/no-defaut-value-for-var ()
493 "Test that the absence of a default value for a variable DOES THROW
494 a proper error."
495 (org-test-at-id "f2df5ba6-75fa-4e6b-8441-65ed84963627"
496 (org-babel-next-src-block)
497 (let ((err
498 (should-error (org-babel-execute-src-block) :type 'error)))
499 (should
500 (equal
501 '(error
502 "Variable \"x\" must be assigned a default value")
503 err)))))
505 (ert-deftest test-ob/just-one-results-block ()
506 "Test that evaluating two times the same code block does not result in a
507 duplicate results block."
508 (org-test-with-temp-text "#+begin_src sh\necho Hello\n#+end_src\n"
509 (org-babel-execute-src-block)
510 (org-babel-execute-src-block) ; second code block execution
511 (should (search-forward "Hello")) ; the string inside the source code block
512 (should (search-forward "Hello")) ; the same string in the results block
513 (should-error (search-forward "Hello"))))
515 (ert-deftest test-ob/nested-code-block ()
516 "Test nested code blocks inside code blocks don't cause problems."
517 (should
518 (string= "#+begin_src emacs-lisp\n 'foo\n#+end_src"
519 (org-test-with-temp-text "#+begin_src org :results silent
520 ,#+begin_src emacs-lisp
521 'foo
522 ,#+end_src
523 #+end_src"
524 (let ((org-edit-src-content-indentation 2)
525 (org-src-preserve-indentation nil))
526 (org-babel-execute-src-block))))))
528 (ert-deftest test-ob/partial-nested-code-block ()
529 "Test nested code blocks inside code blocks don't cause problems."
530 (org-test-with-temp-text "#+begin_src org :results silent
531 ,#+begin_src emacs-lisp
532 #+end_src"
533 (should (string= "#+begin_src emacs-lisp" (org-babel-execute-src-block)))))
535 (ert-deftest test-ob/does-not-replace-a-block-with-the-results ()
536 (org-test-with-temp-text "#+NAME: foo
537 #+BEGIN_SRC emacs-lisp
538 'foo
539 #+END_SRC\n"
540 (org-babel-next-src-block 1)
541 (should (eq 'foo (org-babel-execute-src-block)))
542 (goto-char (point-min))
543 (org-babel-next-src-block 1)
544 (should (looking-at org-babel-src-block-regexp))))
546 (ert-deftest test-ob/catches-all-references ()
547 (org-test-with-temp-text "
548 #+NAME: literal-example
549 #+BEGIN_EXAMPLE
550 A literal example
551 on two lines
552 #+END_EXAMPLE
554 #+NAME: read-literal-example
555 #+BEGIN_SRC emacs-lisp :var x=literal-example
556 (concatenate 'string x \" for me.\")
557 #+END_SRC"
558 (org-babel-next-src-block 1)
559 (should (string= (org-babel-execute-src-block)
560 "A literal example\non two lines\n for me."))))
562 (ert-deftest test-ob/ignore-reference-in-commented-headings ()
563 (should
564 (= 2
565 (org-test-with-temp-text
567 * COMMENT H1
568 #+NAME: n
571 * H2
572 #+NAME: n
575 * Code
577 <point>#+BEGIN_SRC emacs-lisp :var x=n
579 #+END_SRC"
580 (org-babel-execute-src-block)))))
582 (ert-deftest test-ob/do-not-resolve-to-partial-names-data ()
583 (org-test-with-temp-text "
584 #+name: base_plus
585 | 1 |
586 | 2 |
588 #+name: base
589 | 3 |
590 | 4 |
592 #+begin_src emacs-lisp :var x=base
594 #+end_src"
595 (org-babel-next-src-block 1)
596 (should (equal (org-babel-execute-src-block) '((3) (4))))))
598 (ert-deftest test-ob/do-not-resolve-to-partial-names-code ()
599 (org-test-with-temp-text "
600 #+name: base_plus
601 #+begin_src emacs-lisp
602 'bar
603 #+end_src
605 #+name: base
606 #+begin_src emacs-lisp
607 'foo
608 #+end_src
610 #+begin_src emacs-lisp :var x=base
612 #+end_src"
613 (org-babel-next-src-block 3)
614 (should (equal (org-babel-execute-src-block) "foo"))))
616 (ert-deftest test-ob/allow-spaces-around-=-in-var-specs ()
617 (org-test-with-temp-text "#+begin_src emacs-lisp :var a = 1 b = 2 c= 3 d =4
618 (+ a b c d)
619 #+end_src
621 (should (= 10 (org-babel-execute-src-block)))))
623 (ert-deftest test-ob/org-babel-update-intermediate ()
624 (org-test-with-temp-text "#+name: foo
625 #+begin_src emacs-lisp
627 #+end_src
629 #+results: foo
632 #+begin_src emacs-lisp :var it=foo
633 (+ it 1)
634 #+end_src"
635 (let ((org-babel-update-intermediate nil))
636 (goto-char (point-min))
637 (org-babel-next-src-block 2)
638 (should (= 3 (org-babel-execute-src-block)))
639 (goto-char (point-min))
640 (forward-line 6)
641 (should (looking-at ": 4")))
642 (let ((org-babel-update-intermediate t))
643 (goto-char (point-min))
644 (org-babel-next-src-block 2)
645 (should (= 3 (org-babel-execute-src-block)))
646 (goto-char (point-min))
647 (forward-line 6)
648 (should (looking-at ": 2")))))
650 (ert-deftest test-ob/eval-header-argument ()
651 (cl-flet ((check-eval (eval runp)
652 (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
653 (setq foo :evald)
654 #+end_src" eval)
655 (let ((foo :not-run))
656 (if runp
657 (progn (should (org-babel-execute-src-block))
658 (should (eq foo :evald)))
659 (progn (should-not (org-babel-execute-src-block))
660 (should-not (eq foo :evald))))))))
661 (check-eval "never" nil)
662 (check-eval "no" nil)
663 (check-eval "never-export" t)
664 (check-eval "no-export" t)
665 (let ((org-babel-exp-reference-buffer (current-buffer)))
666 (check-eval "never" nil)
667 (check-eval "no" nil)
668 (check-eval "never-export" nil)
669 (check-eval "no-export" nil))))
671 (ert-deftest test-ob/noweb-expansion-1 ()
672 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
673 <<foo>>
674 #+end_src
676 #+name: foo
677 #+begin_src sh
679 #+end_src"
680 (should (string= (org-babel-expand-noweb-references) "bar"))))
682 (ert-deftest test-ob/noweb-expansion-2 ()
683 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
684 <<foo>>
685 #+end_src
687 #+name: foo
688 #+begin_src sh :noweb-sep \"\"
690 #+end_src
692 #+begin_src sh :noweb-ref foo :noweb-sep \"\"
694 #+end_src"
695 (should (string= (org-babel-expand-noweb-references) "barbaz"))))
697 (ert-deftest test-ob/splitting-variable-lists-in-references ()
698 (org-test-with-temp-text ""
699 (should (= 1 (length (org-babel-ref-split-args
700 "a=\"this, no work\""))))
701 (should (= 2 (length (org-babel-ref-split-args
702 "a=\"this, no work\", b=1"))))))
704 (ert-deftest test-ob/balanced-split ()
705 "Test `org-babel-balanced-split' specifications."
706 (should (equal
707 '(":a 1" "b [2 3]" "c (4 :d (5 6))")
708 (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))"
709 '((32 9) . 58))))
710 ;; Handle un-balanced parens.
711 (should
712 (equal '(":foo ((6)" "bar 1")
713 (org-babel-balanced-split ":foo ((6) :bar 1" '((32 9) . 58))))
714 (should
715 (equal '(":foo \"(foo\"" "bar 2")
716 (org-babel-balanced-split ":foo \"(foo\" :bar 2" '((32 9) . 58))))
717 ;; Handle un-balanced quotes.
718 (should
719 (equal '(":foo \"1" "bar 3")
720 (org-babel-balanced-split ":foo \"1 :bar 3" '((32 9) . 58)))))
722 (ert-deftest test-ob/commented-last-block-line-no-var ()
723 (org-test-with-temp-text-in-file "
724 #+begin_src emacs-lisp
726 #+end_src"
727 (org-babel-next-src-block)
728 (org-babel-execute-maybe)
729 (should (re-search-forward "\\#\\+results:" nil t))
730 (forward-line)
731 (should
732 (string=
734 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
735 (org-test-with-temp-text-in-file "
736 #+begin_src emacs-lisp
737 \"some text\";;
738 #+end_src"
739 (org-babel-next-src-block)
740 (org-babel-execute-maybe)
741 (should (re-search-forward "\\#\\+results:" nil t))
742 (forward-line)
743 (should
744 (string=
745 ": some text"
746 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
748 (ert-deftest test-ob/commented-last-block-line-with-var ()
749 (org-test-with-temp-text-in-file "
750 #+begin_src emacs-lisp :var a=1
752 #+end_src"
753 (org-babel-next-src-block)
754 (org-babel-execute-maybe)
755 (re-search-forward "\\#\\+results:" nil t)
756 (forward-line)
757 (should (string=
759 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
760 (org-test-with-temp-text-in-file "
761 #+begin_src emacs-lisp :var a=2
763 #+end_src"
764 (org-babel-next-src-block)
765 (org-babel-execute-maybe)
766 (re-search-forward "\\#\\+results:" nil t)
767 (forward-line)
768 (should (string=
769 ": 2"
770 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
772 (ert-deftest test-ob/org-babel-insert-result ()
773 "Test `org-babel-insert-result' specifications."
774 ;; Do not error when output is an improper list.
775 (should
776 (org-test-with-temp-text
778 <point>#+BEGIN_SRC emacs-lisp
779 '((1 . nil) (2 . 3))
780 #+END_SRC
782 (org-babel-execute-maybe) t))
783 ;; Escape headlines when producing an example block.
784 (should
785 (string-match-p
786 ",\\* Not an headline"
787 (org-test-with-temp-text
789 <point>#+BEGIN_SRC emacs-lisp
790 \"* Not an headline\"
791 #+END_SRC
793 (let ((org-babel-min-lines-for-block-output 1)) (org-babel-execute-maybe))
794 (buffer-string))))
795 ;; Escape special syntax in example blocks.
796 (should
797 (string-match-p
798 ",#\\+END_SRC"
799 (org-test-with-temp-text
801 <point>#+BEGIN_SRC emacs-lisp
802 \"#+END_SRC\"
803 #+END_SRC
805 (let ((org-babel-min-lines-for-block-output 1)) (org-babel-execute-maybe))
806 (buffer-string))))
807 ;; No escaping is done with other blocks or raw type.
808 (should-not
809 (string-match-p
810 ",\\* Not an headline"
811 (org-test-with-temp-text
813 <point>#+BEGIN_SRC emacs-lisp
814 \"* Not an headline\"
815 #+END_SRC
817 (let ((org-babel-min-lines-for-block-output 10))
818 (org-babel-execute-maybe))
819 (buffer-string))))
820 (should-not
821 (string-match-p
822 ",\\* Not an headline"
823 (org-test-with-temp-text
825 <point>#+BEGIN_SRC emacs-lisp :results raw
826 \"* Not an headline\"
827 #+END_SRC
829 (org-babel-execute-maybe)
830 (buffer-string))))
831 (should-not
832 (string-match-p
833 ",\\* Not an headline"
834 (org-test-with-temp-text
836 <point>#+BEGIN_SRC emacs-lisp :results drawer
837 \"* Not an headline\"
838 #+END_SRC
840 (org-babel-execute-maybe)
841 (buffer-string)))))
843 (ert-deftest test-ob/remove-inline-result ()
844 "Test `org-babel-remove-inline-result' honors whitespace."
845 (let*
846 ((inline-sb "src_emacs-lisp{(+ 1 2)}")
847 (inline-res " {{{results(=3=)}}}")
848 (inline-sb-dot (concat inline-sb "."))
849 (inline-sb-res-dot (concat inline-sb inline-res ".")))
850 (org-test-with-temp-text
851 ;; Insert inline_src_block followed by dot.
852 inline-sb-dot
853 ;; Insert result before dot.
854 (org-babel-execute-maybe)
855 (should (string= inline-sb-res-dot
856 (buffer-substring-no-properties
857 (point-at-bol) (point-at-eol))))
858 ;; Delete whitespace and result.
859 (org-babel-remove-inline-result)
860 (should (string= inline-sb-dot
861 (buffer-substring-no-properties
862 (point-at-bol) (point-at-eol))))
863 ;; Add whitespace and result before dot.
864 (search-forward inline-sb)
865 (insert " " inline-res)
866 (goto-char (point-at-bol))
867 ;; Remove whitespace and result.
868 (org-babel-remove-inline-result)
869 (should (string= inline-sb-dot
870 (buffer-substring-no-properties
871 (point-at-bol) (point-at-eol))))
872 ;; Add whitespace before dot.
873 (search-forward inline-sb)
874 (insert " ")
875 (goto-char (point-at-bol))
876 ;; Add result before whitespace.
877 (org-babel-execute-maybe)
878 ;; Remove result - leave trailing whitespace and dot.
879 (org-babel-remove-inline-result)
880 (should (string= (concat inline-sb " .")
881 (buffer-substring-no-properties
882 (point-at-bol) (point-at-eol)))))))
884 (defun test-ob-verify-result-and-removed-result (result buffer-text)
885 "Test helper function to test `org-babel-remove-result'.
886 A temp buffer is populated with BUFFER-TEXT, the first block is executed,
887 and the result of execution is verified against RESULT.
889 The block is actually executed /twice/ to ensure result
890 replacement happens correctly."
891 (org-test-with-temp-text
892 buffer-text
893 (org-babel-next-src-block) (org-babel-execute-maybe) (org-babel-execute-maybe)
894 (should (re-search-forward "\\#\\+results:" nil t))
895 (forward-line)
896 (should (string= result
897 (buffer-substring-no-properties
898 (point-at-bol)
899 (- (point-max) 16))))
900 (org-babel-previous-src-block) (org-babel-remove-result)
901 (should (string= buffer-text
902 (buffer-substring-no-properties
903 (point-min) (point-max))))))
905 (ert-deftest test-ob/org-babel-remove-result--results-default ()
906 "Test `org-babel-remove-result' with default :results."
907 (mapcar (lambda (language)
908 (test-ob-verify-result-and-removed-result
909 "\n"
910 (concat
911 "* org-babel-remove-result
912 #+begin_src " language "
913 #+end_src
915 * next heading")))
916 '("sh" "emacs-lisp")))
918 (ert-deftest test-ob/org-babel-remove-result--results-list ()
919 "Test `org-babel-remove-result' with :results list."
920 (test-ob-verify-result-and-removed-result
921 "- 1
924 - (quote (4 5))"
926 "* org-babel-remove-result
927 #+begin_src emacs-lisp :results list
928 '(1 2 3 '(4 5))
929 #+end_src
931 * next heading"))
933 (ert-deftest test-ob/org-babel-results-indented-wrap ()
934 "Ensure that wrapped results are inserted correction when indented.
935 If not inserted correctly then the second evaluation will fail
936 trying to find the :END: marker."
937 (org-test-with-temp-text
938 "- indented
939 #+begin_src sh :results file wrap
940 echo test.txt
941 #+end_src"
942 (org-babel-next-src-block 1)
943 (org-babel-execute-src-block)
944 (org-babel-execute-src-block)))
946 (ert-deftest test-ob/file-desc-header-argument ()
947 "Test that the :file-desc header argument is used."
948 (org-test-with-temp-text "#+begin_src emacs-lisp :results file :file-desc bar
949 \"foo\"
950 #+end_src
952 #+begin_src emacs-lisp :results file :file-desc
953 \"foo\"
954 #+end_src"
955 (org-babel-execute-src-block)
956 (org-babel-next-src-block 1)
957 (org-babel-execute-src-block)
958 (goto-char (point-min))
959 (should (search-forward "[[file:foo][bar]]" nil t))
960 (should (search-forward "[[file:foo][foo]]" nil t))))
962 (ert-deftest test-ob/org-babel-remove-result--results-pp ()
963 "Test `org-babel-remove-result' with :results pp."
964 (test-ob-verify-result-and-removed-result
965 ": \"I /am/ working!\""
967 "* org-babel-remove-result
968 #+begin_src emacs-lisp :results pp
969 \"I /am/ working!\")
970 #+end_src
972 * next heading"))
974 (ert-deftest test-ob/inline-src_blk-preceded-punct-preceded-by-point ()
975 (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }")
976 (org-babel-inline-result-wrap "=%s="))
977 (org-test-with-temp-text
978 test-line
979 (forward-char 1)
980 (org-babel-execute-maybe)
981 (should (re-search-forward "=\"x\"=" nil t))
982 (forward-line))))
984 (ert-deftest test-ob/commented-last-block-line-with-var ()
985 (org-test-with-temp-text-in-file "
986 #+begin_src emacs-lisp :var a=1
988 #+end_src"
989 (org-babel-next-src-block)
990 (org-babel-execute-maybe)
991 (re-search-forward "\\#\\+results:" nil t)
992 (forward-line)
993 (should (string=
995 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
996 (org-test-with-temp-text-in-file "
997 #+begin_src emacs-lisp :var a=2
999 #+end_src"
1000 (org-babel-next-src-block)
1001 (org-babel-execute-maybe)
1002 (re-search-forward "\\#\\+results:" nil t)
1003 (forward-line)
1004 (should (string=
1005 ": 2"
1006 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
1008 (defun test-ob-verify-result-and-removed-result (result buffer-text)
1009 "Test helper function to test `org-babel-remove-result'.
1010 A temp buffer is populated with BUFFER-TEXT, the first block is executed,
1011 and the result of execution is verified against RESULT.
1013 The block is actually executed /twice/ to ensure result
1014 replacement happens correctly."
1015 (org-test-with-temp-text
1016 buffer-text
1017 (org-babel-next-src-block) (org-babel-execute-maybe) (org-babel-execute-maybe)
1018 (should (re-search-forward "\\#\\+results:" nil t))
1019 (forward-line)
1020 (should (string= result
1021 (buffer-substring-no-properties
1022 (point-at-bol)
1023 (- (point-max) 16))))
1024 (org-babel-previous-src-block) (org-babel-remove-result)
1025 (should (string= buffer-text
1026 (buffer-substring-no-properties
1027 (point-min) (point-max))))))
1029 (ert-deftest test-ob/org-babel-remove-result--results-default ()
1030 "Test `org-babel-remove-result' with default :results."
1031 (mapcar (lambda (language)
1032 (test-ob-verify-result-and-removed-result
1033 "\n"
1034 (concat
1035 "* org-babel-remove-result
1036 #+begin_src " language "
1037 #+end_src
1039 * next heading")))
1040 '("sh" "emacs-lisp")))
1042 (ert-deftest test-ob/org-babel-remove-result--results-list ()
1043 "Test `org-babel-remove-result' with :results list."
1044 (test-ob-verify-result-and-removed-result
1045 "- 1
1048 - (quote (4 5))"
1050 "* org-babel-remove-result
1051 #+begin_src emacs-lisp :results list
1052 '(1 2 3 '(4 5))
1053 #+end_src
1055 * next heading"))
1057 (ert-deftest test-ob/org-babel-remove-result--results-wrap ()
1058 "Test `org-babel-remove-result' with :results wrap."
1059 (test-ob-verify-result-and-removed-result
1060 ":RESULTS:
1061 hello there
1062 :END:"
1064 "* org-babel-remove-result
1066 #+begin_src emacs-lisp :results wrap
1067 \"hello there\"
1068 #+end_src
1070 * next heading"))
1072 (ert-deftest test-ob/org-babel-remove-result--results-org ()
1073 "Test `org-babel-remove-result' with :results org."
1074 (test-ob-verify-result-and-removed-result
1075 "#+BEGIN_SRC org
1076 ,* heading
1077 ,** subheading
1078 content
1079 #+END_SRC"
1081 "* org-babel-remove-result
1082 #+begin_src emacs-lisp :results org
1083 \"* heading
1084 ,** subheading
1085 content\"
1086 #+end_src
1088 * next heading"))
1090 (ert-deftest test-ob/org-babel-remove-result--results-html ()
1091 "Test `org-babel-remove-result' with :results html."
1092 (test-ob-verify-result-and-removed-result
1093 "#+BEGIN_EXPORT html
1094 <head><body></body></head>
1095 #+END_EXPORT"
1097 "* org-babel-remove-result
1098 #+begin_src emacs-lisp :results html
1099 \"<head><body></body></head>\"
1100 #+end_src
1102 * next heading"))
1104 (ert-deftest test-ob/org-babel-remove-result--results-latex ()
1105 "Test `org-babel-remove-result' with :results latex."
1106 (test-ob-verify-result-and-removed-result
1107 "#+BEGIN_EXPORT latex
1108 Line 1
1109 Line 2
1110 Line 3
1111 #+END_EXPORT"
1113 "* org-babel-remove-result
1114 #+begin_src emacs-lisp :results latex
1115 \"Line 1
1116 Line 2
1117 Line 3\"
1118 #+end_src
1120 * next heading"))
1122 (ert-deftest test-ob/org-babel-remove-result--results-code ()
1123 "Test `org-babel-remove-result' with :results code."
1125 (test-ob-verify-result-and-removed-result
1126 "#+BEGIN_SRC emacs-lisp
1127 \"I am working!\"
1128 #+END_SRC"
1130 "* org-babel-remove-result
1131 #+begin_src emacs-lisp :results code
1132 (message \"I am working!\")
1133 #+end_src
1135 * next heading"))
1137 (ert-deftest test-ob/org-babel-remove-result--results-pp ()
1138 "Test `org-babel-remove-result' with :results pp."
1139 (test-ob-verify-result-and-removed-result
1140 ": \"I /am/ working!\""
1142 "* org-babel-remove-result
1143 #+begin_src emacs-lisp :results pp
1144 \"I /am/ working!\")
1145 #+end_src
1147 * next heading"))
1149 (ert-deftest test-ob/results-do-not-replace-code-blocks ()
1150 (org-test-with-temp-text "Block two has a space after the name.
1152 #+name: foo
1153 #+begin_src emacs-lisp
1155 #+end_src
1157 #+name: foo
1158 #+begin_src emacs-lisp
1160 #+end_src
1162 #+name: foo
1163 #+begin_src emacs-lisp
1165 #+end_src
1167 #+RESULTS: foo
1168 : foo
1170 (dolist (num '(1 2 3))
1171 ;; execute the block
1172 (goto-char (point-min))
1173 (org-babel-next-src-block num) (org-babel-execute-src-block)
1174 ;; check the results
1175 (goto-char (point-max))
1176 (move-beginning-of-line 0)
1177 (should (looking-at (format ": %d" num))))))
1179 (ert-deftest test-ob/blocks-with-spaces ()
1180 "Test expansion of blocks followed by blank lines."
1181 ;; Preserve number of blank lines after block.
1182 (should
1183 (equal "#+BEGIN_SRC emacs-lisp
1184 \(+ 1 2)
1185 #+END_SRC
1187 #+RESULTS:
1188 : 3\n\n\n"
1189 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp
1190 \(+ 1 2)
1191 #+END_SRC\n\n\n"
1192 (let ((org-babel-next-src-block "RESULTS"))
1193 (org-babel-execute-src-block))
1194 (buffer-string))))
1195 ;; Do not add spurious blank lines after results.
1196 (should
1197 (equal
1199 - item 1
1201 #+begin_src emacs-lisp
1203 #+end_src
1205 #+RESULTS:
1208 - item 2"
1209 (org-test-with-temp-text "
1210 - item 1
1212 #+begin_src emacs-lisp<point>
1214 #+end_src
1216 - item 2"
1217 (org-babel-execute-src-block)
1218 (buffer-string))))
1219 (should
1220 (equal
1222 - item 1
1224 #+begin_src emacs-lisp
1226 #+end_src
1228 #+RESULTS:
1231 - item 2"
1232 (org-test-with-temp-text "
1233 - item 1
1235 #+begin_src emacs-lisp<point>
1237 #+end_src
1239 #+RESULTS:
1242 - item 2"
1243 (org-babel-execute-src-block)
1244 (buffer-string)))))
1246 (ert-deftest test-ob/results-in-narrowed-buffer ()
1247 "Test block execution in a narrowed buffer."
1248 ;; If results don't exist, they should be inserted in visible part
1249 ;; of the buffer.
1250 (should
1251 (equal
1252 "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS:\n: 3"
1253 (org-test-with-temp-text
1254 "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
1255 (narrow-to-region (point) (save-excursion (forward-line 3) (point)))
1256 (let ((org-babel-results-keyword "RESULTS"))
1257 (org-babel-execute-src-block))
1258 (org-trim (buffer-string)))))
1259 (should
1260 (equal
1261 "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3"
1262 (org-test-with-temp-text
1263 "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
1264 (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
1265 (let ((org-babel-results-keyword "RESULTS"))
1266 (org-babel-execute-src-block))
1267 (org-trim (buffer-string)))))
1268 ;; Results in visible part of buffer, should be updated here.
1269 (should
1270 (equal
1271 "#+NAME: test
1272 #+BEGIN_SRC emacs-lisp
1273 \(+ 1 2)
1274 #+END_SRC
1276 #+RESULTS: test
1277 : 3"
1278 (org-test-with-temp-text
1279 "#+NAME: test
1280 #+BEGIN_SRC emacs-lisp
1281 \(+ 1 2)
1282 #+END_SRC
1284 #+RESULTS: test
1287 Paragraph"
1288 (narrow-to-region (point) (save-excursion (forward-line 7) (point)))
1289 (let ((org-babel-results-keyword "RESULTS"))
1290 (org-babel-execute-src-block))
1291 (org-trim (buffer-string)))))
1292 ;; Results in invisible part of buffer, should be updated there.
1293 (org-test-with-temp-text
1294 "#+NAME: test
1295 #+BEGIN_SRC emacs-lisp
1296 \(+ 1 2)
1297 #+END_SRC
1299 #+RESULTS: test
1302 Paragraph"
1303 (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
1304 (let ((org-babel-results-keyword "RESULTS"))
1305 (org-babel-execute-src-block))
1306 (should-not (re-search-forward "^#\\+RESULTS:" nil t))
1307 (widen)
1308 (should (re-search-forward "^: 3" nil t))))
1310 (ert-deftest test-ob/specific-colnames ()
1311 "Test passing specific column names."
1312 (should
1313 (equal "#+name: input-table
1314 | id | var1 |
1315 |----+------|
1316 | 1 | bar |
1317 | 2 | baz |
1319 #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
1320 echo \"$data\"
1321 #+end_src
1323 #+RESULTS:
1324 | Rev | Author |
1325 |-----+--------|
1326 | 1 | bar |
1327 | 2 | baz |
1329 (org-test-with-temp-text
1330 "#+name: input-table
1331 | id | var1 |
1332 |----+------|
1333 | 1 | bar |
1334 | 2 | baz |
1336 #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
1337 echo \"$data\"
1338 #+end_src
1340 ;; we should find a code block
1341 (should (re-search-forward org-babel-src-block-regexp nil t))
1342 (goto-char (match-beginning 0))
1343 ;; now that we've located the code block, it may be evaluated
1344 (let ((org-babel-execute-src-block "RESULTS"))
1345 (org-babel-execute-src-block))
1346 (buffer-string)))))
1348 (ert-deftest test-ob/location-of-header-arg-eval ()
1349 "Test location of header argument evaluation."
1350 (org-test-with-temp-text "
1351 #+name: top-block
1352 #+begin_src emacs-lisp :var pt=(point)
1354 #+end_src
1356 #+name: bottom-block
1357 #+begin_src emacs-lisp :var pt=top-block()
1359 #+end_src
1361 ;; the value of the second block should be greater than the first
1362 (should
1363 (< (progn (re-search-forward org-babel-src-block-regexp nil t)
1364 (goto-char (match-beginning 0))
1365 (prog1 (save-match-data (org-babel-execute-src-block))
1366 (goto-char (match-end 0))))
1367 (progn (re-search-forward org-babel-src-block-regexp nil t)
1368 (goto-char (match-beginning 0))
1369 (org-babel-execute-src-block))))))
1371 (ert-deftest test-ob/preserve-results-indentation ()
1372 "Preserve indentation when executing a src block."
1373 (should
1374 (equal
1375 '(2 2)
1376 (org-test-with-temp-text " #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1377 (org-babel-execute-src-block)
1378 (let ((case-fold-search t)) (search-forward "RESULTS"))
1379 (list (org-get-indentation)
1380 (progn (forward-line) (org-get-indentation))))))
1381 (should
1382 (equal
1383 '(2 2)
1384 (org-test-with-temp-text
1385 " #+name: block\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1386 (org-babel-execute-src-block)
1387 (let ((case-fold-search t)) (search-forward "RESULTS"))
1388 (list (org-get-indentation)
1389 (progn (forward-line) (org-get-indentation))))))
1390 ;; Don't get fooled by TAB-based indentation.
1391 (should
1392 (equal
1393 '(6 6)
1394 (org-test-with-temp-text
1395 "\t #+begin_src emacs-lisp\n\t (+ 1 1)\n\t #+end_src"
1396 (setq tab-width 4)
1397 (org-babel-execute-src-block)
1398 (let ((case-fold-search t)) (search-forward "RESULTS"))
1399 (list (org-get-indentation)
1400 (progn (forward-line) (org-get-indentation)))))))
1402 (ert-deftest test-ob/safe-header-args ()
1403 "Detect safe and unsafe header args."
1404 (let ((safe-args '((:cache . "foo")
1405 (:results . "output")
1406 (:eval . "never")
1407 (:eval . "query")))
1408 (unsafe-args '((:eval . "yes")
1409 (:results . "output file")
1410 (:foo . "bar")))
1411 (malformed-args '((bar . "foo")
1412 ("foo" . "bar")
1413 :foo))
1414 (safe-p (org-babel-header-args-safe-fn org-babel-safe-header-args)))
1415 (dolist (arg safe-args)
1416 (should (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args)))
1417 (dolist (arg unsafe-args)
1418 (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
1419 (dolist (arg malformed-args)
1420 (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
1421 (should (not (funcall safe-p (append safe-args unsafe-args))))))
1423 (ert-deftest test-ob/noweb-expansions-in-cache ()
1424 "Ensure that noweb expansions are expanded before caching."
1425 (let ((noweb-expansions-in-cache-var 0))
1426 (org-test-with-temp-text "
1427 #+name: foo
1428 #+begin_src emacs-lisp
1429 \"I said\"
1430 #+end_src
1432 #+name: bar
1433 #+begin_src emacs-lisp :noweb yes :cache yes
1434 (setq noweb-expansions-in-cache-var
1435 (+ 1 noweb-expansions-in-cache-var))
1436 (concat <<foo>> \" check noweb expansions\")
1437 #+end_src
1439 ;; run the second block to create the cache
1440 (goto-char (point-min))
1441 (re-search-forward (regexp-quote "#+name: bar"))
1442 (should (string= "I said check noweb expansions"
1443 (org-babel-execute-src-block)))
1444 (should (= noweb-expansions-in-cache-var 1))
1445 ;; change the value of the first block
1446 (goto-char (point-min))
1447 (re-search-forward (regexp-quote "said"))
1448 (goto-char (match-beginning 0))
1449 (insert "haven't ")
1450 (re-search-forward (regexp-quote "#+name: bar"))
1451 (should (string= "I haven't said check noweb expansions"
1452 (org-babel-execute-src-block)))
1453 (should (= noweb-expansions-in-cache-var 2)))))
1455 (ert-deftest test-ob/file-ext-and-output-dir ()
1456 (org-test-at-id "93573e1d-6486-442e-b6d0-3fedbdc37c9b"
1457 (org-babel-next-src-block)
1458 (should (equal "file-ext-basic.txt"
1459 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1460 (org-babel-next-src-block)
1461 (should (equal "foo/file-ext-dir-relative.txt"
1462 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1463 (org-babel-next-src-block)
1464 (should (equal "foo/file-ext-dir-relative-slash.txt"
1465 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1466 (org-babel-next-src-block)
1467 (should (equal "/tmp/file-ext-dir-absolute.txt"
1468 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1469 (org-babel-next-src-block)
1470 (should (equal "foo.bar"
1471 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1472 (org-babel-next-src-block)
1473 (should (equal "xxx/foo.bar"
1474 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1477 (ert-deftest test-ob/script-escape ()
1478 ;; Delimited lists of numbers
1479 (should (equal '(1 2 3)
1480 (org-babel-script-escape "[1 2 3]")))
1481 (should (equal '(1 2 3)
1482 (org-babel-script-escape "{1 2 3}")))
1483 (should (equal '(1 2 3)
1484 (org-babel-script-escape "(1 2 3)")))
1485 ;; Delimited lists of double-quoted strings
1486 (should (equal '("foo" "bar")
1487 (org-babel-script-escape "(\"foo\" \"bar\")")))
1488 (should (equal '("foo" "bar")
1489 (org-babel-script-escape "[\"foo\" \"bar\"]")))
1490 (should (equal '("foo" "bar")
1491 (org-babel-script-escape "{\"foo\" \"bar\"}")))
1492 ;; ... with commas
1493 (should (equal '("foo" "bar")
1494 (org-babel-script-escape "(\"foo\", \"bar\")")))
1495 (should (equal '("foo" "bar")
1496 (org-babel-script-escape "[\"foo\", \"bar\"]")))
1497 (should (equal '("foo" "bar")
1498 (org-babel-script-escape "{\"foo\", \"bar\"}")))
1499 ;; Delimited lists of single-quoted strings
1500 (should (equal '("foo" "bar")
1501 (org-babel-script-escape "('foo' 'bar')")))
1502 (should (equal '("foo" "bar")
1503 (org-babel-script-escape "['foo' 'bar']")))
1504 (should (equal '("foo" "bar")
1505 (org-babel-script-escape "{'foo' 'bar'}")))
1506 ;; ... with commas
1507 (should (equal '("foo" "bar")
1508 (org-babel-script-escape "('foo', 'bar')")))
1509 (should (equal '("foo" "bar")
1510 (org-babel-script-escape "['foo', 'bar']")))
1511 (should (equal '("foo" "bar")
1512 (org-babel-script-escape "{'foo', 'bar'}")))
1513 ;; Single quoted strings
1514 (should (equal "foo"
1515 (org-babel-script-escape "'foo'")))
1516 ;; ... with internal double quote
1517 (should (equal "foo\"bar"
1518 (org-babel-script-escape "'foo\"bar'")))
1519 ;; ... with internal backslash
1520 (should (equal "foo\\bar"
1521 (org-babel-script-escape "'foo\\bar'")))
1522 ;; ... with internal escaped backslash
1523 (should (equal "foo\\bar"
1524 (org-babel-script-escape "'foo\\\\bar'")))
1525 ;; ... with internal backslash-double quote
1526 (should (equal "foo\\\"bar"
1527 (org-babel-script-escape "'foo\\\"bar'")))
1528 ;; ... with internal escaped backslash-double quote
1529 (should (equal "foo\\\"bar"
1530 (org-babel-script-escape "'foo\\\\\"bar'")))
1531 ;; ... with internal escaped single quote
1532 (should (equal "foo'bar"
1533 (org-babel-script-escape "'foo\\'bar'")))
1534 ;; ... with internal escaped backslash-escaped single quote
1535 (should (equal "foo\\'bar"
1536 (org-babel-script-escape "'foo\\\\\\'bar'")))
1537 ;; Double quoted strings
1538 (should (equal "foo"
1539 (org-babel-script-escape "\"foo\"")))
1540 ;; ... with internal single quote
1541 (should (equal "foo'bar"
1542 (org-babel-script-escape "\"foo'bar\"")))
1543 ;; ... with internal backslash
1544 (should (equal "foo\\bar"
1545 (org-babel-script-escape "\"foo\\bar\"")))
1546 ;; ... with internal escaped backslash
1547 (should (equal "foo\\bar"
1548 (org-babel-script-escape "\"foo\\\\bar\"")))
1549 ;; ... with internal backslash-single quote
1550 (should (equal "foo\\'bar"
1551 (org-babel-script-escape "\"foo\\'bar\"")))
1552 ;; ... with internal escaped backslash-single quote
1553 (should (equal "foo\\'bar"
1554 (org-babel-script-escape "\"foo\\\\'bar\"")))
1555 ;; ... with internal escaped double quote
1556 (should (equal "foo\"bar"
1557 (org-babel-script-escape "\"foo\\\"bar\"")))
1558 ;; ... with internal escaped backslash-escaped double quote
1559 (should (equal "foo\\\"bar"
1560 (org-babel-script-escape "\"foo\\\\\\\"bar\""))))
1562 (ert-deftest test-ob/process-params-no-duplicates ()
1563 (should
1564 (equal (org-babel-process-params '((:colname-names)
1565 (:rowname-names)
1566 (:result-params)
1567 (:result-type)
1568 (:var . "\"foo\"")))
1569 '((:var)
1570 (:colname-names)
1571 (:rowname-names)
1572 (:result-params)
1573 (:result-type . value)))))
1575 (defun org-test-babel-confirm-evaluate (eval-value)
1576 (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
1578 #+end_src" eval-value)
1579 (goto-char (point-min))
1580 (let ((info (org-babel-get-src-block-info)))
1581 (org-babel-check-confirm-evaluate info))))
1583 (ert-deftest test-ob/check-eval ()
1584 (let ((org-confirm-babel-evaluate t))
1585 ;; Non-export tests
1586 (dolist (pair '(("no" . nil)
1587 ("never" . nil)
1588 ("query" . query)
1589 ("yes" . query)))
1590 (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))
1591 ;; Export tests
1592 (let ((org-babel-exp-reference-buffer t))
1593 (dolist (pair '(("no" . nil)
1594 ("never" . nil)
1595 ("query" . query)
1596 ("yes" . query)
1597 ("never-export" . nil)
1598 ("no-export" . nil)
1599 ("query-export" . query)))
1600 (message (car pair))
1601 (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))))
1602 (let ((org-confirm-babel-evaluate nil))
1603 ;; Non-export tests
1604 (dolist (pair '(("no" . nil)
1605 ("never" . nil)
1606 ("query" . query)
1607 ("yes" . t)))
1608 (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))
1609 ;; Export tests
1610 (let ((org-babel-exp-reference-buffer t))
1611 (dolist (pair '(("no" . nil)
1612 ("never" . nil)
1613 ("query" . query)
1614 ("yes" . t)
1615 ("never-export" . nil)
1616 ("no-export" . nil)
1617 ("query-export" . query)))
1618 (message (car pair))
1619 (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair)))))))
1621 (defun org-test-ob/update-block-body ()
1622 "Test `org-babel-update-block-body' specifications."
1623 (should
1624 (equal "#+begin_src elisp\n 2\n#+end_src"
1625 (let ((org-edit-src-content-indentation 2))
1626 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1627 (org-babel-update-block-body "2")
1628 (buffer-string)))))
1629 ;; Preserve block indentation.
1630 (should
1631 (equal " #+begin_src elisp\n 2\n #+end_src"
1632 (let ((org-edit-src-content-indentation 1))
1633 (org-test-with-temp-text
1634 " #+begin_src elisp\n (+ 1 1)\n #+end_src"
1635 (org-babel-update-block-body "2")
1636 (buffer-string)))))
1637 ;; Ignore NEW-BODY global indentation.
1638 (should
1639 (equal "#+begin_src elisp\n 2\n#+end_src"
1640 (let ((org-edit-src-content-indentation 2))
1641 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1642 (org-babel-update-block-body " 2")
1643 (buffer-string)))))
1644 ;; When indentation should be preserved ignore the two rules above.
1645 (should
1646 (equal " #+begin_src elisp\n2\n #+end_src"
1647 (let ((org-edit-src-content-indentation 1)
1648 (org-src-preserve-indentation t))
1649 (org-test-with-temp-text
1650 " #+begin_src elisp\n (+ 1 1)\n #+end_src"
1651 (org-babel-update-block-body "2")
1652 (buffer-string)))))
1653 (should
1654 (equal " #+begin_src elisp -i\n2\n #+end_src"
1655 (let ((org-edit-src-content-indentation 1))
1656 (org-test-with-temp-text
1657 " #+begin_src elisp -i\n (+ 1 1)\n #+end_src"
1658 (org-babel-update-block-body "2")
1659 (buffer-string)))))
1660 (should
1661 (equal "#+begin_src elisp\n 2\n#+end_src"
1662 (let ((org-edit-src-content-indentation 2)
1663 (org-src-preserve-indentation t))
1664 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1665 (org-babel-update-block-body " 2")
1666 (buffer-string)))))
1667 (should
1668 (equal "#+begin_src elisp -i\n 2\n#+end_src"
1669 (let ((org-edit-src-content-indentation 2)
1670 (org-src-preserve-indentation t))
1671 (org-test-with-temp-text "#+begin_src elisp -i\n(+ 1 1)\n#+end_src"
1672 (org-babel-update-block-body " 2")
1673 (buffer-string))))))
1675 (ert-deftest test-ob/find-named-result ()
1676 "Test `org-babel-find-named-result' specifications."
1677 (should
1678 (= 1
1679 (org-test-with-temp-text "#+results: foo\n: result"
1680 (org-babel-find-named-result "foo"))))
1681 (should-not
1682 (org-test-with-temp-text "#+results: foo\n: result"
1683 (org-babel-find-named-result "bar")))
1684 (should-not
1685 (org-test-with-temp-text "#+results: foobar\n: result"
1686 (org-babel-find-named-result "foo")))
1687 ;; Search is case insensitive.
1688 (should
1689 (org-test-with-temp-text "#+RESULTS: FOO\n: result"
1690 (org-babel-find-named-result "foo")))
1691 ;; Handle hash in results keyword.
1692 (should
1693 (org-test-with-temp-text "#+results[hash]: FOO\n: result"
1694 (org-babel-find-named-result "foo")))
1695 ;; Accept orphaned affiliated keywords.
1696 (should
1697 (org-test-with-temp-text "#+results: foo"
1698 (org-babel-find-named-result "foo"))))
1700 (ert-deftest test-ob/where-is-src-block-result ()
1701 "Test `org-babel-where-is-src-block-result' specifications."
1702 ;; Find anonymous results.
1703 (should
1704 (equal "#+RESULTS:"
1705 (org-test-with-temp-text
1706 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS:\n: 2"
1707 (goto-char (org-babel-where-is-src-block-result))
1708 (buffer-substring-no-properties (point) (line-end-position)))))
1709 ;; Find named results. Those have priority over anonymous ones.
1710 (should
1711 (equal "#+RESULTS: example"
1712 (org-test-with-temp-text
1714 <point>#+NAME: example
1715 #+BEGIN_SRC emacs-lisp
1716 \(+ 1 1)
1717 #+END_SRC
1719 #+RESULTS: example
1720 : 2"
1721 (goto-char (org-babel-where-is-src-block-result))
1722 (buffer-substring-no-properties (point) (line-end-position)))))
1723 (should
1724 (equal "#+RESULTS: example"
1725 (org-test-with-temp-text
1727 <point>#+NAME: example
1728 #+BEGIN_SRC emacs-lisp
1729 \(+ 1 1)
1730 #+END_SRC
1732 #+RESULTS:
1733 : fake
1735 #+RESULTS: example
1736 : 2"
1737 (goto-char (org-babel-where-is-src-block-result))
1738 (buffer-substring-no-properties (point) (line-end-position)))))
1739 ;; Return nil when no result is found.
1740 (should-not
1741 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1742 (org-babel-where-is-src-block-result)))
1743 (should-not
1744 (org-test-with-temp-text
1745 "- item\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n"
1746 (org-babel-where-is-src-block-result)))
1747 ;; When optional argument INSERT is non-nil, add RESULTS keyword
1748 ;; whenever no RESULTS can be found.
1749 (should
1750 (equal
1751 "#+RESULTS:"
1752 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1753 (let ((org-babel-results-keyword "RESULTS"))
1754 (goto-char (org-babel-where-is-src-block-result t)))
1755 (buffer-substring-no-properties (point) (line-end-position)))))
1756 ;; Insert a named RESULTS keyword if possible.
1757 (should
1758 (equal
1759 "#+RESULTS: e"
1760 (org-test-with-temp-text
1761 "#+NAME: e\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1762 (let ((org-babel-results-keyword "RESULTS"))
1763 (goto-char (org-babel-where-is-src-block-result t)))
1764 (buffer-substring-no-properties (point) (line-end-position)))))
1765 ;; When optional argument HASH is provided, clear RESULTS keyword
1766 ;; and related contents if they do not match it.
1767 (should
1768 (equal
1769 "#+RESULTS[bbbb]:"
1770 (org-test-with-temp-text
1771 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS[aaaa]:\n: 3"
1772 (let ((org-babel-results-keyword "RESULTS"))
1773 (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
1774 (org-trim (buffer-substring-no-properties (point) (point-max))))))
1775 (should
1776 (equal
1777 "#+RESULTS[bbbb]:"
1778 (org-test-with-temp-text
1779 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS[aaaa]:"
1780 (let ((org-babel-results-keyword "RESULTS"))
1781 (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
1782 (org-trim (buffer-substring-no-properties (point) (point-max))))))
1783 ;; Handle hashes with times.
1784 (should
1785 (equal
1786 "#+RESULTS[<2014-03-04 00:41:10> bbbb]:"
1787 (org-test-with-temp-text
1789 <point>#+BEGIN_SRC emacs-lisp
1790 \(+ 1 1)
1791 #+END_SRC
1793 #+RESULTS[<2012-03-29 16:40:12> aaaa]:"
1794 (let ((org-babel-results-keyword "RESULTS")
1795 (org-babel-hash-show-time t))
1796 (cl-letf (((symbol-function 'format-time-string)
1797 (lambda (&rest _) "<2014-03-04 00:41:10>")))
1798 (goto-char (org-babel-where-is-src-block-result nil nil "bbbb"))
1799 (org-trim (buffer-substring-no-properties (point) (point-max))))))))
1800 (should
1801 (equal
1802 "#+RESULTS[<2012-03-29 16:40:12> aaaa]:"
1803 (org-test-with-temp-text
1805 <point>#+BEGIN_SRC emacs-lisp
1806 \(+ 1 1)
1807 #+END_SRC
1809 #+RESULTS[<2012-03-29 16:40:12> aaaa]:"
1810 (let ((org-babel-results-keyword "RESULTS")
1811 (org-babel-hash-show-time t))
1812 (cl-letf (((symbol-function 'format-time-string)
1813 (lambda (&rest _) "<2014-03-04 00:41:10>")))
1814 (goto-char (org-babel-where-is-src-block-result nil nil "aaaa"))
1815 (org-trim (buffer-substring-no-properties (point) (point-max))))))))
1816 ;; RESULTS keyword may not be the last affiliated keyword.
1817 (should
1818 (equal
1819 "#+RESULTS[bbbb]:"
1820 (org-test-with-temp-text
1822 <point>#+BEGIN_SRC emacs-lisp
1823 \(+ 1 1)
1824 #+END_SRC
1826 #+RESULTS[aaaa]:
1827 #+NAME: e
1828 : 3"
1829 (let ((org-babel-results-keyword "RESULTS"))
1830 (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
1831 (org-trim (buffer-substring-no-properties (point) (point-max))))))
1832 ;; HASH does nothing if no RESULTS can be found. However, if INSERT
1833 ;; is also non-nil, RESULTS keyword is inserted along with the
1834 ;; expected hash.
1835 (should
1836 (equal
1837 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1838 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1839 (org-babel-where-is-src-block-result nil nil "bbbb")
1840 (buffer-string))))
1841 (should
1842 (equal
1843 "#+RESULTS[bbbb]:"
1844 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1845 (let ((org-babel-results-keyword "RESULTS"))
1846 (goto-char (org-babel-where-is-src-block-result t nil "bbbb")))
1847 (org-trim (buffer-substring-no-properties (point) (point-max)))))))
1849 (ert-deftest test-ob/goto-named-src-block ()
1850 "Test interactive use of `org-babel-goto-named-src-block'."
1851 (org-test-with-temp-text-in-file
1853 #+NAME: abc
1854 #+BEGIN_SRC emacs-lisp :results value
1855 (1+ 1)
1856 #+END_SRC
1857 #+CALL: abc( lorem() ) :results raw :wrap EXAMPLE
1858 #+BEGIN_SRC emacs-lisp
1859 <<abc>>
1860 #+END_SRC
1862 #+RESULTS: abc
1865 ;; non-existent name
1866 (should-not
1867 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\nno-name\n"))
1868 ;; correct name
1869 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\nabc\n")
1870 (should (= 14 (point)))
1871 ;; call line - autocompletion
1872 (forward-line 3)
1873 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1874 (should (= 14 (point)))
1875 ;; noweb reference - autocompletion
1876 (forward-line 5)
1877 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1878 (should (= 14 (point)))
1879 ;; at symbol - autocompletion
1880 (forward-line 7)
1881 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1882 (should (= 14 (point)))
1883 ;; in results - autocompletion
1884 (forward-line 8)
1885 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1886 (should (= 14 (point)))
1887 (forward-line 9)
1888 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1889 (should (= 14 (point)))))
1891 (ert-deftest test-ob/evaluate-body-with-coderefs ()
1892 (should
1893 (= 2
1894 (org-test-with-temp-text
1895 "#+begin_src emacs-lisp -l \"#(ref:%s)\"\n2 #(ref:foo)\n#+end_src"
1896 (org-babel-execute-src-block))))
1897 (should
1898 (= 3
1899 (org-test-with-temp-text
1900 "#+begin_src emacs-lisp\n3 #(ref:foo)\n#+end_src"
1901 (let ((org-coderef-label-format "#(ref:%s)"))
1902 (org-babel-execute-src-block))))))
1904 (provide 'test-ob)
1906 ;;; test-ob ends here