From 56b874a43e00d0d0823dfd8552b22aba33e95942 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Mon, 13 Aug 2001 17:46:55 +0000 Subject: Merge typeset fixes and tests from dev trunk. --- Test/B02typeset.ztst | 243 +++++++++++++++++++++++++++++++++++++++++++++++++ Test/D06subscript.ztst | 180 ++++++++++++++++++++++++++++++++++++ 2 files changed, 423 insertions(+) create mode 100644 Test/B02typeset.ztst create mode 100644 Test/D06subscript.ztst (limited to 'Test') diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst new file mode 100644 index 000000000..2dc015d31 --- /dev/null +++ b/Test/B02typeset.ztst @@ -0,0 +1,243 @@ +# There are certain usages of typeset and its synonyms that it is not +# possible to test here, because they must appear at the top level and +# everything that follows is processed by an "eval" within a function. + +# Equivalences: +# declare typeset but declare does not accept -m +# export typeset -x and typeset -x implies -g +# float typeset -E +# functions typeset -f +# integer typeset -i +# local typeset +g -m approximately +# readonly typeset -r + +# Tested elsewhere: +# Equivalence of autoload and typeset -fu A05execution +# Associative array creation & assignment D04parameter, D06subscript +# Effects of GLOBAL_EXPORT E01options +# Function tracing (typeset -ft) E02xtrace + +# Not yet tested: +# Justification (-L, -R, -Z) +# Case conversion (-l, -u) +# Assorted illegal flag combinations + +%prep + + setopt noglob + + scalar=scalar + array=(a r r a y) + + scope00() { + typeset scalar + scalar=local + typeset -a array + array=(l o c a l) + print $scalar $array + } + scope01() { + local scalar + scalar=local + local -a array + array=(l o c a l) + print $scalar $array + } + scope02() { + declare scalar + scalar=local + declare -a array + array=(l o c a l) + print $scalar $array + } + scope10() { + export outer=outer + /bin/sh -fc 'echo $outer' + } + scope11() { + typeset -x outer=outer + /bin/sh -fc 'echo $outer' + } + scope12() { + local -x outer=inner + /bin/sh -fc 'echo $outer' + } + scope13() { + local -xT OUTER outer + outer=(i n n e r) + /bin/sh -fc 'echo $OUTER' + } + + # Bug? `typeset -h' complains that ! # $ * - ? @ are not identifiers. + stress00() { + typeset -h +g -m [[:alpha:]_]* + unset -m [[:alpha:]_]* + typeset +m [[:alpha:]_]* + } + +%test + + typeset +m scalar array +0:Report types of parameters with typeset +m +>scalar +>array array + + scope00 + print $scalar $array +0:Simple local declarations +>local l o c a l +>scalar a r r a y + + scope01 + print $scalar $array +0:Equivalence of local and typeset in functions +>local l o c a l +>scalar a r r a y + + scope02 + print $scalar $array +0:Basic equivalence of declare and typeset +>local l o c a l +>scalar a r r a y + + declare +m +1:Differences of declare and typeset +?(eval):1: bad option: -m + + scope10 + print $outer +0:Global export +>outer +>outer + + scope11 + print $outer +0:Equivalence of export and typeset -x +>outer +>outer + + scope12 + print $outer +0:Local export +>inner +>outer + + float f=3.14159 + typeset +m f + float -E3 f + print $f + float -F f + print $f +0:Floating point, adding a precision, and fixed point +>float local f +>3.14e+00 +>3.142 + + integer i=3.141 + typeset +m i + integer -i2 i + print $i +0:Integer and changing the base +>integer local i +>2#11 + + float -E3 f=3.141 + typeset +m f + integer -i2 f + typeset +m f + print $f +0:Conversion of floating point to integer +>float local f +>integer local f +>2#11 + + typeset -f +0q:Equivalence of functions and typeset -f +>$(functions) + + readonly r=success + print $r + r=failure +1:Readonly declaration +>success +?(eval):3: read-only variable: r + + typeset r=success + readonly r + print $r + r=failure +1:Convert to readonly +>success +?(eval):4: read-only variable: r + + typeset -gU array + print $array +0:Uniquified arrays and non-local scope +>a r y + + typeset -T SCALAR=l:o:c:a:l array + print $array + typeset -U SCALAR + print $SCALAR $array +0:Tied parameters and uniquified colon-arrays +>l o c a l +>l:o:c:a l o c a + + typeset -T SCALAR array + typeset +T SCALAR +1:Untying is prohibited +?(eval):typeset:2: use unset to remove tied variables + + OUTER=outer + scope13 + print $OUTER +0:Export of tied parameters +>i:n:n:e:r +>outer + + local array[2]=x +1:Illegal local array element assignment +?(eval):local:1: array[2]: can't create local array elements + + local -a array + typeset array[1]=a array[2]=b array[3]=c + print $array +0:Legal local array element assignment +>a b c + + local -A assoc + local b=1 ;: to stomp assoc[1] if assoc[b] is broken + typeset assoc[1]=a assoc[b]=2 assoc[3]=c + print $assoc[1] $assoc[b] $assoc[3] +0:Legal local associative array element assignment +>a 2 c + + local scalar scalar[1]=a scalar[2]=b scalar[3]=c + print $scalar +0:Local scalar subscript assignment +>abc + + stress00 + print $scalar $array +0q:Stress test: all parameters are local and unset, using -m +>scalar a r y + + # The first declare works around the "not an identifier" bug with -h + declare \! \# \$ * - ? @ + typeset -h +g -m * + unset -m * + integer i=9 + float -H f=9 + declare -t scalar + declare -H -a array + typeset + typeset + +0:Parameter hiding and tagging, printing types and values +>array local array +>float local f +>integer local i=9 +>local tagged scalar='' +>array local array +>float local f +>integer local i +>local tagged scalar diff --git a/Test/D06subscript.ztst b/Test/D06subscript.ztst new file mode 100644 index 000000000..db991c54e --- /dev/null +++ b/Test/D06subscript.ztst @@ -0,0 +1,180 @@ +# Test parameter subscripting. + +%prep + + s='Twinkle, twinkle, little *, [how] I [wonder] what? You are!' + a=('1' ']' '?' '\2' '\]' '\?' '\\3' '\\]' '\\?' '\\\4' '\\\]' '\\\?') + typeset -g -A A + A=($a) + +%test + + x=',' + print $s[(i)winkle] $s[(I)winkle] + print ${s[(i)You are]} $#s + print ${s[(r)$x,(R)$x]} +0:Scalar pattern subscripts without wildcards +>2 11 +>53 60 +>, twinkle, little *, + + x='*' + print $s[(i)*] $s[(i)\*] $s[(i)$x*] $s[(i)${(q)x}*] $s[(I)$x\*] + print $s[(r)?,(R)\?] $s[(r)\?,(R)?] + print $s[(r)\*,(R)*] + print $s[(r)\],(R)\[] +0:Scalar pattern subscripts with wildcards +>1 26 1 26 26 +>Twinkle, twinkle, little *, [how] I [wonder] what? ? You are! +>*, [how] I [wonder] what? You are! +>] I [ + + # $s[(R)x] actually is $s[0], but zsh treats 0 as 1 for subscripting. + print $s[(i)x] : $s[(I)x] + print $s[(r)x] : $s[(R)x] +0:Scalar pattern subscripts that do not match +>61 : 0 +>: T + + print -R $s[$s[(i)\[]] $s[(i)$s[(r)\*]] $s[(i)${(q)s[(r)\]]}] +0:Scalar subscripting using a pattern subscript to get the index +>[ 1 33 + + print -R $a[(r)?] $a[(R)?] + print $a[(n:2:i)?] $a[(n:2:I)?] + print $a[(i)\?] $a[(I)\?] + print $a[(i)*] $a[(i)\*] +0:Array pattern subscripts +>1 ? +>2 2 +>3 3 +>1 13 + + # It'd be nice to do some of the following with (r), but we run into + # limitations of the ztst script parsing of backslashes in the output. + print -R $a[(i)\\\\?] $a[(i)\\\\\?] + print -R $a[(i)\\\\\\\\?] $a[(i)\\\\\\\\\?] + print -R ${a[(i)\\\\\\\\?]} ${a[(i)\\\\\\\\\?]} + print -R "$a[(i)\\\\\\\\?] $a[(i)\\\\\\\\\?]" + print -R $a[(i)\]] $a[(i)\\\\\]] $a[(i)\\\\\\\\\]] $a[(i)\\\\\\\\\\\\\]] + print -R $a[(i)${(q)a[5]}] $a[(i)${(q)a[8]}] $a[(i)${(q)a[11]}] + print -R $a[(i)${a[3]}] $a[(i)${a[6]}] $a[(i)${a[9]}] $a[(i)${a[12]}] +0:Array pattern subscripts with multiple backslashes +>4 6 +>7 9 +>7 9 +>7 9 +>2 5 8 11 +>5 8 11 +>1 3 4 6 + + print -R $A[1] $A[?] $A[\\\\3] $A[\\\]] + print -R $A[$a[11]] + print -R $A[${(q)a[5]}] +0:Associative array lookup (direct subscripting) +>] \2 \\] \? +>\\\? +>\\\? + + # The (o) is necessary here for predictable output ordering + print -R $A[(I)\?] ${(o)A[(I)?]} + print -R $A[(i)\\\\\\\\3] + print -R $A[(I)\\\\\\\\\?] ${(o)A[(I)\\\\\\\\?]} +0:Associative array lookup (pattern subscripting) +>? 1 ? +>\\3 +>\\? \\3 \\? + + print -R $A[(R)\?] : ${(o)A[(R)?]} + print -R $A[(R)\\\\\?] ${(o)A[(R)\\\\?]} ${(o)A[(R)\\\\\?]} + print -R ${(o)A[(R)\\\\\\\\\]]} +0:Associative array lookup (reverse subscripting) +>: ] +>\? \2 \? \? +>\\] + + eval 'A[*]=star' +1:Illegal associative array assignment +?ZTST_execchunk:2: A: attempt to set slice of associative array + + x='*' + A[$x]=xstar + A[${(q)x}]=qxstar + print -R ${(k)A[(r)xstar]} $A[$x] + print -R ${(k)A[(r)qxstar]} $A[${(q)x}] + A[(e)*]=star + A[\*]=backstar + print -R ${(k)A[(r)star]} $A[(e)*] + print -R ${(k)A[(r)backstar]} $A[\*] +0:Associative array assignment +>* xstar +>\* qxstar +>* star +>\* backstar + + o='[' + c=']' + A[\]]=cbrack + A[\[]=obrack + A[\\\[]=backobrack + A[\\\]]=backcbrack + print -R $A[$o] $A[$c] $A[\[] $A[\]] $A[\\\[] $A[\\\]] + print -R $A[(i)\[] $A[(i)\]] $A[(i)\\\\\[] $A[(i)\\\\\]] +0:Associative array keys with open and close brackets +>obrack cbrack obrack cbrack backobrack backcbrack +>[ ] \[ \] + + print -R $A[$o] $A[$s[(r)\[]] + print -R $A[(r)$c] $A[(r)$s[(r)\]]] + print -R $A[$A[(i)\\\\\]]] +0:Associative array lookup using a pattern subscript to get the key +>obrack obrack +>] ] +>backcbrack + + print -R ${A[${A[(r)\\\\\\\\\]]}]::=zounds} + print -R ${A[${A[(r)\\\\\\\\\]]}]} + print -R $A[\\\\\]] +0:Associative array substitution-assignment with reverse pattern subscript key +>zounds +>zounds +>zounds + + print -R ${(o)A[(K)\]]} + print -R ${(o)A[(K)\\\]]} +0:Associative array keys interpreted as patterns +>\2 backcbrack cbrack star +>\\\4 \\\? star zounds + + typeset -g "A[one\"two\"three\"quotes]"=QQQ + typeset -g 'A[one\"two\"three\"quotes]'=qqq + print -R "$A[one\"two\"three\"quotes]" + print -R $A[one\"two\"three\"quotes] + A[one"two"three"four"quotes]=QqQq + print -R $A[one"two"three"four"quotes] + print -R $A[$A[(i)one\"two\"three\"quotes]] + print -R "$A[$A[(i)one\"two\"three\"quotes]]" +0:Associative array keys with double quotes +>QQQ +>qqq +>QqQq +>qqq +>QQQ + + print ${x::=$A[$A[(i)one\"two\"three\"quotes]]} + print $x + print ${x::="$A[$A[(i)one\"two\"three\"quotes]]"} + print $x +0:More keys with double quotes, used in assignment-expansion +>qqq +>qqq +>QQQ +>QQQ + + qqq=lower + QQQ=upper + print ${(P)A[one\"two\"three\"quotes]} + print "${(P)A[$A[(i)one\"two\"three\"quotes]]}" +0:Keys with double quotes and the (P) expansion flag +>lower +>upper -- cgit 1.4.1