ob-tangle/collect-blocks: Small refactoring and extra commentary
* testing/lisp/test-ob-tangle.el (ob-tangle/collect-blocks): Use `format-spec' instead of `format' for better readability. Add extra comments explaining the logic of testing. Add "." at the end of `lambda' docstrings.
This commit is contained in:
parent
3ee10d57f1
commit
410cecc0e7
|
@ -576,7 +576,8 @@ another block
|
||||||
(test-dir (file-name-directory org-file))
|
(test-dir (file-name-directory org-file))
|
||||||
(el-file-abs (concat (file-name-sans-extension org-file) ".el"))
|
(el-file-abs (concat (file-name-sans-extension org-file) ".el"))
|
||||||
(el-file-rel (file-name-nondirectory el-file-abs)))
|
(el-file-rel (file-name-nondirectory el-file-abs)))
|
||||||
(insert (format "* H1 with :tangle in properties
|
(insert
|
||||||
|
(format-spec "* H1 with :tangle in properties
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:header-args: :tangle relative.el
|
:header-args: :tangle relative.el
|
||||||
:END:
|
:END:
|
||||||
|
@ -593,8 +594,8 @@ another block
|
||||||
\"H1: should be ignored\"
|
\"H1: should be ignored\"
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+begin_src emacs-lisp :tangle %s
|
#+begin_src emacs-lisp :tangle %a
|
||||||
\"H1: absolute org-file.lang-ext :tangle %s\"
|
\"H1: absolute org-file.lang-ext :tangle %a\"
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+begin_src emacs-lisp :tangle relative.el
|
#+begin_src emacs-lisp :tangle relative.el
|
||||||
|
@ -627,8 +628,8 @@ another block
|
||||||
\"H2: should be ignored\"
|
\"H2: should be ignored\"
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+begin_src emacs-lisp :tangle %s
|
#+begin_src emacs-lisp :tangle %r
|
||||||
\"H2: relative org-file.lang-ext :tangle %s\"
|
\"H2: relative org-file.lang-ext :tangle %r\"
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+begin_src emacs-lisp :tangle relative.el
|
#+begin_src emacs-lisp :tangle relative.el
|
||||||
|
@ -645,20 +646,27 @@ another block
|
||||||
|
|
||||||
#+begin_src emacs-lisp :tangle ~/../../tmp/absolute.el
|
#+begin_src emacs-lisp :tangle ~/../../tmp/absolute.el
|
||||||
\"H2: :tangle ~/../../tmp/absolute.el\"
|
\"H2: :tangle ~/../../tmp/absolute.el\"
|
||||||
#+end_src" el-file-abs el-file-abs el-file-rel el-file-rel))
|
#+end_src"
|
||||||
|
`((?a . ,el-file-abs)
|
||||||
|
(?r . ,el-file-rel))))
|
||||||
|
;; We check the collected blocks to tangle by counting equal
|
||||||
|
;; file names in the output of
|
||||||
|
;; `org-babel-tangle-collect-blocks'.
|
||||||
(letrec ((sort-fn (lambda (lst) (seq-sort-by #'car #'string-lessp lst)))
|
(letrec ((sort-fn (lambda (lst) (seq-sort-by #'car #'string-lessp lst)))
|
||||||
(normalize-expected-targets-alist
|
(normalize-expected-targets-alist
|
||||||
(lambda (blocks-per-target-alist)
|
(lambda (blocks-per-target-alist)
|
||||||
"Convert to absolute file names and sort expected targets"
|
"Convert to absolute file names and sort expected targets."
|
||||||
(funcall sort-fn
|
(funcall sort-fn
|
||||||
(map-apply (lambda (file nblocks)
|
(map-apply (lambda (file nblocks)
|
||||||
(cons (expand-file-name file test-dir) nblocks))
|
(cons (expand-file-name file test-dir) nblocks))
|
||||||
blocks-per-target-alist))))
|
blocks-per-target-alist))))
|
||||||
(count-blocks-in-target-files
|
(count-blocks-in-target-files
|
||||||
(lambda (collected-blocks)
|
(lambda (collected-blocks)
|
||||||
"Get sorted alist of target file names with number of blocks in each"
|
"Get sorted alist of target file names with number of blocks in each."
|
||||||
(funcall sort-fn (map-apply (lambda (file blocks)
|
(funcall sort-fn (map-apply (lambda (file blocks)
|
||||||
|
;; Blocks are grouped by file name.
|
||||||
(cons file (length blocks)))
|
(cons file (length blocks)))
|
||||||
|
;; From `org-babel-tangle-collect-blocks'.
|
||||||
collected-blocks)))))
|
collected-blocks)))))
|
||||||
(should (equal (funcall normalize-expected-targets-alist
|
(should (equal (funcall normalize-expected-targets-alist
|
||||||
`(("/tmp/absolute.el" . 4)
|
`(("/tmp/absolute.el" . 4)
|
||||||
|
|
Loading…
Reference in New Issue