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

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

[nongnu] elpa/bash-completion b4757884b0 145/313: Expand the tests to be


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion b4757884b0 145/313: Expand the tests to better cover wordbreak and command argument
Date: Sat, 3 Dec 2022 10:59:25 -0500 (EST)

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

    Expand the tests to better cover wordbreak and command argument
    completion. Fixes a potential issue that might have caused an
    unnecessary wordbreak completion to run when there were no wordbreak.
---
 bash-completion-test.el | 44 ++++++++++++++++++++++++++++++++++++++++----
 bash-completion.el      | 20 ++++++++++----------
 2 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/bash-completion-test.el b/bash-completion-test.el
index c65414973d..64a902e1cf 100644
--- a/bash-completion-test.el
+++ b/bash-completion-test.el
@@ -487,9 +487,7 @@ garbage
                                       "~" "~" nil 'default nil)))
 
   (cl-letf (((symbol-function 'file-accessible-directory-p)
-             (lambda (d)
-               (message "check: %s" d)
-               (equal d "/tmp/somedir"))))
+             (lambda (d) (equal d "/tmp/somedir"))))
     (let ((default-directory "/tmp/"))
       ;; append / for directory
       (should (equal "somedir/"
@@ -706,7 +704,10 @@ before calling `bash-completion-dynamic-complete-nocomint'.
 "
   `(let ((default-directory "/tmp/test")
          (bash-completion-alist '()))
-     (lexical-let ((--process-buffer) (--test-buffer) (--send-results) 
(--captured-commands (list))
+     (lexical-let ((--process-buffer)
+                   (--test-buffer)
+                   (--send-results (list))
+                   (--captured-commands (list))
                    (--directories (list)))
        (with-temp-buffer
          (setq --process-buffer (current-buffer))
@@ -782,6 +783,16 @@ before calling `bash-completion-dynamic-complete-nocomint'.
               '("without\\ space" "with\\ space" "with\\ slash/")
               (nth 2 (bash-completion-dynamic-complete-nocomint 3 
(point))))))))
 
+(ert-deftest bash-completion-trailing-custom-flag-completion ()
+  (--with-fake-bash-completion-send
+   (setq bash-completion-alist '(("ls" "compgen" "args")))
+   (push "--color\n--color=\n" --send-results)
+   (insert "$ ls --c")
+   (let ((bash-completion-nospace nil))
+     (should (equal
+              '("--color" "--color=")
+              (nth 2 (bash-completion-dynamic-complete-nocomint 3 
(point))))))))
+
 (ert-deftest bash-completion-complete-dir-with-spaces-test ()
   (--with-fake-bash-completion-send
    (push "/tmp/test/Documents" --directories)
@@ -840,4 +851,29 @@ before calling `bash-completion-dynamic-complete-nocomint'.
                           "compgen -b -c -a -A function -- b 2>/dev/null")
                   (pop --captured-commands)))))
 
+(ert-deftest bash-completion-failed-completion ()
+  (--with-fake-bash-completion-send
+   (setq --send-results '("" "bad"))
+   (insert "$ ls --")
+   (should
+    (null (nth 2 (bash-completion-dynamic-complete-nocomint 3 (point)))))))
+
+(ert-deftest bash-completion-wordbreak-completion ()
+  (--with-fake-bash-completion-send
+   (push "/tmp/test/bin" --directories)
+   (setq --send-results '("" "./binary\n./bind\n./bin\n"))
+   (insert "$ export PATH=$PATH:./b")
+   (should
+    (equal '(21 24 ("./binary" "./bind" "./bin/"))
+           (bash-completion-dynamic-complete-nocomint 3 (point))))))
+
+(ert-deftest bash-completion-single-wordbreak-completion ()
+  (--with-fake-bash-completion-send
+   (push "/tmp/test/bin" --directories)
+   (setq --send-results '("" "./world\n"))
+   (insert "$ set a=./hello:./w")
+   (should
+    (equal '(17 20 ("./world "))
+           (bash-completion-dynamic-complete-nocomint 3 (point))))))
+
 ;;; bash-completion_test.el ends here
diff --git a/bash-completion.el b/bash-completion.el
index 0f06fce4b2..9457499925 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -382,14 +382,14 @@ This function is not meant to be called outside of
           (substring unparsed-stub
                      separator-pos-in-unparsed
                      (length unparsed-stub))))
-    (when before-wordbreak
+    (when (> (length before-wordbreak) 0)
       (bash-completion-send (concat
                             (bash-completion-cd-command-prefix)
                             "compgen -o default -- "
                             (bash-completion-quote after-wordbreak)))
       (let ((completions
             (bash-completion-extract-candidates
-              after-wordbreak unparsed-after-wordbreak open-quote 'default)))
+              after-wordbreak unparsed-after-wordbreak open-quote 'wordbreak)))
        (list (+ stub-start separator-pos-in-unparsed)
               pos
              completions)))))
@@ -748,9 +748,9 @@ of candidates.
 OPEN-QUOTE should be the quote that's still open in prefix.  A
 character (' or \") or nil.  
 
-COMPLETION-TYPE describes the type of completion that was executed,
-as generated by `bash-completion-generate-line'. It is used to choose
-whether to add a space and detect directories.
+COMPLETION-TYPE describes the type of completion that was
+executed: 'default, 'custom, 'command or 'wordbreak. It is used
+to choose whether to add a space and detect directories.
 
 If SINGLE is non-nil, this is the single completion candidate.
 
@@ -808,15 +808,15 @@ for directory name detection to work."
             (eq ?/ last-char))
         (setq suffix ""))
        ((and
-         (memq completion-type '(command default))
+         (memq completion-type '(command default wordbreak))
          (file-accessible-directory-p
-         (expand-file-name (bash-completion-unescape
-                            open-quote (concat parsed-prefix rest))
-                           default-directory)))
+          (expand-file-name (bash-completion-unescape
+                             open-quote (concat parsed-prefix rest))
+                            default-directory)))
         (setq suffix "/"))
        ((and (not open-quote)
              (or (eq completion-type 'command)
-                 (and (eq completion-type 'default)
+                 (and (memq completion-type '(default wordbreak))
                       single)))
         (setq suffix (if bash-completion-nospace "" " ")))))
 



reply via email to

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