2009-06-09 23:52:47 +02:00
|
|
|
proc setup {} {
|
|
|
|
save_env
|
|
|
|
}; # setup()
|
|
|
|
|
|
|
|
|
|
|
|
proc teardown {} {
|
2009-09-07 00:26:27 +02:00
|
|
|
assert_env_unmodified {
|
|
|
|
/COMP_CWORD=/d
|
|
|
|
/COMP_LINE=/d
|
|
|
|
/COMP_POINT=/d
|
|
|
|
/COMP_WORDS=/d
|
2009-09-16 22:20:15 +02:00
|
|
|
# Delete 'COMP_WORDBREAKS' occupying two lines
|
|
|
|
/COMP_WORDBREAKS=/{N
|
|
|
|
d}
|
2009-09-07 00:26:27 +02:00
|
|
|
}
|
2009-06-09 23:52:47 +02:00
|
|
|
}; # teardown()
|
|
|
|
|
|
|
|
|
|
|
|
setup
|
|
|
|
|
|
|
|
|
|
|
|
set test "_get_cword should run without errors"
|
|
|
|
assert_bash_exec {_get_cword > /dev/null} $test
|
|
|
|
|
|
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
|
|
|
# See also ./lib/completions/alias.exp. Here `_get_cword' is actually tested
|
|
|
|
# by moving the cursor left into the current word.
|
|
|
|
|
|
|
|
|
2009-09-07 00:26:27 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
2009-09-07 00:26:27 +02:00
|
|
|
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"}
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
2009-09-07 00:26:27 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
2009-09-07 00:26:27 +02:00
|
|
|
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}
|
2009-12-02 22:38:30 +01:00
|
|
|
assert_bash_list {"b\\ c"} $cmd $test
|
2009-09-07 00:26:27 +02:00
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
2009-09-16 22:20:15 +02:00
|
|
|
set test {a b\| c should return b\ }; # | = cursor position
|
|
|
|
set cmd {COMP_WORDS=(a 'b\ c'); COMP_CWORD=1; COMP_LINE='a b\ c'; COMP_POINT=4; _get_cword}
|
2009-12-02 22:38:30 +01:00
|
|
|
assert_bash_list {"b\\"} $cmd $test
|
2009-09-16 22:20:15 +02:00
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
|
|
|
set test {a "b\| should return "b\ }; # | = cursor position
|
2009-09-16 22:20:15 +02:00
|
|
|
set cmd {COMP_WORDS=(a '"b\'); COMP_CWORD=1; COMP_LINE='a "b\'; COMP_POINT=5; _get_cword}
|
2009-12-02 22:38:30 +01:00
|
|
|
assert_bash_list {"\"b\\"} $cmd $test
|
2009-09-20 14:11:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
sync_after_int
|
2009-09-16 22:20:15 +02:00
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
set test {a 'b c| should return 'b c}; # | = cursor position
|
2009-12-06 23:16:31 +01:00
|
|
|
if {
|
|
|
|
[lindex $::BASH_VERSINFO 0] == 4 &&
|
|
|
|
[lindex $::BASH_VERSINFO 1] == 0 &&
|
|
|
|
[lindex $::BASH_VERSINFO 2] < 35
|
|
|
|
} {
|
2009-09-20 14:11:26 +02:00
|
|
|
set cmd {COMP_WORDS=(a "'" b c); COMP_CWORD=3}
|
2009-12-06 23:16:31 +01:00
|
|
|
} else {
|
|
|
|
set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1}
|
2009-09-20 14:11:26 +02:00
|
|
|
}; # if
|
|
|
|
append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_cword}
|
2009-09-07 00:26:27 +02:00
|
|
|
send "$cmd\r"
|
|
|
|
expect -ex "$cmd\r\n"
|
|
|
|
expect {
|
2009-09-20 14:11:26 +02:00
|
|
|
-ex "'b c/@" { pass "$test" }
|
2009-12-06 23:16:31 +01:00
|
|
|
-ex "c/@" {
|
|
|
|
if {
|
|
|
|
[lindex $::BASH_VERSINFO 0] == 4 &&
|
|
|
|
[lindex $::BASH_VERSINFO 1] == 0 &&
|
|
|
|
[lindex $::BASH_VERSINFO 2] < 35
|
|
|
|
} {xfail "$test"} {fail "$test"}
|
|
|
|
}
|
2009-09-07 00:26:27 +02:00
|
|
|
}; # expect
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
|
|
|
set test {a "b c| should return "b c}; # | = cursor position
|
2009-12-06 23:16:31 +01:00
|
|
|
if {
|
|
|
|
[lindex $::BASH_VERSINFO 0] == 4 &&
|
|
|
|
[lindex $::BASH_VERSINFO 1] == 0 &&
|
|
|
|
[lindex $::BASH_VERSINFO 2] < 35
|
|
|
|
} {
|
|
|
|
set cmd {COMP_WORDS=(a "\"" b c); COMP_CWORD=3}
|
|
|
|
} else {
|
|
|
|
set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1}
|
|
|
|
}; # if
|
|
|
|
append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6; _get_cword};
|
2009-09-07 00:26:27 +02:00
|
|
|
send "$cmd\r"
|
|
|
|
expect -ex "$cmd\r\n"
|
|
|
|
expect {
|
2009-09-20 14:11:26 +02:00
|
|
|
-ex "\"b c/@" { pass "$test" }
|
2009-12-06 23:16:31 +01:00
|
|
|
-ex "c/@" {
|
|
|
|
if {
|
|
|
|
[lindex $::BASH_VERSINFO 0] == 4 &&
|
|
|
|
[lindex $::BASH_VERSINFO 1] == 0 &&
|
|
|
|
[lindex $::BASH_VERSINFO 2] < 35
|
|
|
|
} {xfail "$test"} {fail "$test"}
|
|
|
|
}
|
2009-09-07 00:26:27 +02:00
|
|
|
}; # expect
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
2009-12-06 23:16:31 +01:00
|
|
|
set test {a b:c| with WORDBREAKS += : should return b:c (bash-3) or c (bash-4)}; # | = cursor position
|
2009-12-05 14:53:47 +01:00
|
|
|
if {[lindex $::BASH_VERSINFO 0] <= 3} {
|
2009-09-20 14:11:26 +02:00
|
|
|
set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1}
|
|
|
|
set expected b:c
|
|
|
|
} else {
|
2009-12-06 23:16:31 +01:00
|
|
|
set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3}
|
2009-09-20 14:11:26 +02:00
|
|
|
set expected c
|
|
|
|
}; # if
|
|
|
|
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword}
|
|
|
|
assert_bash_list $expected $cmd $test
|
|
|
|
|
|
|
|
|
|
|
|
sync_after_int
|
2009-09-07 00:26:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
set test {a b:c| with WORDBREAKS -= : should return b:c}; # | = cursor position
|
2009-12-05 14:53:47 +01:00
|
|
|
if {[lindex $::BASH_VERSINFO 0] <= 3} {
|
2009-09-20 14:11:26 +02:00
|
|
|
set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1}
|
|
|
|
} else {
|
|
|
|
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
|
|
|
|
}; # if
|
|
|
|
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword :}
|
2009-09-07 00:26:27 +02:00
|
|
|
assert_bash_list b:c $cmd $test
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
2009-12-06 23:16:31 +01:00
|
|
|
set test {a :| with WORDBREAKS -= : should return :}; # | = cursor position
|
|
|
|
set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3; _get_cword :}
|
|
|
|
assert_bash_list : $cmd $test
|
|
|
|
|
|
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
2009-09-07 00:26:27 +02:00
|
|
|
# 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
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
2009-09-16 22:20:15 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
|
|
|
set test {a b=c| should return b=c (bash-3) or c (bash-4)}; # | = cursor position
|
2009-12-05 14:53:47 +01:00
|
|
|
if {[lindex $::BASH_VERSINFO] <= 3} {
|
2009-09-20 14:11:26 +02:00
|
|
|
set cmd {COMP_WORDS=(a "b=c"); COMP_CWORD=1}
|
|
|
|
set expected b=c
|
|
|
|
} else {
|
|
|
|
set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3}
|
|
|
|
set expected c
|
|
|
|
}; # if
|
|
|
|
append cmd {; COMP_LINE='a b=c'; COMP_POINT=5; _get_cword}
|
|
|
|
assert_bash_list $expected $cmd $test
|
|
|
|
|
|
|
|
|
|
|
|
sync_after_int
|
2009-09-16 22:20:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
set test {a *| should return *}; # | = cursor position
|
|
|
|
set cmd {COMP_WORDS=(a \*); COMP_CWORD=1; COMP_LINE='a *'; COMP_POINT=4; _get_cword}
|
|
|
|
assert_bash_list * $cmd $test
|
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
|
|
|
|
set test {a $(b c| should return $(b c}; # | = cursor position
|
2009-09-16 22:20:15 +02:00
|
|
|
set cmd {COMP_WORDS=(a '$(b c'); COMP_CWORD=1; COMP_LINE='a $(b c'; COMP_POINT=7; _get_cword}
|
2009-09-20 14:11:26 +02:00
|
|
|
#assert_bash_list {{$(b\ c}} $cmd $test
|
|
|
|
send "$cmd\r"
|
|
|
|
expect -ex "$cmd\r\n"
|
|
|
|
expect {
|
|
|
|
-ex "\$(b c/@" { pass "$test" }
|
|
|
|
# Expected failure on bash-4
|
|
|
|
-ex "c/@" { xfail "$test" }
|
|
|
|
}; # expect
|
|
|
|
|
|
|
|
|
|
|
|
sync_after_int
|
2009-09-16 22:20:15 +02:00
|
|
|
|
|
|
|
|
2009-09-20 14:11:26 +02:00
|
|
|
set test {a $(b c\ d| should return $(b c\ d}; # | = cursor position
|
2009-09-16 22:20:15 +02:00
|
|
|
set cmd {COMP_WORDS=(a '$(b c\ d'); COMP_CWORD=1; COMP_LINE='a $(b c\ d'; COMP_POINT=10; _get_cword}
|
2009-09-20 14:11:26 +02:00
|
|
|
#assert_bash_list {{$(b\ c\\\ d}} $cmd $test
|
|
|
|
send "$cmd\r"
|
|
|
|
expect -ex "$cmd\r\n"
|
|
|
|
expect {
|
|
|
|
-ex "\$(b c\\ d/@" { pass "$test" }
|
|
|
|
# Expected failure on bash-4
|
|
|
|
-ex "c\\ d/@" { xfail "$test" }
|
|
|
|
}; # expect
|
|
|
|
|
|
|
|
|
|
|
|
sync_after_int
|
2009-09-16 22:20:15 +02:00
|
|
|
|
|
|
|
|
2009-06-09 23:52:47 +02:00
|
|
|
teardown
|