From: zzapper <david@tvis.co.uk>
To: zsh-users@sunsite.dk
Subject: Re: zsh tips plea (tip of the day)
Date: Sun, 25 Jul 2004 11:41:17 +0100 [thread overview]
Message-ID: <ub37g0t0qv3blrc3cc6ips7dhtjur6ga74@4ax.com> (raw)
In-Reply-To: <lap5g0143nvvfkea4bai5bv9g173basclu@4ax.com>
Hi
Here's a script written to test zsh itself seems to contain some good examples of globbing
#!/usr/local/bin/zsh -f
setopt extendedglob badpattern
unsetopt kshglob
failed=0
while read res str pat; do
[[ $res = '#' ]] && continue
[[ $str = ${~pat} ]]
ts=$?
[[ $1 = -q ]] || print "$ts: [[ $str = $pat ]]"
if [[ ( $ts -gt 0 && $res = t) || ($ts -eq 0 && $res = f) ]]; then
print "Test failed: [[ $str = $pat ]]"
(( failed++ ))
fi
done <<EOT
#
t foo~ foo~
t foo~ (foo~)
t foo~ (foo~|)
t foo.c *.c~boo*
f foo.c *.c~boo*~foo*
# closures
t fofo (fo#)#
t ffo (fo#)#
t foooofo (fo#)#
t foooofof (fo#)#
t fooofoofofooo (fo#)#
f foooofof (fo##)#
f xfoooofof (fo#)#
f foooofofx (fo#)#
t ofxoofxo ((ofo#x)#o)#
f ofooofoofofooo (fo#)#
t foooxfooxfoxfooox (fo#x)#
f foooxfooxofoxfooox (fo#x)#
t foooxfooxfxfooox (fo#x)#
t ofxoofxo ((ofo#x)#o)#
t ofoooxoofxo ((ofo#x)#o)#
t ofoooxoofxoofoooxoofxo ((ofo#x)#o)#
t ofoooxoofxoofoooxoofxoo ((ofo#x)#o)#
f ofoooxoofxoofoooxoofxofo ((ofo#x)#o)#
t ofoooxoofxoofoooxoofxooofxofxo ((ofo#x)#o)#
t aac ((a))#a(c)
t ac ((a))#a(c)
f c ((a))#a(c)
t aaac ((a))#a(c)
f baaac ((a))#a(c)
t abcd ?(a|b)c#d
t abcd (ab|ab#)c#d
t acd (ab|ab#)c#d
t abbcd (ab|ab#)c#d
t effgz (bc##d|ef#g?|(h|)i(j|k))
t efgz (bc##d|ef#g?|(h|)i(j|k))
t egz (bc##d|ef#g?|(h|)i(j|k))
t egzefffgzbcdij (bc##d|ef#g?|(h|)i(j|k))#
f egz (bc##d|ef##g?|(h|)i(j|k))
t ofoofo (ofo##)#
t oxfoxoxfox (oxf(ox)##)#
f oxfoxfox (oxf(ox)##)#
t ofoofo (ofo##|f)#
# The following is supposed to match only as fo+ofo+ofo
t foofoofo (foo|f|fo)(f|ofo##)#
t oofooofo (of|oofo##)#
t fffooofoooooffoofffooofff (f#o#)#
# If the following is really slow, that's a bug.
f fffooofoooooffoofffooofffx (f#o#)#
# The following tests backtracking in alternation matches
t fofoofoofofoo (fo|foo)#
# Exclusion: test both types
t foo ((^x))
t foo ((^x)*)
f foo ((^foo))
t foo ((^foo)*)
t foobar ((^foo))
t foobar ((^foo)*)
f foot z*~*x
t zoot z*~*x
f foox z*~*x
f zoox z*~*x
t moo.cow (*~*.*).(*~*.*)
f mad.moo.cow (*~*.*).(*~*.*)
t moo.cow (^*.*).(^*.*)
f sane.moo.cow (^*.*).(^*.*)
f mucca.pazza mu(^c#)?.pa(^z#)?
f _foo~ _(|*[^~])
t fff ((^f))
t fff ((^f)#)
t fff ((^f)##)
t ooo ((^f))
t ooo ((^f)#)
t ooo ((^f)##)
t foo ((^f))
t foo ((^f)#)
t foo ((^f)##)
f f ((^f))
f f ((^f)#)
f f ((^f)##)
t foot (^z*|*x)
f zoot (^z*|*x)
t foox (^z*|*x)
t zoox (^z*|*x)
t foo (^foo)#
f foob (^foo)b*
t foobb (^foo)b*
f foob (*~foo)b*
t foobb (*~foo)b*
f zsh ^z*
t a%1X [[:alpha:][:punct:]]#[[:digit:]][^[:lower:]]
f a%1 [[:alpha:][:punct:]]#[[:digit:]][^[:lower:]]
t [: [[:]#
t :] []:]#
t :] [:]]#
t [ [[]
t ] []]
t [] [^]]]
# Case insensitive matching
t fooxx (#i)FOOXX
f fooxx (#l)FOOXX
t FOOXX (#l)fooxx
f fooxx (#i)FOO(#I)X(#i)X
t fooXx (#i)FOO(#I)X(#i)X
t fooxx ((#i)FOOX)x
f fooxx ((#i)FOOX)X
f BAR (bar|(#i)foo)
t FOO (bar|(#i)foo)
t Modules (#i)*m*
t fooGRUD (#i)(bar|(#I)foo|(#i)rod)grud
f FOOGRUD (#i)(bar|(#I)foo|(#i)rod)grud
t readme (#i)readme~README|readme
# the readme doesn't get excluded the second time...
t readme (#i)readme~README|readme~README
# Ranges with backtracking
t 633 <1-1000>33
t 633 <-1000>33
t 633 <1->33
t 633 <->33
# Approximate matching
t READ.ME (#ia1)readme
f READ..ME (#ia1)readme
t README (#ia1)readm
t READM (#ia1)readme
t README (#ia1)eadme
t EADME (#ia1)readme
t READEM (#ia1)readme
f ADME (#ia1)readme
f README (#ia1)read
t bob (#a1)[b][b]
f bob (#a1)[b][b]a
t bob (#a1)[b]o[b]a
f bob (#a1)[c]o[b]
t abcd (#a2)XbcX
t abcd (#a2)ad
t ad (#a2)abcd
t abcd (#a2)bd
t bd (#a2)abcd
t badc (#a2)abcd
# This next one is a little tricky: a[d]bc[] = a[]bc[d]
t adbc (#a2)abcd
f dcba (#a2)abcd
# the next one is [d][cb][a] = [a][bc][d] with a transposition
t dcba (#a3)abcd
t aabaXaaabY (#a1)(a#b)#Y
t aabaXaaabY (#a1)(a#b)(a#b)Y
t aaXaaaaabY (#a1)(a#b)(a#b)Y
t aaaXaaabY (#a1)(a##b)##Y
t aaaXbaabY (#a1)(a##b)##Y
f read.me (#ia1)README~READ.ME
t read.me (#ia1)README~READ_ME
f read.me (#ia1)README~(#a1)READ_ME
t test *((#s)|/)test((#e)|/)*
t test/path *((#s)|/)test((#e)|/)*
t path/test *((#s)|/)test((#e)|/)*
t path/test/ohyes *((#s)|/)test((#e)|/)*
f atest *((#s)|/)test((#e)|/)*
f testy *((#s)|/)test((#e)|/)*
f testy/path *((#s)|/)test((#e)|/)*
f path/atest *((#s)|/)test((#e)|/)*
f atest/path *((#s)|/)test((#e)|/)*
f path/testy *((#s)|/)test((#e)|/)*
f path/testy/ohyes *((#s)|/)test((#e)|/)*
f path/atest/ohyes *((#s)|/)test((#e)|/)*
EOT
print "$failed tests failed."
zzapper (vim, cygwin, wiki & zsh)
--
vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?"
http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
next prev parent reply other threads:[~2004-07-25 10:44 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-23 11:12 zzapper
2004-07-23 11:24 ` Peter Stephenson
2004-07-23 11:39 ` Joakim Ryden
2004-07-23 22:55 ` Aaron Davies
2004-07-24 7:22 ` Vincent Lefevre
2004-07-24 8:00 ` Atom 'Smasher'
2004-07-24 8:10 ` Vincent Lefevre
2004-07-24 8:32 ` Atom 'Smasher'
2004-07-24 11:23 ` Vincent Lefevre
2004-07-24 12:42 ` Geoff Wing
2004-07-25 0:46 ` Vincent Lefevre
2004-07-25 4:54 ` xargs (Re: zsh tips plea (tip of the day)) Bart Schaefer
2004-07-24 17:47 ` zsh tips plea (tip of the day) Atom 'Smasher'
2004-07-24 15:52 ` Aaron Davies
2004-07-23 12:49 ` Björn Lindström
2004-07-28 15:18 ` Felix Rosencrantz
2004-07-28 16:17 ` DervishD
2004-07-28 18:03 ` Björn Lindström
2004-07-23 16:55 ` Atom 'Smasher'
2004-07-23 20:04 ` Vincent Lefevre
2004-07-23 20:23 ` Philippe Troin
2004-07-23 20:26 ` Vincent Lefevre
2004-07-23 21:37 ` Philippe Troin
2004-07-23 21:50 ` Vincent Lefevre
2004-07-23 22:02 ` Dan Nelson
2004-07-24 7:14 ` Vincent Lefevre
2004-07-28 12:08 ` Vincent Lefevre
2004-07-24 16:42 ` zzapper
2004-07-24 18:44 ` Bart Schaefer
2004-07-24 22:45 ` zzapper
2004-07-25 10:41 ` zzapper [this message]
2004-07-25 10:53 ` zzapper
2004-07-26 14:13 ` Peter Stephenson
2004-07-26 17:01 ` Bart Schaefer
2004-07-29 15:24 ` zzapper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ub37g0t0qv3blrc3cc6ips7dhtjur6ga74@4ax.com \
--to=david@tvis.co.uk \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).