From 020992b46b5a7c2ae18c677afb5c29c00de58059 Mon Sep 17 00:00:00 2001 From: Mehmet Tekman Date: Tue, 1 Aug 2023 05:14:46 +0200 Subject: [PATCH 1/3] * testing/lisp/test-ob.el: New tests for merge-params (test-ob/get-src-block-property): (test-ob/merge-params): add new tests for the merge-params source block header handling function. (test-ob/merge-params-tangle): add new tests for tangle specific headers. --- testing/lisp/test-ob.el | 146 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index c8dbd44f4..460afbf9b 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -314,6 +314,152 @@ this is simple" (org-babel-next-src-block) (should (= 14 (org-babel-execute-src-block))))) +(defun test-ob/get-src-block-property (properties) + "Get plist of PROPERTIES and values for the first src block in buffer. +PROPERTIES is a list of property keywords or a single keyword." + (org-with-wide-buffer + (goto-char (point-min)) + (org-babel-next-src-block) + (org-set-regexps-and-options) + (let ((all-props (nth 2 (org-babel-get-src-block-info)))) + (if (listp properties) + (apply #'nconc (mapcar (lambda (p) (list p (cdr (assoc p all-props)))) properties)) + (list properties (cdr (assoc properties all-props))))))) + +(ert-deftest test-ob/merge-params() + "Test the output of merging multiple header parameters." + (should + (equal '(:file-mode "#o755") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :file-mode #o755 +* One +#+begin_src conf +#+end_src" + (test-ob/get-src-block-property :file-mode)))) + (should + (equal '(:file-mode "anything" :exports "both") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :file-mode #o755 :exports both +* One +#+begin_src conf :file-mode anything +#+end_src" + (test-ob/get-src-block-property '(:file-mode :exports))))) + (should + (equal '(:mkdirp "no" :dir nil :padline "yes") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :dir /tmp/ :padline no +* One +:PROPERTIES: +:header-args: :mkdirp no +:END: +#+begin_src conf :padline yes +#+end_src" + (test-ob/get-src-block-property '(:mkdirp :dir :padline))))) + (should + (equal '(:results "value code replace file" :file "file") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :results file :file file +* One +#+begin_src conf :results code value +#+end_src" + (test-ob/get-src-block-property '(:results :file))))) + (should + (equal '(:results "value html silent") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :results file +* One +:PROPERTIES: +:header-args: :results html silent +:END: +#+begin_src conf :results value +#+end_src" + (test-ob/get-src-block-property :results))))) + +(ert-deftest test-ob/merge-params-tangle() + "Test the output of merging multiple header parameters." + (should + (equal '(:tangle "/tmp/default_tangle.txt") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should ;; 2. inherit-document-header-with-local-sync-action + (equal '(:tangle "skip") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* Two +#+begin_src conf :tangle skip +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should + (equal '(:tangle "randomfile") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* Three +#+begin_src conf :tangle randomfile +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should + (equal '(:tangle "newfile.txt") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* Four +:PROPERTIES: +:header-args: :tangle \"newfile.txt\" +:END: +** A +#+begin_src conf +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should + (equal '(:tangle "./headfile.txt") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle ./headfile.txt +* Five +:PROPERTIES: +:header-args: :tangle ./headfile.txt +:END: +** A +#+begin_src conf +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should + (equal '(:tangle "yes") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* Eleven +:PROPERTIES: +:header-args: :tangle \"foo.txt\" +:END: +#+begin_src conf :tangle yes +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should + (equal '(:tangle "file with spaces.txt") + (org-test-with-temp-text + "\ +* Twelve +:PROPERTIES: +:header-args: :tangle \"foo.txt\" +:END: +** A +#+begin_src conf :tangle \"file with spaces.txt\" +#+end_src" + (test-ob/get-src-block-property :tangle))))) + (ert-deftest test-ob/inline-src-blocks () (should (= 1 -- 2.41.0