1# $FreeBSD: head/tools/regression/bin/sh/expansion/trim3.0 207127 2010-04-23 17:26:49Z jilles $
2
3e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
4h='##' c='\\\\'
5failures=''
6ok=''
7
8testcase() {
9	code="$1"
10	expected="$2"
11	oIFS="$IFS"
12	eval "$code"
13	IFS='|'
14	result="$#|$*"
15	IFS="$oIFS"
16	if [ "x$result" = "x$expected" ]; then
17		ok=x$ok
18	else
19		failures=x$failures
20		echo "For $code, expected $expected actual $result"
21	fi
22}
23
24# This doesn't make much sense, but it fails in dash so I'm adding it here:
25testcase 'set -- "${w%${w#???}}"'		'1|a b'
26
27testcase 'set -- ${p#/et[}'			'1|c]/'
28testcase 'set -- "${p#/et[}"'			'1|c]/'
29testcase 'set -- "${p%${p#????}}"'		'1|/et['
30
31testcase 'set -- ${b%'\'}\''}'			'1|{{(#)}'
32
33testcase 'set -- ${c#\\}'			'1|\\\'
34testcase 'set -- ${c#\\\\}'			'1|\\'
35testcase 'set -- ${c#\\\\\\}'			'1|\'
36testcase 'set -- ${c#\\\\\\\\}'			'0|'
37testcase 'set -- "${c#\\}"'			'1|\\\'
38testcase 'set -- "${c#\\\\}"'			'1|\\'
39testcase 'set -- "${c#\\\\\\}"'			'1|\'
40testcase 'set -- "${c#\\\\\\\\}"'		'1|'
41testcase 'set -- "${c#"$c"}"'			'1|'
42testcase 'set -- ${c#"$c"}'			'0|'
43testcase 'set -- "${c%"$c"}"'			'1|'
44testcase 'set -- ${c%"$c"}'			'0|'
45
46test "x$failures" = x
47