]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/extglob.tests
Imported from ../bash-3.2.tar.gz.
[thirdparty/bash.git] / tests / extglob.tests
CommitLineData
cce855bc
JA
1# test the ksh-like extended globbing features: [!@*?+](patlist)
2
3shopt -s extglob
4
5expect()
6{
7 echo expect "$@"
8}
9
10case "/dev/udp/129.22.8.102/45" in
11/dev/@(tcp|udp)/*/*) echo ok 1;;
12*) echo bad 1;;
13esac
14
15# valid numbers
16case 12 in
170|[1-9]*([0-9])) echo ok 2;;
18*) echo bad 2;;
19esac
20
21case 12abc in
220|[1-9]*([0-9])) echo bad 3;;
23*) echo ok 3;;
24esac
25
26case 1 in
270|[1-9]*([0-9])) echo ok 4;;
28*) echo bad 4;;
29esac
30
31# octal numbers
32case 07 in
33+([0-7])) echo ok 5;;
34*) echo bad 5;;
35esac
36
37case 0377 in
38+([0-7])) echo ok 6;;
39*) echo bad 6;;
40esac
41
42case 09 in
43+([0-7])) echo bad 7;;
44*) echo ok 7;;
45esac
46
47# stuff from korn's book
48case paragraph in
49para@(chute|graph)) echo ok 8;;
50*) echo bad 8;;
51esac
52
53case paramour in
54para@(chute|graph)) echo bad 9;;
55*) echo ok 9;;
56esac
57
58case para991 in
59para?([345]|99)1) echo ok 10;;
60*) echo bad 10;;
61esac
62
63case para381 in
64para?([345]|99)1) echo bad 11;;
65*) echo ok 11;;
66esac
67
68case paragraph in
69para*([0-9])) echo bad 12;;
70*) echo ok 12;;
71esac
72
73case para in
74para*([0-9])) echo ok 13;;
75*) echo bad 13;;
76esac
77
78case para13829383746592 in
79para*([0-9])) echo ok 14;;
80*) echo bad 14;;
81esac
82
83case paragraph in
84para*([0-9])) echo bad 15;;
85*) echo ok 15;;
86esac
87
88case para in
89para+([0-9])) echo bad 16;;
90*) echo ok 16;;
91esac
92
93case para987346523 in
94para+([0-9])) echo ok 17;;
95*) echo bad 17;;
96esac
97
98case paragraph in
99para!(*.[0-9])) echo ok 18;;
100*) echo bad 18;;
101esac
102
103case para.38 in
104para!(*.[0-9])) echo ok 19;;
105*) echo bad 19;;
106esac
107
108case para.graph in
109para!(*.[0-9])) echo ok 20;;
110*) echo bad 20;;
111esac
112
113case para39 in
114para!(*.[0-9])) echo ok 21;;
115*) echo bad 21;;
116esac
117
118# tests derived from those in rosenblatt's korn shell book
119
120case "" in
121*(0|1|3|5|7|9)) echo ok 22;;
122*) echo bad 22;
123esac
124
125case 137577991 in
126*(0|1|3|5|7|9)) echo ok 23;;
127*) echo bad 23;
128esac
129
130case 2468 in
131*(0|1|3|5|7|9)) echo bad 24;;
132*) echo ok 24;
133esac
134
135case file.c in
136*.c?(c)) echo ok 25;;
137*) echo bad 25;;
138esac
139
140case file.C in
141*.c?(c)) echo bad 26;;
142*) echo ok 26;;
143esac
144
145case file.cc in
146*.c?(c)) echo ok 27;;
147*) echo bad 27;;
148esac
149
150case file.ccc in
151*.c?(c)) echo bad 28;;
152*) echo ok 28;;
153esac
154
155case parse.y in
156!(*.c|*.h|Makefile.in|config*|README)) echo ok 29;;
157*) echo bad 29;;
158esac
159
160case shell.c in
161!(*.c|*.h|Makefile.in|config*|README)) echo bad 30;;
162*) echo ok 30;;
163esac
164
165case Makefile in
166!(*.c|*.h|Makefile.in|config*|README)) echo ok 31;;
167*) echo bad 31;;
168esac
169
170case "VMS.FILE;1" in
171*\;[1-9]*([0-9])) echo ok 32;;
172*) echo bad 32;;
173esac
174
175case "VMS.FILE;0" in
176*\;[1-9]*([0-9])) echo bad 33;;
177*) echo ok 33;;
178esac
179case "VMS.FILE;" in
180*\;[1-9]*([0-9])) echo bad 34;;
181*) echo ok 34;;
182esac
183case "VMS.FILE;139" in
184*\;[1-9]*([0-9])) echo ok 35;;
185*) echo bad 35;;
186esac
187case "VMS.FILE;1N" in
188*\;[1-9]*([0-9])) echo bad 36;;
189*) echo ok 36;;
190esac
191
192# tests derived from the pd-ksh test suite
193
194MYDIR=$PWD # save where we are
195
0628567a 196TESTDIR=/tmp/eglob-test-$$
cce855bc
JA
197mkdir $TESTDIR
198builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
199rm -rf *
200
201touch abcx abcz bbc
202expect '!([*)*'
203echo !([*)*
204
205expect '+(a|b[)*'
206echo +(a|b[)*
207
208expect '[a*(]*z'
209echo [a*(]*)z
210
211rm -f abcx abcz bbc
212
213touch abc
214
215expect '+()c'
216echo +()c
217expect '+()x'
218echo +()x
219expect abc
220echo +(*)c
221expect '+(*)x'
222echo +(*)x
223
224# extended globbing should not be performed on the output of substitutions
225x='@(*)'
226expect '@(*)'
227echo $x
228
229expect 'no-file+(a|b)stuff'
230echo no-file+(a|b)stuff
231expect 'no-file+(a*(c)|b)stuff'
232echo no-file+(a*(c)|b)stuff
233
234touch abd acd
235
236expect 'abd acd'
237echo a+(b|c)d
238
239expect 'acd'
240echo a!(@(b|B))d
241
242expect 'abd'
243echo a[b*(foo|bar)]d
244
245# simple kleene star tests
246expect no
247case foo in *(a|b[)) echo yes;; *) echo no;; esac
248
249expect yes
250case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
251
252# this doesn't work right yet; it is an incorrectly formed pattern
253expect yes
254case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
255
256# check extended globbing in pattern removal -- these don't work right yet
257x=abcdef
258
259expect '1: bcdef'
260echo 1: ${x#+(a|abc)}
261expect '2: def'
262echo 2: ${x##+(a|abc)}
263expect '3: abcde'
264echo 3: ${x%+(def|f)}
265expect '4: abc'
266echo 4: ${x%%+(f|def)}
267
268# these work ok
269
270expect '5: ef'
271echo 5: ${x#*(a|b)cd}
272expect '6: ef'
273echo 6: "${x#*(a|b)cd}"
274expect '7: abcdef'
275echo 7: ${x#"*(a|b)cd"}
276
b72432fd
JA
277# More tests derived from a bug report concerning extended glob patterns
278# following a *
279builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
280rm -rf *
281
282touch ab abcdef abef abcfef
283
284expect 'ab abef'
285echo ab*(e|f)
286
287expect 'abcfef abef'
288echo ab?*(e|f)
289
290expect abcdef
291echo ab*d+(e|f)
292
293expect 'ab abcdef abcfef abef'
294echo ab**(e|f)
295
296expect 'abcdef abcfef abef'
297echo ab*+(e|f)
298
299case 'abcfefg' in
300ab**(e|f)) echo ok 37;;
301*) echo bad 37;;
302esac
303
304case 'abcfefg' in
305ab**(e|f)g) echo ok 38;;
306*a) echo bad 38;;
307esac
308
309case ab in
310ab*+(e|f)) echo bad 39;;
311*) echo ok 39;;
312esac
313
314case abef in
315ab***ef) echo ok 40;;
316*) echo bad 40;;
317esac
318
319case abef in
320ab**) echo ok 41;;
321*) echo bad 41;;
322esac
323
b80f6443
JA
324# bug in all versions up to and including bash-2.05b
325case "123abc" in
326*?(a)bc) echo ok 42;;
327*) echo bad 42;;
328esac
329
b72432fd
JA
330# clean up and do the next one
331
332builtin cd /
333rm -rf $TESTDIR
334
335mkdir $TESTDIR
336builtin cd $TESTDIR
337
bb70624e 338LC_COLLATE=C # have to set this; it affects the sorting
b72432fd
JA
339touch a.b a,b a:b a-b a\;b a\ b a_b
340
341echo a[^[:alnum:]]b
342echo a[-.,:\;\ _]b
343
344echo a@([^[:alnum:]])b
345echo a@([-.,:; _])b
346echo a@([.])b
347echo a@([^.])b
348echo a@([^x])b
349echo a+([^[:alnum:]])b
350
351echo a@(.|[^[:alnum:]])b
cce855bc
JA
352
353builtin cd /
354rm -rf $TESTDIR
355
95732b49
JA
356x=abcdef
357recho "${x#*(a|b)cd}"
358
cce855bc
JA
359# this is for the benefit of pure coverage, so it writes the pcv file
360# in the right place
361builtin cd $MYDIR
362
0628567a
JA
363${THIS_SH} ./extglob1.sub
364
cce855bc 365exit 0