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