From f6891e33522c1ec321d01d8c3986fbf789c79224 Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Fri, 20 Oct 2023 17:10:36 +0700 Subject: [PATCH 1/3] test-ox-ascii.el: Test custom links * testing/lisp/test-ox-ascii.el (test-ox-ascii--restore-syntax) (test-ox-ascii--link-export-inline): Helper functions. (test-ox-ascii/link-custom-protocol-fallback) (test-ox-ascii/link-custom-protocol-string): Test export of custom link types having the :export parameters or relying on format provided by default when `org-ascii-links-to-notes' enabled or disabled. --- testing/lisp/test-ox-ascii.el | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/testing/lisp/test-ox-ascii.el b/testing/lisp/test-ox-ascii.el index fe12c0c27..07def1633 100644 --- a/testing/lisp/test-ox-ascii.el +++ b/testing/lisp/test-ox-ascii.el @@ -27,7 +27,91 @@ (require 'ox-ascii nil t) (unless (featurep 'ox-ascii) (signal 'missing-test-dependency "org-export-ascii")) +(defun test-ox-ascii--restore-syntax () + (org-link-make-regexps) + (when (featurep 'org-element) (org-element-update-syntax))) + +(defun test-ox-ascii--link-export-inline (path desc backend info) + (and (org-export-derived-backend-p backend 'ascii) + (let ((description (and (org-string-nw-p desc) (org-trim desc))) + (target (format "(|tststr:%s|)" path))) + (if description + (format "[|%s|] %s" description target) + target)))) +(ert-deftest test-ox-ascii/link-custom-protocol-fallback () + "Test link custom protocol fallback." + (unwind-protect + (let ((org-link-parameters)) + (org-link-set-parameters "tstdflt") + ;; As notes. + (let ((org-ascii-links-to-notes t)) + (should ; With description. + (string-equal + (org-export-string-as + "Link [[tstdflt:path-descr][with description]] as note." + 'ascii t) + "Link [with description] as note. +\n +[with description] \n")) + (should ; No description. + (string-equal + (org-export-string-as + "Link [[tstdflt:path-no-descr]] without description (note)." + 'ascii t) + "Link without description (note).\n"))) + ;; Inline. + (let ((org-ascii-links-to-notes nil)) + (should ; With description. + (string-equal + (org-export-string-as + "Inline link [[tstdflt:path-descr][with description]]." + 'ascii t) + "Inline link [with description] ().\n")) + (should ; No description. + (string-equal + (org-export-string-as + "Inline link [[tstdflt:path-no-descr]] without description." + 'ascii t) + "Inline link without description.\n")))) + (test-ox-ascii--restore-syntax))) + +(ert-deftest test-ox-ascii/link-custom-protocol-string () + "Test link custom protocol forced inline (string return value)." + (unwind-protect + (let ((org-link-parameters)) + (org-link-set-parameters "tststr" + :export #'test-ox-ascii--link-export-inline) + ;; Inline despite as notes is requested. + (let ((org-ascii-links-to-notes t)) + (should ; With description. + (string-equal + (org-export-string-as + "Link [[tststr:path-descr][with description]] as string (opt note)." + 'ascii t) + "Link [|with description|] (|tststr:path-descr|) as string (opt note).\n")) + (should ; No description. + (string-equal + (org-export-string-as + "Link [[tststr:path-no-descr]] without description as string (opt note)." + 'ascii t) + "Link (|tststr:path-no-descr|) without description as string (opt note).\n"))) + ;; Inline. + (let ((org-ascii-links-to-notes nil)) + (should ; With description. + (string-equal + (org-export-string-as + "Link [[tststr:path-descr][with description]] as string (opt inline)." + 'ascii t) + "Link [|with description|] (|tststr:path-descr|) as string (opt inline).\n")) + (should ; No description. + (string-equal + (org-export-string-as + "Link without description as string (opt inline)." + 'ascii t) + "Link (|tststr:path-no-descr|) without description as string (opt +inline).\n")))) + (test-ox-ascii--restore-syntax))) (ert-deftest test-ox-ascii/list () "Test lists." -- 2.39.2