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