[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/hyperdrive 6c203e3e34 58/82: Test: Test inserting links
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/hyperdrive 6c203e3e34 58/82: Test: Test inserting links |
Date: |
Mon, 25 Sep 2023 19:00:54 -0400 (EDT) |
branch: elpa/hyperdrive
commit 6c203e3e34d33b3986795818faf07f32013d378c
Author: Joseph Turner <joseph@ushin.org>
Commit: Joseph Turner <joseph@ushin.org>
Test: Test inserting links
---
tests/test-hyperdrive-org-link.el | 112 ++++++++++++++++++++++++++++++++++++++
1 file changed, 112 insertions(+)
diff --git a/tests/test-hyperdrive-org-link.el
b/tests/test-hyperdrive-org-link.el
index 5072a59004..3d6f5d4082 100644
--- a/tests/test-hyperdrive-org-link.el
+++ b/tests/test-hyperdrive-org-link.el
@@ -161,6 +161,118 @@ Point is indicated by ★."
(hyperdrive-test-org-store-link-deftest org-mode-on-heading-with-custom-id)
(hyperdrive-test-org-store-link-deftest org-mode-on-heading-no-custom-id)
+;;;;; Inserting links
+
+(cl-defun hyperdrive-test-org-entry-create (&key public-key path)
+ (hyperdrive-entry-create
+ :hyperdrive (hyperdrive-create :public-key public-key)
+ :path path))
+
+(cl-defun hyperdrive-test-org-insert-link-string (scenario &key public-key
path)
+ "Return link for SCENARIO inserted into entry with PUBLIC-KEY and PATH."
+ (declare (indent defun))
+ (pcase-let* (((map :url :desc) (alist-get scenario
hyperdrive-test-org-store-link-scenarios))
+ (org-stored-links `((,url ,desc))))
+ (with-temp-buffer
+ (org-mode)
+ (hyperdrive-mode)
+ (setq-local hyperdrive-current-entry (hyperdrive-test-org-entry-create
+ :public-key public-key :path path))
+ (org-insert-link nil url desc)
+ (buffer-string))))
+
+(cl-defmacro hyperdrive-test-org-insert-link-deftest (name &key public-key
path results)
+ "Test inserted link in entry with PUBLIC-KEY and PATH.
+Scenario is the first part of NAME, and RESULTS contain let-bound
+variables and the expected link."
+ (declare (indent defun))
+ (let ((scenario (intern (string-trim-right (symbol-name name)
+ (rx "/" (1+ anything) eos))))
+ body-forms)
+ (pcase-dolist ((map (:let vars) (:result result)) results)
+ (let* ((olfpt (cadadr (assoc 'org-link-file-path-type vars)))
+ (test-name (intern (format "hyperdrive-test-org-insert-link/%s/%s"
+ name olfpt))))
+ (push `(ert-deftest ,test-name ()
+ (let (,@vars)
+ (should (string= ,result
+ (hyperdrive-test-org-insert-link-string
',scenario
+ :public-key ,public-key :path ,path)))))
+ body-forms)))
+ `(progn ,@body-forms)))
+
+(hyperdrive-test-org-insert-link-deftest
org-mode-before-heading/same-drive-same-path
+ :public-key "deadbeef"
+ :path "/foo/bar quux.org"
+ :results (( :let ((org-link-file-path-type 'relative))
+ :result "[[./bar quux.org]]")
+ ( :let ((org-link-file-path-type 'absolute))
+ :result "[[/foo/bar quux.org]]")
+ ( :let ((org-link-file-path-type 'noabbrev))
+ :result "[[/foo/bar quux.org]]")
+ ( :let ((org-link-file-path-type 'adaptive))
+ :result "[[./bar quux.org]]")))
+
+(hyperdrive-test-org-insert-link-deftest
org-mode-on-heading-with-custom-id/same-drive-same-path
+ :public-key "deadbeef"
+ :path "/foo/bar quux.org"
+ :results (( :let ((org-link-file-path-type 'relative))
+ :result "[[#baz zot][Heading A]]")
+ ( :let ((org-link-file-path-type 'absolute))
+ :result "[[#baz zot][Heading A]]")
+ ( :let ((org-link-file-path-type 'noabbrev))
+ :result "[[#baz zot][Heading A]]")
+ ( :let ((org-link-file-path-type 'adaptive))
+ :result "[[#baz zot][Heading A]]")))
+
+(hyperdrive-test-org-insert-link-deftest
org-mode-on-heading-no-custom-id/same-drive-same-path
+ :public-key "deadbeef"
+ :path "/foo/bar quux.org"
+ :results (( :let ((org-link-file-path-type 'relative))
+ :result "[[*Heading A][Heading A]]")
+ ( :let ((org-link-file-path-type 'absolute))
+ :result "[[*Heading A][Heading A]]")
+ ( :let ((org-link-file-path-type 'noabbrev))
+ :result "[[*Heading A][Heading A]]")
+ ( :let ((org-link-file-path-type 'adaptive))
+ :result "[[*Heading A][Heading A]]")))
+
+(hyperdrive-test-org-insert-link-deftest
org-mode-before-heading/same-drive-different-path
+ :public-key "deadbeef"
+ :path "/thud.org"
+ :results (( :let ((org-link-file-path-type 'relative))
+ :result "[[./foo/bar quux.org]]")
+ ( :let ((org-link-file-path-type 'absolute))
+ :result "[[/foo/bar quux.org]]")
+ ( :let ((org-link-file-path-type 'noabbrev))
+ :result "[[/foo/bar quux.org]]")
+ ( :let ((org-link-file-path-type 'adaptive))
+ :result "[[./foo/bar quux.org]]")))
+
+(hyperdrive-test-org-insert-link-deftest
org-mode-on-heading-with-custom-id/same-drive-different-path
+ :public-key "deadbeef"
+ :path "/thud.org"
+ :results (( :let ((org-link-file-path-type 'relative))
+ :result "[[./foo/bar quux.org::#baz zot][Heading A]]")
+ ( :let ((org-link-file-path-type 'absolute))
+ :result "[[/foo/bar quux.org::#baz zot][Heading A]]")
+ ( :let ((org-link-file-path-type 'noabbrev))
+ :result "[[/foo/bar quux.org::#baz zot][Heading A]]")
+ ( :let ((org-link-file-path-type 'adaptive))
+ :result "[[./foo/bar quux.org::#baz zot][Heading A]]")))
+
+(hyperdrive-test-org-insert-link-deftest
org-mode-on-heading-no-custom-id/same-drive-different-path
+ :public-key "deadbeef"
+ :path "/thud.org"
+ :results (( :let ((org-link-file-path-type 'relative))
+ :result "[[./foo/bar quux.org::*Heading A][Heading A]]")
+ ( :let ((org-link-file-path-type 'absolute))
+ :result "[[/foo/bar quux.org::*Heading A][Heading A]]")
+ ( :let ((org-link-file-path-type 'noabbrev))
+ :result "[[/foo/bar quux.org::*Heading A][Heading A]]")
+ ( :let ((org-link-file-path-type 'adaptive))
+ :result "[[./foo/bar quux.org::*Heading A][Heading A]]")))
+
;; + Hyperdrive Org links :: Links to hyperdrive files/directories that are
valid within Org documents.
;; - With protocol prefix
- [nongnu] elpa/hyperdrive 36a18f326e 34/82: Change: (--org-normalize-link) Return early with search option, (continued)
- [nongnu] elpa/hyperdrive 36a18f326e 34/82: Change: (--org-normalize-link) Return early with search option, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 91c3478593 36/82: Change: (hyperdrive--org-normalize-link) Use file-name-directory, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive c4567c4b9f 46/82: Change: (hyperdrive--org-normalize-link) Use hyperdrive-entry-url, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 28151f3db9 39/82: Change: (--org-normalize-link) Split adaptive into absolute/relative, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 25af84f5e4 52/82: Change: (hyperdrive--org-link) Add "::" to stored link, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 032a77ea2d 43/82: Test: -org-link/same-drive-different-path with heading, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive c99013b23a 61/82: Comment: Add outline heading, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 2c3bc705c7 56/82: Test: Add hyperdrive-test-org-store-link-deftest macro, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 46e6a1201f 54/82: Comment: Add TODO, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 68e55a0ab6 55/82: Test: Add hyperdrive-test-org-store-link-scenarios, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 6c203e3e34 58/82: Test: Test inserting links,
ELPA Syncer <=
- [nongnu] elpa/hyperdrive 0d92314c4f 65/82: Docs: Document new advised org-insert-link behavior, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 834c4a8908 63/82: Change: Rename test-hyperdrive-org.el, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 658164484b 68/82: Tidy: (hyperdrive-test-org-entry-create) Don't bind org-stored-links, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 373d55c1d8 73/82: Comment: Add TODO, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 8c4c989c01 75/82: WIP: Don't store "::" in target in entry etc slot, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 759142d99e 77/82: Tests: Remove old Org link tests from main test file, ELPA Syncer, 2023/09/25