377 lines
9.8 KiB
Plaintext
377 lines
9.8 KiB
Plaintext
proc setup {} {
|
|
assert_bash_exec {unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS}
|
|
save_env
|
|
}
|
|
|
|
|
|
proc teardown {} {
|
|
assert_bash_exec { \
|
|
unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS cur prev words cword \
|
|
cur2 prev2 words2 cword2 \
|
|
}
|
|
# Delete 'COMP_WORDBREAKS' occupying two lines
|
|
assert_env_unmodified {
|
|
/COMP_WORDBREAKS=/{N
|
|
d
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
setup
|
|
|
|
|
|
set test "_get_comp_words_by_ref should run without errors"
|
|
assert_bash_exec {_get_comp_words_by_ref cur > /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.
|
|
|
|
|
|
set test "a b|"; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
assert_bash_list {"b a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test "a |"; # | = cursor position
|
|
set cmd {COMP_WORDS=(a); COMP_CWORD=1; COMP_LINE='a '; COMP_POINT=2; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
assert_bash_list {" a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test "a b |"; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b ''); COMP_CWORD=2; COMP_LINE='a b '; COMP_POINT=4; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
assert_bash_list {" b"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test "a b | with WORDBREAKS -= :"; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b ''); COMP_CWORD=2; COMP_LINE='a b '; COMP_POINT=4; _get_comp_words_by_ref -n : cur; printf %s "$cur"}
|
|
assert_bash_list {} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test "a b|c"; # | = cursor position
|
|
set cmd {COMP_WORDS=(a bc); COMP_CWORD=1; COMP_LINE='a bc'; COMP_POINT=3; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
assert_bash_list {"b a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
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_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
assert_bash_list {"b\\ c a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
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_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
assert_bash_list {"b\\ a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a "b\|}; #"# | = cursor position
|
|
set cmd {COMP_WORDS=(a '"b\'); COMP_CWORD=1; COMP_LINE='a "b\'; COMP_POINT=5; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
assert_bash_list {"\"b\\ a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a 'b c|}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1}
|
|
append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
send "$cmd\r"
|
|
expect -ex "$cmd\r\n"
|
|
expect {
|
|
-ex "'b c a\r\n/@" { pass "$test" }
|
|
-ex "c b\r\n/@" { fail "$test" }
|
|
}
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a "b c|}; #"# | = cursor position
|
|
set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1}
|
|
append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref cur prev; echo "$cur $prev"};
|
|
send "$cmd\r"
|
|
expect -ex "$cmd\r\n"
|
|
expect {
|
|
-ex "\"b c a\r\n/@" { pass "$test" }
|
|
-ex "c b\r\n/@" { fail "$test" }
|
|
}
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b:c| with WORDBREAKS += :}; # | = cursor position
|
|
set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3}
|
|
set expected {"c :"}
|
|
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5}
|
|
# NOTE: Split-send cmd to prevent backspaces (\008) in output
|
|
assert_bash_exec $cmd $test
|
|
set cmd {_get_comp_words_by_ref cur prev; echo "$cur $prev"}
|
|
assert_bash_list $expected $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b:c| with WORDBREAKS -= :}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
|
|
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5}
|
|
assert_bash_exec $cmd $test
|
|
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
|
|
assert_bash_list {"b:c a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b c:| with WORDBREAKS -= :}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3}
|
|
append cmd {; COMP_LINE='a b c:'; COMP_POINT=6}
|
|
assert_bash_exec $cmd $test
|
|
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
|
|
assert_bash_list {"c: b"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b:c | with WORDBREAKS -= :}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b : c ''); COMP_CWORD=4}
|
|
append cmd {; COMP_LINE='a b:c '; COMP_POINT=6}
|
|
assert_bash_exec $cmd $test
|
|
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
|
|
assert_bash_list {" b:c"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a :| with WORDBREAKS -= : should return :}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
|
|
assert_bash_list {": a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b::| with WORDBREAKS -= : should return b::}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2}
|
|
append cmd {; COMP_LINE='a b::'; COMP_POINT=5}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
|
|
assert_bash_list {"b:: a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
# 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}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref cur; printf "%s\n" $cur}
|
|
assert_bash_list -n $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
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}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref cur prev; echo "$cur"}
|
|
assert_bash_list c $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b=c| should return c}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3}
|
|
set expected c
|
|
append cmd {; COMP_LINE='a b=c'; COMP_POINT=5}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref cur prev; echo "$cur"}
|
|
assert_bash_list $expected $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a *| should return *}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a \*); COMP_CWORD=1; COMP_LINE='a *'; COMP_POINT=4}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref cur; echo "$cur"}
|
|
assert_bash_list * $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
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=7}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref cur; printf %s "$cur"}
|
|
send "$cmd\r"
|
|
expect -ex "$cmd\r\n"
|
|
expect {
|
|
-ex "\$(b c/@" { pass "$test" }
|
|
# Expected failure on bash-4
|
|
-ex "c/@" { xfail "$test" }
|
|
}
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a $(b c\ d| should return $(b c\ d}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a '$(b c\ d'); COMP_CWORD=1; COMP_LINE='a $(b c\ d'; COMP_POINT=10}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref cur; printf %s "$cur"}
|
|
#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" }
|
|
}
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a 'b&c| should return 'b&c}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1}
|
|
append cmd {; COMP_LINE="a 'b&c"; COMP_POINT=6}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref cur prev; printf %s "$cur"}
|
|
send "$cmd\r"
|
|
expect -ex "$cmd\r\n"
|
|
expect {
|
|
-ex "'b&c/@" { pass "$test" }
|
|
-ex "c/@" { fail "$test" }
|
|
}
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {unknown argument should raise error}
|
|
set cmd {_get_comp_words_by_ref dummy}
|
|
assert_bash_list {"bash: _get_comp_words_by_ref(): `dummy': unknown argument"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test "a b| to all vars"; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3}
|
|
assert_bash_exec $cmd
|
|
set cmd { \
|
|
_get_comp_words_by_ref words cword prev cur; echo "${words[@]} $cword $cur $prev" \
|
|
}
|
|
assert_bash_list {"a b 1 b a"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test "a b| to alternate vars"; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3;}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref -c cur2 -p prev2 -w words2 -i cword2}
|
|
assert_bash_exec $cmd
|
|
set cmd {echo "$cur2 $prev2 ${words2[@]} $cword2"}
|
|
assert_bash_list {"b a a b 1"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test "a b| to alternate vars"; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3;}
|
|
assert_bash_exec $cmd
|
|
set cmd {_get_comp_words_by_ref -c cur2 -p prev2 -w words2 -i cword2}
|
|
assert_bash_exec $cmd
|
|
set cmd {echo "$cur2 $prev2 ${words2[@]} $cword2"}
|
|
assert_bash_list {"b a a b 1"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b : c| with WORDBREAKS -= :}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3; COMP_LINE='a b : c'; COMP_POINT=7}
|
|
assert_bash_exec $cmd $test
|
|
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
|
|
assert_bash_list {"a b : c"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b: c| with WORDBREAKS -= :}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
|
|
append cmd {; COMP_LINE='a b: c'; COMP_POINT=6}
|
|
assert_bash_exec $cmd $test
|
|
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
|
|
assert_bash_list {"a b: c"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b :c| with WORDBREAKS -= :}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
|
|
append cmd {; COMP_LINE='a b :c'; COMP_POINT=6}
|
|
assert_bash_exec $cmd $test
|
|
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
|
|
assert_bash_list {"a b :c"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
set test {a b\ :c| with WORDBREAKS -= :}; # | = cursor position
|
|
set cmd {COMP_WORDS=(a "b\\ " : c); COMP_CWORD=3}
|
|
append cmd {; COMP_LINE='a b\ :c'; COMP_POINT=7}
|
|
assert_bash_exec $cmd $test
|
|
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
|
|
assert_bash_list {a "b\\ :c"} $cmd $test
|
|
|
|
|
|
sync_after_int
|
|
|
|
|
|
teardown
|