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

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

[nongnu] elpa/bash-completion f5885ec87a 002/313: test case for bash-com


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion f5885ec87a 002/313: test case for bash-complete
Date: Sat, 3 Dec 2022 10:58:59 -0500 (EST)

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

    test case for bash-complete
---
 bash-complete.el      | 22 +++++++++-------
 bash-complete_test.el | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 9 deletions(-)

diff --git a/bash-complete.el b/bash-complete.el
index b15daea8d9..3ea39611fb 100644
--- a/bash-complete.el
+++ b/bash-complete.el
@@ -1,4 +1,6 @@
 
+(require 'comint)
+
 (defun bash-complete-dynamic-complete ()
   "Bash completion function for `comint-complete-dynamic-functions'.
 
@@ -22,6 +24,13 @@ Call bash to do the completion."
                              (bash-complete-comm
                               line pos words cword)))))
 
+;; "hell o" wor\ ld 'baa baaaa'a"hell o"world a
+
+;; (progn
+;;   (load-library "~/.emacs.d/bash-complete.el")
+;;   (let ((start 64) (end 108))
+;;     (bash-complete-split start end 80)))
+
 (defun bash-complete-split (start end pos)
   "Split LINE like bash would do, keep track of current word at POS.
 
@@ -39,22 +48,15 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
       (setq quote char-start))
     (bash-complete-split-1 start end pos quote accum)))
 
-;; "hell o" wor\ ld 'baa baaaa'a"hell o"world a
-
-;; (progn
-;;   (load-library "~/.emacs.d/bash-complete.el")
-;;   (let ((start 64) (end 108))
-;;     (bash-complete-split start end 80)))
-
 (defun bash-complete-split-1 (start end pos quote accum)
   (skip-chars-forward (bash-complete-nonsep quote) end)
   (cond
    ;; an escaped char, skip, whatever it is
-   ((= ?\\ (char-before))
+   ((and (char-before) (= ?\\ (char-before)))
     (forward-char)
     (bash-complete-split-1 start end pos (if (and quote (= quote 
(char-before))) nil quote) accum))
    ;; opening quote
-   ((and (not quote) (or (= ?' (char-after)) (= ?\" (char-after))))
+   ((and (not quote) (char-after) (or (= ?' (char-after)) (= ?\" 
(char-after))))
     (bash-complete-split-0 start end pos accum))
    ;; closing quote
    ((and quote (= quote (char-after)))
@@ -89,3 +91,5 @@ calls compgen.
 The result is a list of candidates, which might be empty."
 
   )
+
+(provide 'bash-complete)
\ No newline at end of file
diff --git a/bash-complete_test.el b/bash-complete_test.el
new file mode 100644
index 0000000000..55789ef11a
--- /dev/null
+++ b/bash-complete_test.el
@@ -0,0 +1,72 @@
+;;; bash-complete_test.el --- Tests jbtn-complete.el
+
+
+;;; Commentary:
+;;
+;; This file defines `bash-complete-regress' and run the
+;; regression tests if and only if regress is already imported.
+;;
+
+;;; History:
+;;
+
+;;; Code:
+(eval-when-compile
+  ;; force reload
+  (load-library "~/.emacs.d/bash-complete.el")
+
+  (require 'sz-testutils)
+
+  ;; This code will not appear in the compiled (.elc) file
+  (put 'bash-complete-regress 'regression-suite t)
+  (setq bash-complete-regress
+   '("bash-complete-regress"
+     ;; Each test in the suite is of the form:
+     ;;   ([description] probe grader)
+     ;;   DESCRIPTION - string
+     ;;   PROBE -  a sexp which runs the actual test
+     ;;   GRADER - the desired result or a sexp which determines
+     ;;   how we did
+
+     ("bash-complete-split simple"
+      (sz-testutils-with-buffer
+       '("a hello world b c")
+       (bash-complete-split 1 (line-end-position) 0))
+      '("a" "hello" "world" "b" "c"))
+
+     ("bash-complete-split escaped space"
+      (sz-testutils-with-buffer
+       '("a hello\\ world b c")
+       (bash-complete-split 1 (line-end-position) 0))
+      '("a" "hello\\ world" "b" "c"))
+
+     ("bash-complete-split double quotes"
+      (sz-testutils-with-buffer
+       '("a \"hello world\" b c")
+       (bash-complete-split 1 (line-end-position) 0))
+      '("a" "\"hello world\"" "b" "c"))
+
+     ("bash-complete-split single quotes"
+      (sz-testutils-with-buffer
+       '("a \"hello world\" b c")
+       (bash-complete-split 1 (line-end-position) 0))
+      '("a" "\"hello world\"" "b" "c"))
+
+     ("bash-complete-split complex quote mix"
+      (sz-testutils-with-buffer
+       '("a hel\"lo w\"o'rld b'c d")
+       (bash-complete-split 1 (line-end-position) 0))
+      '("a" "hel\"lo w\"o'rld b'c" "d"))
+
+      )))
+
+
+;; 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-complete-regress)))
+
+;;; bash-complete_test.el ends here



reply via email to

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