branch: externals/hyperbole
commit c834afd0ee6c1d74dd370b624f8020af066de86f
Author: Mats Lidell <mats.lid...@lidells.se>
Commit: GitHub <nore...@github.com>

    Add test for hpath:delimited-possible-path (#536)
---
 ChangeLog           |  5 +++++
 test/hpath-tests.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 0223a0a542..918302d63e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-06-01  Mats Lidell  <ma...@gnu.org>
+
+* test/hpath-tests.el (hpath--hpath:delimited-possible-path): Add test for
+    hpath:delimited-possible-path.
+
 2024-05-31  Mats Lidell  <ma...@gnu.org>
 
 * test/hui-tests.el (hui--gbut-should-execute-in-current-folder): Add test
diff --git a/test/hpath-tests.el b/test/hpath-tests.el
index fa56693a6a..413d755928 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:      8-Apr-24 at 16:45:22 by Mats Lidell
+;; Last-Mod:      1-Jun-24 at 20:45:10 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -20,6 +20,7 @@
 
 (require 'ert)
 (require 'hpath)
+(require 'el-mock)
 (require 'hy-test-helpers "test/hy-test-helpers")
 
 (declare-function hy-test-helpers:action-key-should-call-hpath:find 
"hy-test-helpers")
@@ -391,5 +392,63 @@ See `hpath:line-and-column-regexp'."
   (should-not (string-match hpath:line-and-column-regexp "/foo/bar.org:LL1"))
   (should-not (string-match hpath:line-and-column-regexp "/foo/bar.org:C1")))
 
+(ert-deftest hpath--hpath:delimited-possible-path ()
+  "Verify delimited path is found in an `ls -R' listings in `shell-mode'."
+  (let ((files
+         '(("file1.ext file2.ext file3.ext"                   ; Space delimited
+            ("file1" "file2" "file3"))
+           ("file1.ext\tfile2.ext\tfile3.ext"                 ; Tab delimited
+            ("file1" "file2" "file3"))
+           ("'file1.ext' 'file2.ext' 'file3.ext'"             ; Single quoted
+            ("file1" "file2" "file3"))
+           ("'file1.ext' file2.ext 'file3.ext'"               ; Single quoted 
mixed
+            ("file1" "file2" "file3"))
+           ("'file 1.ext' 'file 2.ext' 'file 3.ext'"          ; Single quoted 
with space
+            ("file 1" "file 2" "file 3"))
+           ("\"file1.ext\" \"file2.ext\" \"file3.ext\""       ; Double quoted
+            ("file1" "file2" "file3"))
+           ("\"file1.ext\" file2.ext \"file3.ext\""           ; Double quoted 
mixed
+            ("file1" "file2" "file3"))
+           ("\"file 1.ext\" \"file 2.ext\" \"file 3.ext\""    ; Double quoted 
with space
+            ("file 1" "file 2" "file 3"))
+           ("\"file1.ext\" 'file2.ext' \"file3.ext\""         ; Mixed quotes 1
+            ("file1" "file2" "file3"))
+           ("'file1.ext' \"file2.ext\" 'file3.ext'"           ; Mixed quotes 2
+            ("file1" "file2" "file3"))
+           (" file1.ext file2.ext file3.ext"                  ; Leading space
+            ("file1" "file2" "file3"))
+           ("\tfile1.ext file2.ext file3.ext"                 ; Leading tab
+            ("file1" "file2" "file3"))
+
+           ;; Failing cases
+           ;; ("'file1\".ext' 'file2\".ext' 'file3\".ext'"    ; Single quoted 
with double quote
+           ;;  ("file1\"" "file2\"" "file3\""))
+           ;; ("\"file1'.ext\" \"file2'.ext\" \"file3'.ext\"" ; Double quoted 
with single quote
+           ;;  ("file1'" "file2'" "file3'"))
+           )))
+    (dolist (fls files)
+      (with-temp-buffer
+        (insert "\
+$ ls -R dir
+dir/subdir:
+" (car fls))
+        (goto-char (point-min))
+        (shell-mode)
+        (dolist (v (cadr fls))
+          (let ((filename v))
+            (search-forward filename)
+            (should (looking-at-p "\\.ext"))
+            (mocklet (((file-exists-p "dir/subdir") => t))
+              (should (string= (expand-file-name (concat filename ".ext") 
"dir/subdir")
+                               (hpath:delimited-possible-path))))))))))
+
 (provide 'hpath-tests)
+
+:; This file can't be byte-compiled without the `el-mock' package
+;; which is not a dependency of Hyperbole.
+;;
+;; Local Variables:
+;; no-byte-compile: t
+;; End:
+
 ;;; hpath-tests.el ends here

Reply via email to