51
set test "|a"; # | = cursor position
52
set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='a'; COMP_POINT=0; \
53
unset cur prev; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
54
assert_bash_list {" "} $cmd $test
60
set test "|a \$"; # | = cursor position
61
set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='a '; COMP_POINT=0; \
62
unset cur prev; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
63
assert_bash_list {" "} $cmd $test
69
set test " | a \$"; # | = cursor position
70
set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE=' a '; COMP_POINT=1; \
71
unset cur prev; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
72
assert_bash_list {" "} $cmd $test
51
78
set test "a b |"; # | = cursor position
52
79
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"}
53
80
assert_bash_list {" b"} $cmd $test
102
set test "a | b"; # | = cursor position
103
set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=2; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
104
assert_bash_list {" a"} $cmd $test
75
110
set test {a b\ c| should return b\ c}; # | = cursor position
76
111
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"}
77
112
assert_bash_list {"b\\ c a"} $cmd $test
118
set test {a\ b a\ b| should return a\ b}; # | = cursor position
119
set cmd {COMP_WORDS=('a\ b' 'a\ b'); COMP_CWORD=1; COMP_LINE='a\ b a\ b'; COMP_POINT=9; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
120
assert_bash_list {"a\\ b a\\ b"} $cmd $test
83
126
set test {a b\| c should return b\ }; # | = cursor position
84
127
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"}
85
128
assert_bash_list {"b\\ a"} $cmd $test
99
142
set test {a 'b c|}; # | = cursor position
101
[lindex $::BASH_VERSINFO 0] == 4 &&
102
[lindex $::BASH_VERSINFO 1] == 0 &&
103
[lindex $::BASH_VERSINFO 2] < 35
105
set cmd {COMP_WORDS=(a "'" b c); COMP_CWORD=3}
107
set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1}
143
set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1}
109
144
append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
111
146
expect -ex "$cmd\r\n"
113
148
-ex "'b c a\r\n/@" { pass "$test" }
116
[lindex $::BASH_VERSINFO 0] == 4 &&
117
[lindex $::BASH_VERSINFO 1] == 0 &&
118
[lindex $::BASH_VERSINFO 2] < 35
119
} {xfail "$test"} {fail "$test"}
149
-ex "c b\r\n/@" { fail "$test" }
127
156
set test {a "b c|}; #"# | = cursor position
129
[lindex $::BASH_VERSINFO 0] == 4 &&
130
[lindex $::BASH_VERSINFO 1] == 0 &&
131
[lindex $::BASH_VERSINFO 2] < 35
133
set cmd {COMP_WORDS=(a "\"" b c); COMP_CWORD=3}
135
set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1}
157
set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1}
137
158
append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6}
138
159
assert_bash_exec $cmd
139
160
set cmd {_get_comp_words_by_ref cur prev; echo "$cur $prev"};
141
162
expect -ex "$cmd\r\n"
143
164
-ex "\"b c a\r\n/@" { pass "$test" }
146
[lindex $::BASH_VERSINFO 0] == 4 &&
147
[lindex $::BASH_VERSINFO 1] == 0 &&
148
[lindex $::BASH_VERSINFO 2] < 35
149
} {xfail "$test"} {fail "$test"}
165
-ex "c b\r\n/@" { fail "$test" }
157
172
set test {a b:c| with WORDBREAKS += :}; # | = cursor position
158
if {[lindex $::BASH_VERSINFO 0] <= 3} {
159
set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1}
160
set expected {"b:c a"}
162
set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3}
173
set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3}
165
175
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5}
166
176
# NOTE: Split-send cmd to prevent backspaces (\008) in output
167
177
assert_bash_exec $cmd $test
175
185
set test {a b:c| with WORDBREAKS -= :}; # | = cursor position
176
if {[lindex $::BASH_VERSINFO 0] <= 3} {
177
set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1}
179
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
186
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
181
187
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5}
182
188
assert_bash_exec $cmd $test
183
189
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
190
196
set test {a b c:| with WORDBREAKS -= :}; # | = cursor position
191
if {[lindex $::BASH_VERSINFO 0] <= 3} {
192
set cmd {COMP_WORDS=(a b c:); COMP_CWORD=2}
194
set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3}
197
set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3}
196
198
append cmd {; COMP_LINE='a b c:'; COMP_POINT=6}
197
199
assert_bash_exec $cmd $test
198
200
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
205
207
set test {a b:c | with WORDBREAKS -= :}; # | = cursor position
206
if {[lindex $::BASH_VERSINFO 0] <= 3} {
207
set cmd {COMP_WORDS=(a b:c ''); COMP_CWORD=2}
209
set cmd {COMP_WORDS=(a b : c ''); COMP_CWORD=4}
208
set cmd {COMP_WORDS=(a b : c ''); COMP_CWORD=4}
211
209
append cmd {; COMP_LINE='a b:c '; COMP_POINT=6}
212
210
assert_bash_exec $cmd $test
213
211
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
230
228
set test {a b::| with WORDBREAKS -= : should return b::}; # | = cursor position
231
if {[lindex $::BASH_VERSINFO 0] <= 3} {
232
set cmd {COMP_WORDS=(a "b::"); COMP_CWORD=1}
234
set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2}
229
set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2}
236
230
append cmd {; COMP_LINE='a b::'; COMP_POINT=5}
237
231
assert_bash_exec $cmd
238
232
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
267
set test {a b=c| should return b=c (bash-3) or c (bash-4)}; # | = cursor position
268
if {[lindex $::BASH_VERSINFO] <= 3} {
269
set cmd {COMP_WORDS=(a "b=c"); COMP_CWORD=1}
272
set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3}
261
set test {a b=c| should return c}; # | = cursor position
262
set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3}
275
264
append cmd {; COMP_LINE='a b=c'; COMP_POINT=5}
276
265
assert_bash_exec $cmd
277
266
set cmd {_get_comp_words_by_ref cur prev; echo "$cur"}
327
316
set test {a 'b&c| should return 'b&c}; # | = cursor position
329
[lindex $::BASH_VERSINFO 0] == 4 &&
330
[lindex $::BASH_VERSINFO 1] == 0 &&
331
[lindex $::BASH_VERSINFO 2] < 35
333
set cmd {COMP_WORDS=(a "'" b "&" c); COMP_CWORD=4}
335
set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1}
317
set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1}
337
318
append cmd {; COMP_LINE="a 'b&c"; COMP_POINT=6}
338
319
assert_bash_exec $cmd
339
320
set cmd {_get_comp_words_by_ref cur prev; printf %s "$cur"}
341
322
expect -ex "$cmd\r\n"
343
324
-ex "'b&c/@" { pass "$test" }
346
[lindex $::BASH_VERSINFO 0] == 4 &&
347
[lindex $::BASH_VERSINFO 1] == 0 &&
348
[lindex $::BASH_VERSINFO 2] < 35
349
} {xfail "$test"} {fail "$test"}
325
-ex "c/@" { fail "$test" }
376
set test {a b : c| with WORDBREAKS -= :}; # | = cursor position
377
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3; COMP_LINE='a b : c'; COMP_POINT=7}
378
assert_bash_exec $cmd $test
379
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
380
assert_bash_list {"a b : c"} $cmd $test
386
set test {a b: c| with WORDBREAKS -= :}; # | = cursor position
387
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
388
append cmd {; COMP_LINE='a b: c'; COMP_POINT=6}
389
assert_bash_exec $cmd $test
390
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
391
assert_bash_list {"a b: c"} $cmd $test
397
set test {a b :c| with WORDBREAKS -= :}; # | = cursor position
398
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
399
append cmd {; COMP_LINE='a b :c'; COMP_POINT=6}
400
assert_bash_exec $cmd $test
401
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
402
assert_bash_list {"a b :c"} $cmd $test
408
set test {a b\ :c| with WORDBREAKS -= :}; # | = cursor position
409
set cmd {COMP_WORDS=(a "b\\ " : c); COMP_CWORD=3}
410
append cmd {; COMP_LINE='a b\ :c'; COMP_POINT=7}
411
assert_bash_exec $cmd $test
412
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
413
assert_bash_list {a "b\\ :c"} $cmd $test