diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/array.right | 21 | ||||
-rw-r--r-- | tests/array.tests | 2 | ||||
-rw-r--r-- | tests/array18.sub | 34 | ||||
-rwxr-xr-x | tests/dollar-at-star | 1 | ||||
-rw-r--r-- | tests/dollar-at-star3.sub | 27 | ||||
-rw-r--r-- | tests/dollar-at-star4.sub | 15 | ||||
-rw-r--r-- | tests/dollar-at-star5.sub | 53 | ||||
-rw-r--r-- | tests/dollar.right | 44 |
8 files changed, 196 insertions, 1 deletions
diff --git a/tests/array.right b/tests/array.right index 371d5b4b..0afb4136 100644 --- a/tests/array.right +++ b/tests/array.right @@ -411,3 +411,24 @@ one two two ./array17.sub: line 76: ~ : syntax error: operand expected (error token is "~ ") +1 +argv[1] = <> +argv[2] = <> +argv[3] = <> +argv[1] = <bar> +argv[1] = <--> +argv[1] = <> +argv[1] = <qux> +argv[1] = <-> +argv[2] = <-> +argv[1] = < > +argv[1] = <> +argv[2] = <> +argv[3] = <> +argv[1] = <bar> +argv[1] = <--> +argv[1] = <> +argv[1] = <qux> +argv[1] = <-> +argv[2] = <-> +argv[1] = < > diff --git a/tests/array.tests b/tests/array.tests index f886eed7..34953492 100644 --- a/tests/array.tests +++ b/tests/array.tests @@ -402,3 +402,5 @@ ${THIS_SH} ./array15.sub ${THIS_SH} ./array16.sub ${THIS_SH} ./array17.sub + +${THIS_SH} ./array18.sub diff --git a/tests/array18.sub b/tests/array18.sub new file mode 100644 index 00000000..675b194e --- /dev/null +++ b/tests/array18.sub @@ -0,0 +1,34 @@ +# arrays referenced using @ subscript and positional parameters should behave +# the same way + +foo=(0 0 0); [[ -z ${foo[@]#0} ]]; echo $? + +recho "${foo[@]#0}" +bar=${foo[@]#0} +recho bar +recho $bar +recho -$bar- +recho "$bar" + +qux="${foo[@]#0}" +recho qux +recho $qux +recho -$qux- +recho "$qux" + +unset foo qux bar + +set -- 0 0 0 + +recho "${@#0}" +bar=${@#0} +recho bar +recho $bar +recho -$bar- +recho "$bar" + +qux="${@#0}" +recho qux +recho $qux +recho -$qux- +recho "$qux" diff --git a/tests/dollar-at-star b/tests/dollar-at-star index 1ae92e58..611c5c10 100755 --- a/tests/dollar-at-star +++ b/tests/dollar-at-star @@ -216,6 +216,7 @@ ${THIS_SH} ./dollar-at-star1.sub ${THIS_SH} ./dollar-at-star2.sub ${THIS_SH} ./dollar-at-star3.sub ${THIS_SH} ./dollar-at-star4.sub +${THIS_SH} ./dollar-at-star5.sub # tests for special expansion of "$*" and "${array[*]}" when used with other # expansions -- bugs through bash-2.05b diff --git a/tests/dollar-at-star3.sub b/tests/dollar-at-star3.sub index c8bd1e57..b37d64af 100644 --- a/tests/dollar-at-star3.sub +++ b/tests/dollar-at-star3.sub @@ -3,9 +3,35 @@ unset f ; f=abcd first_char=${f[@]:0:1} recho $first_char +first_char=${f[0]:0:1} +recho $first_char + +first_char=${f:0:1} +recho $first_char + first_char="${f[@]:0:1}" recho $first_char +first_char="${f[@]:0:1}" +recho $first_char + +first_char="${f[0]:0:1}" +recho $first_char + +first_char="${f:0:1}" +recho $first_char + +unset f; +f=( one two three ) +first_word=${f[@]:0:1} +recho $first_word + +first_word=${f[0]:0:1} +recho $first_word + +first_word=${f:0:1} +recho $first_word + unset f; f=( one two three ) first_word=${f[@]:0:1} @@ -15,3 +41,4 @@ set -- abc def ghi printf '<%s> ' "123 $@ 456"; echo printf '<%s> ' "123 $@\ 456"; echo + diff --git a/tests/dollar-at-star4.sub b/tests/dollar-at-star4.sub index 59472b5b..690eb677 100644 --- a/tests/dollar-at-star4.sub +++ b/tests/dollar-at-star4.sub @@ -81,4 +81,17 @@ recho ${foo=$@} recho "$foo" shift $# -unset foo +unset foo x + +set -- a b +x=abc + +IFS= +printf "<%s>\n" ${x#$*} +printf "<%s>\n" "${x#$*}" + +x=abcd +set a c +IFS='?' +printf "<%s>\n" ${x#$*} +printf "<%s>\n" "${x#$*}" diff --git a/tests/dollar-at-star5.sub b/tests/dollar-at-star5.sub new file mode 100644 index 00000000..3bd7b0f8 --- /dev/null +++ b/tests/dollar-at-star5.sub @@ -0,0 +1,53 @@ +# testing various combinations of quoted and unquoted expansions of $@, and +# whether they generate empty words after expansion + +n() { echo "$#"; } + +n "$@" +n ${foo-"$@"} +n "${foo-$@}" + +n ""$@ +n """$@" + +n $(true)$@ +n "$(true)$@" +n "$(true)$@" +n "$(true)""$@" + +n $xxx$@ +n "$xxx$@" +n $xxx"$@" +n "$xxx""$@" + +recho $xxx"$@" +echo after 1 + +recho "$xxx$@" +echo after 2 + +recho ${foo:-$xxx"$@"} +echo after 3 + +# this is where these things start to differ +echo same as 1 +recho "${foo:-$xxx"$@"}" +echo same as 2 +recho "${foo:-$xxx$@}" + +echo null fields +recho ""$@ +recho """$@" + +echo null fields in rhs +echo null string with unquoted '$@' +recho ${foo:-""$@} +echo null string with quoted '$@' +recho ${foo:-"""$@"} + +echo assignment +recho "${foo=$@}" +echo variable +recho "$foo" +echo dollar-at +recho "${@}" diff --git a/tests/dollar.right b/tests/dollar.right index 4918da43..5f6fa7f2 100644 --- a/tests/dollar.right +++ b/tests/dollar.right @@ -158,6 +158,14 @@ ok at 8 ok at 9 argv[1] = <a> argv[1] = <a> +argv[1] = <a> +argv[1] = <a> +argv[1] = <a> +argv[1] = <a> +argv[1] = <a> +argv[1] = <one> +argv[1] = <o> +argv[1] = <o> argv[1] = <one> <123 abc> <def> <ghi 456> <123 abc> <def> <ghi\ 456> @@ -185,6 +193,42 @@ argv[1] = <abcd> argv[1] = <a> argv[2] = <b> argv[1] = <a b> +<c> +<c> +<d> +<d> +0 +0 +1 +1 +1 +0 +0 +0 +1 +0 +0 +0 +1 +after 1 +after 2 +after 3 +same as 1 +argv[1] = <> +same as 2 +argv[1] = <> +null fields +argv[1] = <> +argv[1] = <> +null fields in rhs +null string with unquoted $@ +argv[1] = <> +null string with quoted $@ +assignment +argv[1] = <> +variable +argv[1] = <> +dollar-at xa|xb|xc xa|xb|xc a|b|c |