[Bash-completion-commits] [SCM] bash-completion branch, master, updated. e663e1cbc003580debd3848769fe238ec3d631f0
Freddy Vulto
fvulto at gmail.com
Sun Sep 6 22:42:53 UTC 2009
The following commit has been merged in the master branch:
commit e20a4cb06e1e7e4365361c42a6d19a0b6a1dbcb5
Author: Freddy Vulto <fvulto at gmail.com>
Date: Mon Sep 7 00:26:27 2009 +0200
Added unit tests for _get_cword
These are the tests (| = cursor position):
1. a b| should return b
2. a | should return nothing
3. a b|c should return b
4. a b\ c| should return b\ c
5. a 'b c| should return 'b c
6. a "b c| should return "b c
7. a b:c| should return c
8. a b:c| with WORDBREAKS -= : should return b:c
9. a -n| should return -n
Tests 5 & 6 yield "expected failures", see bugreport:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474094 . At a first glance
this bugreport contains useful ideas, so anyone willing to try to make tests 5 &
6 pass, be sure to have a look there first.
To run the automated tests:
$ cd test && ./runUnit _get_cword.exp
diff --git a/test/unit/_get_cword.exp b/test/unit/_get_cword.exp
index f5264d7..25bae29 100644
--- a/test/unit/_get_cword.exp
+++ b/test/unit/_get_cword.exp
@@ -4,7 +4,12 @@ proc setup {} {
proc teardown {} {
- assert_env_unmodified
+ assert_env_unmodified {
+ /COMP_CWORD=/d
+ /COMP_LINE=/d
+ /COMP_POINT=/d
+ /COMP_WORDS=/d
+ }
}; # teardown()
@@ -22,4 +27,66 @@ sync_after_int
# by moving the cursor left into the current word.
+set test "a b| should return b"; # | = cursor position
+set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3; _get_cword}
+assert_bash_list b $cmd $test
+
+
+set test "a | should return nothing"; # | = cursor position
+set cmd {COMP_WORDS=(a); COMP_CWORD=1; COMP_LINE='a '; COMP_POINT=2; _get_cword}
+send "$cmd\r"
+expect -ex "$cmd\r\n/@" {pass "$test"}
+
+
+set test "a b|c should return b"; # | = cursor position
+set cmd {COMP_WORDS=(a bc); COMP_CWORD=1; COMP_LINE='a bc'; COMP_POINT=3; _get_cword}
+assert_bash_list b $cmd $test
+
+
+set test {a b\ c| should return b\ c}; # | = cursor position
+set cmd {COMP_WORDS=(a 'b\ c'); COMP_CWORD=1; COMP_LINE='a b\ c'; COMP_POINT=6; _get_cword}
+assert_bash_list {{"b\\ c"}} $cmd $test
+
+
+# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474094 for useful ideas
+# to make this test pass.
+set test {a 'b c| should return 'b c}; # | = cursor position
+set cmd {COMP_WORDS=(a \' b c); COMP_CWORD=3; COMP_LINE=a\ \'b\ c; COMP_POINT=6; _get_cword}
+send "$cmd\r"
+expect -ex "$cmd\r\n"
+expect {
+ -ex "'b c\r\n/@" { pass "$test" }
+ -ex "c/@" { xfail "$test" }
+}; # expect
+
+
+# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474094 for useful ideas
+# to make this test pass.
+set test {a "b c| should return "b c}; # | = cursor position
+set cmd {COMP_WORDS=(a \" b c); COMP_CWORD=3; COMP_LINE=a\ \"b\ c; COMP_POINT=6; _get_cword}
+send "$cmd\r"
+expect -ex "$cmd\r\n"
+expect {
+ -ex "\"b c\r\n/@" { pass "$test" }
+ -ex "c/@" { xfail "$test" }
+}; # expect
+
+
+set test {a b:c| should return c}; # | = cursor position
+set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword}
+assert_bash_list c $cmd $test
+
+
+set test {a b:c| with WORDBREAKS -= : should return b:c}; # | = cursor position
+set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword :}
+assert_bash_list b:c $cmd $test
+
+
+# This test makes sure `_get_cword' doesn't use `echo' to return it's value,
+# because -n might be interpreted by `echo' and thus will not be returned.
+set test "a -n| should return -n"; # | = cursor position
+set cmd {COMP_WORDS=(a -n); COMP_CWORD=1; COMP_LINE='a -n'; COMP_POINT=4; _get_cword}
+assert_bash_list -n $cmd $test
+
+
teardown
--
bash-completion
More information about the Bash-completion-commits
mailing list