xref: /titanic_50/usr/src/lib/libshell/common/tests/substring.sh (revision 090a8d9e70b0696e7d9bc114c6e021757c9f04fe)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#           Copyright (c) 1982-2007 AT&T Knowledge Ventures            #
5#                      and is licensed under the                       #
6#                  Common Public License, Version 1.0                  #
7#                      by AT&T Knowledge Ventures                      #
8#                                                                      #
9#                A copy of the License is available at                 #
10#            http://www.opensource.org/licenses/cpl1.0.txt             #
11#         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                  David Korn <dgk@research.att.com>                   #
18#                                                                      #
19########################################################################
20function err_exit
21{
22	print -u2 -n "\t"
23	print -u2 -r ${Command}[$1]: "${@:2}"
24	let Errors+=1
25}
26alias err_exit='err_exit $LINENO'
27
28Command=${0##*/}
29integer Errors=0 j=4
30base=/home/dgk/foo//bar
31string1=$base/abcabcabc
32if	[[ ${string1:0} != "$string1" ]]
33then	err_exit "string1:0"
34fi
35if	[[ ${string1: -1} != "c" ]]
36then	err_exit "string1: -1"
37fi
38if	[[ ${string1:0:1000} != "$string1" ]]
39then	err_exit "string1:0"
40fi
41if	[[ ${string1:1} != "${string1#?}" ]]
42then	err_exit "string1:1"
43fi
44if	[[ ${string1:1:4} != home ]]
45then	err_exit "string1:1:4"
46fi
47if	[[ ${string1: -5:4} != bcab ]]
48then	err_exit "string1: -5:4"
49fi
50if	[[ ${string1:1:j} != home ]]
51then	err_exit "string1:1:j"
52fi
53if	[[ ${string1:(j?1:0):j} != home ]]
54then	err_exit "string1:(j?1:0):j"
55fi
56if	[[ ${string1%*zzz*} != "$string1" ]]
57then	err_exit "string1%*zzz*"
58fi
59if	[[ ${string1%%*zzz*} != "$string1" ]]
60then	err_exit "string1%%*zzz*"
61fi
62if	[[ ${string1#*zzz*} != "$string1" ]]
63then	err_exit "string1#*zzz*"
64fi
65if	[[ ${string1##*zzz*} != "$string1" ]]
66then	err_exit "string1##*zzz*"
67fi
68if	[[ ${string1%+(abc)} != "$base/abcabc" ]]
69then	err_exit "string1%+(abc)"
70fi
71if	[[ ${string1%%+(abc)} != "$base/" ]]
72then	err_exit "string1%%+(abc)"
73fi
74if	[[ ${string1%/*} != "$base" ]]
75then	err_exit "string1%/*"
76fi
77if	[[ "${string1%/*}" != "$base" ]]
78then	err_exit '"string1%/*"'
79fi
80if	[[ ${string1%"/*"} != "$string1" ]]
81then	err_exit 'string1%"/*"'
82fi
83if	[[ ${string1%%/*} != "" ]]
84then	err_exit "string1%%/*"
85fi
86if	[[ ${string1#*/bar} != /abcabcabc ]]
87then	err_exit "string1#*bar"
88fi
89if	[[ ${string1##*/bar} != /abcabcabc ]]
90then	err_exit "string1#*bar"
91fi
92if	[[ "${string1#@(*/bar|*/foo)}" != //bar/abcabcabc ]]
93then	err_exit "string1#@(*/bar|*/foo)"
94fi
95if	[[ ${string1##@(*/bar|*/foo)} != /abcabcabc ]]
96then	err_exit "string1##@(*/bar|*/foo)"
97fi
98if	[[ ${string1##*/@(bar|foo)} != /abcabcabc ]]
99then	err_exit "string1##*/@(bar|foo)"
100fi
101foo=abc
102if	[[ ${foo#a[b*} != abc ]]
103then	err_exit "abc#a[b*} != abc"
104fi
105if	[[ ${foo//[0-9]/bar} != abc ]]
106then	err_exit '${foo//[0-9]/bar} not expanding correctly'
107fi
108foo='(abc)'
109if	[[ ${foo#'('} != 'abc)' ]]
110then	err_exit "(abc)#( != abc)"
111fi
112if	[[ ${foo%')'} != '(abc' ]]
113then	err_exit "(abc)%) != (abc"
114fi
115foo=a123b456c
116if	[[ ${foo/[0-9]?/""} != a3b456c ]]
117then	err_exit '${foo/[0-9]?/""} not expanding correctly'
118fi
119if	[[ ${foo//[0-9]/""} != abc ]]
120then	err_exit '${foo//[0-9]/""} not expanding correctly'
121fi
122if	[[ ${foo/#a/b} != b123b456c ]]
123then	err_exit '${foo/#a/b} not expanding correctly'
124fi
125if	[[ ${foo/#?/b} != b123b456c ]]
126then	err_exit '${foo/#?/b} not expanding correctly'
127fi
128if	[[ ${foo/%c/b} != a123b456b ]]
129then	err_exit '${foo/%c/b} not expanding correctly'
130fi
131if	[[ ${foo/%?/b} != a123b456b ]]
132then	err_exit '${foo/%?/b} not expanding correctly'
133fi
134while read -r pattern string expected
135do	if	(( expected ))
136	then	if	[[ $string != $pattern ]]
137		then	err_exit "$pattern does not match $string"
138		fi
139		if	[[ ${string##$pattern} != "" ]]
140		then	err_exit "\${$string##$pattern} not null"
141		fi
142		if	[ "${string##$pattern}" != '' ]
143		then	err_exit "\"\${$string##$pattern}\" not null"
144		fi
145		if	[[ ${string/$pattern} != "" ]]
146		then	err_exit "\${$string/$pattern} not null"
147		fi
148	else	if	[[ $string == $pattern ]]
149		then	err_exit "$pattern matches $string"
150		fi
151	fi
152done <<- \EOF
153	+(a)*+(a)	aabca	1
154	!(*.o)		foo.o	0
155	!(*.o)		foo.c	1
156EOF
157xx=a/b/c/d/e
158yy=${xx#*/}
159if	[[ $yy != b/c/d/e ]]
160then	err_exit '${xx#*/} != a/b/c/d/e when xx=a/b/c/d/e'
161fi
162if	[[ ${xx//\//\\} != 'a\b\c\d\e' ]]
163then	err_exit '${xx//\//\\} not working'
164fi
165x=[123]def
166if	[[ "${x//\[(*)\]/\{\1\}}" != {123}def ]]
167then	err_exit 'closing brace escape not working'
168fi
169unset foo
170foo=one/two/three
171if	[[ ${foo//'/'/_} != one_two_three ]]
172then	err_exit 'single quoting / in replacements failed'
173fi
174if	[[ ${foo//"/"/_} != one_two_three ]]
175then	err_exit 'double quoting / in replacements failed'
176fi
177if	[[ ${foo//\//_} != one_two_three ]]
178then	err_exit 'escaping / in replacements failed'
179fi
180function myexport
181{
182	nameref var=$1
183	if	(( $# > 1 ))
184	then	export	$1=$2
185	fi
186	if	(( $# > 2 ))
187	then	print $(myexport "$1" "$3" )
188		return
189	fi
190	typeset val
191	val=$(export | grep "^$1=")
192	print ${val#"$1="}
193
194}
195export dgk=base
196if	[[ $(myexport dgk fun) != fun ]]
197then	err_exit 'export inside function not working'
198fi
199val=$(export | grep "^dgk=")
200if	[[ ${val#dgk=} != base ]]
201then	err_exit 'export not restored after function call'
202fi
203if	[[ $(myexport dgk fun fun2) != fun2 ]]
204then	err_exit 'export inside function not working with recursive function'
205fi
206val=$(export | grep "^dgk=")
207if	[[ ${val#dgk=} != base ]]
208then	err_exit 'export not restored after recursive function call'
209fi
210if	[[ $(dgk=try3 myexport dgk) != try3 ]]
211then	err_exit 'name=value not added to export list with function call'
212fi
213val=$(export | grep "^dgk=")
214if	[[ ${val#dgk=} != base ]]
215then	err_exit 'export not restored name=value function call'
216fi
217unset zzz
218if	[[ $(myexport zzz fun) != fun ]]
219then	err_exit 'export inside function not working for zzz'
220fi
221if	[[ $(export | grep "zzz=") ]]
222then	err_exit 'zzz exported after function call'
223fi
224set -- foo/bar bam/yes last/file/done
225if	[[ ${@/*\/@(*)/${.sh.match[1]}} != 'bar yes done' ]]
226then	err_exit '.sh.match not working with $@'
227fi
228if	[[ ${@/*\/@(*)/\1} != 'bar yes done' ]]
229then	err_exit '\1 not working with $@'
230fi
231var=(foo/bar bam/yes last/file/done)
232if	[[ ${var[@]/*\/@(*)/${.sh.match[1]}} != 'bar yes done' ]]
233then	err_exit '.sh.match not working with ${var[@]}'
234fi
235if	[[ ${var[@]/*\/@(*)/\1} != 'bar yes done' ]]
236then	err_exit '\1 not working with ${var[@]}'
237fi
238var='abc_d2ef.462abc %%'
239if	[[ ${var/+(\w)/Q} != 'Q.462abc %%' ]]
240then	err_exit '${var/+(\w)/Q} not workding'
241fi
242if	[[ ${var//+(\w)/Q} != 'Q.Q %%' ]]
243then	err_exit '${var//+(\w)/Q} not workding'
244fi
245if	[[ ${var//+(\S)/Q} != 'Q Q' ]]
246then	err_exit '${var//+(\S)/Q} not workding'
247fi
248if	[[ "$(LC_ALL=debug $SHELL <<- \+EOF+
249		x=a<2bc><3xyz>g
250		print ${#x}
251		+EOF+)" != 4
252	]]
253then	err_exit '${#x} not working with multibyte locales'
254fi
255foo='foo+bar+'
256[[ $(print -r -- ${foo//+/'|'}) != 'foo|bar|' ]] && err_exit "\${foobar//+/'|'}"
257[[ $(print -r -- ${foo//+/"|"}) != 'foo|bar|' ]] && err_exit '${foobar//+/"|"}'
258[[ $(print -r -- "${foo//+/'|'}") != 'foo|bar|' ]] && err_exit '"${foobar//+/'"'|'"'}"'
259[[ $(print -r -- "${foo//+/"|"}") != 'foo|bar|' ]] && err_exit '"${foobar//+/"|"}"'
260unset x
261x=abcedfg
262: ${x%@(d)f@(g)}
263[[ ${.sh.match[0]} == dfg ]] || err_exit '.sh.match[0] not dfg'
264[[ ${.sh.match[1]} == d ]] || err_exit '.sh.match[1] not d'
265[[ ${.sh.match[2]} == g ]] || err_exit '.sh.match[2] not g'
266x=abcedddfg
267: ${x%%+(d)f@(g)}
268[[ ${.sh.match[1]} == ddd ]] || err_exit '.sh.match[1] not ddd'
269unset a b
270a='\[abc @(*) def\]'
271b='[abc 123 def]'
272[[ ${b//$a/\1} == 123 ]] || err_exit "\${var/pattern} not working with \[ in pattern"
273unset X
274$SHELL -c '[[ ! ${X[@]:0:300} ]]' 2> /dev/null || err_exit '${X[@]:0:300} with X undefined fails'
275$SHELL -c '[[ ${@:0:300} == "$0" ]]' 2> /dev/null || err_exit '${@:0:300} with no arguments fails'
276i=20030704
277[[ ${i#{6}(?)} == 04 ]] ||  err_exit '${i#{6}(?)} not working'
278[[ ${i#{6,6}(?)} == 04 ]] ||  err_exit '${i#{6,6}(?)} not working'
279LC_ALL=posix
280i="   ."
281[[ $(printf "<%s>\n" ${i#' '}) == '<.>' ]] || err_exit 'printf "<%s>\n" ${i#' '} failed'
282unset x
283x=foo
284[[ "${x%o}(1)" == "fo(1)" ]] ||  err_exit 'print ${}() treated as pattern'
285unset i pattern string
286string=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz
287integer i
288for((i=0; i < ${#string}; i++))
289do	pattern+='@(?)'
290done
291[[ $(string=$string $SHELL -c  ": \${string/$pattern/}; print \${.sh.match[26]}") == Z ]] || err_exit -u2 'sh.match[26] not Z'
292: ${string/$pattern/}
293(( ${#.sh.match[@]} == 53 )) || err_exit '.sh.match has wrong number of elements'
294[[ ${.sh.match[@]:2:4} == 'B C D E'  ]] || err_exit '${.sh.match[@]:2:4} incorrect'
295
296D=$';' E=$'\\\\' Q=$'"' S=$'\'' M='nested pattern substitution failed'
297
298x='-(-)-'
299[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M
300x='-(-)-)-'
301[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M
302x='-(-()-)-'
303[[ ${x/*%(())*/\1} == '()' ]] || err_exit $M
304x='-(-\)-)-'
305[[ ${x/*%(())*/\1} == '(-\)' ]] || err_exit $M
306x='-(-\\)-)-'
307[[ ${x/*%(())*/\1} == '(-\\)' ]] || err_exit $M
308x='-(-(-)-'
309[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M
310x='-(-(-)-)-'
311[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M
312x='-(-[-]-)-'
313[[ ${x/*%(()[])*/\1} == '(-[-]-)' ]] || err_exit $M
314x='-[-(-)-]-'
315[[ ${x/*%(()[])*/\1} == '(-)' ]] || err_exit $M
316x='-(-[-)-]-'
317[[ ${x/*%(()[])*/\1} == '-(-[-)-]-' ]] || err_exit $M
318x='-(-[-]-)-'
319[[ ${x/*%([]())*/\1} == '[-]' ]] || err_exit $M
320x='-[-(-)-]-'
321[[ ${x/*%([]())*/\1} == '[-(-)-]' ]] || err_exit $M
322x='-(-[-)-]-'
323[[ ${x/*%([]())*/\1} == '-(-[-)-]-' ]] || err_exit $M
324
325x='-((-))-'
326[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M
327x='-((-))-'
328[[ ${x/~(-g)*%(())*/\1} == '((-))-' ]] || err_exit $M
329x='-((-))-'
330[[ ${x/~(-g:*)*%(())*/\1} == '(-)' ]] || err_exit $M
331x='-((-))-'
332[[ ${x/~(+g)*%(())*/\1} == '(-)' ]] || err_exit $M
333x='-((-))-'
334[[ ${x/~(+g:*)*%(())*/\1} == '(-)' ]] || err_exit $M
335x='-((-))-'
336[[ ${x/*(?)*%(())*(?)*/:\1:\2:\3:} == ':-(:(-):)-:' ]] || err_exit $M
337x='-((-))-'
338[[ ${x/~(-g)*(?)*%(())*(?)*/:\1:\2:\3:} == '::((-))::-' ]] || err_exit $M
339x='-((-))-'
340[[ ${x/~(-g:*(?))*%(())*(?)*/:\1:\2:\3:} == '::(-):)-:' ]] || err_exit $M
341x='-((-))-'
342[[ ${x/~(+g)*(?)*%(())*(?)*/:\1:\2:\3:} == ':-(:(-):)-:' ]] || err_exit $M
343x='-((-))-'
344[[ ${x/~(+g:*(?))*%(())*(?)*/:\1:\2:\3:} == ':-(:(-):)-:' ]] || err_exit $M
345x='call(a+b,x/(c/d),(0));'
346[[ ${x/+([[:alnum:]])*([[:space:]])(*%(()))*/:\1:\2:\3:} == ':call::(a+b,x/(c/d),(0)):' ]] || err_exit $M
347
348x='-(-;-)-'
349[[ ${x/*%(()D${D})*/\1} == '-(-;-)-' ]] || err_exit $M
350x='-(-);-'
351[[ ${x/*%(()D${D})*/\1} == '(-)' ]] || err_exit $M
352x='-(-)\;-'
353[[ ${x/*%(()D${D})*/\1} == '(-)' ]] || err_exit $M
354x='-(-\;-)-'
355[[ ${x/*%(()D${D}E${E})*/\1} == '(-\;-)' ]] || err_exit $M
356x='-(-)\;-'
357[[ ${x/*%(()D${D}E${E})*/\1} == '(-)' ]] || err_exit $M
358x='-(-(-)\;-)-'
359[[ ${x/*%(()D${D}E${E})*/\1} == '(-)' ]] || err_exit $M
360
361x='-(-")"-)-'
362[[ ${x/*%(()Q${Q})*/\1} == '(-")"-)' ]] || err_exit $M
363x='-(-\")"-)-'
364[[ ${x/*%(()Q${Q})*/\1} == '(-\")"-)' ]] || err_exit $M
365x='-(-\")\"-)-'
366[[ ${x/*%(()Q${Q})*/\1} == '(-\")\"-)' ]] || err_exit $M
367x=$'-(-\\\'")\\\'-)-'
368[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'(-\\\'")\\\'-)' ]] || err_exit $M
369x=$'-(-\\\'")"-)-'
370[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'-(-\\\'")"-)-' ]] || err_exit $M
371x=$'-(-\\\'")"\'-)-'
372[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'(-\\\'")"\'-)' ]] || err_exit $M
373x=$'-(-\\"\')\'\\"-)-'
374[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M
375x=$'-(-\')\\\'\'-)-'
376[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'-(-\')\\\'\'-)-' ]] || err_exit $M
377x=$'-(-\'")\'-)-'
378[[ ${x/*%(()L${S}Q${Q})*/\1} == $'(-\'")\'-)' ]] || err_exit $M
379x=$'-(-\\\'")"-)-'
380[[ ${x/*%(()L${S}Q${Q})*/\1} == $'-(-\\\'")"-)-' ]] || err_exit $M
381x=$'-(-\\\'")"\'-)-'
382[[ ${x/*%(()L${S}Q${Q})*/\1} == $'(-\\\'")"\'-)' ]] || err_exit $M
383x=$'-(-\\"\')\'\\"-)-'
384[[ ${x/*%(()L${S}Q${Q})*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M
385x=$'-(-\')\\\'\'-)-'
386[[ ${x/*%(()L${S}Q${Q})*/\1} == $'-(-\')\\\'\'-)-' ]] || err_exit $M
387x='-(-")"-)-'
388[[ ${x/*%(()Q${Q})*/\1} == '(-")"-)' ]] || err_exit $M
389x='-(-\")"-)-'
390[[ ${x/*%(()Q${Q})*/\1} == '(-\")"-)' ]] || err_exit $M
391x='-(-\")\"-)-'
392[[ ${x/*%(()Q${Q})*/\1} == '(-\")\"-)' ]] || err_exit $M
393
394x='-(-\)-)-'
395[[ ${x/*%(()E${E})*/\1} == '(-\)-)' ]] || err_exit $M
396x='-(-\\)-)-'
397[[ ${x/*%(()E${E})*/\1} == '(-\\)' ]] || err_exit $M
398x='-(-\")"-)-'
399[[ ${x/*%(()E${E}Q${Q})*/\1} == '(-\")' ]] || err_exit $M
400x='-(-\")\"-)-'
401[[ ${x/*%(()E${E}Q${Q})*/\1} == '(-\")' ]] || err_exit $M
402x=$'-(-\'")"-)-'
403[[ ${x/*%(()E${E}Q${S}Q${Q})*/\1} == $'-(-\'")"-)-' ]] || err_exit $M
404x=$'-(-\\\'")"-)-'
405[[ ${x/*%(()E${E}Q${S}Q${Q})*/\1} == $'(-\\\'")"-)' ]] || err_exit $M
406x=$'-(-\\"\')\'\\"-)-'
407[[ ${x/*%(()E${E}Q${S}Q${Q})*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M
408x=$'-(-\\\'")"-)-'
409[[ ${x/*%(()E${E}L${S}Q${Q})*/\1} == $'(-\\\'")"-)' ]] || err_exit $M
410x=$'-(-\\"\')\'\\"-)-'
411[[ ${x/*%(()E${E}L${S}Q${Q})*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M
412x=$'-(-\\"\')\\\'\\"-)-'
413[[ ${x/*%(()E${E}L${S}Q${Q})*/\1} == $'(-\\"\')\\\'\\"-)' ]] || err_exit $M
414x=$'-(-\\"\')\\\'\\"\'-)-'
415[[ ${x/*%(()E${E}L${S}Q${Q})*/\1} == $'-(-\\"\')\\\'\\"\'-)-' ]] || err_exit $M
416
417x='-(-;-)-'
418[[ ${x/*%(()D\;)*/\1} == '-(-;-)-' ]] || err_exit $M
419x='-(-);-'
420[[ ${x/*%(()D\;)*/\1} == '(-)' ]] || err_exit $M
421x='-(-)\;-'
422[[ ${x/*%(()D\;)*/\1} == '(-)' ]] || err_exit $M
423x='-(-\;-)-'
424[[ ${x/*%(()D\;E\\)*/\1} == '(-\;-)' ]] || err_exit $M
425x='-(-);-'
426[[ ${x/*%(()D\;E\\)*/\1} == '(-)' ]] || err_exit $M
427x='-(-)\;-'
428[[ ${x/*%(()D\;E\\)*/\1} == '(-)' ]] || err_exit $M
429x='-(-(-)\;-)-'
430[[ ${x/*%(()D\;E\\)*/\1} == '(-)' ]] || err_exit $M
431
432x='-(-")"-)-'
433[[ ${x/*%(()Q\")*/\1} == '(-")"-)' ]] || err_exit $M
434x='-(-\")"-)-'
435[[ ${x/*%(()Q\")*/\1} == '(-\")"-)' ]] || err_exit $M
436x='-(-\")\"-)-'
437[[ ${x/*%(()Q\")*/\1} == '(-\")\"-)' ]] || err_exit $M
438x=$'-(-\\\'")\\\'-)-'
439[[ ${x/*%(()Q\'Q\")*/\1} == $'(-\\\'")\\\'-)' ]] || err_exit $M
440x=$'-(-\\\'")"-)-'
441[[ ${x/*%(()Q\'Q\")*/\1} == $'-(-\\\'")"-)-' ]] || err_exit $M
442x=$'-(-\\\'")"\'-)-'
443[[ ${x/*%(()Q\'Q\")*/\1} == $'(-\\\'")"\'-)' ]] || err_exit $M
444x=$'-(-\\"\')\'\\"-)-'
445[[ ${x/*%(()Q\'Q\")*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M
446x=$'-(-\')\\\'\'-)-'
447[[ ${x/*%(()Q\'Q\")*/\1} == $'-(-\')\\\'\'-)-' ]] || err_exit $M
448x=$'-(-\'")\'-)-'
449[[ ${x/*%(()L\'Q\")*/\1} == $'(-\'")\'-)' ]] || err_exit $M
450x=$'-(-\\\'")"-)-'
451[[ ${x/*%(()L\'Q\")*/\1} == $'-(-\\\'")"-)-' ]] || err_exit $M
452x=$'-(-\\\'")"\'-)-'
453[[ ${x/*%(()L\'Q\")*/\1} == $'(-\\\'")"\'-)' ]] || err_exit $M
454x=$'-(-\\"\')\'\\"-)-'
455[[ ${x/*%(()L\'Q\")*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M
456x=$'-(-\')\\\'\'-)-'
457[[ ${x/*%(()L\'Q\")*/\1} == $'-(-\')\\\'\'-)-' ]] || err_exit $M
458x='-(-")"-)-'
459[[ ${x/*%(()Q\")*/\1} == '(-")"-)' ]] || err_exit $M
460x='-(-\")"-)-'
461[[ ${x/*%(()Q\")*/\1} == '(-\")"-)' ]] || err_exit $M
462x='-(-\")\"-)-'
463[[ ${x/*%(()Q\")*/\1} == '(-\")\"-)' ]] || err_exit $M
464
465x='-(-\)-)-'
466[[ ${x/*%(()E\\)*/\1} == '(-\)-)' ]] || err_exit $M
467x='-(-\\)-)-'
468[[ ${x/*%(()E\\)*/\1} == '(-\\)' ]] || err_exit $M
469x='-(-\")"-)-'
470[[ ${x/*%(()E\\Q\")*/\1} == '(-\")' ]] || err_exit $M
471x='-(-\")\"-)-'
472[[ ${x/*%(()E\\Q\")*/\1} == '(-\")' ]] || err_exit $M
473x=$'-(-\'")"-)-'
474[[ ${x/*%(()E\\Q\'Q\")*/\1} == $'-(-\'")"-)-' ]] || err_exit $M
475x=$'-(-\\\'")"-)-'
476[[ ${x/*%(()E\\Q\'Q\")*/\1} == $'(-\\\'")"-)' ]] || err_exit $M
477x=$'-(-\\"\')\'\\"-)-'
478[[ ${x/*%(()E\\Q\'Q\")*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M
479x=$'-(-\\\'")"-)-'
480[[ ${x/*%(()E\\L\'Q\")*/\1} == $'(-\\\'")"-)' ]] || err_exit $M
481x=$'-(-\\"\')\'\\"-)-'
482[[ ${x/*%(()E\\L\'Q\")*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M
483x=$'-(-\\"\')\\\'\\"-)-'
484[[ ${x/*%(()E\\L\'Q\")*/\1} == $'(-\\"\')\\\'\\"-)' ]] || err_exit $M
485x=$'-(-\\"\')\\\'\\"\'-)-'
486[[ ${x/*%(()E\\L\'Q\")*/\1} == $'-(-\\"\')\\\'\\"\'-)-' ]] || err_exit $M
487
488pattern=00
489var=100
490[[ $( print $(( ${var%%00} )) ) == 1 ]] || err_exit "arithmetic with embeddded patterns fails"
491[[ $( print $(( ${var%%$pattern} )) ) == 1 ]] || err_exit "arithmetic with embeddded pattern variables fails"
492if	[[ ax == @(a)* ]] && [[ ${.sh.match[1]:0:${#.sh.match[1]}}  != a ]]
493then	err_exit '${.sh.match[1]:1:${#.sh.match[1]}} not expanding correctly'
494fi
495
496string='foo(d:\nt\box\something)bar'
497expected='d:\nt\box\something'
498[[ ${string/*\(+([!\)])\)*/\1} == "$expected" ]] || err_exit "substring expansion failed '${string/*\(+([!\)])\)*/\1}' returned -- '$expected' expected"
499if	[[ $($SHELL -c $'export LC_ALL=en_US.UTF-8; print -r "\342\202\254\342\202\254\342\202\254\342\202\254w\342\202\254\342\202\254\342\202\254\342\202\254" | wc -m' 2>/dev/null) == 10 ]]
500then	LC_ALL=en_US.UTF-8 $SHELL -c b1=$'"\342\202\254\342\202\254\342\202\254\342\202\254w\342\202\254\342\202\254\342\202\254\342\202\254"; [[ ${b1:4:1} == w ]]' || err_exit 'Multibyte ${var:offset:len} not working correctly'
501fi
502{ $SHELL -c 'unset x;[[ ${SHELL:$x} == $SHELL ]]';} 2> /dev/null || err_exit '${var:$x} fails when x is not set'
503{ $SHELL -c 'x=;[[ ${SHELL:$x} == $SHELL ]]';} 2> /dev/null || err_exit '${var:$x} fails when x is null'
504exit $((Errors))
505