xref: /freebsd/bin/sh/tests/expansion/plus-minus3.0 (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1# $FreeBSD$
2
3e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
4h='##'
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
24# We follow original ash behaviour for quoted ${var+-=?} expansions:
25# a double-quote in one switches back to unquoted state.
26# This allows expanding a variable as a single word if it is set
27# and substituting multiple words otherwise.
28# It is also close to the Bourne and Korn shells.
29# POSIX leaves this undefined, and various other shells treat
30# such double-quotes as introducing a second level of quoting
31# which does not do much except quoting close braces.
32
33testcase 'set -- "${p+"/et[c]/"}"'		'1|/etc/'
34testcase 'set -- "${p-"/et[c]/"}"'		'1|/et[c]/'
35testcase 'set -- "${p+"$p"}"'			'1|/etc/'
36testcase 'set -- "${p-"$p"}"'			'1|/et[c]/'
37testcase 'set -- "${p+"""/et[c]/"}"'		'1|/etc/'
38testcase 'set -- "${p-"""/et[c]/"}"'		'1|/et[c]/'
39testcase 'set -- "${p+"""$p"}"'			'1|/etc/'
40testcase 'set -- "${p-"""$p"}"'			'1|/et[c]/'
41testcase 'set -- "${p+"\@"}"'			'1|@'
42testcase 'set -- "${p+"'\''/et[c]/'\''"}"'	'1|/et[c]/'
43
44test "x$failures" = x
45