about summary refs log tree commit diff
path: root/Test/Y03arguments.ztst
blob: 0763c419dbcfa749c00e66234d3d582a17b6dc5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# Tests for _arguments.

%prep
  if [[ $OSTYPE = cygwin ]]; then
    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
  elif ( zmodload zsh/zpty 2>/dev/null ); then
    . $ZTST_srcdir/comptest
    mkdir comp.tmp
    cd comp.tmp
    comptestinit -z $ZTST_testdir/../Src/zsh &&
    {
      comptesteval 'compdef _tst tst'
      tst_arguments () { comptesteval "_tst () { _arguments ${${(@qq)*}} }" }
    }
  else
    ZTST_unimplemented="the zsh/zpty module is not available"
  fi

%test
 tst_arguments ':desc1:(arg1)'
 comptest $'tst \t\C-wa\t\C-war\t\C-warg\t\C-warg1\t\C-wr\t\C-wx\t \ty \t'
0:one non-option argument
>line: {tst arg1 }{}
>line: {tst arg1 }{}
>line: {tst arg1 }{}
>line: {tst arg1 }{}
>line: {tst arg1 }{}
>line: {tst r}{}
>line: {tst x}{}
>line: {tst x }{}
>MESSAGE:{no more arguments}
>line: {tst x y }{}
>MESSAGE:{no more arguments}

 tst_arguments ':desc1:(a b)'
 comptest $'tst \t'
0:a and b
>line: {tst }{}
>DESCRIPTION:{desc1}
>NO:{a}
>NO:{b}

 tst_arguments ':desc1:(arg1)' ':desc2:(arg2)' ':desc3:(arg3)'
 comptest $'tst \t\t\t\C-w\C-w\C-w\C-d'
0:three arguments
>line: {tst arg1 }{}
>line: {tst arg1 arg2 }{}
>line: {tst arg1 arg2 arg3 }{}
>DESCRIPTION:{desc1}
>NO:{arg1}

 tst_arguments '1:desc1:(arg1)'
 comptest $'tst \t\t'
0:first argument
>line: {tst arg1 }{}
>line: {tst arg1 }{}
>MESSAGE:{no more arguments}

 tst_arguments '-\+[opt]'
 comptest $'tst -\C-d'
0:-+
>DESCRIPTION:{option}
>NO:{-+  -- opt}

 tst_arguments -+o
 comptest $'tst -\t\t\t\C-w\C-w+\t\t\t'
0:option beginning with + and -.
>line: {tst -o }{}
>line: {tst -o +o }{}
>line: {tst -o +o }{}
>MESSAGE:{no arguments}
>line: {tst +o }{}
>line: {tst +o -o }{}
>line: {tst +o -o }{}
>MESSAGE:{no arguments}

 tst_arguments '-o:1:(a):2:(b)'
 comptest $'tst \t\t\t'
0:two option arguments
>line: {tst -o }{}
>line: {tst -o a }{}
>line: {tst -o a b }{}

 tst_arguments '-x:arg:'
 comptest $'tst -x\t'
0:sticky option argument
>line: {tst -x }{}

 tst_arguments '-x[desc]'
 comptest $'tst -x\t'
0:end of option sequence
>line: {tst -x }{}

 tst_arguments '-x' ':arg:'
 comptest $'tst -\t'
0:argument beginning with minus
>line: {tst -}{}
>DESCRIPTION:{arg}
>DESCRIPTION:{option}
>NO:{-x}

 tst_arguments '-o::optarg:(oa)' ':arg1:(a1)'
 comptest $'tst -o\t\t'
0:optional option argument
>line: {tst -o }{}
>line: {tst -o }{}
>DESCRIPTION:{optarg}
>NO:{oa}
>DESCRIPTION:{arg1}
>NO:{a1}

 tst_arguments '-o:*a:a:(a)' ':A:(A)' ':B:(B)'
 comptest $'tst A -o a \t'
0:variable length option arguments
>line: {tst A -o a B }{}

 tst_arguments -s '-a' '-b' ':descr:{compadd - $+opt_args[-a]}'
 comptest $'tst -ab \t'
0:opt_args
>line: {tst -ab 1 }{}

 tst_arguments '-a:one: :two' ':descr:{compadd -Q - $opt_args[-a]}'
 comptest $'tst -a 1:x \\2 \t'
0:opt_args with multiple arguments and quoting of colons and backslashes
>line: {tst -a 1:x \2 1\:x:\\2 }{}

 tst_arguments '-a' '*::rest:{compadd - -b}'
 comptest $'tst arg -\t'
0:rest arguments
>line: {tst arg -b }{}

 tst_arguments '-e:*last:::b:{compadd "${(j:,:)words}"}' ':arg1:(arg1)'
 comptest $'tst -\t\tla\t\C-hst\t\t\eb\eb\C-b\t\t'
0:words array in rest arguments
>line: {tst -e }{}
>line: {tst -e  }{}
>line: {tst -e  la }{}
>line: {tst -e  last }{}
>line: {tst -e  last arg1 }{}
>line: {tst -e ,last }{ last arg1}
>line: {tst -e ,last ,last,,last }{ last arg1}

 tst_arguments -s '-d+:msg1:' '*::msg2:{compadd $CURRENT}' 
 comptest $'tst add \t\t\t'
0:opt_args
>line: {tst add 2 }{}
>line: {tst add 2 3 }{}
>line: {tst add 2 3 4 }{}

 tst_arguments -s '-a' '-b' '-c' ':words:compadd - abyyy abzzz' 
 comptest $'tst ab\t'
0:options and words (zsh-workers:12257)
>line: {tst ab}{}
>DESCRIPTION:{words}
>NO:{abyyy}
>NO:{abzzz}

 tst_arguments -x :word
 comptest $'tst -- -\t'
0:option after --
>line: {tst -- -x }{}

 tst_arguments -S -x ':word:()'
 comptest $'tst -- -\t'
0:disallowed option after --
>line: {tst -- -}{}

 tst_arguments -S -x ':word:()'
 comptest $'tst - --\eB\C-b\t'
0:allowed option before --
>line: {tst -x }{ --}

 tst_arguments -x :word
 comptest $'tst word -\t'
0:option after a word
>line: {tst word -x }{}

 tst_arguments -A '-*' -x :word
 comptest $'tst word -\t'
0:option after word that doesn't match -A pattern
>line: {tst word -}{}
>MESSAGE:{no more arguments}

 tst_arguments -A '-*' -x ':word:(-word)'
 comptest $'tst  word\eB\C-b-\t'
0:option before a word that doesn't match -A pattern
>line: {tst -}{ word}
>DESCRIPTION:{word}
>NO:{-word}
>DESCRIPTION:{option}
>NO:{-x}

 tst_arguments -A '-*' -h -V -a '*: :(-x more)'
 comptest $'tst -a -x m\t'
0:continue completion after rest argument that looks like an option
>line: {tst -a -x more }{}

 tst_arguments -A '-*' - help -h -V - other -a '*: :(-x more)'
 comptest $'tst -a -x m\t'
0:continue completion after rest argument that looks like an option (with sets)
>line: {tst -a -x more }{}

 tst_arguments '(-v)-a' '(set1--m -a)-b' - '(set1)' -m -n - set2 -v -w
 comptest $'tst -a -\t' $'\C-w\C-w-'{b,m,v}$' -\t'
0:exclusion lists
>line: {tst -a -}{}
>DESCRIPTION:{option}
>NO:{-b}
>NO:{-m}
>NO:{-n}
>NO:{-w}
>line: {tst -b -}{}
>DESCRIPTION:{option}
>NO:{-n}
>NO:{-v}
>NO:{-w}
>line: {tst -m -}{}
>DESCRIPTION:{option}
>NO:{-a}
>NO:{-b}
>NO:{-v}
>NO:{-w}
>line: {tst -v -}{}
>DESCRIPTION:{option}
>NO:{-a}
>NO:{-b}
>NO:{-m}
>NO:{-n}
>NO:{-w}

 tst_arguments '(-)-h' -a -b -c
 comptest $'tst -h -\t'
0:exclude all other options
>line: {tst -h -}{}
>MESSAGE:{no arguments}

# this would ideally not offer -b as it is already on the command-line
 tst_arguments -a '(-a)-b'
 comptest $'tst - -b\C-b\C-b\C-b\t'
0:exclusion only applies to later words
>line: {tst -}{ -b}
>DESCRIPTION:{option}
>NO:{-a}
>NO:{-b}

 tst_arguments --abc --aah :arg:
 comptesteval 'setopt bashautolist automenu'
 comptest $'tst --a\t\t\t'
0:with message and bashautolist, a third tab will get menu completion
>line: {tst --a}{}
>line: {tst --a}{}
>DESCRIPTION:{arg}
>DESCRIPTION:{option}
>NO:{--aah}
>NO:{--abc}
>line: {tst --aah}{}

 tst_arguments --abc --aah :arg:
 comptesteval 'setopt bashautolist noautomenu'
 comptest $'tst --a\t\t\t'
0:with message and bashautolist, a third tab is needed to display the list
>line: {tst --a}{}
>line: {tst --a}{}
>DESCRIPTION:{arg}
>DESCRIPTION:{option}
>NO:{--aah}
>NO:{--abc}
>line: {tst --a}{}

 tst_arguments --abc --aah :arg:
 comptesteval 'setopt nobashautolist noautomenu'
 comptest $'tst --\t\t'
0:with message and noautomenu second tab redisplays the list
>line: {tst --}{}
>DESCRIPTION:{arg}
>DESCRIPTION:{option}
>NO:{--aah}
>NO:{--abc}
>line: {tst --}{}
>DESCRIPTION:{arg}
>DESCRIPTION:{option}
>NO:{--aah}
>NO:{--abc}

 tst_arguments --abc --aah :arg:
 comptesteval 'setopt nobashautolist automenu'
 comptest $'tst --\t\t'
0:with message two tabs will start menu completion
>line: {tst --}{}
>DESCRIPTION:{arg}
>DESCRIPTION:{option}
>NO:{--aah}
>NO:{--abc}
>line: {tst --aah}{}

 tst_arguments --abc --aah :arg:
 comptesteval 'zstyle ":completion:*::::" completer _oldlist _complete'
 comptest $'tst --\t\t'
0:with message and _oldlist, two tabs will start menu completion
>line: {tst --}{}
>DESCRIPTION:{arg}
>DESCRIPTION:{option}
>NO:{--aah}
>NO:{--abc}
>line: {tst --aah}{}

%clean

  zmodload -ui zsh/zpty