xref: /freebsd/bin/sh/tests/expansion/plus-minus3.0 (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1*13de33a5SJulio Merino
2*13de33a5SJulio Merinoe= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
3*13de33a5SJulio Merinoh='##'
4*13de33a5SJulio Merinofailures=''
5*13de33a5SJulio Merinook=''
6*13de33a5SJulio Merino
7*13de33a5SJulio Merinotestcase() {
8*13de33a5SJulio Merino	code="$1"
9*13de33a5SJulio Merino	expected="$2"
10*13de33a5SJulio Merino	oIFS="$IFS"
11*13de33a5SJulio Merino	eval "$code"
12*13de33a5SJulio Merino	IFS='|'
13*13de33a5SJulio Merino	result="$#|$*"
14*13de33a5SJulio Merino	IFS="$oIFS"
15*13de33a5SJulio Merino	if [ "x$result" = "x$expected" ]; then
16*13de33a5SJulio Merino		ok=x$ok
17*13de33a5SJulio Merino	else
18*13de33a5SJulio Merino		failures=x$failures
19*13de33a5SJulio Merino		echo "For $code, expected $expected actual $result"
20*13de33a5SJulio Merino	fi
21*13de33a5SJulio Merino}
22*13de33a5SJulio Merino
23*13de33a5SJulio Merino# We follow original ash behaviour for quoted ${var+-=?} expansions:
24*13de33a5SJulio Merino# a double-quote in one switches back to unquoted state.
25*13de33a5SJulio Merino# This allows expanding a variable as a single word if it is set
26*13de33a5SJulio Merino# and substituting multiple words otherwise.
27*13de33a5SJulio Merino# It is also close to the Bourne and Korn shells.
28*13de33a5SJulio Merino# POSIX leaves this undefined, and various other shells treat
29*13de33a5SJulio Merino# such double-quotes as introducing a second level of quoting
30*13de33a5SJulio Merino# which does not do much except quoting close braces.
31*13de33a5SJulio Merino
32*13de33a5SJulio Merinotestcase 'set -- "${p+"/et[c]/"}"'		'1|/etc/'
33*13de33a5SJulio Merinotestcase 'set -- "${p-"/et[c]/"}"'		'1|/et[c]/'
34*13de33a5SJulio Merinotestcase 'set -- "${p+"$p"}"'			'1|/etc/'
35*13de33a5SJulio Merinotestcase 'set -- "${p-"$p"}"'			'1|/et[c]/'
36*13de33a5SJulio Merinotestcase 'set -- "${p+"""/et[c]/"}"'		'1|/etc/'
37*13de33a5SJulio Merinotestcase 'set -- "${p-"""/et[c]/"}"'		'1|/et[c]/'
38*13de33a5SJulio Merinotestcase 'set -- "${p+"""$p"}"'			'1|/etc/'
39*13de33a5SJulio Merinotestcase 'set -- "${p-"""$p"}"'			'1|/et[c]/'
40*13de33a5SJulio Merinotestcase 'set -- "${p+"\@"}"'			'1|@'
41*13de33a5SJulio Merinotestcase 'set -- "${p+"'\''/et[c]/'\''"}"'	'1|/et[c]/'
42*13de33a5SJulio Merino
43*13de33a5SJulio Merinotest "x$failures" = x
44