xref: /freebsd/bin/sh/tests/expansion/trim9.0 (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1
2# POSIX does not specify these but they occasionally occur in the wild.
3# This just serves to keep working what currently works.
4
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
24testcase 'shift $#; set -- "${*#Q}"'		'1|'
25testcase 'shift $#; set -- "${*##Q}"'		'1|'
26testcase 'shift $#; set -- "${*%Q}"'		'1|'
27testcase 'shift $#; set -- "${*%%Q}"'		'1|'
28testcase 'set -- Q R; set -- "${*#Q}"'		'1| R'
29testcase 'set -- Q R; set -- "${*##Q}"'		'1| R'
30testcase 'set -- Q R; set -- "${*%R}"'		'1|Q '
31testcase 'set -- Q R; set -- "${*%%R}"'		'1|Q '
32testcase 'set -- Q R; set -- "${*#S}"'		'1|Q R'
33testcase 'set -- Q R; set -- "${*##S}"'		'1|Q R'
34testcase 'set -- Q R; set -- "${*%S}"'		'1|Q R'
35testcase 'set -- Q R; set -- "${*%%S}"'		'1|Q R'
36testcase 'set -- Q R; set -- ${*#Q}'		'1|R'
37testcase 'set -- Q R; set -- ${*##Q}'		'1|R'
38testcase 'set -- Q R; set -- ${*%R}'		'1|Q'
39testcase 'set -- Q R; set -- ${*%%R}'		'1|Q'
40testcase 'set -- Q R; set -- ${*#S}'		'2|Q|R'
41testcase 'set -- Q R; set -- ${*##S}'		'2|Q|R'
42testcase 'set -- Q R; set -- ${*%S}'		'2|Q|R'
43testcase 'set -- Q R; set -- ${*%%S}'		'2|Q|R'
44testcase 'set -- Q R; set -- ${@#Q}'		'1|R'
45testcase 'set -- Q R; set -- ${@##Q}'		'1|R'
46testcase 'set -- Q R; set -- ${@%R}'		'1|Q'
47testcase 'set -- Q R; set -- ${@%%R}'		'1|Q'
48testcase 'set -- Q R; set -- ${@#S}'		'2|Q|R'
49testcase 'set -- Q R; set -- ${@##S}'		'2|Q|R'
50testcase 'set -- Q R; set -- ${@%S}'		'2|Q|R'
51testcase 'set -- Q R; set -- ${@%%S}'		'2|Q|R'
52testcase 'set -- Q R; set -- "${@#Q}"'		'2||R'
53testcase 'set -- Q R; set -- "${@%R}"'		'2|Q|'
54testcase 'set -- Q R; set -- "${@%%R}"'		'2|Q|'
55testcase 'set -- Q R; set -- "${@#S}"'		'2|Q|R'
56testcase 'set -- Q R; set -- "${@##S}"'		'2|Q|R'
57testcase 'set -- Q R; set -- "${@%S}"'		'2|Q|R'
58testcase 'set -- Q R; set -- "${@%%S}"'		'2|Q|R'
59
60test "x$failures" = x
61