ob-core: Get :noweb-ref from definition instead of point of call
* lisp/ob-core.el (org-babel-expand-noweb-references): Get :noweb-ref from definition instead of point of call. * testing/lisp/test-ob.el (test-ob/noweb-expansion-1): (test-ob/noweb-expansion-2): Merge tests. Add test.
This commit is contained in:
parent
4932e2197a
commit
3acc212c8f
|
@ -2771,7 +2771,8 @@ block but are passed literally to the \"example-block\"."
|
||||||
body)))
|
body)))
|
||||||
(setq expansion (cons sep (cons full expansion)))))
|
(setq expansion (cons sep (cons full expansion)))))
|
||||||
(org-babel-map-src-blocks nil
|
(org-babel-map-src-blocks nil
|
||||||
(let ((i (org-babel-get-src-block-info 'light)))
|
(let ((i (let ((org-babel-current-src-block-location (point)))
|
||||||
|
(org-babel-get-src-block-info 'light))))
|
||||||
(when (equal (or (cdr (assq :noweb-ref (nth 2 i)))
|
(when (equal (or (cdr (assq :noweb-ref (nth 2 i)))
|
||||||
(nth 4 i))
|
(nth 4 i))
|
||||||
source-name)
|
source-name)
|
||||||
|
|
|
@ -668,8 +668,12 @@ x
|
||||||
(check-eval "never-export" nil)
|
(check-eval "never-export" nil)
|
||||||
(check-eval "no-export" nil))))
|
(check-eval "no-export" nil))))
|
||||||
|
|
||||||
(ert-deftest test-ob/noweb-expansion-1 ()
|
(ert-deftest test-ob/noweb-expansion ()
|
||||||
(org-test-with-temp-text "#+begin_src sh :results output :tangle yes
|
;; Standard test.
|
||||||
|
(should
|
||||||
|
(string=
|
||||||
|
"bar"
|
||||||
|
(org-test-with-temp-text "#+begin_src sh :results output :tangle yes
|
||||||
<<foo>>
|
<<foo>>
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
@ -677,10 +681,12 @@ x
|
||||||
#+begin_src sh
|
#+begin_src sh
|
||||||
bar
|
bar
|
||||||
#+end_src"
|
#+end_src"
|
||||||
(should (string= (org-babel-expand-noweb-references) "bar"))))
|
(org-babel-expand-noweb-references))))
|
||||||
|
;; Handle :noweb-sep.
|
||||||
(ert-deftest test-ob/noweb-expansion-2 ()
|
(should
|
||||||
(org-test-with-temp-text "#+begin_src sh :results output :tangle yes
|
(string=
|
||||||
|
"barbaz"
|
||||||
|
(org-test-with-temp-text "#+begin_src sh :results output :tangle yes
|
||||||
<<foo>>
|
<<foo>>
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
@ -692,7 +698,31 @@ x
|
||||||
#+begin_src sh :noweb-ref foo :noweb-sep \"\"
|
#+begin_src sh :noweb-ref foo :noweb-sep \"\"
|
||||||
baz
|
baz
|
||||||
#+end_src"
|
#+end_src"
|
||||||
(should (string= (org-babel-expand-noweb-references) "barbaz"))))
|
(org-babel-expand-noweb-references))))
|
||||||
|
;; :noweb-ref is extracted from definition, not point of call.
|
||||||
|
(should
|
||||||
|
(string=
|
||||||
|
"(+ 1 1)"
|
||||||
|
(org-test-with-temp-text
|
||||||
|
"
|
||||||
|
* Call
|
||||||
|
:PROPERTIES:
|
||||||
|
:header-args: :noweb-ref bar
|
||||||
|
:END:
|
||||||
|
|
||||||
|
<point>#+begin_src emacs-lisp :results output :tangle yes
|
||||||
|
<<foo>>
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
* Evaluation
|
||||||
|
:PROPERTIES:
|
||||||
|
:header-args: :noweb-ref foo
|
||||||
|
:END:
|
||||||
|
|
||||||
|
#+begin_src sh :noweb-sep \"\"
|
||||||
|
(+ 1 1)
|
||||||
|
#+end_src"
|
||||||
|
(org-babel-expand-noweb-references)))))
|
||||||
|
|
||||||
(ert-deftest test-ob/splitting-variable-lists-in-references ()
|
(ert-deftest test-ob/splitting-variable-lists-in-references ()
|
||||||
(org-test-with-temp-text ""
|
(org-test-with-temp-text ""
|
||||||
|
|
Loading…
Reference in New Issue