[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 "" " ")))))
- [nongnu] elpa/bash-completion bab4cf6e8d 109/313: Merge remote-tracking branch 'origin/master' into complete_D, (continued)
- [nongnu] elpa/bash-completion bab4cf6e8d 109/313: Merge remote-tracking branch 'origin/master' into complete_D, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion dce43a54c5 119/313: Update comment in bash-completion-test, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5209200f3b 120/313: Using cl-letf instead of flet., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9588a9c0dd 125/313: Updated README, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion c5f2b2756f 129/313: Define sz-testutils as a global variable., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f085c41d8d 131/313: Add defcustom for bash-completion-args, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8ca917f428 133/313: Stop escaping = in completion. fixes #18, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 319886faa9 138/313: Add / after directory names - even if they contain spaces or special, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f2ea2b65df 141/313: Detect directories when expanding commands and add a slash instead of a, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 44bc73449e 144/313: Fixes strange behavior when completing --., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b4757884b0 145/313: Expand the tests to better cover wordbreak and command argument,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 6ab1fe406b 148/313: Always quote the stub before passing it to compgen., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a789093cd3 155/313: Run tests on older versions of Emacs., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5e05365dc8 153/313: Cleanup tests, split them into unit and integration tests., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 09c93ffbdb 165/313: Explicitly disable support for Emacs version older than 24.1., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 62c6567af6 158/313: Complete argument rename, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5eb85cf1fc 166/313: Remove obsolete functions bash-completion-dynamic-complete-0 and, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9b94818f88 167/313: Remove support for pre-Emacs24.1 backward compatibility., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 912e1e8153 170/313: Add an option to disable default Readline completion when no matches are found (#29), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 959e27dae3 171/313: Add remote shell support, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 68f7d937b7 175/313: Make wordbreak completion work with bash-completion-enable-caching., ELPA Syncer, 2022/12/03