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

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

[nongnu] elpa/bash-completion 0ffaad3ef0 035/313: wordbreak-split


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 0ffaad3ef0 035/313: wordbreak-split
Date: Sat, 3 Dec 2022 10:59:13 -0500 (EST)

branch: elpa/bash-completion
commit 0ffaad3ef055c2a622bd78900f1046bec43c39f9
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>

    wordbreak-split
---
 bash-completion.el      |  15 ++++---
 bash-completion_test.el | 113 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 118 insertions(+), 10 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index 4c2f2a6742..bae4f7f446 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -29,7 +29,8 @@ the following entry is added to `bash-completion-alist':
 See `bash-completion-add-to-alist'.
 ")
 
-(defvar bash-completion-wordbreaks (append "\"'@><=;|&(:" nil))
+(defvar bash-completion-wordbreaks-str "\"'@><=;|&(:")
+(defvar bash-completion-wordbreaks (append bash-completion-wordbreaks-str nil))
 
 (defun bash-completion-setup ()
   (add-hook 'shell-dynamic-complete-functions
@@ -229,10 +230,12 @@ The result is a list of candidates, which might be empty."
 (defun bash-completion-ends-with (str suffix)
   (let ((suffix-len (length suffix))
        (str-len (length str)))
-    (and
-     (>= str-len suffix-len)
-     (equal (substring str (- suffix-len)) suffix))))
-  
+    (or
+     (= 0 suffix-len)
+     (and
+      (>= str-len suffix-len)
+      (equal (substring str (- suffix-len)) suffix)))))
+
 (defun bash-completion-starts-with (str prefix)
   (let ((prefix-len (length prefix))
        (str-len (length str)))
@@ -241,7 +244,7 @@ The result is a list of candidates, which might be empty."
      (equal (substring str 0 prefix-len) prefix))))
 
 (defun bash-completion-addsuffix (str)
-  (if (and (null (string-match "[/: ]$" str))
+  (if (and (null (string-match (concat "[" (regexp-quote 
bash-completion-wordbreaks-str) "/ ]$") str))
           (file-accessible-directory-p (expand-file-name str 
default-directory)))
       (progn
        (concat str "/"))
diff --git a/bash-completion_test.el b/bash-completion_test.el
index 6063af32cf..81d0b71c46 100644
--- a/bash-completion_test.el
+++ b/bash-completion_test.el
@@ -18,7 +18,11 @@
   (require 'sz-testutils)
   (require 'cl)
 
+  (defvar bash-completion-run-integration-tests t
+    "Run integration tests. Set to nil to disable them.")
   ;; This code will not appear in the compiled (.elc) file
+
+  ;; ---------- unit tests
   (put 'bash-completion-regress 'regression-suite t)
   (setq bash-completion-regress
    '("bash-completion-regress"
@@ -290,15 +294,116 @@ garbage
           (bash-completion-send "cmd" 'process 3.14))))
          "line1\nline2\n")
 
-      )))
-
+     ("bash-completion-cd-command-prefix no current dir"
+      (let ((default-directory nil))
+       (bash-completion-cd-command-prefix))
+      "")
+
+     ("bash-completion-cd-command-prefix current dir"
+      (let ((default-directory "/tmp/x"))
+       (bash-completion-cd-command-prefix))
+      "cd 2>/dev/null /tmp/x ; ")
+
+     ("bash-completion-cd-command-prefix expand tilde"
+      (let ((default-directory "~/x"))
+       (bash-completion-cd-command-prefix))
+      (concat "cd 2>/dev/null " (expand-file-name "~/x") " ; "))
+
+     ("bash-completion-addsuffix ends with /"
+      (flet ((file-accessible-directory-p (a) (error "unexpected")))
+       (bash-completion-addsuffix "hello/"))
+      "hello/")
+
+     ("bash-completion-addsuffix ends with space"
+      (flet ((file-accessible-directory-p (a) (error "unexpected")))
+       (bash-completion-addsuffix "hello "))
+      "hello ")
+
+     ("bash-completion-addsuffix ends with separator"
+      (flet ((file-accessible-directory-p (a) (error "unexpected")))
+       (bash-completion-addsuffix "hello:"))
+      "hello:")
+
+     ("bash-completion-addsuffix check directory"
+      (flet ((file-accessible-directory-p (a) (equal a "/tmp/hello")))
+       (let ((default-directory "/tmp"))
+         (bash-completion-addsuffix "hello")))
+      "hello/")
+
+     ("bash-completion-addsuffix check directory, expand tilde"
+      (flet ((file-accessible-directory-p (a) (equal a (concat 
(expand-file-name "y" "~/x")))))
+       (let ((default-directory "~/x"))
+         (bash-completion-addsuffix "y")))
+      "y/")
+
+     ("bash-completion-starts-with"
+      (list
+       (bash-completion-starts-with "" "hello ")
+       (bash-completion-starts-with "hello world" "hello ")
+       (bash-completion-starts-with "hello world" "hullo ")
+       (bash-completion-starts-with "hello" ""))
+      '(nil t nil t))
+
+     ("bash-completion-ends-with"
+      (list
+       (bash-completion-ends-with "" "world")
+       (bash-completion-ends-with "hello world" "world")
+       (bash-completion-ends-with "hello world" "wurld")
+       (bash-completion-ends-with "hello" ""))
+      '(nil t nil t))
+     
+     ("bash-completion-last-wordbreak-split"
+      (list
+       (bash-completion-last-wordbreak-split "a:b:c:d:e")
+       (bash-completion-last-wordbreak-split "hello=world")
+       (bash-completion-last-wordbreak-split "hello>world")
+       (bash-completion-last-wordbreak-split "hello"))
+      '(("a:b:c:d:" . "e")
+       ("hello=" . "world")
+       ("hello>" . "world")
+       ("" . "hello")))
+
+     ))
+
+  ;; ---------- integration tests
+  (put 'bash-completion-regress-integration 'regression-suite t)
+  (setq bash-completion-regress-integration '(
+       ("bash-completion interaction"
+       (let ((bash-completion-process nil)
+             (bash-completion-alist nil))
+         (list
+          (bash-completion-is-running)
+          (buffer-live-p (bash-completion-buffer))
+          (bash-completion-is-running)
+          (bash-completion-comm "hel" 4 '("hel") 0)
+          (progn
+            (bash-completion-send "echo $EMACS_BASH_COMPLETE")
+            (with-current-buffer (bash-completion-buffer)
+              (buffer-string)))
+          (bash-completion-reset)
+          (bash-completion-is-running)))
+       '(nil t t ("help ") "t\n" nil nil))
+
+       ("bash-completion setenv"
+       (let ((bash-completion-process nil)
+             (bash-completion-alist nil))
+         (prog1
+             (progn
+               (bash-completion-send "echo $EMACS_BASH_COMPLETE")
+               (with-current-buffer (bash-completion-buffer)
+                 (buffer-string)))
+           (bash-completion-reset)))
+       "t\n")
+       )))
 
 ;; Run diagnostics when this module is evaluated or compiled
 ;; if and only if the "regress" package is already loaded.
 ;; This code will not appear in the compiled (.elc) file
 (eval-when-compile
   (autoload 'regress "regress" "run regression test suites" t)
-  (if (featurep 'regress)
-      (regress bash-completion-regress)))
+  (when (featurep 'regress)
+    (regress bash-completion-regress)
+    (when bash-completion-run-integration-tests
+      (regress bash-completion-regress-integration))))
 
 ;;; bash-completion_test.el ends here



reply via email to

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