zsh-workers
 help / color / mirror / code / Atom feed
* B02typeset.ztst
@ 2001-08-13  3:54 Bart Schaefer
  2001-08-13 10:23 ` B02typeset.ztst Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2001-08-13  3:54 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 334 bytes --]

Attached.  It depends on the patch in 15611, so I'll commit both (maybe
altered) after I've gotten feedback.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   

[-- Attachment #2: Test various options and arguments to typeset --]
[-- Type: text/plain , Size: 4149 bytes --]

# 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.
# This includes but may not be limited to printing all values (with no
# arguments) or all names (with argument `+').

# Equivalences:
#  declare	typeset
#  export	typeset -x (implies -g)
#  float	typeset -E
#  functions	typeset -f
#  integer	typeset -i
#  local	typeset +g (almost)
#  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)
#  Hiding (-H)
#  Tagging (-t)

%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'
  }

  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

 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
0:Stress test: all parameters are local and unset, using -m
>scalar a r y

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: B02typeset.ztst
  2001-08-13  3:54 B02typeset.ztst Bart Schaefer
@ 2001-08-13 10:23 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2001-08-13 10:23 UTC (permalink / raw)
  To: Zsh hackers list

Bart Schaefer wrote:
> Attached.  It depends on the patch in 15611, so I'll commit both (maybe
> altered) after I've gotten feedback.

That's OK by me.  The `local foo[..]' stuff strikes me as way out enough
that as long as it works consistently the exact interface isn't so
important.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-13 10:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-13  3:54 B02typeset.ztst Bart Schaefer
2001-08-13 10:23 ` B02typeset.ztst Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).