emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/hyperdrive dd795f5f2a 53/82: Test: Add tests for storing l


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive dd795f5f2a 53/82: Test: Add tests for storing links
Date: Mon, 25 Sep 2023 19:00:54 -0400 (EDT)

branch: elpa/hyperdrive
commit dd795f5f2ab4a1b5decdb31c4ff695d563382e5c
Author: Joseph Turner <joseph@ushin.org>
Commit: Joseph Turner <joseph@ushin.org>

    Test: Add tests for storing links
---
 tests/test-hyperdrive-org-link.el | 52 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/tests/test-hyperdrive-org-link.el 
b/tests/test-hyperdrive-org-link.el
index 3c89b0c69c..812be73c2c 100644
--- a/tests/test-hyperdrive-org-link.el
+++ b/tests/test-hyperdrive-org-link.el
@@ -81,6 +81,58 @@
 
 ;;;; Tests
 
+;;;;; Storing links
+
+(cl-defun hyperdrive-test-org-store-link (contents &key public-key path)
+  "Return stored link to entry with PUBLIC-KEY, PATH, and CONTENTS.
+Point is indicated by ★."
+  (declare (indent defun))
+  (let ((org-id-link-to-org-use-id nil)
+        ;; (default-directory "/")
+        (entry (hyperdrive-entry-create
+                :hyperdrive (hyperdrive-create :public-key public-key)
+                :path path))
+        org-stored-links)
+    (with-temp-buffer
+      (insert contents)
+      (org-mode)
+      (hyperdrive-mode)
+      (setq-local hyperdrive-current-entry entry)
+      (goto-char (point-min))
+      (search-forward "★")
+      (org-store-link nil 'interactive))
+    org-stored-links))
+
+(ert-deftest hyperdrive-test-org-link-store/before-heading ()
+  (cl-destructuring-bind ((url desc))
+      (hyperdrive-test-org-store-link
+        "★
+* Heading A"
+        :public-key "deadbeef" :path "/foo/bar quux.org")
+    (should (string= "hyper://deadbeef/foo/bar%20quux.org" url))
+    (should (null desc))))
+
+(ert-deftest hyperdrive-test-org-link-store/on-heading-with-custom-id ()
+  (cl-destructuring-bind ((url desc))
+      (hyperdrive-test-org-store-link
+        "* Heading A
+:PROPERTIES:
+:CUSTOM_ID: baz zot
+:END:
+★"
+        :public-key "deadbeef" :path "/foo/bar quux.org")
+    (should (string= "hyper://deadbeef/foo/bar%20quux.org#%3A%3A%23baz%20zot" 
url))
+    (should (string= "Heading A" desc))))
+
+(ert-deftest hyperdrive-test-org-link-store/on-heading-no-custom-id ()
+  (cl-destructuring-bind ((url desc))
+      (hyperdrive-test-org-store-link
+        "* Heading A
+★"
+        :public-key "deadbeef" :path "/foo/bar quux.org")
+    (should (string= 
"hyper://deadbeef/foo/bar%20quux.org#%3A%3A%2AHeading%20A" url))
+    (should (string= "Heading A" desc))))
+
 ;; + Hyperdrive Org links :: Links to hyperdrive files/directories that are 
valid within Org documents.
 
 ;;   - With protocol prefix



reply via email to

[Prev in Thread] Current Thread [Next in Thread]