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.
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.
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/>.
14 # test the ksh-like extended globbing features: [!@*?+](patlist)
23 case "/dev/udp/129.22.8.102/45" in
24 /dev/@(tcp|udp)/*/*) echo ok 1;;
30 0|[1-9]*([0-9])) echo ok 2;;
35 0|[1-9]*([0-9])) echo bad 3;;
40 0|[1-9]*([0-9])) echo ok 4;;
56 +([0-7])) echo bad 7;;
60 # stuff from korn's book
62 para@(chute|graph)) echo ok 8;;
67 para@(chute|graph)) echo bad 9;;
72 para?([345]|99)1) echo ok 10;;
77 para?([345]|99)1) echo bad 11;;
82 para*([0-9])) echo bad 12;;
87 para*([0-9])) echo ok 13;;
91 case para13829383746592 in
92 para*([0-9])) echo ok 14;;
97 para*([0-9])) echo bad 15;;
102 para+([0-9])) echo bad 16;;
106 case para987346523 in
107 para+([0-9])) echo ok 17;;
112 para!(*.[0-9])) echo ok 18;;
117 para!(*.[0-9])) echo ok 19;;
122 para!(*.[0-9])) echo ok 20;;
127 para!(*.[0-9])) echo ok 21;;
131 # tests derived from those in rosenblatt's korn shell book
134 *(0|1|3|5|7|9)) echo ok 22;;
139 *(0|1|3|5|7|9)) echo ok 23;;
144 *(0|1|3|5|7|9)) echo bad 24;;
149 *.c?(c)) echo ok 25;;
154 *.c?(c)) echo bad 26;;
159 *.c?(c)) echo ok 27;;
164 *.c?(c)) echo bad 28;;
169 !(*.c|*.h|Makefile.in|config*|README)) echo ok 29;;
174 !(*.c|*.h|Makefile.in|config*|README)) echo bad 30;;
179 !(*.c|*.h|Makefile.in|config*|README)) echo ok 31;;
184 *\;[1-9]*([0-9])) echo ok 32;;
189 *\;[1-9]*([0-9])) echo bad 33;;
193 *\;[1-9]*([0-9])) echo bad 34;;
196 case "VMS.FILE;139" in
197 *\;[1-9]*([0-9])) echo ok 35;;
200 case "VMS.FILE;1N" in
201 *\;[1-9]*([0-9])) echo bad 36;;
205 # tests derived from the pd-ksh test suite
207 MYDIR=$PWD # save where we are
209 : ${TMPDIR:=/var/tmp}
210 TESTDIR=$TMPDIR/eglob-test-$$
212 builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
238 # extended globbing should not be performed on the output of substitutions
243 expect 'no-file+(a|b)stuff'
244 echo no-file+(a|b)stuff
245 expect 'no-file+(a*(c)|b)stuff'
246 echo no-file+(a*(c)|b)stuff
259 # simple kleene star tests
261 case foo in *(a|b[)) echo yes;; *) echo no;; esac
264 case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
266 # this doesn't work right yet; it is an incorrectly formed pattern
268 case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
270 # check extended globbing in pattern removal -- these don't work right yet
274 echo 1: ${x#+(a|abc)}
276 echo 2: ${x##+(a|abc)}
278 echo 3: ${x%+(def|f)}
280 echo 4: ${x%%+(f|def)}
285 echo 5: ${x#*(a|b)cd}
287 echo 6: "${x#*(a|b)cd}"
289 echo 7: ${x#"*(a|b)cd"}
291 # More tests derived from a bug report concerning extended glob patterns
293 builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
296 touch ab abcdef abef abcfef
307 expect 'ab abcdef abcfef abef'
310 expect 'abcdef abcfef abef'
314 ab**(e|f)) echo ok 37;;
319 ab**(e|f)g) echo ok 38;;
324 ab*+(e|f)) echo bad 39;;
329 ab***ef) echo ok 40;;
338 # bug in all versions up to and including bush-2.05b
340 *?(a)bc) echo ok 42;;
344 # clean up and do the next one
352 LC_COLLATE=C # have to set this; it affects the sorting
353 touch a.b a,b a:b a-b a\;b a\ b a_b
358 echo a@([^[:alnum:]])b
363 echo a+([^[:alnum:]])b
365 echo a@(.|[^[:alnum:]])b
371 recho "${x#*(a|b)cd}"
375 echo ${TEST//*([[:space:]]),*([[:space:]])/,}
378 # this is for the benefit of pure coverage, so it writes the pcv file
382 ${THIS_SH} ./extglob1.sub
384 ${THIS_SH} ./extglob1a.sub
386 ${THIS_SH} ./extglob3.sub
388 ${THIS_SH} ./extglob4.sub
390 ${THIS_SH} ./extglob5.sub