xref: /freebsd/bin/sh/tests/expansion/trim1.0 (revision d0b2dbfa)
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
23testcase 'set -- ${t%t}'			'1|texttex'
24testcase 'set -- "${t%t}"'			'1|texttex'
25testcase 'set -- ${t%e*}'			'1|textt'
26testcase 'set -- "${t%e*}"'			'1|textt'
27testcase 'set -- ${t%%e*}'			'1|t'
28testcase 'set -- "${t%%e*}"'			'1|t'
29testcase 'set -- ${t%%*}'			'0|'
30testcase 'set -- "${t%%*}"'			'1|'
31testcase 'set -- ${t#t}'			'1|exttext'
32testcase 'set -- "${t#t}"'			'1|exttext'
33testcase 'set -- ${t#*x}'			'1|ttext'
34testcase 'set -- "${t#*x}"'			'1|ttext'
35testcase 'set -- ${t##*x}'			'1|t'
36testcase 'set -- "${t##*x}"'			'1|t'
37testcase 'set -- ${t##*}'			'0|'
38testcase 'set -- "${t##*}"'			'1|'
39testcase 'set -- ${t%e$a}'			'1|textt'
40
41set -f
42testcase 'set -- ${s%[?]*}'			'1|ast*que'
43testcase 'set -- "${s%[?]*}"'			'1|ast*que'
44testcase 'set -- ${s%[*]*}'			'1|ast'
45testcase 'set -- "${s%[*]*}"'			'1|ast'
46set +f
47
48testcase 'set -- $b'				'1|{{(#)}}'
49testcase 'set -- ${b%\}}'			'1|{{(#)}'
50testcase 'set -- ${b#{}'			'1|{(#)}}'
51testcase 'set -- "${b#{}"'			'1|{(#)}}'
52# Parentheses are special in ksh, check that they can be escaped
53testcase 'set -- ${b%\)*}'			'1|{{(#'
54testcase 'set -- ${b#{}'			'1|{(#)}}'
55testcase 'set -- $h'				'1|##'
56testcase 'set -- ${h#\#}'			'1|#'
57testcase 'set -- ${h###}'			'1|#'
58testcase 'set -- "${h###}"'			'1|#'
59testcase 'set -- ${h%#}'			'1|#'
60testcase 'set -- "${h%#}"'			'1|#'
61
62set -f
63testcase 'set -- ${s%"${s#?}"}'			'1|a'
64testcase 'set -- ${s%"${s#????}"}'		'1|ast*'
65testcase 'set -- ${s%"${s#????????}"}'		'1|ast*que?'
66testcase 'set -- ${s#"${s%?}"}'			'1|n'
67testcase 'set -- ${s#"${s%????}"}'		'1|?non'
68testcase 'set -- ${s#"${s%????????}"}'		'1|*que?non'
69set +f
70testcase 'set -- "${s%"${s#?}"}"'		'1|a'
71testcase 'set -- "${s%"${s#????}"}"'		'1|ast*'
72testcase 'set -- "${s%"${s#????????}"}"'	'1|ast*que?'
73testcase 'set -- "${s#"${s%?}"}"'		'1|n'
74testcase 'set -- "${s#"${s%????}"}"'		'1|?non'
75testcase 'set -- "${s#"${s%????????}"}"'	'1|*que?non'
76testcase 'set -- ${p#${p}}'			'1|/etc/'
77testcase 'set -- "${p#${p}}"'			'1|/et[c]/'
78testcase 'set -- ${p#*[[]}'			'1|c]/'
79testcase 'set -- "${p#*[[]}"'			'1|c]/'
80testcase 'set -- ${p#*\[}'			'1|c]/'
81testcase 'set -- ${p#*"["}'			'1|c]/'
82testcase 'set -- "${p#*"["}"'			'1|c]/'
83
84test "x$failures" = x
85