diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index c8dbd44f4..de92cb90b 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -314,6 +314,147 @@ (ert-deftest test-ob/parse-header-args2 () (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. The +expected output is given in the contents of the source code block +in each test. The desired test header parameters are given +either as a symbol or a list in the `idtest-alist' variable. +Multiple header parameters must be separated by a newline and +exactly two spaces in the block contents." + (should ;; 1. inherit-document-header-args + (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 "/tmp/default_tangle.txt skip") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle skip +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should ;; 3. override-document-header-with-local-tfile + (equal '(:tangle "randomfile sync") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle randomfile sync +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should ;; 4. override-document-and-parent-header-with-local-tfile-and-action + (equal '(:tangle "randomfile sync") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +:PROPERTIES: +:header-args: :tangle \"newfile.txt\" import +:END: +** Two +#+begin_src conf :tangle randomfile sync +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should ;; 5. test-tangle-and-default-results-param-together + (equal '(:tangle "randomfile" :results "replace") + (org-test-with-temp-text + "\ +* One +#+begin_src conf :tangle randomfile +#+end_src" + (test-ob/get-src-block-property '(:tangle :results))))) + (should ;; 6. inherit-document-tfile-take-only-last-local-sync-action + (equal '(:tangle "/tmp/default_tangle.txt export") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle import export +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should ;; 7. ignore-document-header-take-last-tfile-and-sync-action + (equal '(:tangle "fname2 export") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle fname1 fname2 sync export +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should ;; 8. test-results-and-exports + (equal '(:results "wrap file replace" :exports "code") + (org-test-with-temp-text + "\ +* One +#+begin_src sh :results file wrap +#+end_src" + (test-ob/get-src-block-property '(:results :exports))))) + (should-not ;; 9. do-not-tangle-this-block -- + (equal '(:tangle "no") + ;; THIS SHOULD NOT FAIL WITH NEW MERGE FUNCTION. + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle no +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should ;; 10. test-tangle-exports-and-comments + (equal '(:tangle "foo.txt" :exports "verbatim code" :comments "link") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +:PROPERTIES: +:header-args: :tangle no :exports verbatim +:END: +#+begin_src conf :tangle \"foo.txt\" :comments link +#+end_src" + (test-ob/get-src-block-property '(:tangle :exports :comments))))) + (should ;; 11. override-document-and-heading-tfile-with-yes + (equal '(:tangle "foo.txt") + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +:PROPERTIES: +:header-args: :tangle \"foo.txt\" +:END: +#+begin_src conf :tangle yes +#+end_src" + (test-ob/get-src-block-property :tangle)))) + (should-not ;; 12. tangle-file-with-spaces + ;; THIS SHOULD NOT FAIL WITH NEW MERGE FUNCTION. + (equal '(:tangle "file with spaces.txt") + (org-test-with-temp-text + "\ +* One +:PROPERTIES: +:header-args: :tangle \"foo.txt\" +:END: +** Two +#+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