xref: /freebsd/bin/sh/tests/expansion/trim9.0 (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1*cf1330beSJilles Tjoelker
2*cf1330beSJilles Tjoelker# POSIX does not specify these but they occasionally occur in the wild.
3*cf1330beSJilles Tjoelker# This just serves to keep working what currently works.
4*cf1330beSJilles Tjoelker
5*cf1330beSJilles Tjoelkerfailures=''
6*cf1330beSJilles Tjoelkerok=''
7*cf1330beSJilles Tjoelker
8*cf1330beSJilles Tjoelkertestcase() {
9*cf1330beSJilles Tjoelker	code="$1"
10*cf1330beSJilles Tjoelker	expected="$2"
11*cf1330beSJilles Tjoelker	oIFS="$IFS"
12*cf1330beSJilles Tjoelker	eval "$code"
13*cf1330beSJilles Tjoelker	IFS='|'
14*cf1330beSJilles Tjoelker	result="$#|$*"
15*cf1330beSJilles Tjoelker	IFS="$oIFS"
16*cf1330beSJilles Tjoelker	if [ "x$result" = "x$expected" ]; then
17*cf1330beSJilles Tjoelker		ok=x$ok
18*cf1330beSJilles Tjoelker	else
19*cf1330beSJilles Tjoelker		failures=x$failures
20*cf1330beSJilles Tjoelker		echo "For $code, expected $expected actual $result"
21*cf1330beSJilles Tjoelker	fi
22*cf1330beSJilles Tjoelker}
23*cf1330beSJilles Tjoelker
24*cf1330beSJilles Tjoelkertestcase 'shift $#; set -- "${*#Q}"'		'1|'
25*cf1330beSJilles Tjoelkertestcase 'shift $#; set -- "${*##Q}"'		'1|'
26*cf1330beSJilles Tjoelkertestcase 'shift $#; set -- "${*%Q}"'		'1|'
27*cf1330beSJilles Tjoelkertestcase 'shift $#; set -- "${*%%Q}"'		'1|'
28*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${*#Q}"'		'1| R'
29*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${*##Q}"'		'1| R'
30*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${*%R}"'		'1|Q '
31*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${*%%R}"'		'1|Q '
32*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${*#S}"'		'1|Q R'
33*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${*##S}"'		'1|Q R'
34*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${*%S}"'		'1|Q R'
35*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${*%%S}"'		'1|Q R'
36*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${*#Q}'		'1|R'
37*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${*##Q}'		'1|R'
38*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${*%R}'		'1|Q'
39*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${*%%R}'		'1|Q'
40*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${*#S}'		'2|Q|R'
41*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${*##S}'		'2|Q|R'
42*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${*%S}'		'2|Q|R'
43*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${*%%S}'		'2|Q|R'
44*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${@#Q}'		'1|R'
45*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${@##Q}'		'1|R'
46*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${@%R}'		'1|Q'
47*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${@%%R}'		'1|Q'
48*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${@#S}'		'2|Q|R'
49*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${@##S}'		'2|Q|R'
50*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${@%S}'		'2|Q|R'
51*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- ${@%%S}'		'2|Q|R'
52*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${@#Q}"'		'2||R'
53*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${@%R}"'		'2|Q|'
54*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${@%%R}"'		'2|Q|'
55*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${@#S}"'		'2|Q|R'
56*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${@##S}"'		'2|Q|R'
57*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${@%S}"'		'2|Q|R'
58*cf1330beSJilles Tjoelkertestcase 'set -- Q R; set -- "${@%%S}"'		'2|Q|R'
59*cf1330beSJilles Tjoelker
60*cf1330beSJilles Tjoelkertest "x$failures" = x
61