]> git.saurik.com Git - apple/shell_cmds.git/blob - sh/tests/expansion/plus-minus3.0
d7fc9231ff7329b130071f7199b798b25fb0fd6b
[apple/shell_cmds.git] / sh / tests / expansion / plus-minus3.0
1 # $FreeBSD: head/bin/sh/tests/expansion/plus-minus3.0 206817 2010-04-18 22:13:45Z jilles $
2
3 e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
4 h='##'
5 failures=''
6 ok=''
7
8 testcase() {
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
33 testcase 'set -- "${p+"/et[c]/"}"' '1|/etc/'
34 testcase 'set -- "${p-"/et[c]/"}"' '1|/et[c]/'
35 testcase 'set -- "${p+"$p"}"' '1|/etc/'
36 testcase 'set -- "${p-"$p"}"' '1|/et[c]/'
37 testcase 'set -- "${p+"""/et[c]/"}"' '1|/etc/'
38 testcase 'set -- "${p-"""/et[c]/"}"' '1|/et[c]/'
39 testcase 'set -- "${p+"""$p"}"' '1|/etc/'
40 testcase 'set -- "${p-"""$p"}"' '1|/et[c]/'
41 testcase 'set -- "${p+"\@"}"' '1|@'
42 testcase 'set -- "${p+"'\''/et[c]/'\''"}"' '1|/et[c]/'
43
44 test "x$failures" = x