1 ;;; test-ob.el --- tests for ob.el
3 ;; Copyright (c) 2010-2012 Eric Schulte
4 ;; Authors: Eric Schulte, Martyn Jago
6 ;; Released under the GNU General Public License version 3
7 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
9 (let ((load-path (cons (expand-file-name
10 ".." (file-name-directory
11 (or load-file-name buffer-file-name
)))
14 (require 'org-test-ob-consts
))
16 (ert-deftest test-org-babel
/multi-line-header-regexp
()
17 (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
18 org-babel-multi-line-header-regexp
))
19 ;;TODO can be optimised - and what about blah4 blah5 blah6?
21 org-babel-multi-line-header-regexp
22 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))
25 "blah1 blah2 blah3 \t"
28 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n")))
30 ;;TODO Check - should this fail?
32 (not (org-test-string-exact-match
33 org-babel-multi-line-header-regexp
34 " \t #+headers : blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))))
36 (ert-deftest test-org-babel
/src-block-regexp
()
39 "#+begin_src language -n-r-a-b -c :argument-1 yes :argument-2 no\n"
40 "echo this is a test\n"
41 "echo Currently in ' $PWD\n"
44 (flags "-n-r-a-b -c ")
45 (arguments ":argument-1 yes :argument-2 no")
46 (body "echo this is a test\necho Currently in ' $PWD\n"))
47 (should (string-match org-babel-src-block-regexp test-block
))
48 (should (string-match org-babel-src-block-regexp
(upcase test-block
)))
49 (should (equal language
(match-string 2 test-block
)))
50 ;;TODO Consider refactoring
51 (should (equal flags
(match-string 3 test-block
)))
52 (should (equal arguments
(match-string 4 test-block
)))
53 (should (equal body
(match-string 5 test-block
)))
55 (should (org-test-string-exact-match
56 org-babel-src-block-regexp
57 (replace-regexp-in-string flags
"" test-block
)))
59 (should (org-test-string-exact-match
60 org-babel-src-block-regexp
61 (replace-regexp-in-string arguments
"" test-block
)))
62 ;; should be valid with no body
63 (should (org-test-string-exact-match
64 org-babel-src-block-regexp
65 (replace-regexp-in-string body
"" test-block
)))))
67 (ert-deftest test-org-babel
/get-header
()
68 (should (not (org-babel-get-header
69 org-babel-default-header-args
:doesnt-exist
)))
70 (should(equal '((:session .
"none"))
72 org-babel-default-header-args
:session
)))
73 (should(equal '((:session .
"none"))
75 org-babel-default-header-args
:session nil
)))
76 (should (not (org-babel-get-header
77 org-babel-default-header-args
:SESSION
)))
78 (should (equal '((:tangle .
"no"))
80 org-babel-default-header-args
:tangle
)))
82 (should (equal org-babel-default-header-args
84 org-babel-default-header-args
:doesnt-exist
'others
)))
85 (should (equal org-babel-default-header-args
87 org-babel-default-header-args nil
'others
)))
91 org-babel-default-header-args
:noweb
'others
)))))
93 (ert-deftest test-org-babel
/default-inline-header-args
()
95 '((:session .
"none") (:results .
"replace") (:exports .
"results"))
96 org-babel-default-inline-header-args
)))
98 ;;; ob-get-src-block-info
99 (ert-deftest test-org-babel
/get-src-block-info-language
()
100 (org-test-at-marker nil org-test-file-ob-anchor
101 (let ((info (org-babel-get-src-block-info)))
102 (should (string= "emacs-lisp" (nth 0 info
))))))
104 (ert-deftest test-org-babel
/get-src-block-info-body
()
105 (org-test-at-marker nil org-test-file-ob-anchor
106 (let ((info (org-babel-get-src-block-info)))
107 (should (string-match (regexp-quote org-test-file-ob-anchor
)
110 (ert-deftest test-org-babel
/get-src-block-info-tangle
()
111 (org-test-at-marker nil org-test-file-ob-anchor
112 (let ((info (org-babel-get-src-block-info)))
113 (should (string= "no" (cdr (assoc :tangle
(nth 2 info
))))))))
115 (ert-deftest test-org-babel
/elisp-in-header-arguments
()
116 "Test execution of elisp forms in header arguments."
117 (org-test-with-temp-text-in-file "
119 * elisp forms in header arguments
123 #+begin_src emacs-lisp
128 (goto-char (point-min))
129 (org-babel-next-src-block)
130 (let ((info (org-babel-get-src-block-info)))
131 (should (= 42 (org-babel-execute-src-block)))))))
133 (ert-deftest test-org-babel
/simple-named-code-block
()
134 "Test that simple named code blocks can be evaluated."
135 (org-test-with-temp-text-in-file "
137 #+name: i-have-a-name
138 #+begin_src emacs-lisp
143 (org-babel-next-src-block 1)
144 (should (= 42 (org-babel-execute-src-block))))))
146 (ert-deftest test-org-babel
/simple-variable-resolution
()
147 "Test that simple variable resolution is working."
148 (org-test-with-temp-text-in-file "
151 #+begin_src emacs-lisp
155 #+begin_src emacs-lisp :var four=four
160 (org-babel-next-src-block 2)
161 (should (= 4 (org-babel-execute-src-block)))
163 (should (string= ": 4" (buffer-substring
167 (ert-deftest test-org-babel
/multi-line-header-arguments
()
168 "Test that multi-line header arguments and can be read."
169 (org-test-with-temp-text-in-file "
171 #+headers: :var letters='(a b c d e f g)
172 #+begin_src emacs-lisp :var numbers='(1 2 3 4 5 6 7)
173 (map 'list #'list numbers letters)
177 (org-babel-next-src-block)
178 (let ((results (org-babel-execute-src-block)))
179 (should(equal 'a
(cadr (assoc 1 results
))))
180 (should(equal 'd
(cadr (assoc 4 results
))))))))
182 (ert-deftest test-org-babel
/parse-header-args
()
183 (org-test-with-temp-text-in-file "
185 #+begin_src example-lang :session :results output :var num=9
190 (org-babel-next-src-block)
191 (let* ((info (org-babel-get-src-block-info))
192 (params (nth 2 info
)))
193 (message "%S" params
)
194 (should(equal "example-lang" (nth 0 info
)))
195 (should(string= "the body" (org-babel-trim (nth 1 info
))))
196 (should-not (member '(:session\ \ \ \
) params
))
197 (should(equal '(:session
) (assoc :session params
)))
198 (should(equal '(:result-type . output
) (assoc :result-type params
)))
199 (should(equal '(num .
9) (cdr (assoc :var params
))))))))
201 (ert-deftest test-org-babel
/parse-header-args2
()
202 (org-test-with-temp-text-in-file "
204 * resolving sub-trees as references
206 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
210 #+begin_src org :noweb yes
212 <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
215 ** simple subtree with custom ID
217 :CUSTOM_ID: simple-subtree
222 (should (string-match (regexp-quote "this is simple")
223 (org-babel-ref-resolve "simple-subtree")))
224 (org-babel-next-src-block)
225 (should (= 14 (org-babel-execute-src-block))))))
227 (ert-deftest test-org-babel
/inline-src-blocks
()
228 (org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
229 (macrolet ((at-next (&rest body
)
232 (re-search-forward org-babel-inline-src-block-regexp nil t
)
233 (goto-char (match-beginning 1))
234 (save-match-data ,@body
))))
235 (at-next (should (equal 1 (org-babel-execute-src-block))))
236 (at-next (should (equal 2 (org-babel-execute-src-block))))
237 (at-next (should (equal 3 (org-babel-execute-src-block)))))))
239 (ert-deftest test-org-babel
/org-babel-get-inline-src-block-matches
()
240 (org-test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74"
241 (let ((test-point (point)))
242 (should (fboundp 'org-babel-get-inline-src-block-matches
))
243 (should (re-search-forward "src_" nil t
)) ;; 1
244 (should (org-babel-get-inline-src-block-matches))
245 (should (re-search-forward "}" nil
(point-at-bol))) ;; 1
246 (should-not (org-babel-get-inline-src-block-matches))
247 (should (re-search-forward "in" nil t
)) ;; 2
248 (should-not (org-babel-get-inline-src-block-matches))
249 (should (re-search-forward "echo" nil t
)) ;; 2
250 (should (org-babel-get-inline-src-block-matches))
251 (should (re-search-forward "blocks" nil t
)) ;; 3
252 (backward-char 8) ;; 3
253 (should (org-babel-get-inline-src-block-matches))
255 (should-not (org-babel-get-inline-src-block-matches))
256 (should (re-search-forward ":results" nil t
)) ;; 4
257 (should (org-babel-get-inline-src-block-matches))
259 (should-not (org-babel-get-inline-src-block-matches)))))
261 (ert-deftest test-org-babel
/inline-src_blk-default-results-replace-line-1
()
262 (let ((test-line "src_sh{echo 1}"))
263 ;; src_ at bol line 1...
264 (org-test-with-temp-text
266 (goto-char (point-min)) (org-ctrl-c-ctrl-c)
268 (concat test-line
" =1=")
269 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
270 (forward-char) (org-ctrl-c-ctrl-c)
272 (concat test-line
" =1= =1=")
273 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
274 (re-search-forward "1}")
275 (should-error (org-ctrl-c-ctrl-c))
276 (backward-char) ;; last char of block body
279 (concat test-line
" =1= =1= =1=")
280 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
281 ;; src_ follows space line 1...
282 (let ((test-line " src_emacs-lisp{ 1 }"))
283 (org-test-with-temp-text
285 (should-error (org-ctrl-c-ctrl-c))
286 (forward-char) (org-ctrl-c-ctrl-c)
288 (concat test-line
" =1=")
289 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
290 (re-search-forward "{ 1 ") (org-ctrl-c-ctrl-c)
292 (concat test-line
" =1= =1=")
293 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
295 (should-error (org-ctrl-c-ctrl-c)))))
297 (ert-deftest test-org-babel
/inline-src_blk-default-results-replace-line-2
()
298 ;; src_ at bol line 2...
299 (let ((test-line " src_emacs-lisp{ \"x\" }"))
300 (org-test-with-temp-text
301 (concat "\n" test-line
)
302 (should-error (org-ctrl-c-ctrl-c))
303 (goto-char (point-min))
304 (should-error (org-ctrl-c-ctrl-c))
306 (should-error (org-ctrl-c-ctrl-c))
307 (forward-char) (org-ctrl-c-ctrl-c)
309 (concat test-line
" =x=")
310 (buffer-substring-no-properties
311 (point-at-bol) (point-at-eol))))))
313 (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }"))
314 (org-test-with-temp-text
316 (goto-char (point-max))
317 (insert (concat "\n" test-line
" end"))
318 (re-search-backward "src") (org-ctrl-c-ctrl-c)
320 (concat test-line
" =y= end")
321 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
322 (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
324 (concat test-line
" =y= =y= end")
325 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
327 (should-error (org-ctrl-c-ctrl-c))))))
329 (ert-deftest test-org-babel
/inline-src_blk-manual-results-replace
()
330 (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }"))
331 (org-test-with-temp-text
332 (concat "\n" test-line
)
333 (should-error (org-ctrl-c-ctrl-c))
334 (goto-char (point-max))
335 (should-error (org-ctrl-c-ctrl-c))
337 (should-error (org-ctrl-c-ctrl-c))
338 (forward-char) (org-ctrl-c-ctrl-c)
340 (concat test-line
" =x=")
341 (buffer-substring-no-properties
342 (point-at-bol) (point-at-eol))))))
344 (let ((test-line (concat " Some text prior to block "
345 "src_emacs-lisp[:results replace]{ \"y\" }")))
346 (org-test-with-temp-text test-line
347 (goto-char (point-max))
348 (insert (concat "\n" test-line
" end"))
349 (re-search-backward "src") (org-ctrl-c-ctrl-c)
351 (concat test-line
" =y= end")
352 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
353 (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
355 (concat test-line
" =y= =y= end")
356 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
358 (should-error (org-ctrl-c-ctrl-c)))))
360 (ert-deftest test-org-babel
/inline-src_blk-results-silent
()
361 (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
362 (org-test-with-temp-text test-line
364 (should (string= test-line
365 (buffer-substring-no-properties
366 (point-at-bol) (point-at-eol))))
368 (should-error (org-ctrl-c-ctrl-c))))
369 (let ((test-line (concat " Some text prior to block src_emacs-lisp"
370 "[ :results silent ]{ \"y\" }")))
371 (org-test-with-temp-text
373 (goto-char (point-max))
374 (insert (concat "\n" test-line
" end"))
375 (re-search-backward "src_") (org-ctrl-c-ctrl-c)
376 (should (string= (concat test-line
" end")
377 (buffer-substring-no-properties
378 (point-at-bol) (point-at-eol))))
379 (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
380 (should (string= (concat test-line
" end")
381 (buffer-substring-no-properties
382 (point-at-bol) (point-at-eol))))
384 (should-error (org-ctrl-c-ctrl-c)))))
386 (ert-deftest test-org-babel
/inline-src_blk-results-raw
()
387 (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
388 (org-test-with-temp-text test-line
390 (should (string= (concat test-line
" x")
392 (let ((test-line (concat " Some text prior to block "
393 "src_emacs-lisp[ :results raw ]{ \"the\" }")))
394 (org-test-with-temp-text (concat test-line
" end")
395 (re-search-forward "src_") (org-ctrl-c-ctrl-c)
396 (should (string= (concat test-line
" the end")
397 (buffer-substring-no-properties
398 (point-at-bol) (point-at-eol))))
399 (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
400 (should (string= (concat test-line
" the the end")
401 (buffer-substring-no-properties
402 (point-at-bol) (point-at-eol))))
404 (should-error (org-ctrl-c-ctrl-c)))))
406 (ert-deftest test-org-babel
/inline-src_blk-results-file
()
407 (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\" }"))
408 (org-test-with-temp-text
411 (should (string= (concat test-line
" [[file:~/test-file]]")
412 (buffer-substring-no-properties
413 (point-min) (point-max)))))))
415 (ert-deftest test-org-babel
/inline-src_blk-results-scalar
()
416 (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\" }"))
417 (org-test-with-temp-text
420 (should (string= (concat test-line
" =\"x\"=")
421 (buffer-substring-no-properties
422 (point-min) (point-max)))))))
424 (ert-deftest test-org-babel
/inline-src_blk-results-verbatim
()
425 (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\" }"))
426 (org-test-with-temp-text
429 (should (string= (concat test-line
" =\"x\"=")
430 (buffer-substring-no-properties
431 (point-min) (point-max)))))))
433 (ert-deftest test-org-babel
/combining-scalar-and-raw-result-types
()
434 (org-test-with-temp-text-in-file "
436 #+begin_src sh :results scalar
437 echo \"[[file:./cv.cls]]\"
443 #+begin_src sh :results raw scalar
444 echo \"[[file:./cv.cls]]\"
447 (flet ((next-result ()
448 (org-babel-next-src-block)
449 (org-babel-execute-src-block)
450 (goto-char (org-babel-where-is-src-block-result))
452 (goto-char (point-min))
454 (should (org-babel-in-example-or-verbatim))
456 (should (not (org-babel-in-example-or-verbatim))))))
458 (ert-deftest test-org-babel
/no-defaut-value-for-var
()
459 "Test that the absence of a default value for a variable DOES THROW
461 (org-test-at-id "f2df5ba6-75fa-4e6b-8441-65ed84963627"
462 (org-babel-next-src-block)
464 (should-error (org-babel-execute-src-block) :type
'error
)))
468 "variable \"x\" in block \"carre\" must be assigned a default value")
471 (ert-deftest test-org-babel
/just-one-results-block
()
472 "Test that evaluating two times the same code block does not result in a
473 duplicate results block."
474 (org-test-with-temp-text "#+begin_src sh\necho Hello\n#+end_src\n"
475 (org-babel-execute-src-block)
476 (org-babel-execute-src-block) ; second code block execution
477 (should (search-forward "Hello")) ; the string inside the source code block
478 (should (search-forward "Hello")) ; the same string in the results block
479 (should-error (search-forward "Hello"))))
481 (ert-deftest test-org-babel
/nested-code-block
()
482 "Test nested code blocks inside code blocks don't cause problems."
483 (org-test-with-temp-text "#+begin_src org :results silent
484 ,#+begin_src emacs-lisp
488 (should (string= (org-babel-execute-src-block)
489 "#+begin_src emacs-lisp\n 'foo\n#+end_src"))))
491 (ert-deftest test-org-babel
/partial-nested-code-block
()
492 "Test nested code blocks inside code blocks don't cause problems."
493 (org-test-with-temp-text "#+begin_src org :results silent
494 ,#+begin_src emacs-lisp
496 (should (string= "#+begin_src emacs-lisp" (org-babel-execute-src-block)))))
498 (ert-deftest test-ob
/does-not-replace-a-block-with-the-results
()
499 (org-test-with-temp-text "#+NAME: foo
500 #+BEGIN_SRC emacs-lisp
503 (org-babel-next-src-block 1)
504 (should (eq 'foo
(org-babel-execute-src-block)))
505 (goto-char (point-min))
506 (org-babel-next-src-block 1)
507 (should (looking-at org-babel-src-block-regexp
))))
509 (ert-deftest test-ob
/catches-all-references
()
510 (org-test-with-temp-text "
511 #+NAME: literal-example
517 #+NAME: read-literal-example
518 #+BEGIN_SRC emacs-lisp :var x=literal-example
519 (concatenate 'string x \" for me.\")
521 (org-babel-next-src-block 1)
522 (should (string= (org-babel-execute-src-block)
523 "A literal example\non two lines for me."))))
525 (ert-deftest test-ob
/resolve-code-blocks-before-data-blocks
()
526 (org-test-with-temp-text "
531 #+begin_src emacs-lisp
535 #+begin_src emacs-lisp :var foo=foo
538 (org-babel-next-src-block 2)
539 (should (string= (org-babel-execute-src-block) "baz"))))
541 (ert-deftest test-ob
/do-not-resolve-to-partial-names-data
()
542 (org-test-with-temp-text "
551 #+begin_src emacs-lisp :var x=base
554 (org-babel-next-src-block 1)
555 (should (equal (org-babel-execute-src-block) '((3) (4))))))
557 (ert-deftest test-ob
/do-not-resolve-to-partial-names-code
()
558 (org-test-with-temp-text "
560 #+begin_src emacs-lisp
565 #+begin_src emacs-lisp
569 #+begin_src emacs-lisp :var x=base
572 (org-babel-next-src-block 3)
573 (should (equal (org-babel-execute-src-block) "foo"))))
575 (ert-deftest test-ob
/allow-spaces-around-
=-in-var-specs
()
576 (org-test-with-temp-text "#+begin_src emacs-lisp :var a = 1 b = 2 c= 3 d =4
580 (should (= 10 (org-babel-execute-src-block)))))
582 (ert-deftest test-ob
/org-babel-update-intermediate
()
583 (org-test-with-temp-text "#+name: foo
584 #+begin_src emacs-lisp
591 #+begin_src emacs-lisp :var it=foo
594 (let ((org-babel-update-intermediate nil
))
595 (goto-char (point-min))
596 (org-babel-next-src-block 2)
597 (should (= 3 (org-babel-execute-src-block)))
598 (goto-char (point-min))
600 (should (looking-at ": 4")))
601 (let ((org-babel-update-intermediate t
))
602 (goto-char (point-min))
603 (org-babel-next-src-block 2)
604 (should (= 3 (org-babel-execute-src-block)))
605 (goto-char (point-min))
607 (should (looking-at ": 2")))))
609 (ert-deftest test-ob
/eval-header-argument
()
610 (flet ((check-eval (eval runp
)
611 (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
614 (let ((foo :not-run
))
616 (progn (should (org-babel-execute-src-block))
617 (should (eq foo
:evald
)))
618 (progn (should-not (org-babel-execute-src-block))
619 (should-not (eq foo
:evald
))))))))
620 (check-eval "never" nil
)
621 (check-eval "no" nil
)
622 (check-eval "never-export" t
)
623 (check-eval "no-export" t
)
624 (let ((org-current-export-file "something"))
625 (check-eval "never" nil
)
626 (check-eval "no" nil
)
627 (check-eval "never-export" nil
)
628 (check-eval "no-export" nil
))))
630 (ert-deftest test-ob
/noweb-expansion-1
()
631 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
639 (should (string= (org-babel-expand-noweb-references) "bar"))))
641 (ert-deftest test-ob
/noweb-expansion-2
()
642 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
647 #+begin_src sh :noweb-sep \"\"
651 #+begin_src sh :noweb-ref foo :noweb-sep \"\"
654 (should (string= (org-babel-expand-noweb-references) "barbaz"))))
656 (ert-deftest test-ob
/splitting-variable-lists-in-references
()
657 (org-test-with-temp-text ""
658 (should (= 1 (length (org-babel-ref-split-args
659 "a=\"this, no work\""))))
660 (should (= 2 (length (org-babel-ref-split-args
661 "a=\"this, no work\", b=1"))))))
663 (ert-deftest test-ob
/org-babel-balanced-split
()
665 '(":a 1" "b [2 3]" "c (4 :d (5 6))")
666 (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))"
669 (ert-deftest test-ob
/commented-last-block-line-no-var
()
670 (org-test-with-temp-text-in-file "
671 #+begin_src emacs-lisp
675 (org-babel-next-src-block)
677 (should (re-search-forward "\\#\\+results:" nil t
))
682 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
683 (org-test-with-temp-text-in-file "
684 #+begin_src emacs-lisp
689 (org-babel-next-src-block)
691 (should (re-search-forward "\\#\\+results:" nil t
))
696 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
698 (ert-deftest test-ob
/commented-last-block-line-with-var
()
699 (org-test-with-temp-text-in-file "
700 #+begin_src emacs-lisp :var a=1
704 (org-babel-next-src-block)
706 (re-search-forward "\\#\\+results:" nil t
)
710 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
711 (org-test-with-temp-text-in-file "
712 #+begin_src emacs-lisp :var a=2
716 (org-babel-next-src-block)
718 (re-search-forward "\\#\\+results:" nil t
)
722 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
724 (defun test-ob-verify-result-and-removed-result (result buffer-text
)
725 "Test helper function to test `org-babel-remove-result'.
726 A temp buffer is populated with BUFFER-TEXT, the first block is executed,
727 and the result of execution is verified against RESULT.
729 The block is actually executed /twice/ to ensure result
730 replacement happens correctly."
731 (org-test-with-temp-text
734 (org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
735 (should (re-search-forward "\\#\\+results:" nil t
))
737 (should (string= result
738 (buffer-substring-no-properties
740 (- (point-max) 16))))
741 (org-babel-previous-src-block) (org-babel-remove-result)
742 (should (string= buffer-text
743 (buffer-substring-no-properties
744 (point-min) (point-max)))))))
746 (ert-deftest test-ob
/org-babel-remove-result--results-default
()
747 "Test `org-babel-remove-result' with default :results."
748 (mapcar (lambda (language)
749 (test-ob-verify-result-and-removed-result
752 "* org-babel-remove-result
753 #+begin_src " language
"
757 '("sh" "emacs-lisp")))
759 (ert-deftest test-ob
/org-babel-remove-result--results-list
()
760 "Test `org-babel-remove-result' with :results list."
761 (test-ob-verify-result-and-removed-result
767 "* org-babel-remove-result
768 #+begin_src emacs-lisp :results list
774 (ert-deftest test-ob
/org-babel-remove-result--results-wrap
()
775 "Test `org-babel-remove-result' with :results wrap."
776 (test-ob-verify-result-and-removed-result
781 "* org-babel-remove-result
783 #+begin_src emacs-lisp :results wrap
789 (ert-deftest test-ob
/org-babel-remove-result--results-org
()
790 "Test `org-babel-remove-result' with :results org."
791 (test-ob-verify-result-and-removed-result
798 "* org-babel-remove-result
799 #+begin_src emacs-lisp :results org
807 (ert-deftest test-ob
/org-babel-remove-result--results-html
()
808 "Test `org-babel-remove-result' with :results html."
809 (test-ob-verify-result-and-removed-result
811 <head><body></body></head>
814 "* org-babel-remove-result
815 #+begin_src emacs-lisp :results html
816 \"<head><body></body></head>\"
821 (ert-deftest test-ob
/org-babel-remove-result--results-latex
()
822 "Test `org-babel-remove-result' with :results latex."
823 (test-ob-verify-result-and-removed-result
830 "* org-babel-remove-result
831 #+begin_src emacs-lisp :results latex
839 (ert-deftest test-ob
/org-babel-remove-result--results-code
()
840 "Test `org-babel-remove-result' with :results code."
842 (test-ob-verify-result-and-removed-result
843 "#+BEGIN_SRC emacs-lisp
847 "* org-babel-remove-result
848 #+begin_src emacs-lisp :results code
849 (message \"I am working!\")
854 (ert-deftest test-ob
/org-babel-remove-result--results-pp
()
855 "Test `org-babel-remove-result' with :results pp."
856 (test-ob-verify-result-and-removed-result
857 ": \"I /am/ working!\""
859 "* org-babel-remove-result
860 #+begin_src emacs-lisp :results pp
866 (ert-deftest test-org-babel
/inline-src_blk-preceded-punct-preceded-by-point
()
867 (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }"))
868 (org-test-with-temp-text
872 (should (string= (concat test-line
" =\"x\"=")
873 (buffer-substring-no-properties
874 (point-min) (point-max)))))))
876 (ert-deftest test-org-babel
/inline-src-block-preceded-by-equality
()
877 (let ((test-line "=src_emacs-lisp[ :results verbatim ]{ \"x\" }"))
878 (org-test-with-temp-text
882 (should (string= (concat test-line
" =\"x\"=")
883 (buffer-substring-no-properties
884 (point-min) (point-max)))))))
886 (ert-deftest test-org-babel
/inline-src-block-enclosed-within-parenthesis
()
887 (let ((test-line "(src_emacs-lisp[ :results verbatim ]{ \"x\" }"))
888 (org-test-with-temp-text
889 (concat test-line
")")
892 (should (string= (concat test-line
" =\"x\"=)" )
893 (buffer-substring-no-properties
894 (point-min) (point-max)))))))
896 (ert-deftest test-org-babel
/inline-src-block-enclosed-within-parenthesis
()
897 (let ((test-line "{src_emacs-lisp[ :results verbatim ]{ \"x\" }"))
898 (org-test-with-temp-text
899 (concat test-line
"}")
902 (should (string= (concat test-line
" =\"x\"=}")
903 (buffer-substring-no-properties
904 (point-min) (point-max)))))))
906 (ert-deftest test-org-babel
/inline-src_blk-preceded-by-letter
()
907 "Test inline source block invalid where preceded by letter"
909 ;; inline-src-blk preceded by letter
910 (org-test-with-temp-text
911 "asrc_emacs-lisp[ :results verbatim ]{ \"x\" }"
915 (org-ctrl-c-ctrl-c))))
916 (should (equal `(error "C-c C-c can do nothing useful at this location")
919 (ert-deftest test-org-babel
/inline-src_blk-preceded-by-number
()
920 "Test inline source block invalid where preceded by number"
922 ;; inline-src-blk preceded by number
923 (org-test-with-temp-text
924 "0src_emacs-lisp[ :results verbatim ]{ \"x\" }"
928 (org-ctrl-c-ctrl-c))))
929 (should (equal `(error "C-c C-c can do nothing useful at this location")
934 ;;; test-ob ends here