summaryrefslogtreecommitdiffstats
path: root/Test/B02typeset.ztst
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-06-18 14:54:41 +0100
committerPeter Stephenson <pws@zsh.org>2015-06-24 10:21:12 +0100
commit39b28980f38e83e15cdeb19a489b5659af97fe93 (patch)
treee68f09fc59fc7008ff732704cbabed7e3df5f188 /Test/B02typeset.ztst
parent35573: turn off POSIX_BUILTINS in completion. (diff)
downloadzsh-39b28980f38e83e15cdeb19a489b5659af97fe93.tar
zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.tar.gz
zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.tar.bz2
zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.tar.lz
zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.tar.xz
zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.tar.zst
zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.zip
various posts: Implement assignment parsing for typeset.
Typeset assignments now work like raw assignments except for no "+=" and no GLOB_ASSIGN. Documented in typeset builtin doc and mentioned in release notes. Tests to ensure basic sanity. Enabled by default, can be turned off by "disable -r" with typeset family of commands.
Diffstat (limited to 'Test/B02typeset.ztst')
-rw-r--r--Test/B02typeset.ztst145
1 files changed, 144 insertions, 1 deletions
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index 57a7caa12..4afb18962 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -22,6 +22,8 @@
%prep
+ mkdir typeset.tmp && cd typeset.tmp
+
setopt noglob
scalar=scalar
@@ -231,7 +233,7 @@
typeset -T THIS will not work
1:Tied array syntax
-?(eval):typeset:1: -T requires names of scalar and array
+?(eval):typeset:1: too many arguments for -T
local array[2]=x
1:Illegal local array element assignment
@@ -508,3 +510,144 @@
>a2=(three four)
>typeset -r r1=yes
>typeset -r r2=no
+
+ one=hidden two=hidden three=hidden four=hidden five=hidden
+ fn() {
+ local bleugh="four=vier"
+ typeset -R10 one=eins two=(zwei dio) three $bleugh five=(cinq cinque)
+ three=drei
+ print -l $one $two $three $four $five
+ }
+ fn
+ print -l $one $two $three $four $five
+0:typeset reserved word interface: basic
+> eins
+>zwei
+>dio
+> drei
+> vier
+>cinq
+>cinque
+>hidden
+>hidden
+>hidden
+>hidden
+>hidden
+
+ (
+ setopt glob
+ mkdir -p arrayglob
+ touch arrayglob/{one,two,three,four,five,six,seven}
+ fn() {
+ typeset array=(arrayglob/[tf]*)
+ print -l ${array:t}
+ #
+ typeset {first,second,third}=the_same_value array=(
+ extends
+ over
+ multiple
+ lines
+ )
+ print -l $first $second $third "$array"
+ #
+ integer i=$(echo 1 + 2 + 3 + 4)
+ print $i
+ #
+ # only noted by accident this was broken..
+ # we need to turn off special recognition
+ # of assignments within assignments...
+ typeset careful=( i=1 j=2 k=3 )
+ print -l $careful
+ }
+ fn
+ )
+0:typeset reserved word, more complicated cases
+>five
+>four
+>three
+>two
+>the_same_value
+>the_same_value
+>the_same_value
+>extends over multiple lines
+>10
+>i=1
+>j=2
+>k=3
+
+ (
+ # reserved word is recognised at parsing.
+ # yes, this is documented.
+ # anyway, that means we need to
+ # re-eval the function...
+ fn='
+ fn() {
+ typeset foo=`echo one word=two`
+ print $foo
+ print $word
+ }
+ '
+ print reserved
+ eval $fn; fn
+ print builtin
+ disable -r typeset
+ eval $fn; fn
+ enable -r typeset
+ disable typeset
+ print reserved
+ eval $fn; fn
+ )
+0:reserved word and builtin interfaces
+>reserved
+>one word=two
+>
+>builtin
+>one
+>two
+>reserved
+>one word=two
+>
+
+ fn() {
+ emulate -L zsh
+ setopt typeset_silent
+ local k
+ typeset -A hash=(k1 v1 k2 v2)
+ typeset foo=word array=(more than one word)
+ for k in ${(ko)hash}; do
+ print $k $hash[$k]
+ done
+ print -l $foo $array
+ typeset -A hash
+ typeset foo array
+ for k in ${(ko)hash}; do
+ print $k $hash[$k]
+ done
+ print -l $foo $array
+ typeset hash=(k3 v3 k4 v4) array=(odd number here)
+ for k in ${(ko)hash}; do
+ print $k $hash[$k]
+ done
+ print -l $array
+ }
+ fn
+0:typeset preserves existing variable types
+>k1 v1
+>k2 v2
+>word
+>more
+>than
+>one
+>word
+>k1 v1
+>k2 v2
+>word
+>more
+>than
+>one
+>word
+>k3 v3
+>k4 v4
+>odd
+>number
+>here