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

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

[nongnu] elpa/hyperdrive c19696aaf6 01/31: Chore: Favor format over conc


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive c19696aaf6 01/31: Chore: Favor format over concat when constructing URLs
Date: Fri, 1 Dec 2023 01:00:37 -0500 (EST)

branch: elpa/hyperdrive
commit c19696aaf6b6bc1088418f1f7d17e82012767506
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Joseph Turner <joseph@ushin.org>

    Chore: Favor format over concat when constructing URLs
    
    In some cases we can now avoid having to use `number-to-string'.
    This also leads to more natural results, when having to add line-
    breaks to avoid long lines.
    
    Co-authored-by: Joseph Turner <joseph@ushin.org>
---
 hyperdrive-lib.el        |  8 +++++---
 hyperdrive.el            |  2 +-
 tests/test-hyperdrive.el | 17 +++++++++--------
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index 144585eeea..5b7893d7bb 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -219,12 +219,13 @@ PLZ-ERR should be a `plz-error' struct."
   "Return non-nil if `hyper-gateway' is running and accessible."
   ;; FIXME: Ensure a very short timeout for this request.
   (condition-case nil
-      (plz 'get (concat "http://localhost:"; (number-to-string 
h/hyper-gateway-port) "/"))
+      (plz 'get (format "http://localhost:%d/"; h/hyper-gateway-port))
     (error nil)))
 
 (defun h//httpify-url (url)
   "Return localhost HTTP URL for HYPER-URL."
-  (concat "http://localhost:"; (number-to-string h/hyper-gateway-port) "/hyper/"
+  (format "http://localhost:%d/hyper/%s";
+          h/hyper-gateway-port
           (substring url (length h//hyper-prefix))))
 
 (cl-defun h//write (url &key body then else queue)
@@ -1208,7 +1209,8 @@ With PURGE, delete hash table entry for HYPERDRIVE."
 That is, if the SEED has been used to create a local
 hyperdrive."
   (condition-case err
-      (pcase (h/api 'get (concat "hyper://localhost/?key=" (url-hexify-string 
seed))
+      (pcase (h/api 'get (format "hyper://localhost/?key=%s"
+                                 (url-hexify-string seed))
                :as 'response :noquery t)
         ((and (pred plz-response-p)
               response
diff --git a/hyperdrive.el b/hyperdrive.el
index 6036ecab6f..6cba22c3b0 100644
--- a/hyperdrive.el
+++ b/hyperdrive.el
@@ -112,7 +112,7 @@
 Gateway must be running."
   (interactive)
   (condition-case err
-      (let ((url (concat "http://localhost:"; (number-to-string 
h/hyper-gateway-port) "/")))
+      (let ((url (format "http://localhost:%d/"; h/hyper-gateway-port)))
         (h/message "hyper-gateway version %s"
                    (alist-get 'version (plz 'get url :as #'json-read))))
     (plz-error (h/api-default-else nil (caddr err)))))
diff --git a/tests/test-hyperdrive.el b/tests/test-hyperdrive.el
index 64baf43e7b..4a9897088b 100644
--- a/tests/test-hyperdrive.el
+++ b/tests/test-hyperdrive.el
@@ -117,21 +117,22 @@
 (h/deftest entry-url-round-trip ()
 
   (let ((url (he/url (h/url-entry (make-url "")))))
-    (should (equal url (concat "hyper://" test-hyperdrive-public-key "/"))))
+    (should (equal url (format "hyper://%s/" test-hyperdrive-public-key))))
 
   (let ((url (he/url (h/url-entry (make-url "/")))))
-    (should (equal url (concat "hyper://" test-hyperdrive-public-key "/"))))
+    (should (equal url (format "hyper://%s/" test-hyperdrive-public-key))))
 
   (let ((url (he/url (h/url-entry (make-url "/name-without-spaces")))))
-    (should (equal url (concat "hyper://" test-hyperdrive-public-key 
"/name-without-spaces"))))
+    (should (equal url (format "hyper://%s/name-without-spaces"
+                               test-hyperdrive-public-key))))
 
   (let ((url (he/url (h/url-entry (make-url "/name%20without%20spaces")))))
-    (should (equal url (concat "hyper://" test-hyperdrive-public-key 
"/name%20without%20spaces"))))
+    (should (equal url (format "hyper://%s/name%%20without%%20spaces"
+                               test-hyperdrive-public-key))))
 
-  (let ((url (he/url (h/url-entry
-                      (make-url "/name%20without%20spaces/subdir")))))
-    (should (equal url (concat "hyper://" test-hyperdrive-public-key
-                               "/name%20without%20spaces/subdir")))))
+  (let ((url (he/url (h/url-entry (make-url 
"/name%20without%20spaces/subdir")))))
+    (should (equal url (format "hyper://%s/name%%20without%%20spaces/subdir"
+                               test-hyperdrive-public-key)))))
 
 ;; Local Variables:
 ;; read-symbol-shorthands: (



reply via email to

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