]> git.saurik.com Git - apple/shell_cmds.git/blame - sh/tests/expansion/plus-minus1.0
shell_cmds-207.11.1.tar.gz
[apple/shell_cmds.git] / sh / tests / expansion / plus-minus1.0
CommitLineData
deb63bfb 1# $FreeBSD: head/bin/sh/tests/expansion/plus-minus1.0 216738 2010-12-27 15:57:41Z emaste $
71aad674
A
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
24testcase 'set -- a b' '2|a|b'
25testcase 'set --' '0|'
26testcase 'set -- ${e}' '0|'
27testcase 'set -- "${e}"' '1|'
28
29testcase 'set -- $p' '1|/etc/'
30testcase 'set -- "$p"' '1|/et[c]/'
31testcase 'set -- ${s+$p}' '1|/etc/'
32testcase 'set -- "${s+$p}"' '1|/et[c]/'
33testcase 'set -- ${s+"$p"}' '1|/et[c]/'
34# Dquotes in dquotes is undefined for Bourne shell operators
35#testcase 'set -- "${s+"$p"}"' '1|/et[c]/'
36testcase 'set -- ${e:-$p}' '1|/etc/'
37testcase 'set -- "${e:-$p}"' '1|/et[c]/'
38testcase 'set -- ${e:-"$p"}' '1|/et[c]/'
39# Dquotes in dquotes is undefined for Bourne shell operators
40#testcase 'set -- "${e:-"$p"}"' '1|/et[c]/'
41testcase 'set -- ${e:+"$e"}' '0|'
42testcase 'set -- ${e:+$w"$e"}' '0|'
43testcase 'set -- ${w:+"$w"}' '1|a b c'
44testcase 'set -- ${w:+$w"$w"}' '3|a|b|ca b c'
45
46testcase 'set -- "${s+a b}"' '1|a b'
47testcase 'set -- "${e:-a b}"' '1|a b'
48testcase 'set -- ${e:-\}}' '1|}'
49testcase 'set -- ${e:+{}}' '1|}'
50testcase 'set -- "${e:+{}}"' '1|}'
51
52testcase 'set -- ${e+x}${e+x}' '1|xx'
53testcase 'set -- "${e+x}"${e+x}' '1|xx'
54testcase 'set -- ${e+x}"${e+x}"' '1|xx'
55testcase 'set -- "${e+x}${e+x}"' '1|xx'
56testcase 'set -- "${e+x}""${e+x}"' '1|xx'
57
58testcase 'set -- ${e:-${e:-$p}}' '1|/etc/'
59testcase 'set -- "${e:-${e:-$p}}"' '1|/et[c]/'
60testcase 'set -- ${e:-"${e:-$p}"}' '1|/et[c]/'
61testcase 'set -- ${e:-${e:-"$p"}}' '1|/et[c]/'
62testcase 'set -- ${e:-${e:-${e:-$w}}}' '3|a|b|c'
63testcase 'set -- ${e:-${e:-${e:-"$w"}}}' '1|a b c'
64testcase 'set -- ${e:-${e:-"${e:-$w}"}}' '1|a b c'
65testcase 'set -- ${e:-"${e:-${e:-$w}}"}' '1|a b c'
66testcase 'set -- "${e:-${e:-${e:-$w}}}"' '1|a b c'
67
68testcase 'shift $#; set -- ${1+"$@"}' '0|'
69testcase 'set -- ""; set -- ${1+"$@"}' '1|'
70testcase 'set -- "" a; set -- ${1+"$@"}' '2||a'
71testcase 'set -- a ""; set -- ${1+"$@"}' '2|a|'
72testcase 'set -- a b; set -- ${1+"$@"}' '2|a|b'
73testcase 'set -- a\ b; set -- ${1+"$@"}' '1|a b'
74testcase 'set -- " " ""; set -- ${1+"$@"}' '2| |'
75
76test "x$failures" = x