xref: /freebsd/bin/sh/tests/expansion/trim2.0 (revision abd87254)
1
2e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
3h='##'
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
23set -f
24testcase 'set -- $s'				'1|ast*que?non'
25testcase 'set -- ${s%\?*}'			'1|ast*que'
26testcase 'set -- "${s%\?*}"'			'1|ast*que'
27testcase 'set -- ${s%\**}'			'1|ast'
28testcase 'set -- "${s%\**}"'			'1|ast'
29testcase 'set -- ${s%"$q"*}'			'1|ast*que'
30testcase 'set -- "${s%"$q"*}"'			'1|ast*que'
31testcase 'set -- ${s%"$a"*}'			'1|ast'
32testcase 'set -- "${s%"$a"*}"'			'1|ast'
33testcase 'set -- ${s%"$q"$a}'			'1|ast*que'
34testcase 'set -- "${s%"$q"$a}"'			'1|ast*que'
35testcase 'set -- ${s%"$a"$a}'			'1|ast'
36testcase 'set -- "${s%"$a"$a}"'			'1|ast'
37set +f
38
39testcase 'set -- "${b%\}}"'			'1|{{(#)}'
40# Parentheses are special in ksh, check that they can be escaped
41testcase 'set -- "${b%\)*}"'			'1|{{(#'
42testcase 'set -- "${h#\#}"'			'1|#'
43
44testcase 'set -- ${p%"${p#?}"}'			'1|/'
45testcase 'set -- ${p%"${p#??????}"}'		'1|/etc'
46testcase 'set -- ${p%"${p#???????}"}'		'1|/etc/'
47testcase 'set -- "${p%"${p#?}"}"'		'1|/'
48testcase 'set -- "${p%"${p#??????}"}"'		'1|/et[c]'
49testcase 'set -- "${p%"${p#???????}"}"'		'1|/et[c]/'
50testcase 'set -- ${p#"${p}"}'			'0|'
51testcase 'set -- "${p#"${p}"}"'			'1|'
52testcase 'set -- "${p#*\[}"'			'1|c]/'
53
54test "x$failures" = x
55