xref: /freebsd/bin/sh/tests/expansion/trim8.0 (revision ab393e9548f8cc0ee28499c411963b798ebb38a5)
1
2unset LC_ALL
3LC_CTYPE=en_US.UTF-8
4export LC_CTYPE
5
6c1=e
7# a umlaut
8c2=$(printf '\303\244')
9# euro sign
10c3=$(printf '\342\202\254')
11# some sort of 't' outside BMP
12c4=$(printf '\360\235\225\245')
13
14s=$c1$c2$c3$c4
15
16testcase() {
17	code="$1"
18	expected="$2"
19	oIFS="$IFS"
20	eval "$code"
21	IFS='|'
22	result="$#|$*"
23	IFS="$oIFS"
24	if [ "x$result" = "x$expected" ]; then
25		ok=x$ok
26	else
27		failures=x$failures
28		echo "For $code, expected $expected actual $result"
29	fi
30}
31
32testcase 'set -- "$s"'				"1|$s"
33testcase 'set -- "${s#$c2}"'			"1|$s"
34testcase 'set -- "${s#*}"'			"1|$s"
35testcase 'set -- "${s#$c1}"'			"1|$c2$c3$c4"
36testcase 'set -- "${s#$c1$c2}"'			"1|$c3$c4"
37testcase 'set -- "${s#$c1$c2$c3}"'		"1|$c4"
38testcase 'set -- "${s#$c1$c2$c3$c4}"'		"1|"
39testcase 'set -- "${s#?}"'			"1|$c2$c3$c4"
40testcase 'set -- "${s#??}"'			"1|$c3$c4"
41testcase 'set -- "${s#???}"'			"1|$c4"
42testcase 'set -- "${s#????}"'			"1|"
43testcase 'set -- "${s#*$c3}"'			"1|$c4"
44testcase 'set -- "${s%$c4}"'			"1|$c1$c2$c3"
45testcase 'set -- "${s%$c3$c4}"'			"1|$c1$c2"
46testcase 'set -- "${s%$c2$c3$c4}"'		"1|$c1"
47testcase 'set -- "${s%$c1$c2$c3$c4}"'		"1|"
48testcase 'set -- "${s%?}"'			"1|$c1$c2$c3"
49testcase 'set -- "${s%??}"'			"1|$c1$c2"
50testcase 'set -- "${s%???}"'			"1|$c1"
51testcase 'set -- "${s%????}"'			"1|"
52testcase 'set -- "${s%$c2*}"'			"1|$c1"
53testcase 'set -- "${s##$c2}"'			"1|$s"
54testcase 'set -- "${s##*}"'			"1|"
55testcase 'set -- "${s##$c1}"'			"1|$c2$c3$c4"
56testcase 'set -- "${s##$c1$c2}"'		"1|$c3$c4"
57testcase 'set -- "${s##$c1$c2$c3}"'		"1|$c4"
58testcase 'set -- "${s##$c1$c2$c3$c4}"'		"1|"
59testcase 'set -- "${s##?}"'			"1|$c2$c3$c4"
60testcase 'set -- "${s##??}"'			"1|$c3$c4"
61testcase 'set -- "${s##???}"'			"1|$c4"
62testcase 'set -- "${s##????}"'			"1|"
63testcase 'set -- "${s##*$c3}"'			"1|$c4"
64testcase 'set -- "${s%%$c4}"'			"1|$c1$c2$c3"
65testcase 'set -- "${s%%$c3$c4}"'		"1|$c1$c2"
66testcase 'set -- "${s%%$c2$c3$c4}"'		"1|$c1"
67testcase 'set -- "${s%%$c1$c2$c3$c4}"'		"1|"
68testcase 'set -- "${s%%?}"'			"1|$c1$c2$c3"
69testcase 'set -- "${s%%??}"'			"1|$c1$c2"
70testcase 'set -- "${s%%???}"'			"1|$c1"
71testcase 'set -- "${s%%????}"'			"1|"
72testcase 'set -- "${s%%$c2*}"'			"1|$c1"
73
74test "x$failures" = x
75