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

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

[elpa] externals/hyperbole 027eb85174 014/143: Merge matsl-rsw-hpath-exp


From: ELPA Syncer
Subject: [elpa] externals/hyperbole 027eb85174 014/143: Merge matsl-rsw-hpath-expand' into rsw
Date: Mon, 19 Feb 2024 15:58:46 -0500 (EST)

branch: externals/hyperbole
commit 027eb85174545e332f82ff3d82e6562c5b58e957
Merge: 6550a0ac7c 2f5d06dd4c
Author: bw <rsw@gnu.org>
Commit: bw <rsw@gnu.org>

    Merge matsl-rsw-hpath-expand' into rsw
    
    Fix 'hpath--expand-auto-variable-alist' and
    'hpath--resolve-auto-variable-alist' tests.
---
 ChangeLog           |  9 +++++
 hpath.el            |  2 +-
 test/hpath-tests.el | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 104 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 92cb4d0681..447190c6eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,15 @@
   hyrolo.el (hyrolo-file-list): Update doc to specify allowable file suffixes
     and types.
 
+2023-12-23  Mats Lidell  <matsl@gnu.org>
+
+* test/hpath-tests.el (hpath--expand-no-wildcards-existing-path)
+    (hpath--expand-variations-non-existing-path)
+    (hpath--expand-elisp-variable, hpath--expand-environment-variable)
+    (hpath--expand-auto-variable-alist, hpath--resolve-auto-variable-alist)
+    (hpath--expand-list-return-a-list, hpath--expand-list-match-regexp):
+    Add tests for hpath:expand and hpath:expand-list.
+
 2023-12-23  Bob Weiner  <rsw@gnu.org>
 
 * hypb.el (hypb:major-mode-from-file-name): Add for initial use in "hyrolo.el".
diff --git a/hpath.el b/hpath.el
index eabe439456..e22171d80c 100644
--- a/hpath.el
+++ b/hpath.el
@@ -3,7 +3,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:     1-Nov-91 at 00:44:23
-;; Last-Mod:     16-Dec-23 at 16:47:24 by Bob Weiner
+;; Last-Mod:     17-Dec-23 at 23:01:29 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
diff --git a/test/hpath-tests.el b/test/hpath-tests.el
index afd29b3fe0..9a16799fdb 100644
--- a/test/hpath-tests.el
+++ b/test/hpath-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <matsl@gnu.org>
 ;;
 ;; Orig-Date:    28-Feb-21 at 23:26:00
-;; Last-Mod:     14-Nov-23 at 00:35:22 by Bob Weiner
+;; Last-Mod:     17-Dec-23 at 19:35:06 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -285,5 +285,98 @@
       (should-not (hpath:at-p))
       (should-not (hpath:is-p fn)))))
 
+(ert-deftest hpath--expand-no-wildcards-existing-path ()
+  "Verify expand with no wildcards gives path back."
+  (let ((file (make-temp-file "hypb")))
+    (unwind-protect
+        (should (string= (hpath:expand file) file))
+      (hy-delete-file-and-buffer file))))
+
+(ert-deftest hpath--expand-variations-non-existing-path ()
+  "Verify expand non existing paths."
+  (should (string= (hpath:expand "/not/existing/file") "/not/existing/file"))
+  (should-not (hpath:expand "/not/existing/file" t))
+  (should (string= (hpath:expand "/not/existing/file*" t) 
"/not/existing/file*"))
+  (should (string= (hpath:expand "/not/existing/file[]" t) 
"/not/existing/file[]"))
+  (should (string= (hpath:expand "/not/existing/file?" t) 
"/not/existing/file?")))
+
+(ert-deftest hpath--expand-elisp-variable ()
+  "Verify an elisp ${variable} is expanded."
+  (let ((hyperb-no-trailing-slash (substring hyperb:dir 0 -1)))
+    (should (string= (hpath:expand "${hyperb:dir}") hyperb-no-trailing-slash))
+    (should (string= (hpath:expand "${hyperb:dir}" t) 
hyperb-no-trailing-slash))
+    (should (string= (hpath:expand "${hyperb:dir}/notexisting") 
"${hyperb:dir}/notexisting"))
+    (should-not (hpath:expand "${hyperb:dir}/notexisting" t))))
+
+(ert-deftest hpath--expand-environment-variable ()
+  "Verify that a $VAR environment is expanded."
+  (let ((envvar "hpath_test"))
+    (unwind-protect
+        (progn
+          (setenv "HPATH" envvar)
+          (should (string= (hpath:expand "$HPATH") envvar))
+          ; Should next not work? See below where is works
+          ;(should (string= (hpath:expand "${HPATH}") envvar))
+          (should-not (hpath:expand "$HPATH" t))
+          (should-not (hpath:expand "${HPATH}" t)))
+      (setenv "HPATH")))
+  (let ((file (make-temp-file "hypb")))
+    (unwind-protect
+        (progn
+          (setenv "HPATH" file)
+          (should (string= (hpath:expand "$HPATH") file))
+          (should (string= (hpath:expand "${HPATH}") file))
+          (should (string= (hpath:expand "$HPATH" t) file))
+          (should (string= (hpath:expand "${HPATH}" t) file)))
+      (setenv "HPATH")
+      (hy-delete-file-and-buffer file))))
+
+(ert-deftest hpath--expand-auto-variable-alist ()
+  "Verify relative paths matching auto-variable-alist are expanded."
+  (let ((hpath:auto-variable-alist '(("\\.el" . load-path))))
+    (should (string= (hpath:expand "dired.el")
+                    (locate-library "dired.el")))
+    (should (string= (hpath:expand "dired.elc")
+                    (hpath:resolve "dired.elc")))))
+
+(ert-deftest hpath--resolve-auto-variable-alist ()
+  "Verify relative paths matching auto-variable-alist are resolved."
+  (let ((hpath:auto-variable-alist '(("\\.el" . load-path))))
+    (should (string= (hpath:resolve "dired.el")
+                    (locate-library "dired.el")))
+    (should (string= (hpath:resolve "dired.elc")
+                    (hpath:expand "dired.elc")))))
+
+(ert-deftest hpath--expand-list-return-a-list ()
+  "Verify expand-list should return a list of paths."
+  (let ((file (make-temp-file "hypb")))
+    (unwind-protect
+        (progn
+          (should (equal (hpath:expand-list '("/file1")) '("/file1")))
+          (should (equal (hpath:expand-list '("/file1") ".*" t) '()))
+          (should (equal (hpath:expand-list (list file)) (list file)))
+          (should (equal (hpath:expand-list (list file) ".*" t) (list file)))
+          (should (equal (hpath:expand-list '("/file1" "/file2")) '("/file1" 
"/file2")))
+          (should (equal (hpath:expand-list (list "/file1" file)) (list 
"/file1" file)))
+          (should (equal (hpath:expand-list (list "/file1" file) ".*" t) (list 
file))))
+      (hy-delete-file-and-buffer file))))
+
+(ert-deftest hpath--expand-list-match-regexp ()
+  "Verify expand-list selects files using match regexp."
+  (let* ((temporary-file-directory (make-temp-file "hypb" t))
+         (org1-file (make-temp-file "hypb" nil ".org"))
+         (org2-file (make-temp-file "hypb" nil ".org"))
+         (kotl-file (make-temp-file "hypb" nil ".kotl")))
+    (unwind-protect
+        (progn
+          (should (= (length (hpath:expand-list (list 
temporary-file-directory))) 3))
+          (should (= (length (hpath:expand-list (list 
temporary-file-directory) ".*")) 3))
+          (should (= (length (hpath:expand-list (list 
temporary-file-directory) ".org")) 2))
+          (should (= (length (hpath:expand-list (list 
temporary-file-directory) ".kotl")) 1))
+          (should (= (length (hpath:expand-list (list 
temporary-file-directory) ".md")) 0)))
+      (dolist (f (list org1-file org2-file kotl-file))
+        (hy-delete-file-and-buffer f))
+      (delete-directory temporary-file-directory))))
+
 (provide 'hpath-tests)
 ;;; hpath-tests.el ends here



reply via email to

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