branch: externals/hyperbole commit 2f5d06dd4c76616e598b5758f9e0e43c54edff94 Author: Mats Lidell <mats.lid...@lidells.se> Commit: Mats Lidell <mats.lid...@lidells.se>
Add tests for hpath:expand and hpath:expand-list --- ChangeLog | 9 +++++ hpath.el | 2 +- test/hpath-tests.el | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f865876778..227e052a73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-12-23 Mats Lidell <ma...@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 <r...@gnu.org> * hactypes.el (link-to-regexp-match): Fix to use arg 'n' in the regexp search. 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..6027fb1360 100644 --- a/test/hpath-tests.el +++ b/test/hpath-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell <ma...@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." + :expected-result :failed + (let ((hpath:auto-variable-alist '(("\\.elc" . load-path)))) + ;; FIXME: This test expands dired.el although auto-variable-alist + ;; suggests it should not. Needs to be investigated since current + ;; expansion behavior likely is correct. + (should (string= (hpath:expand "dired.el") "dired.el")) + (should (string= (hpath:expand "dired.elc") (locate-library "dired.elc"))))) + +(ert-deftest hpath--resolve-auto-variable-alist () + "Verify relative paths matching auto-variable-alist are resolved." + (let ((hpath:auto-variable-alist '(("\\.elc" . load-path)))) + (should (string= (hpath:resolve "dired.el") "dired.el")) + (should (string= (hpath:resolve "dired.elc") (locate-library "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