babel: fix up org-babel-script-escape
[org-mode/org-kjn.git] / testing / lisp / test-ob.el
blob6f68da25d728815b8504527ab604f48f31cc408e
1 ;;; test-ob.el --- tests for ob.el
3 ;; Copyright (c) 2010-2014 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-org-babel/multi-line-header-regexp ()
24 (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
25 org-babel-multi-line-header-regexp))
26 ;;TODO can be optimised - and what about blah4 blah5 blah6?
27 (should (string-match
28 org-babel-multi-line-header-regexp
29 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))
30 (should
31 (equal
32 "blah1 blah2 blah3 \t"
33 (match-string
35 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n")))
37 ;;TODO Check - should this fail?
38 (should
39 (not (org-test-string-exact-match
40 org-babel-multi-line-header-regexp
41 " \t #+headers : blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))))
43 (ert-deftest test-org-babel/src-block-regexp ()
44 (let ((test-block
45 (concat
46 "#+begin_src language -n-r-a-b -c :argument-1 yes :argument-2 no\n"
47 "echo this is a test\n"
48 "echo Currently in ' $PWD\n"
49 "#+end_src"))
50 (language "language")
51 (flags "-n-r-a-b -c ")
52 (arguments ":argument-1 yes :argument-2 no")
53 (body "echo this is a test\necho Currently in ' $PWD\n"))
54 (should (string-match org-babel-src-block-regexp test-block))
55 (should (string-match org-babel-src-block-regexp (upcase test-block)))
56 (should (equal language (match-string 2 test-block)))
57 ;;TODO Consider refactoring
58 (should (equal flags (match-string 3 test-block)))
59 (should (equal arguments (match-string 4 test-block)))
60 (should (equal body (match-string 5 test-block)))
61 ;;no switches
62 (should (org-test-string-exact-match
63 org-babel-src-block-regexp
64 (replace-regexp-in-string flags "" test-block)))
65 ;;no header arguments
66 (should (org-test-string-exact-match
67 org-babel-src-block-regexp
68 (replace-regexp-in-string arguments "" test-block)))
69 ;; should be valid with no body
70 (should (org-test-string-exact-match
71 org-babel-src-block-regexp
72 (replace-regexp-in-string body "" test-block)))))
74 (ert-deftest test-org-babel/get-header ()
75 (should (not (org-babel-get-header
76 org-babel-default-header-args :doesnt-exist)))
77 (should(equal '((:session . "none"))
78 (org-babel-get-header
79 org-babel-default-header-args :session)))
80 (should(equal '((:session . "none"))
81 (org-babel-get-header
82 org-babel-default-header-args :session nil)))
83 (should (not (org-babel-get-header
84 org-babel-default-header-args :SESSION)))
85 (should (equal '((:tangle . "no"))
86 (org-babel-get-header
87 org-babel-default-header-args :tangle)))
88 ;; with OTHERS option
89 (should (equal org-babel-default-header-args
90 (org-babel-get-header
91 org-babel-default-header-args :doesnt-exist 'others)))
92 (should (equal org-babel-default-header-args
93 (org-babel-get-header
94 org-babel-default-header-args nil 'others)))
95 (should (null
96 (assoc :noweb
97 (org-babel-get-header
98 org-babel-default-header-args :noweb 'others)))))
100 (ert-deftest test-org-babel/default-inline-header-args ()
101 (should(equal
102 '((:session . "none")
103 (:results . "replace")
104 (:exports . "results")
105 (:hlines . "yes"))
106 org-babel-default-inline-header-args)))
108 (ert-deftest ob-test/org-babel-combine-header-arg-lists ()
109 (let ((results (org-babel-combine-header-arg-lists
110 '((foo . :any)
111 (bar)
112 (baz . ((foo bar) (baz)))
113 (qux . ((foo bar baz qux)))
114 (quux . ((foo bar))))
115 '((bar)
116 (baz . ((baz)))
117 (quux . :any)))))
118 (dolist (pair '((foo . :any)
119 (bar)
120 (baz . ((baz)))
121 (quux . :any)
122 (qux . ((foo bar baz qux)))))
123 (should (equal (cdr pair)
124 (cdr (assoc (car pair) results)))))))
126 ;;; ob-get-src-block-info
127 (ert-deftest test-org-babel/get-src-block-info-language ()
128 (org-test-at-marker nil org-test-file-ob-anchor
129 (let ((info (org-babel-get-src-block-info)))
130 (should (string= "emacs-lisp" (nth 0 info))))))
132 (ert-deftest test-org-babel/get-src-block-info-body ()
133 (org-test-at-marker nil org-test-file-ob-anchor
134 (let ((info (org-babel-get-src-block-info)))
135 (should (string-match (regexp-quote org-test-file-ob-anchor)
136 (nth 1 info))))))
138 (ert-deftest test-org-babel/get-src-block-info-tangle ()
139 (org-test-at-marker nil org-test-file-ob-anchor
140 (let ((info (org-babel-get-src-block-info)))
141 (should (string= "no" (cdr (assoc :tangle (nth 2 info))))))))
143 (ert-deftest test-org-babel/elisp-in-header-arguments ()
144 "Test execution of elisp forms in header arguments."
145 (org-test-with-temp-text-in-file "
147 * elisp forms in header arguments
148 :PROPERTIES:
149 :var: prop = (* 7 6)
150 :END:
151 #+begin_src emacs-lisp
152 prop
153 #+end_src"
154 (goto-char (point-min))
155 (org-babel-next-src-block)
156 (let ((info (org-babel-get-src-block-info)))
157 (should (= 42 (org-babel-execute-src-block))))))
159 (ert-deftest test-org-babel/simple-named-code-block ()
160 "Test that simple named code blocks can be evaluated."
161 (org-test-with-temp-text-in-file "
163 #+name: i-have-a-name
164 #+begin_src emacs-lisp
166 #+end_src"
167 (org-babel-next-src-block 1)
168 (should (= 42 (org-babel-execute-src-block)))))
170 (ert-deftest test-org-babel/simple-variable-resolution ()
171 "Test that simple variable resolution is working."
172 (org-test-with-temp-text-in-file "
174 #+name: four
175 #+begin_src emacs-lisp
176 (list 1 2 3 4)
177 #+end_src
179 #+begin_src emacs-lisp :var four=four
180 (length four)
181 #+end_src"
183 (org-babel-next-src-block 2)
184 (should (= 4 (org-babel-execute-src-block)))
185 (forward-line 5)
186 (should (string= ": 4" (buffer-substring
187 (point-at-bol)
188 (point-at-eol))))))
190 (ert-deftest test-org-babel/multi-line-header-arguments ()
191 "Test that multi-line header arguments and can be read."
192 (org-test-with-temp-text-in-file "
194 #+headers: :var letters='(a b c d e f g)
195 #+begin_src emacs-lisp :var numbers='(1 2 3 4 5 6 7)
196 (require 'cl)
197 (defalias 'my-map (if (org-version-check \"24.2.50\" \"cl\" :predicate)
198 'cl-map
199 'map))
200 (my-map 'list #'list numbers letters)
201 #+end_src"
203 (org-babel-next-src-block)
204 (let ((results (org-babel-execute-src-block)))
205 (should(equal 'a (cadr (assoc 1 results))))
206 (should(equal 'd (cadr (assoc 4 results)))))))
208 (ert-deftest test-org-babel/parse-header-args ()
209 (org-test-with-temp-text-in-file "
211 #+begin_src example-lang :session :results output :var num=9
212 the body
213 #+end_src"
215 (org-babel-next-src-block)
216 (let* ((info (org-babel-get-src-block-info))
217 (params (nth 2 info)))
218 (message "%S" params)
219 (should (equal "example-lang" (nth 0 info)))
220 (should (string= "the body" (org-babel-trim (nth 1 info))))
221 (should-not (member '(:session\ \ \ \ ) params))
222 (should (equal '(:session) (assoc :session params)))
223 (should (equal '(:result-type . output) (assoc :result-type params)))
224 (should (equal '(num . 9) (cdr (assoc :var params)))))))
226 (ert-deftest test-org-babel/parse-header-args2 ()
227 (org-test-with-temp-text-in-file "
229 * resolving sub-trees as references
231 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
232 (length text)
233 #+end_src
235 #+begin_src org :noweb yes
236 <<simple-subtree>>
237 <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
238 #+end_src
240 ** simple subtree with custom ID
241 :PROPERTIES:
242 :CUSTOM_ID: simple-subtree
243 :END:
244 this is simple"
246 (should (string-match (regexp-quote "this is simple")
247 (org-babel-ref-resolve "simple-subtree")))
248 (org-babel-next-src-block)
249 (should (= 14 (org-babel-execute-src-block)))))
251 (ert-deftest test-org-babel/inline-src-blocks ()
252 (macrolet ((at-next (&rest body)
253 `(progn
254 (move-end-of-line 1)
255 (re-search-forward org-babel-inline-src-block-regexp nil t)
256 (goto-char (match-beginning 1))
257 (save-match-data ,@body))))
258 (org-test-at-id
259 "54cb8dc3-298c-4883-a933-029b3c9d4b18"
260 (at-next (should (equal 1 (org-babel-execute-src-block))))
261 (at-next (should (equal 2 (org-babel-execute-src-block))))
262 (at-next (should (equal 3 (org-babel-execute-src-block)))))
263 (org-test-at-id
264 "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
265 (at-next (should (equal 1 (org-babel-execute-src-block))))
266 (at-next (should (equal 2 (org-babel-execute-src-block))))
267 (at-next (should (equal 3 (org-babel-execute-src-block))))
268 (at-next (should (equal 4 (org-babel-execute-src-block)))))))
270 (ert-deftest test-org-babel/org-babel-get-inline-src-block-matches ()
271 (flet ((test-at-id (id)
272 (org-test-at-id
274 (let ((test-point (point)))
275 (should (fboundp 'org-babel-get-inline-src-block-matches))
276 (should (re-search-forward "src_" nil t)) ;; 1
277 (should (org-babel-get-inline-src-block-matches))
278 (should (re-search-forward "}" nil (point-at-bol))) ;; 1
279 (should-not (org-babel-get-inline-src-block-matches))
280 (should (re-search-forward "in" nil t)) ;; 2
281 (should-not (org-babel-get-inline-src-block-matches))
282 (should (re-search-forward "echo" nil t)) ;; 2
283 (should (org-babel-get-inline-src-block-matches))
284 (should (re-search-forward "blocks" nil t)) ;; 3
285 (backward-char 8) ;; 3
286 (should (org-babel-get-inline-src-block-matches))
287 (forward-char 1) ;;3
288 (should-not (org-babel-get-inline-src-block-matches))
289 (should (re-search-forward ":results" nil t)) ;; 4
290 (should (org-babel-get-inline-src-block-matches))
291 (end-of-line)
292 (should-not (org-babel-get-inline-src-block-matches))))))
293 (test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74")
294 (test-at-id "d55dada7-de0e-4340-8061-787cccbedee5")))
296 (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-1 ()
297 (let ((test-line "src_sh{echo 1}")
298 (org-babel-inline-result-wrap "=%s="))
299 ;; src_ at bol line 1...
300 (org-test-with-temp-text
301 test-line
302 (goto-char (point-min)) (org-ctrl-c-ctrl-c)
303 (should (string=
304 (concat test-line " =1=")
305 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
306 (forward-char) (org-ctrl-c-ctrl-c)
307 (should (string=
308 (concat test-line " =1= =1=")
309 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
310 (re-search-forward "1}")
311 (should-error (org-ctrl-c-ctrl-c))
312 (backward-char) ;; last char of block body
313 (org-ctrl-c-ctrl-c)
314 (should (string=
315 (concat test-line " =1= =1= =1=")
316 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
317 ;; src_ follows space line 1...
318 (let ((test-line " src_emacs-lisp{ 1 }"))
319 (org-test-with-temp-text
320 test-line
321 (should-error (org-ctrl-c-ctrl-c))
322 (forward-char) (org-ctrl-c-ctrl-c)
323 (should (string=
324 (concat test-line " =1=")
325 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
326 (re-search-forward "{ 1 ") (org-ctrl-c-ctrl-c)
327 (should (string=
328 (concat test-line " =1= =1=")
329 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
330 (forward-char)
331 (should-error (org-ctrl-c-ctrl-c))))))
333 (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-2 ()
334 ;; src_ at bol line 2...
335 (let ((test-line " src_emacs-lisp{ \"x\" }")
336 (org-babel-inline-result-wrap "=%s="))
337 (org-test-with-temp-text
338 (concat "\n" test-line)
339 (should-error (org-ctrl-c-ctrl-c))
340 (goto-char (point-min))
341 (should-error (org-ctrl-c-ctrl-c))
342 (forward-line)
343 (should-error (org-ctrl-c-ctrl-c))
344 (forward-char) (org-ctrl-c-ctrl-c)
345 (should (string=
346 (concat test-line " =x=")
347 (buffer-substring-no-properties
348 (point-at-bol) (point-at-eol))))))
350 (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }")
351 (org-babel-inline-result-wrap "=%s="))
352 (org-test-with-temp-text
353 test-line
354 (goto-char (point-max))
355 (insert (concat "\n" test-line " end"))
356 (re-search-backward "src") (org-ctrl-c-ctrl-c)
357 (should (string=
358 (concat test-line " =y= end")
359 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
360 (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
361 (should (string=
362 (concat test-line " =y= =y= end")
363 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
364 (forward-char)
365 (should-error (org-ctrl-c-ctrl-c)))))
367 (ert-deftest test-org-babel/inline-src_blk-manual-results-replace ()
368 (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }")
369 (org-babel-inline-result-wrap "=%s="))
370 (org-test-with-temp-text
371 (concat "\n" test-line)
372 (should-error (org-ctrl-c-ctrl-c))
373 (goto-char (point-max))
374 (should-error (org-ctrl-c-ctrl-c))
375 (beginning-of-line)
376 (should-error (org-ctrl-c-ctrl-c))
377 (forward-char) (org-ctrl-c-ctrl-c)
378 (should (string=
379 (concat test-line " =x=")
380 (buffer-substring-no-properties
381 (point-at-bol) (point-at-eol))))))
383 (let ((test-line (concat " Some text prior to block "
384 "src_emacs-lisp[:results replace]{ \"y\" }"))
385 (org-babel-inline-result-wrap "=%s="))
386 (org-test-with-temp-text test-line
387 (goto-char (point-max))
388 (insert (concat "\n" test-line " end"))
389 (re-search-backward "src") (org-ctrl-c-ctrl-c)
390 (should (string=
391 (concat test-line " =y= end")
392 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
393 (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
394 (should (string=
395 (concat test-line " =y= =y= end")
396 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
397 (forward-char)
398 (should-error (org-ctrl-c-ctrl-c)))))
400 (ert-deftest test-org-babel/inline-src_blk-results-silent ()
401 (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
402 (org-test-with-temp-text test-line
403 (org-ctrl-c-ctrl-c)
404 (should (string= test-line
405 (buffer-substring-no-properties
406 (point-at-bol) (point-at-eol))))
407 (end-of-buffer)
408 (should-error (org-ctrl-c-ctrl-c))))
409 (let ((test-line (concat " Some text prior to block src_emacs-lisp"
410 "[ :results silent ]{ \"y\" }")))
411 (org-test-with-temp-text
412 test-line
413 (goto-char (point-max))
414 (insert (concat "\n" test-line " end"))
415 (re-search-backward "src_") (org-ctrl-c-ctrl-c)
416 (should (string= (concat test-line " end")
417 (buffer-substring-no-properties
418 (point-at-bol) (point-at-eol))))
419 (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
420 (should (string= (concat test-line " end")
421 (buffer-substring-no-properties
422 (point-at-bol) (point-at-eol))))
423 (forward-char)
424 (should-error (org-ctrl-c-ctrl-c)))))
426 (ert-deftest test-org-babel/inline-src_blk-results-raw ()
427 (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
428 (org-test-with-temp-text test-line
429 (org-ctrl-c-ctrl-c)
430 (should (string= (concat test-line " x")
431 (buffer-string)))))
432 (let ((test-line (concat " Some text prior to block "
433 "src_emacs-lisp[ :results raw ]{ \"the\" }")))
434 (org-test-with-temp-text (concat test-line " end")
435 (re-search-forward "src_") (org-ctrl-c-ctrl-c)
436 (should (string= (concat test-line " the end")
437 (buffer-substring-no-properties
438 (point-at-bol) (point-at-eol))))
439 (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
440 (should (string= (concat test-line " the the end")
441 (buffer-substring-no-properties
442 (point-at-bol) (point-at-eol))))
443 (forward-char)
444 (should-error (org-ctrl-c-ctrl-c)))))
446 (ert-deftest test-org-babel/inline-src_blk-results-file ()
447 (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\" }"))
448 (org-test-with-temp-text
449 test-line
450 (org-ctrl-c-ctrl-c)
451 (should (string= (concat test-line " [[file:~/test-file]]")
452 (buffer-substring-no-properties
453 (point-min) (point-max)))))))
455 (ert-deftest test-org-babel/inline-src_blk-results-scalar ()
456 (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\" }")
457 (org-babel-inline-result-wrap "=%s="))
458 (org-test-with-temp-text
459 test-line
460 (org-ctrl-c-ctrl-c)
461 (should (string= (concat test-line " =\"x\"=")
462 (buffer-substring-no-properties
463 (point-min) (point-max)))))))
465 (ert-deftest test-org-babel/inline-src_blk-results-verbatim ()
466 (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\" }")
467 (org-babel-inline-result-wrap "=%s="))
468 (org-test-with-temp-text
469 test-line
470 (org-ctrl-c-ctrl-c)
471 (should (string= (concat test-line " =\"x\"=")
472 (buffer-substring-no-properties
473 (point-min) (point-max)))))))
475 (ert-deftest test-org-babel/combining-scalar-and-raw-result-types ()
476 (org-test-with-temp-text-in-file "
478 #+begin_src sh :results scalar
479 echo \"[[file:./cv.cls]]\"
480 #+end_src
482 #+name:
483 : [[file:./cv.cls]]
485 #+begin_src sh :results raw scalar
486 echo \"[[file:./cv.cls]]\"
487 #+end_src
489 (flet ((next-result ()
490 (org-babel-next-src-block)
491 (org-babel-execute-src-block)
492 (goto-char (org-babel-where-is-src-block-result))
493 (forward-line 1)))
494 (goto-char (point-min))
495 (next-result)
496 (should (org-babel-in-example-or-verbatim))
497 (next-result)
498 (should (not (org-babel-in-example-or-verbatim))))))
500 (ert-deftest test-org-babel/no-defaut-value-for-var ()
501 "Test that the absence of a default value for a variable DOES THROW
502 a proper error."
503 (org-test-at-id "f2df5ba6-75fa-4e6b-8441-65ed84963627"
504 (org-babel-next-src-block)
505 (let ((err
506 (should-error (org-babel-execute-src-block) :type 'error)))
507 (should
508 (equal
509 '(error
510 "Variable \"x\" must be assigned a default value")
511 err)))))
513 (ert-deftest test-org-babel/just-one-results-block ()
514 "Test that evaluating two times the same code block does not result in a
515 duplicate results block."
516 (org-test-with-temp-text "#+begin_src sh\necho Hello\n#+end_src\n"
517 (org-babel-execute-src-block)
518 (org-babel-execute-src-block) ; second code block execution
519 (should (search-forward "Hello")) ; the string inside the source code block
520 (should (search-forward "Hello")) ; the same string in the results block
521 (should-error (search-forward "Hello"))))
523 (ert-deftest test-org-babel/nested-code-block ()
524 "Test nested code blocks inside code blocks don't cause problems."
525 (should
526 (string= "#+begin_src emacs-lisp\n 'foo\n#+end_src"
527 (org-test-with-temp-text "#+begin_src org :results silent
528 ,#+begin_src emacs-lisp
529 , 'foo
530 ,#+end_src
531 #+end_src"
532 (let ((org-edit-src-content-indentation 2)
533 (org-src-preserve-indentation nil))
534 (org-babel-execute-src-block))))))
536 (ert-deftest test-org-babel/partial-nested-code-block ()
537 "Test nested code blocks inside code blocks don't cause problems."
538 (org-test-with-temp-text "#+begin_src org :results silent
539 ,#+begin_src emacs-lisp
540 #+end_src"
541 (should (string= "#+begin_src emacs-lisp" (org-babel-execute-src-block)))))
543 (ert-deftest test-ob/does-not-replace-a-block-with-the-results ()
544 (org-test-with-temp-text "#+NAME: foo
545 #+BEGIN_SRC emacs-lisp
546 'foo
547 #+END_SRC\n"
548 (org-babel-next-src-block 1)
549 (should (eq 'foo (org-babel-execute-src-block)))
550 (goto-char (point-min))
551 (org-babel-next-src-block 1)
552 (should (looking-at org-babel-src-block-regexp))))
554 (ert-deftest test-ob/catches-all-references ()
555 (org-test-with-temp-text "
556 #+NAME: literal-example
557 #+BEGIN_EXAMPLE
558 A literal example
559 on two lines
560 #+END_EXAMPLE
562 #+NAME: read-literal-example
563 #+BEGIN_SRC emacs-lisp :var x=literal-example
564 (concatenate 'string x \" for me.\")
565 #+END_SRC"
566 (org-babel-next-src-block 1)
567 (should (string= (org-babel-execute-src-block)
568 "A literal example\non two lines\n for me."))))
570 (ert-deftest test-ob/resolve-code-blocks-before-data-blocks ()
571 (org-test-with-temp-text "
572 #+name: foo
573 : bar
575 #+name: foo
576 #+begin_src emacs-lisp
577 \"baz\"
578 #+end_src
580 #+begin_src emacs-lisp :var foo=foo
582 #+end_src"
583 (org-babel-next-src-block 2)
584 (should (string= (org-babel-execute-src-block) "baz"))))
586 (ert-deftest test-ob/do-not-resolve-to-partial-names-data ()
587 (org-test-with-temp-text "
588 #+tblname: base_plus
589 | 1 |
590 | 2 |
592 #+tblname: base
593 | 3 |
594 | 4 |
596 #+begin_src emacs-lisp :var x=base
598 #+end_src"
599 (org-babel-next-src-block 1)
600 (should (equal (org-babel-execute-src-block) '((3) (4))))))
602 (ert-deftest test-ob/do-not-resolve-to-partial-names-code ()
603 (org-test-with-temp-text "
604 #+name: base_plus
605 #+begin_src emacs-lisp
606 'bar
607 #+end_src
609 #+name: base
610 #+begin_src emacs-lisp
611 'foo
612 #+end_src
614 #+begin_src emacs-lisp :var x=base
616 #+end_src"
617 (org-babel-next-src-block 3)
618 (should (equal (org-babel-execute-src-block) "foo"))))
620 (ert-deftest test-ob/allow-spaces-around-=-in-var-specs ()
621 (org-test-with-temp-text "#+begin_src emacs-lisp :var a = 1 b = 2 c= 3 d =4
622 (+ a b c d)
623 #+end_src
625 (should (= 10 (org-babel-execute-src-block)))))
627 (ert-deftest test-ob/org-babel-update-intermediate ()
628 (org-test-with-temp-text "#+name: foo
629 #+begin_src emacs-lisp
631 #+end_src
633 #+results: foo
636 #+begin_src emacs-lisp :var it=foo
637 (+ it 1)
638 #+end_src"
639 (let ((org-babel-update-intermediate nil))
640 (goto-char (point-min))
641 (org-babel-next-src-block 2)
642 (should (= 3 (org-babel-execute-src-block)))
643 (goto-char (point-min))
644 (forward-line 6)
645 (should (looking-at ": 4")))
646 (let ((org-babel-update-intermediate t))
647 (goto-char (point-min))
648 (org-babel-next-src-block 2)
649 (should (= 3 (org-babel-execute-src-block)))
650 (goto-char (point-min))
651 (forward-line 6)
652 (should (looking-at ": 2")))))
654 (ert-deftest test-ob/eval-header-argument ()
655 (flet ((check-eval (eval runp)
656 (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
657 (setq foo :evald)
658 #+end_src" eval)
659 (let ((foo :not-run))
660 (if runp
661 (progn (should (org-babel-execute-src-block))
662 (should (eq foo :evald)))
663 (progn (should-not (org-babel-execute-src-block))
664 (should-not (eq foo :evald))))))))
665 (check-eval "never" nil)
666 (check-eval "no" nil)
667 (check-eval "never-export" t)
668 (check-eval "no-export" t)
669 (let ((org-babel-exp-reference-buffer (current-buffer)))
670 (check-eval "never" nil)
671 (check-eval "no" nil)
672 (check-eval "never-export" nil)
673 (check-eval "no-export" nil))))
675 (ert-deftest test-ob/noweb-expansion-1 ()
676 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
677 <<foo>>
678 #+end_src
680 #+name: foo
681 #+begin_src sh
683 #+end_src"
684 (should (string= (org-babel-expand-noweb-references) "bar"))))
686 (ert-deftest test-ob/noweb-expansion-2 ()
687 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
688 <<foo>>
689 #+end_src
691 #+name: foo
692 #+begin_src sh :noweb-sep \"\"
694 #+end_src
696 #+begin_src sh :noweb-ref foo :noweb-sep \"\"
698 #+end_src"
699 (should (string= (org-babel-expand-noweb-references) "barbaz"))))
701 (ert-deftest test-ob/splitting-variable-lists-in-references ()
702 (org-test-with-temp-text ""
703 (should (= 1 (length (org-babel-ref-split-args
704 "a=\"this, no work\""))))
705 (should (= 2 (length (org-babel-ref-split-args
706 "a=\"this, no work\", b=1"))))))
708 (ert-deftest test-ob/org-babel-balanced-split ()
709 (should (equal
710 '(":a 1" "b [2 3]" "c (4 :d (5 6))")
711 (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))"
712 '((32 9) . 58)))))
714 (ert-deftest test-ob/commented-last-block-line-no-var ()
715 (org-test-with-temp-text-in-file "
716 #+begin_src emacs-lisp
718 #+end_src"
719 (org-babel-next-src-block)
720 (org-ctrl-c-ctrl-c)
721 (should (re-search-forward "\\#\\+results:" nil t))
722 (forward-line)
723 (should
724 (string=
726 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
727 (org-test-with-temp-text-in-file "
728 #+begin_src emacs-lisp
729 \"some text\";;
730 #+end_src"
731 (org-babel-next-src-block)
732 (org-ctrl-c-ctrl-c)
733 (should (re-search-forward "\\#\\+results:" nil t))
734 (forward-line)
735 (should
736 (string=
737 ": some text"
738 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
740 (ert-deftest test-ob/commented-last-block-line-with-var ()
741 (org-test-with-temp-text-in-file "
742 #+begin_src emacs-lisp :var a=1
744 #+end_src"
745 (org-babel-next-src-block)
746 (org-ctrl-c-ctrl-c)
747 (re-search-forward "\\#\\+results:" nil t)
748 (forward-line)
749 (should (string=
751 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
752 (org-test-with-temp-text-in-file "
753 #+begin_src emacs-lisp :var a=2
755 #+end_src"
756 (org-babel-next-src-block)
757 (org-ctrl-c-ctrl-c)
758 (re-search-forward "\\#\\+results:" nil t)
759 (forward-line)
760 (should (string=
761 ": 2"
762 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
764 (defun test-ob-verify-result-and-removed-result (result buffer-text)
765 "Test helper function to test `org-babel-remove-result'.
766 A temp buffer is populated with BUFFER-TEXT, the first block is executed,
767 and the result of execution is verified against RESULT.
769 The block is actually executed /twice/ to ensure result
770 replacement happens correctly."
771 (org-test-with-temp-text
772 buffer-text
773 (org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
774 (should (re-search-forward "\\#\\+results:" nil t))
775 (forward-line)
776 (should (string= result
777 (buffer-substring-no-properties
778 (point-at-bol)
779 (- (point-max) 16))))
780 (org-babel-previous-src-block) (org-babel-remove-result)
781 (should (string= buffer-text
782 (buffer-substring-no-properties
783 (point-min) (point-max))))))
785 (ert-deftest test-ob/org-babel-remove-result--results-default ()
786 "Test `org-babel-remove-result' with default :results."
787 (mapcar (lambda (language)
788 (test-ob-verify-result-and-removed-result
789 "\n"
790 (concat
791 "* org-babel-remove-result
792 #+begin_src " language "
793 #+end_src
795 * next heading")))
796 '("sh" "emacs-lisp")))
798 (ert-deftest test-ob/org-babel-remove-result--results-list ()
799 "Test `org-babel-remove-result' with :results list."
800 (test-ob-verify-result-and-removed-result
801 "- 1
804 - (quote (4 5))"
806 "* org-babel-remove-result
807 #+begin_src emacs-lisp :results list
808 '(1 2 3 '(4 5))
809 #+end_src
811 * next heading"))
813 (ert-deftest test-ob/org-babel-results-indented-wrap ()
814 "Ensure that wrapped results are inserted correction when indented.
815 If not inserted correctly then the second evaluation will fail
816 trying to find the :END: marker."
817 (org-test-with-temp-text
818 "- indented
819 #+begin_src sh :results file wrap
820 echo test.txt
821 #+end_src"
822 (org-babel-next-src-block 1)
823 (org-babel-execute-src-block)
824 (org-babel-execute-src-block)))
826 (ert-deftest test-ob/file-desc-header-argument ()
827 "Test that the :file-desc header argument is used."
828 (org-test-with-temp-text "#+begin_src emacs-lisp :results file :file-desc bar
829 \"foo\"
830 #+end_src
832 #+begin_src emacs-lisp :results file :file-desc
833 \"foo\"
834 #+end_src"
835 (org-babel-execute-src-block)
836 (org-babel-next-src-block 1)
837 (org-babel-execute-src-block)
838 (goto-char (point-min))
839 (should (search-forward "[[file:foo][bar]]" nil t))
840 (should (search-forward "[[file:foo][foo]]" nil t))))
842 (ert-deftest test-ob/org-babel-remove-result--results-pp ()
843 "Test `org-babel-remove-result' with :results pp."
844 (test-ob-verify-result-and-removed-result
845 ": \"I /am/ working!\""
847 "* org-babel-remove-result
848 #+begin_src emacs-lisp :results pp
849 \"I /am/ working!\")
850 #+end_src
852 * next heading"))
854 (ert-deftest test-org-babel/inline-src_blk-preceded-punct-preceded-by-point ()
855 (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }")
856 (org-babel-inline-result-wrap "=%s="))
857 (org-test-with-temp-text
858 test-line
859 (forward-char 1)
860 (org-ctrl-c-ctrl-c)
861 (should (re-search-forward "=\"x\"=" nil t))
862 (forward-line))))
864 (ert-deftest test-ob/commented-last-block-line-with-var ()
865 (org-test-with-temp-text-in-file "
866 #+begin_src emacs-lisp :var a=1
868 #+end_src"
869 (org-babel-next-src-block)
870 (org-ctrl-c-ctrl-c)
871 (re-search-forward "\\#\\+results:" nil t)
872 (forward-line)
873 (should (string=
875 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
876 (org-test-with-temp-text-in-file "
877 #+begin_src emacs-lisp :var a=2
879 #+end_src"
880 (org-babel-next-src-block)
881 (org-ctrl-c-ctrl-c)
882 (re-search-forward "\\#\\+results:" nil t)
883 (forward-line)
884 (should (string=
885 ": 2"
886 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
888 (defun test-ob-verify-result-and-removed-result (result buffer-text)
889 "Test helper function to test `org-babel-remove-result'.
890 A temp buffer is populated with BUFFER-TEXT, the first block is executed,
891 and the result of execution is verified against RESULT.
893 The block is actually executed /twice/ to ensure result
894 replacement happens correctly."
895 (org-test-with-temp-text
896 buffer-text
897 (org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
898 (should (re-search-forward "\\#\\+results:" nil t))
899 (forward-line)
900 (should (string= result
901 (buffer-substring-no-properties
902 (point-at-bol)
903 (- (point-max) 16))))
904 (org-babel-previous-src-block) (org-babel-remove-result)
905 (should (string= buffer-text
906 (buffer-substring-no-properties
907 (point-min) (point-max))))))
909 (ert-deftest test-ob/org-babel-remove-result--results-default ()
910 "Test `org-babel-remove-result' with default :results."
911 (mapcar (lambda (language)
912 (test-ob-verify-result-and-removed-result
913 "\n"
914 (concat
915 "* org-babel-remove-result
916 #+begin_src " language "
917 #+end_src
919 * next heading")))
920 '("sh" "emacs-lisp")))
922 (ert-deftest test-ob/org-babel-remove-result--results-list ()
923 "Test `org-babel-remove-result' with :results list."
924 (test-ob-verify-result-and-removed-result
925 "- 1
928 - (quote (4 5))"
930 "* org-babel-remove-result
931 #+begin_src emacs-lisp :results list
932 '(1 2 3 '(4 5))
933 #+end_src
935 * next heading"))
937 (ert-deftest test-ob/org-babel-remove-result--results-wrap ()
938 "Test `org-babel-remove-result' with :results wrap."
939 (test-ob-verify-result-and-removed-result
940 ":RESULTS:
941 hello there
942 :END:"
944 "* org-babel-remove-result
946 #+begin_src emacs-lisp :results wrap
947 \"hello there\"
948 #+end_src
950 * next heading"))
952 (ert-deftest test-ob/org-babel-remove-result--results-org ()
953 "Test `org-babel-remove-result' with :results org."
954 (test-ob-verify-result-and-removed-result
955 "#+BEGIN_SRC org
956 ,* heading
957 ,** subheading
958 content
959 #+END_SRC"
961 "* org-babel-remove-result
962 #+begin_src emacs-lisp :results org
963 \"* heading
964 ,** subheading
965 content\"
966 #+end_src
968 * next heading"))
970 (ert-deftest test-ob/org-babel-remove-result--results-html ()
971 "Test `org-babel-remove-result' with :results html."
972 (test-ob-verify-result-and-removed-result
973 "#+BEGIN_HTML
974 <head><body></body></head>
975 #+END_HTML"
977 "* org-babel-remove-result
978 #+begin_src emacs-lisp :results html
979 \"<head><body></body></head>\"
980 #+end_src
982 * next heading"))
984 (ert-deftest test-ob/org-babel-remove-result--results-latex ()
985 "Test `org-babel-remove-result' with :results latex."
986 (test-ob-verify-result-and-removed-result
987 "#+BEGIN_LaTeX
988 Line 1
989 Line 2
990 Line 3
991 #+END_LaTeX"
993 "* org-babel-remove-result
994 #+begin_src emacs-lisp :results latex
995 \"Line 1
996 Line 2
997 Line 3\"
998 #+end_src
1000 * next heading"))
1002 (ert-deftest test-ob/org-babel-remove-result--results-code ()
1003 "Test `org-babel-remove-result' with :results code."
1005 (test-ob-verify-result-and-removed-result
1006 "#+BEGIN_SRC emacs-lisp
1007 \"I am working!\"
1008 #+END_SRC"
1010 "* org-babel-remove-result
1011 #+begin_src emacs-lisp :results code
1012 (message \"I am working!\")
1013 #+end_src
1015 * next heading"))
1017 (ert-deftest test-ob/org-babel-remove-result--results-pp ()
1018 "Test `org-babel-remove-result' with :results pp."
1019 (test-ob-verify-result-and-removed-result
1020 ": \"I /am/ working!\""
1022 "* org-babel-remove-result
1023 #+begin_src emacs-lisp :results pp
1024 \"I /am/ working!\")
1025 #+end_src
1027 * next heading"))
1029 (ert-deftest test-ob/results-do-not-replace-code-blocks ()
1030 (org-test-with-temp-text "Block two has a space after the name.
1032 #+name: foo
1033 #+begin_src emacs-lisp
1035 #+end_src
1037 #+name: foo
1038 #+begin_src emacs-lisp
1040 #+end_src
1042 #+name: foo
1043 #+begin_src emacs-lisp
1045 #+end_src
1047 #+RESULTS: foo
1048 : foo
1050 (dolist (num '(1 2 3))
1051 ;; execute the block
1052 (goto-char (point-min))
1053 (org-babel-next-src-block num) (org-babel-execute-src-block)
1054 ;; check the results
1055 (goto-char (point-max))
1056 (move-beginning-of-line 0)
1057 (should (looking-at (format ": %d" num))))))
1059 (ert-deftest test-ob/blocks-with-spaces ()
1060 "Test expansion of blocks followed by blank lines."
1061 (should
1062 (equal "#+BEGIN_SRC emacs-lisp
1063 \(+ 1 2)
1064 #+END_SRC
1066 #+RESULTS:
1067 : 3\n\n\n"
1068 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp
1069 \(+ 1 2)
1070 #+END_SRC\n\n\n"
1071 (let ((org-babel-next-src-block "RESULTS"))
1072 (org-babel-execute-src-block))
1073 (buffer-string)))))
1075 (ert-deftest test-ob/results-in-narrowed-buffer ()
1076 "Test block execution in a narrowed buffer."
1077 ;; If results don't exist, they should be inserted in visible part
1078 ;; of the buffer.
1079 (should
1080 (equal
1081 "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS:\n: 3"
1082 (org-test-with-temp-text
1083 "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
1084 (narrow-to-region (point) (save-excursion (forward-line 3) (point)))
1085 (let ((org-babel-results-keyword "RESULTS"))
1086 (org-babel-execute-src-block))
1087 (org-trim (buffer-string)))))
1088 (should
1089 (equal
1090 "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3"
1091 (org-test-with-temp-text
1092 "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
1093 (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
1094 (let ((org-babel-results-keyword "RESULTS"))
1095 (org-babel-execute-src-block))
1096 (org-trim (buffer-string)))))
1097 ;; Results in visible part of buffer, should be updated here.
1098 (should
1099 (equal
1100 "#+NAME: test
1101 #+BEGIN_SRC emacs-lisp
1102 \(+ 1 2)
1103 #+END_SRC
1105 #+RESULTS: test
1106 : 3"
1107 (org-test-with-temp-text
1108 "#+NAME: test
1109 #+BEGIN_SRC emacs-lisp
1110 \(+ 1 2)
1111 #+END_SRC
1113 #+RESULTS: test
1116 Paragraph"
1117 (narrow-to-region (point) (save-excursion (forward-line 7) (point)))
1118 (let ((org-babel-results-keyword "RESULTS"))
1119 (org-babel-execute-src-block))
1120 (org-trim (buffer-string)))))
1121 ;; Results in invisible part of buffer, should be updated there.
1122 (org-test-with-temp-text
1123 "#+NAME: test
1124 #+BEGIN_SRC emacs-lisp
1125 \(+ 1 2)
1126 #+END_SRC
1128 #+RESULTS: test
1131 Paragraph"
1132 (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
1133 (let ((org-babel-results-keyword "RESULTS"))
1134 (org-babel-execute-src-block))
1135 (should-not (re-search-forward "^#\\+RESULTS:" nil t))
1136 (widen)
1137 (should (should (re-search-forward "^: 3" nil t)))))
1139 (ert-deftest test-ob/specific-colnames ()
1140 "Test passing specific column names."
1141 (should
1142 (equal "#+name: input-table
1143 | id | var1 |
1144 |----+------|
1145 | 1 | bar |
1146 | 2 | baz |
1148 #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
1149 echo \"$data\"
1150 #+end_src
1152 #+RESULTS:
1153 | Rev | Author |
1154 |-----+--------|
1155 | 1 | bar |
1156 | 2 | baz |
1159 (org-test-with-temp-text
1160 "#+name: input-table
1161 | id | var1 |
1162 |----+------|
1163 | 1 | bar |
1164 | 2 | baz |
1166 #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
1167 echo \"$data\"
1168 #+end_src
1170 ;; we should find a code block
1171 (should (re-search-forward org-babel-src-block-regexp nil t))
1172 (goto-char (match-beginning 0))
1173 ;; now that we've located the code block, it may be evaluated
1174 (let ((org-babel-execute-src-block "RESULTS"))
1175 (org-babel-execute-src-block))
1176 (buffer-string)))))
1178 (ert-deftest test-ob/location-of-header-arg-eval ()
1179 "Test location of header argument evaluation."
1180 (org-test-with-temp-text "
1181 #+name: top-block
1182 #+begin_src emacs-lisp :var pt=(point)
1184 #+end_src
1186 #+name: bottom-block
1187 #+begin_src emacs-lisp :var pt=top-block()
1189 #+end_src
1191 ;; the value of the second block should be greater than the first
1192 (should
1193 (< (progn (re-search-forward org-babel-src-block-regexp nil t)
1194 (goto-char (match-beginning 0))
1195 (prog1 (save-match-data (org-babel-execute-src-block))
1196 (goto-char (match-end 0))))
1197 (progn (re-search-forward org-babel-src-block-regexp nil t)
1198 (goto-char (match-beginning 0))
1199 (org-babel-execute-src-block))))))
1201 (ert-deftest test-ob/preserve-results-indentation ()
1202 "Preserve indentation when executing a src block."
1203 (should
1204 (equal '(2 2)
1205 (org-test-with-temp-text
1206 " #+begin_src emacs-lisp\n (+ 1 1)\n #+end_src"
1207 (org-babel-execute-src-block)
1208 (buffer-string)
1209 (let ((case-fold-search t)) (search-forward "#+results:"))
1210 ;; Check if both #+RESULTS: keyword and actual results are
1211 ;; indented by 2 columns.
1212 (list (org-get-indentation)
1213 (progn (forward-line) (org-get-indentation)))))))
1215 (ert-deftest test-ob/safe-header-args ()
1216 "Detect safe and unsafe header args."
1217 (let ((safe-args '((:cache . "foo")
1218 (:results . "output")
1219 (:eval . "never")
1220 (:eval . "query")))
1221 (unsafe-args '((:eval . "yes")
1222 (:results . "output file")
1223 (:foo . "bar")))
1224 (malformed-args '((bar . "foo")
1225 ("foo" . "bar")
1226 :foo))
1227 (safe-p (org-babel-header-args-safe-fn org-babel-safe-header-args)))
1228 (dolist (arg safe-args)
1229 (should (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args)))
1230 (dolist (arg unsafe-args)
1231 (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
1232 (dolist (arg malformed-args)
1233 (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
1234 (should (not (funcall safe-p (append safe-args unsafe-args))))))
1236 (ert-deftest test-ob/noweb-expansions-in-cache ()
1237 "Ensure that noweb expansions are expanded before caching."
1238 (let ((noweb-expansions-in-cache-var 0))
1239 (org-test-with-temp-text "
1240 #+name: foo
1241 #+begin_src emacs-lisp
1242 \"I said\"
1243 #+end_src
1245 #+name: bar
1246 #+begin_src emacs-lisp :noweb yes :cache yes
1247 (setq noweb-expansions-in-cache-var
1248 (+ 1 noweb-expansions-in-cache-var))
1249 (concat <<foo>> \" check noweb expansions\")
1250 #+end_src
1252 ;; run the second block to create the cache
1253 (goto-char (point-min))
1254 (re-search-forward (regexp-quote "#+name: bar"))
1255 (should (string= "I said check noweb expansions"
1256 (org-babel-execute-src-block)))
1257 (should (= noweb-expansions-in-cache-var 1))
1258 ;; change the value of the first block
1259 (goto-char (point-min))
1260 (re-search-forward (regexp-quote "said"))
1261 (goto-char (match-beginning 0))
1262 (insert "haven't ")
1263 (re-search-forward (regexp-quote "#+name: bar"))
1264 (should (string= "I haven't said check noweb expansions"
1265 (org-babel-execute-src-block)))
1266 (should (= noweb-expansions-in-cache-var 2)))))
1268 (ert-deftest test-org-babel/file-ext-and-output-dir ()
1269 (org-test-at-id "93573e1d-6486-442e-b6d0-3fedbdc37c9b"
1270 (org-babel-next-src-block)
1271 (should (equal "file-ext-basic.txt"
1272 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1273 (org-babel-next-src-block)
1274 (should (equal "foo/file-ext-dir-relative.txt"
1275 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1276 (org-babel-next-src-block)
1277 (should (equal "foo/file-ext-dir-relative-slash.txt"
1278 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1279 (org-babel-next-src-block)
1280 (should (equal "/tmp/file-ext-dir-absolute.txt"
1281 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1282 (org-babel-next-src-block)
1283 (should (equal "foo.bar"
1284 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1285 (org-babel-next-src-block)
1286 (should (equal "xxx/foo.bar"
1287 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1290 (ert-deftest test-org-babel/script-escape ()
1291 ;; Delimited lists of numbers
1292 (should (equal '(1 2 3)
1293 (org-babel-script-escape "[1 2 3]")))
1294 (should (equal '(1 2 3)
1295 (org-babel-script-escape "{1 2 3}")))
1296 (should (equal '(1 2 3)
1297 (org-babel-script-escape "(1 2 3)")))
1298 ;; Delimited lists of double-quoted strings
1299 (should (equal '("foo" "bar")
1300 (org-babel-script-escape "(\"foo\" \"bar\")")))
1301 (should (equal '("foo" "bar")
1302 (org-babel-script-escape "[\"foo\" \"bar\"]")))
1303 (should (equal '("foo" "bar")
1304 (org-babel-script-escape "{\"foo\" \"bar\"}")))
1305 ;; ... with commas
1306 (should (equal '("foo" "bar")
1307 (org-babel-script-escape "(\"foo\", \"bar\")")))
1308 (should (equal '("foo" "bar")
1309 (org-babel-script-escape "[\"foo\", \"bar\"]")))
1310 (should (equal '("foo" "bar")
1311 (org-babel-script-escape "{\"foo\", \"bar\"}")))
1312 ;; Delimited lists of single-quoted strings
1313 (should (equal '("foo" "bar")
1314 (org-babel-script-escape "('foo' 'bar')")))
1315 (should (equal '("foo" "bar")
1316 (org-babel-script-escape "['foo' 'bar']")))
1317 (should (equal '("foo" "bar")
1318 (org-babel-script-escape "{'foo' 'bar'}")))
1319 ;; ... with commas
1320 (should (equal '("foo" "bar")
1321 (org-babel-script-escape "('foo', 'bar')")))
1322 (should (equal '("foo" "bar")
1323 (org-babel-script-escape "['foo', 'bar']")))
1324 (should (equal '("foo" "bar")
1325 (org-babel-script-escape "{'foo', 'bar'}")))
1326 ;; Single quoted strings
1327 (should (equal "foo"
1328 (org-babel-script-escape "'foo'")))
1329 ;; ... with internal double quote
1330 (should (equal "foo\"bar"
1331 (org-babel-script-escape "'foo\"bar'")))
1332 ;; ... with internal backslash
1333 (should (equal "foo\\bar"
1334 (org-babel-script-escape "'foo\\bar'")))
1335 ;; ... with internal escaped backslash
1336 (should (equal "foo\\bar"
1337 (org-babel-script-escape "'foo\\\\bar'")))
1338 ;; ... with internal backslash-double quote
1339 (should (equal "foo\\\"bar"
1340 (org-babel-script-escape "'foo\\\"bar'")))
1341 ;; ... with internal escaped backslash-double quote
1342 (should (equal "foo\\\"bar"
1343 (org-babel-script-escape "'foo\\\\\"bar'")))
1344 ;; ... with internal escaped single quote
1345 (should (equal "foo'bar"
1346 (org-babel-script-escape "'foo\\'bar'")))
1347 ;; ... with internal escaped backslash-escaped single quote
1348 (should (equal "foo\\'bar"
1349 (org-babel-script-escape "'foo\\\\\\'bar'")))
1350 ;; Double quoted strings
1351 (should (equal "foo"
1352 (org-babel-script-escape "\"foo\"")))
1353 ;; ... with internal single quote
1354 (should (equal "foo'bar"
1355 (org-babel-script-escape "\"foo'bar\"")))
1356 ;; ... with internal backslash
1357 (should (equal "foo\\bar"
1358 (org-babel-script-escape "\"foo\\bar\"")))
1359 ;; ... with internal escaped backslash
1360 (should (equal "foo\\bar"
1361 (org-babel-script-escape "\"foo\\\\bar\"")))
1362 ;; ... with internal backslash-single quote
1363 (should (equal "foo\\'bar"
1364 (org-babel-script-escape "\"foo\\'bar\"")))
1365 ;; ... with internal escaped backslash-single quote
1366 (should (equal "foo\\'bar"
1367 (org-babel-script-escape "\"foo\\\\'bar\"")))
1368 ;; ... with internal escaped double quote
1369 (should (equal "foo\"bar"
1370 (org-babel-script-escape "\"foo\\\"bar\"")))
1371 ;; ... with internal escaped backslash-escaped double quote
1372 (should (equal "foo\\\"bar"
1373 (org-babel-script-escape "\"foo\\\\\\\"bar\""))))
1375 (provide 'test-ob)
1377 ;;; test-ob ends here