diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 78cd29576..b6e42dc99 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -8236,6 +8236,72 @@ two (call-interactively #'org-paste-subtree) (buffer-string))))) +(ert-deftest org-test/org--open-file-format-spec () + "Test `org-open-file' helper `org--open-file-format-spec'." + (let ((def-spec '(("s" . "file.pdf") ("1" . "10") ("2" . "pattern")))) + (should (equal "zathura --page 10 --find pattern file.pdf" + (org--open-file-format-spec + "zathura --page %1 --find %2 %s" def-spec))) + (should (equal "no subst" + (org--open-file-format-spec + "no subst" def-spec))) + (should (equal "simple file.pdf" + (org--open-file-format-spec + "simple %s" def-spec))) + (should (equal "with --page 10 file.pdf" + (org--open-file-format-spec + "with --page %1 %s" def-spec))) + (should (equal "file.pdf at start" + (org--open-file-format-spec + "%s at start" def-spec))) + (should (equal "in the file.pdf middle" + (org--open-file-format-spec + "in the %s middle" def-spec))) + (should (equal "literal %" + (org--open-file-format-spec + "literal %%" def-spec))) + (should (equal "literal %s in the middle" + (org--open-file-format-spec + "literal %%s in the middle" def-spec))) + (should (equal "% literal at start" + (org--open-file-format-spec + "%% literal at start" def-spec))) + (should (equal "" (org--open-file-format-spec "" def-spec))) + (should (equal "adjucent 10file.pdf substitutions" + (org--open-file-format-spec + "adjucent %1%s substitutions" def-spec)))) + + (should (equal "many -f first -s second -t third -e eigth file.pdf" + (org--open-file-format-spec + "many -f %1 -s %2 -t %3 -e %8 %s" + '(("1" . "first") ("2" . "second") ("3" . "third") + ("4" . "fourth") ("5" . "firth") ("6" . "sixth") + ("7" . "seventh") ("8" . "eigth") ("s" . "file.pdf"))))) + + ;; I am afraid to add recursive substitutions like ("%s" . "recursive %s"). + (should (equal "no-recursion-with file-%1.pdf --page 10" + (org--open-file-format-spec + "no-recursion-with %s --page %1" + '(("s" . "file-%1.pdf") ("1" . "10"))))) + (should (equal "no-recursion-with --search printf-%s file.pdf" + (org--open-file-format-spec + "no-recursion-with --search %1 %s" + '(("s" . "file.pdf") ("1" . "printf-%s"))))) + + (let* ((err + (should-error (org--open-file-format-spec "invalid-end %" ()) + :type 'error)) + (text (cadr err))) + (should (and (stringp text) + (string-match-p "’invalid-end %’" text)))) + (let* ((err + (should-error (org--open-file-format-spec "missed --subst %1 %s" + '(("s" . "file.pdf"))) + :type 'error)) + (text (cadr err))) + (should (and (stringp text) + (string-match-p "’missed --subst %1 %s’" text))))) + (provide 'test-org) ;;; test-org.el ends here