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:
Nicolas Goaziou 2017-12-20 13:06:52 +01:00
parent 4932e2197a
commit 3acc212c8f
2 changed files with 39 additions and 8 deletions

View File

@ -2771,7 +2771,8 @@ block but are passed literally to the \"example-block\"."
body)))
(setq expansion (cons sep (cons full expansion)))))
(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)))
(nth 4 i))
source-name)

View File

@ -668,8 +668,12 @@ x
(check-eval "never-export" nil)
(check-eval "no-export" nil))))
(ert-deftest test-ob/noweb-expansion-1 ()
(org-test-with-temp-text "#+begin_src sh :results output :tangle yes
(ert-deftest test-ob/noweb-expansion ()
;; Standard test.
(should
(string=
"bar"
(org-test-with-temp-text "#+begin_src sh :results output :tangle yes
<<foo>>
#+end_src
@ -677,10 +681,12 @@ x
#+begin_src sh
bar
#+end_src"
(should (string= (org-babel-expand-noweb-references) "bar"))))
(ert-deftest test-ob/noweb-expansion-2 ()
(org-test-with-temp-text "#+begin_src sh :results output :tangle yes
(org-babel-expand-noweb-references))))
;; Handle :noweb-sep.
(should
(string=
"barbaz"
(org-test-with-temp-text "#+begin_src sh :results output :tangle yes
<<foo>>
#+end_src
@ -692,7 +698,31 @@ x
#+begin_src sh :noweb-ref foo :noweb-sep \"\"
baz
#+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 ()
(org-test-with-temp-text ""