diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2012-06-24 22:28:35 +0000 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2012-06-24 22:28:35 +0000 |
commit | 3950ffe2a485479f6561c27364d3d7df5a21d124 (patch) | |
tree | 468c6e14449d1b1e279222ec32f676b0311917d2 /src/cmd/ksh93/tests/enum.sh | |
download | ksh-upstream.tar.gz |
Imported Upstream version 93u+upstream
Diffstat (limited to 'src/cmd/ksh93/tests/enum.sh')
-rwxr-xr-x | src/cmd/ksh93/tests/enum.sh | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/cmd/ksh93/tests/enum.sh b/src/cmd/ksh93/tests/enum.sh new file mode 100755 index 0000000..134a0a3 --- /dev/null +++ b/src/cmd/ksh93/tests/enum.sh @@ -0,0 +1,68 @@ +######################################################################## +# # +# This software is part of the ast package # +# Copyright (c) 1982-2011 AT&T Intellectual Property # +# and is licensed under the # +# Eclipse Public License, Version 1.0 # +# by AT&T Intellectual Property # +# # +# A copy of the License is available at # +# http://www.eclipse.org/org/documents/epl-v10.html # +# (with md5 checksum b35adb5213ca9657e911e9befb180842) # +# # +# Information and Software Systems Research # +# AT&T Research # +# Florham Park NJ # +# # +# David Korn <dgk@research.att.com> # +# # +######################################################################## +function err_exit +{ + print -u2 -n "\t" + print -u2 -r ${Command}[$1]: "${@:2}" + (( Errors+=1 )) +} +alias err_exit='err_exit $LINENO' + +Command=${0##*/} +integer Errors=0 +enum Color_t=(red green blue orange yellow) +enum -i Sex_t=(Male Female) +for ((i=0; i < 1000; i++)) +do +Color_t x +[[ $x == red ]] || err_exit 'Color_t does not default to red' +x=orange +[[ $x == orange ]] || err_exit '$x should be orange' +( x=violet) 2> /dev/null && err_exit 'x=violet should fail' +x[2]=green +[[ ${x[2]} == green ]] || err_exit '${x[2]} should be green' +(( x[2] == 1 )) || err_exit '((x[2]!=1))' +[[ $((x[2])) == 1 ]] || err_exit '$((x[2]))!=1' +[[ $x == orange ]] || err_exit '$x is no longer orange' +Color_t -A y +y[foo]=yellow +[[ ${y[foo]} == yellow ]] || err_exit '${y[foo]} != yellow' +(( y[foo] == 4 )) || err_exit '(( y[foo] != 4))' +unset y +typeset -a [Color_t] z +z[green]=xyz +[[ ${z[green]} == xyz ]] || err_exit '${z[green]} should be xyz' +[[ ${z[1]} == xyz ]] || err_exit '${z[1]} should be xyz' +z[orange]=bam +[[ ${!z[@]} == 'green orange' ]] || err_exit '${!z[@]} == "green orange"' +unset x +Sex_t x +[[ $x == Male ]] || err_exit 'Sex_t not defaulting to Male' +x=female +[[ $x == Female ]] || err_exit 'Sex_t not case sensitive' +unset x y z +done +( +typeset -T X_t=( typeset name=aha ) +typeset -a[X_t] arr +) 2> /dev/null +[[ $? == 1 ]] || err_exit 'typeset -a[X_t] should generate an error message when X-t is not an enumeriation type' + +exit $((Errors<125?Errors:125)) |