1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-08 00:06:04 +02:00

Test additions; 3.1.7-pre-1

This commit is contained in:
Peter Stephenson 2000-04-19 19:03:09 +00:00
parent e1a22eb2f9
commit 155df70ca8
6 changed files with 536 additions and 4 deletions

View File

@ -1,3 +1,10 @@
2000-04-19 Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
* Config/version.mk: 3.1.7-pre-1
* Test/.distfiles, Test/12procsubst.ztst, Test/13parameter.ztst,
Test/ztst.zsh: new tests; use null glob clearing up.
2000-04-19 Peter Stephenson <pws@cambridgesiliconradio.com>
* Ollivier Robert: 10844: prefer curses to termcap on HPUX 11

View File

@ -27,5 +27,5 @@
# This must also serve as a shell script, so do not add spaces around the
# `=' signs.
VERSION=3.1.6-dev-22
VERSION_DATE='April 9, 2000'
VERSION=3.1.7-pre-1
VERSION_DATE='April 19, 2000'

View File

@ -1,3 +1,9 @@
DISTFILES_SRC='
Makefile.in cd.ztst ztst.zsh
.cvsignore .distfiles Makefile.in
ztst.zsh comptest
01grammar.ztst 02alias.ztst 03quoting.ztst 04redirect.ztst
05command.ztst 06arith.ztst 07cond.ztst 08traps.ztst 09funcdef.ztst
10prompt.ztst 11glob.ztst 12procsubst.ztst 13parameter.ztst
50cd.ztst 51xtrace.ztst 52zregexparse.ztst
53completion.ztst
'

25
Test/12procsubst.ztst Normal file
View File

@ -0,0 +1,25 @@
# Tests for process substitution: <(...), >(...) and =(...).
%prep
mkdir procsubst.tmp
cd procsubst.tmp
print 'First\tSecond\tThird\tFourth' >FILE1
print 'Erste\tZweite\tDritte\tVierte' >FILE2
%test
paste <(cut -f1 FILE1) <(cut -f3 FILE2)
0:<(...) substitution
>First Dritte
paste <(cut -f2 FILE1) <(cut -f4 FILE2) > >(sed 's/e/E/g' >OUTFILE)
sleep 1 # since the sed is asynchronous
cat OUTFILE
0:>(...) substitution
>SEcond ViErtE
diff =(cat FILE1) =(cat FILE2)
1:=(...) substituion
>1c1
>< First Second Third Fourth
>---
>> Erste Zweite Dritte Vierte

493
Test/13parameter.ztst Normal file
View File

@ -0,0 +1,493 @@
# Test parameter expansion. Phew.
%prep
mkdir parameter.tmp
cd parameter.tmp
touch boringfile evenmoreboringfile
%test
foo='the first parameter'
bar='the second parameter'
print -l $foo ${bar}
0:Basic scalar parameter substitution
>the first parameter
>the second parameter
array1=(the first array)
array2=(the second array)
print -l $array1 ${array2}
0:Basic array parameter substitution
>the
>first
>array
>the
>second
>array
setopt ksharrays
print -l $array1 ${array2}
unsetopt ksharrays
0:Basic ksharray substitution
>the
>the
setopt shwordsplit
print -l $foo ${bar}
unsetopt shwordsplit
0:Basic shwordsplit option handling
>the
>first
>parameter
>the
>second
>parameter
print $+foo ${+foo} $+notappearinginthistest ${+notappearinginthistest}
0:$+...
>1 1 0 0
set1=set1v
null1=
print ${set1:-set1d} ${set1-set2d} ${null1:-null1d} ${null1-null2d} x
print ${unset1:-unset1d} ${unset1-unset2d} x
0:${...:-...} and ${...-...}
>set1v set1v null1d x
>unset1d unset2d x
set2=irrelevant
print ${set1:=set1d} ${set2::=set2d}
print $set2
wasnull1=
wasnull2=
print ${wasnull1=wasnull1d} ${wasnull2:=wasnull2d}
print $wasnull1 $wasnull2
0:${...:=...}, ${...::=...}, ${...=...}
>set1v set2d
>set2d
>wasnull2d
>wasnull2d
(print ${set1:?okhere}; print ${unset1:?exiting1}; print not reached;)
(print ${null1?okhere}; print ${null1:?exiting2}; print not reached;)
1:${...:?...}, ${...?...}
>set1v
>
?ZTST_execchunk:2: unset1: exiting1
?ZTST_execchunk:2: null1: exiting2
print ${set1:+word1} ${set1+word2} ${null1:+word3} ${null1+word4}
print ${unset1:+word5} ${unset1+word6}
0:${...:+...}, ${...+...}
>word1 word2 word4
>
str1='This is very boring indeed.'
print ${str1#*s}
print ${str1##*s}
print $str1##s
0:${...#...}, ${...##...}
> is very boring indeed.
> very boring indeed.
>This is very boring indeed.##s
str2='If you'\''re reading this you should go and fix some bugs instead.'
print ${str2%d*}
print ${str2%%d*}
0:${...%...}, ${...%%...}
>If you're reading this you should go and fix some bugs instea
>If you're rea
str1='does match'
str2='does not match'
print ${str1:#does * match}
print ${str2:#does * match}
0:${...:#...}
>does match
>
array1=(arthur boldly claws dogs every fight)
print ${array1:#[aeiou]*}
print ${(M)array1:#[aeiou]*}
0:${...:#...}, ${(M)...:#...} with array
>boldly claws dogs fight
>arthur every
str1="$array1"
print ${str1/[aeiou]*g/a braw bricht moonlicht nicht the nic}
print ${(S)str1/[aeiou]*g/relishe}
0:scalar ${.../.../...}, ${(S).../.../...}
>a braw bricht moonlicht nicht the nicht
>relishes every fight
print ${array1/[aeiou]*/Y}
print ${(S)array1/[aeiou]*/Y}
0:array ${.../.../...}, ${(S).../.../...}
>Y bY clY dY Y fY
>Yrthur bYldly clYws dYgs Yvery fYght
str1='o this is so, so so very dull'
print ${str1//o*/Please no}
print ${(S)str1//o*/Please no}
0:scalar ${...//.../...}, ${(S)...//.../...}
>Please no
>Please no this is sPlease no, sPlease no sPlease no very dull
print ${array1//[aeiou]*/Y}
print ${(S)array1//[aeiou]*/Y}
0:array ${...//.../...}, ${(S)...//.../...}
>Y bY clY dY Y fY
>YrthYr bYldly clYws dYgs YvYry fYght
print ${array1:/[aeiou]*/expletive deleted}
0:array ${...:/...}
>expletive deleted boldly claws dogs expletive deleted fight
str1='twocubed'
array=(the number of protons in an oxygen nucleus)
print $#str1 ${#str1} "$#str1 ${#str1}" $#array ${#array} "$#array ${#array}"
0:${#...}, $#...
>8 8 8 8 8 8 8 8
array=(once bitten twice shy)
print IF${array}THEN
print IF${^array}THEN
0:basic ${^...}
>IFonce bitten twice shyTHEN
>IFonceTHEN IFbittenTHEN IFtwiceTHEN IFshyTHEN
# WHY DO I NEED TO QUOTE ${array} HERE?????
print IF{"${array}",THEN}ELSE
print IF{${^array},THEN}ELSE
0:combined ${^...} and {...,...}
>IFonce bitten twice shyELSE IFTHENELSE
>IFonceELSE IFTHENELSE IFbittenELSE IFTHENELSE IFtwiceELSE IFTHENELSE IFshyELSE IFTHENELSE
str1='one word'
print -l $str1 ${=str1} "split ${=str1}wise"
0:${=...}
>one word
>one
>word
>split one
>wordwise
str1='*'
print $str1 ${~str1} $~str1
setopt globsubst
print $str1
unsetopt globsubst
0:${~...} and globsubst
>* boringfile evenmoreboringfile boringfile evenmoreboringfile
>boringfile evenmoreboringfile
print -l "${$(print one word)}" "${=$(print two words)}"
0:splitting of $(...) inside ${...}
>one word
>two
>words
print -l "${(f)$(print first line\\nsecond line\\nthird line)}"
0:${(f)$(...)}
>first line
>second line
>third line
print -l ${(A)newarray=splitting by numbers}
print -l ${(A)=newarray::=splitting by spaces, actually}
0:${(A)...=...}, ${(A)...::=...}
>splitting by numbers
>splitting
>by
>spaces,
>actually
newarray=("split me" "split me" "I\'m yours")
print -l "${(@)newarray}"
0:"${(@)...}"
>split me
>split me
>I'm yours
foo='$(print Howzat)'
print ${(e)foo}
0:${(e)...}
>Howzat
foo='I'\''m nearly out of my mind with tedium'
bar=foo
print ${(P)bar}
0:${(P)...}
>I'm nearly out of my mind with tedium
# it doesn't *say* these are case-insensitive without i...
# I think this is a bug.
foo=(I could be watching that programme I recorded)
print ${(o)foo}
print ${(oi)foo}
print ${(O)foo}
print ${(Oi)foo}
0:${(o)...}, ${(O)...}
>be could I I programme recorded that watching
>be could I I programme recorded that watching
>watching that recorded programme I I could be
>watching that recorded programme I I could be
foo=(yOU KNOW, THE ONE WITH wILLIAM dALRYMPLE)
bar=(doing that tour of India.)
print ${(L)foo}
print ${(U)bar}
0:${(L)...}, ${(U)...}
>you know, the one with william dalrymple
>DOING THAT TOUR OF INDIA.
foo='instead here I am stuck by the computer'
print ${(C)foo}
0:${(C)...}
>Instead Here I Am Stuck By The Computer
foo=$'\x7f\x00'
print ${(V)foo}
0:${(V)...}
>^?^@
foo='playing '\''stupid'\'' "games" \w\i\t\h $quoting.'
print -r ${(q)foo}
print -r ${(qq)foo}
print -r ${(qqq)foo}
print -r ${(qqqq)foo}
0:${(q...)...}
>playing\ \'stupid\'\ \"games\"\ \\w\\i\\t\\h\ \$quoting.
>'playing '\''stupid'\'' "games" \w\i\t\h $quoting.'
>"playing 'stupid' \"games\" \\w\\i\\t\\h \$quoting."
>$'playing \'stupid\' "games" \\w\\i\\t\\h $quoting.'
foo="'and now' \"even the pubs\" \\a\\r\\e shut."
print -r ${(Q)foo}
0:${(Q)...}
>and now even the pubs are shut.
psvar=(dog)
setopt promptsubst
foo='It shouldn'\''t $(happen) to a %1v.'
bar='But `echo what can you do\?`'
print -r ${(%)foo}
print -r ${(%%)bar}
0:${(%)...}
>It shouldn't $(happen) to a dog.
>But what can you do?
foo='unmatched "'
print ${(QX)foo}
1:${(QX)...}
?ZTST_execchunk:2: unmatched "
array=(characters in an array)
print ${(c)#array}
0:${(c)#...}
>22
print ${(w)#array}
str='colon::bolon::solon'
print ${(ws.:.)#str}
print ${(Ws.:.)#str}
0:${(w)...}, ${(W)...}
>4
>3
>5
typeset -A assoc
assoc=(key1 val1 key2 val2)
print ${(o)assoc}
print ${(ok)assoc}
print ${(ov)assoc}
print ${(okv)assoc}
0:${(k)...}, ${(v)...}
>val1 val2
>key1 key2
>val1 val2
>key1 key2 val1 val2
foo=(resulting words uproariously padded)
print ${(pl.10..\x22..X.)foo}
0:${(pl...)...}
>Xresulting """"Xwords roariously """Xpadded
foo=(why in goodness name am I doing this)
print ${(r.5..!..?.)foo}
0:${(r...)...}
>why?! in?!! goodn name? am?!! I?!!! doing this?
array=(I\'m simply putting a brave face on)
print ${(j:--:)array}
0:${(j)...}
>I'm--simply--putting--a--brave--face--on
print ${(F)array}
0:${(F)...}
>I'm
>simply
>putting
>a
>brave
>face
>on
string='zometimez zis getz zplit on a z'
print -l ${(s?z?)string}
0:${(s...)...}
>ometime
>
>is get
>
>plit on a
str=s
arr=(a)
typeset -A ass
ass=(a a)
integer i
float f
print ${(t)str} ${(t)arr} ${(t)ass} ${(t)i} ${(t)f}
0:${(t)...}
>scalar array association-local integer-local float-local
# it's not quite clear that these are actually right unless you know
# the algorithm: search along the string for the point at which the
# first (last) match occurs, for ## (%%), then take the shortest possible
# version of that for # (%). it's as good a definition as anything.
string='where is the white windmill, whispered walter wisely'
print ${(S)string#h*e}
print ${(S)string##h*e}
print ${(S)string%h*e}
print ${(S)string%%h*e}
0:${(S)...#...} etc.
>wre is the white windmill, whispered walter wisely
>wly
>where is the white windmill, wred walter wisely
>where is the white windmill, wly
setopt extendedglob
print ${(SI:1:)string##w[^[:space:]]# }
print ${(SI:1+1:)string##w[^[:space:]]# }
print ${(SI:1+1+1:)string##w[^[:space:]]# }
print ${(SI:1+1+1+1:)string##w[^[:space:]]# }
0:${(I:...:)...}
>is the white windmill, whispered walter wisely
>where is the windmill, whispered walter wisely
>where is the white whispered walter wisely
>where is the white windmill, walter wisely
print ${(MSI:1:)string##w[^[:space:]]# }
0:${(M...)...}
>where
print ${(R)string//w[a-z]# #}
0:${(R)...}
>is the ,
# This (1) doesn't work with // or /
# (2) perhaps ought to be 18, to be consistent with normal zsh
# substring indexing and with backreferences.
print ${(BES)string##white}
0:${(BE...)...}
>14 19
print ${(NS)string##white}
0:${(N)...}
>5
string='abcdefghijklmnopqrstuvwxyz'
print ${${string%[aeiou]*}/(#m)?(#e)/${(U)MATCH}}
0:Rule 1: Nested substitutions
>abcdefghijklmnopqrsT
array=(et Swann avec cette muflerie intermittente)
string="qui reparaissait chez lui"
print ${array[4,5]}
print ${array[4,5][1]}
print ${array[4,5][1][2,3]}
print ${string[4,5]}
print ${string[4,5][1]}
0:Rule 2: Parameter subscripting
>cette muflerie
>cette
>et
> r
>
foo=stringalongamax
print ${${(P)foo[1,6]}[1,3]}
0:Rule 3: Parameter Name Replacement
>qui
print "${array[5,6]}"
print "${(j.:.)array[1,2]}"
0:Rule 4: Double-Quoted Joining
>muflerie intermittente
>et:Swann
print "${${array}[5,7]}"
print "${${(@)array}[1,2]}"
0:Rule 5: Nested Subscripting
>wan
>et Swann
print "${${(@)array}[1,2]#?}"
print "${(@)${(@)array}[1,2]#?}"
0:Rule 6: Modifiers
>t Swann
>t wann
array=(she sells z shells by the z shore)
(IFS='+'; print ${(s.s.)array})
0:Rule 7: Forced Joining, and 8: Forced splitting
>he+ ell +z+ hell +by+the+z+ hore
setopt shwordsplit
string='another poxy boring string'
print -l ${${string}/o/ }
unsetopt shwordsplit
0:Rule 9: Shell Word Splitting
>an
>ther
>p
>xy
>b
>ring
>string
setopt nonomatch
foo='b* e*'
print ${(e)~foo}
print ${(e)~=foo}
0:Rule 10: Re-Evaluation
>b* e*
>boringfile evenmoreboringfile
# ${bar} -> $bar turns this into $$, which doesn't strike me as correct.
bar=confinement
print ${(el.20..X.)${bar}}
0:Rule 11: Padding
>XXXXXXXXXconfinement
foo=(bar baz)
bar=(ax1 bx1)
print "${(@)${foo}[1]}"
print "${${(@)foo}[1]}"
print -l ${(s/x/)bar}
print -l ${(j/x/s/x/)bar}
print -l ${(s/x/)bar%%1*}
0:Examples in manual on parameter expansion
>b
>bar
>a
>1 b
>1
>a
>1
>b
>1
>a
> b

View File

@ -71,7 +71,8 @@ ZTST_terr=${TMPPREFIX}.ztst.terr.$$
ZTST_cleanup() {
cd $ZTST_testdir
rm -rf $ZTST_testdir/dummy.tmp $ZTST_testdir/*.tmp ${TMPPREFIX}.ztst*$$
rm -rf $ZTST_testdir/dummy.tmp $ZTST_testdir/*.tmp(N) \
${TMPPREFIX}.ztst*$$(N)
}
# This cleanup always gets performed, even if we abort. Later,