mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 11:42:21 +00:00
nv_associative(): finally use proper check for enum (re: b98e32fc)
As of the previous commit, I finally know how to properly check for a variable of a type created by 'enum'. We need to check for both the NV_UINT16 attribute and the ENUM_disc discipline. Also: - regression test tweaks - add missing tests for previous commit (f600a5ea)
This commit is contained in:
parent
a66cd72f7d
commit
e3d91ffa90
3 changed files with 25 additions and 10 deletions
|
@ -1777,11 +1777,11 @@ void *nv_associative(register Namval_t *np,const char *sp,int mode)
|
|||
if(sh.subshell)
|
||||
np = sh_assignok(np,1);
|
||||
/*
|
||||
* type == NV_UINT16 (16-bit unsigned integer, see include/nval.h) indicates an
|
||||
* associative array of a type created by the enum command. nelem should not be
|
||||
* increased in that case or 'unset' will fail to completely unset such an array.
|
||||
* For enum types (NV_UINT16 with discipline ENUM_disc), nelem should not
|
||||
* not increased or 'unset' will fail to completely unset such an array.
|
||||
*/
|
||||
if(type != NV_UINT16 && (!ap->header.scope || !nv_search(sp,dtvnext(ap->header.table),0)))
|
||||
if((!ap->header.scope || !nv_search(sp,dtvnext(ap->header.table),0))
|
||||
&& !(type==NV_UINT16 && nv_hasdisc(np, &ENUM_disc)))
|
||||
ap->header.nelem++;
|
||||
if(nv_isnull(mp))
|
||||
{
|
||||
|
|
|
@ -238,7 +238,9 @@ function foo {
|
|||
}
|
||||
foo
|
||||
EOF
|
||||
$SHELL "$multiarray_unset" > /dev/null || err_exit 'Multidimensional arrays with an unset method crash ksh'
|
||||
{ $SHELL "$multiarray_unset" > /dev/null; } 2>/dev/null
|
||||
let "(e=$?)==0" || err_exit 'Multidimensional arrays with an unset method crash ksh' \
|
||||
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
|
||||
|
||||
# ======
|
||||
# Multidimensional indexed array arithmetic assignment operation tests
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
. "${SHTESTS_COMMON:-${0%/*}/_common}"
|
||||
|
||||
enum Color_t=(red green blue orange yellow)
|
||||
enum -i Sex_t=(Male Female)
|
||||
enum -i Bool_t=(False True)
|
||||
for ((i=0; i < 1000; i++))
|
||||
do
|
||||
Color_t x
|
||||
|
@ -47,10 +47,10 @@ z[green]=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'
|
||||
Bool_t x
|
||||
[[ $x == False ]] || err_exit 'Bool_t not defaulting to False'
|
||||
x=true
|
||||
[[ $x == True ]] || err_exit 'Bool_t not case sensitive'
|
||||
unset x y z
|
||||
done
|
||||
(
|
||||
|
@ -133,5 +133,18 @@ got=$("$SHELL" -c 'source ./cmd.sh' 2>&1)
|
|||
[[ $got == "$exp" ]] || err_exit "sourced script failed" \
|
||||
"(expected $(printf %q "$exp"); got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# https://github.com/ksh93/ksh/issues/335
|
||||
unset a
|
||||
Color_t a
|
||||
|
||||
let "a=5" 2>/dev/null && err_exit "arithmetic can assign out of range (positive)"
|
||||
let "a=-1" 2>/dev/null && err_exit "arithmetic can assign out of range (negative)"
|
||||
a=yellow; let "a++" 2>/dev/null && err_exit "arithmetic can assign out of range (increment)"
|
||||
a=red; let "a--" 2>/dev/null && err_exit "arithmetic can assign out of range (decrement)"
|
||||
a=orange; let "a+=2" 2>/dev/null && err_exit "arithmetic can assign out of range (add)"
|
||||
a=green; let "a-=2" 2>/dev/null && err_exit "arithmetic can assign out of range (subtract)"
|
||||
a=blue; let "a*=3" 2>/dev/null && err_exit "arithmetic can assign out of range (multiply)"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Reference in a new issue