1#!/usr/local/bin/zsh -f 2 3setopt kshglob extendedglob 4 5failed=0 6while read res str pat; do 7 [[ $res = '#' ]] && continue 8 [[ $str = ${~pat} ]] 9 ts=$? 10 [[ $1 = -q ]] || print "$ts: [[ $str = $pat ]]" 11 if [[ ( $ts -gt 0 && $res = t) || ($ts -eq 0 && $res = f) ]]; then 12 print "Test failed: [[ $str = $pat ]]" 13 (( failed++ )) 14 fi 15done <<EOT 16t fofo *(f*(o)) 17t ffo *(f*(o)) 18t foooofo *(f*(o)) 19t foooofof *(f*(o)) 20t fooofoofofooo *(f*(o)) 21f foooofof *(f+(o)) 22f xfoooofof *(f*(o)) 23f foooofofx *(f*(o)) 24t ofxoofxo *(*(of*(o)x)o) 25f ofooofoofofooo *(f*(o)) 26t foooxfooxfoxfooox *(f*(o)x) 27f foooxfooxofoxfooox *(f*(o)x) 28t foooxfooxfxfooox *(f*(o)x) 29t ofxoofxo *(*(of*(o)x)o) 30t ofoooxoofxo *(*(of*(o)x)o) 31t ofoooxoofxoofoooxoofxo *(*(of*(o)x)o) 32t ofoooxoofxoofoooxoofxoo *(*(of*(o)x)o) 33f ofoooxoofxoofoooxoofxofo *(*(of*(o)x)o) 34t ofoooxoofxoofoooxoofxooofxofxo *(*(of*(o)x)o) 35t aac *(@(a))a@(c) 36t ac *(@(a))a@(c) 37f c *(@(a))a@(c) 38t aaac *(@(a))a@(c) 39f baaac *(@(a))a@(c) 40t abcd ?@(a|b)*@(c)d 41t abcd @(ab|a*@(b))*(c)d 42t acd @(ab|a*(b))*(c)d 43t abbcd @(ab|a*(b))*(c)d 44t effgz @(b+(c)d|e*(f)g?|?(h)i@(j|k)) 45t efgz @(b+(c)d|e*(f)g?|?(h)i@(j|k)) 46t egz @(b+(c)d|e*(f)g?|?(h)i@(j|k)) 47t egzefffgzbcdij *(b+(c)d|e*(f)g?|?(h)i@(j|k)) 48f egz @(b+(c)d|e+(f)g?|?(h)i@(j|k)) 49t ofoofo *(of+(o)) 50t oxfoxoxfox *(oxf+(ox)) 51f oxfoxfox *(oxf+(ox)) 52t ofoofo *(of+(o)|f) 53# The following is supposed to match only as fo+ofo+ofo 54t foofoofo @(foo|f|fo)*(f|of+(o)) 55t oofooofo *(of|oof+(o)) 56t fffooofoooooffoofffooofff *(*(f)*(o)) 57# If the following is really slow, that's a bug. 58f fffooofoooooffoofffooofffx *(*(f)*(o)) 59# The following tests backtracking in alternation matches 60t fofoofoofofoo *(fo|foo) 61# Exclusion 62t foo !(x) 63t foo !(x)* 64f foo !(foo) 65t foo !(foo)* 66t foobar !(foo) 67t foobar !(foo)* 68t moo.cow !(*.*).!(*.*) 69f mad.moo.cow !(*.*).!(*.*) 70f mucca.pazza mu!(*(c))?.pa!(*(z))? 71f _foo~ _?(*[^~]) 72t fff !(f) 73t fff *(!(f)) 74t fff +(!(f)) 75t ooo !(f) 76t ooo *(!(f)) 77t ooo +(!(f)) 78t foo !(f) 79t foo *(!(f)) 80t foo +(!(f)) 81f f !(f) 82f f *(!(f)) 83f f +(!(f)) 84t foot @(!(z*)|*x) 85f zoot @(!(z*)|*x) 86t foox @(!(z*)|*x) 87t zoox @(!(z*)|*x) 88t foo *(!(foo)) 89f foob !(foo)b* 90t foobb !(foo)b* 91t fooxx (#i)FOOXX 92f fooxx (#l)FOOXX 93t FOOXX (#l)fooxx 94f fooxx (#i)FOO@(#I)X@(#i)X 95t fooXx (#i)FOO@(#I)X@(#i)X 96t fooxx @((#i)FOOX)x 97f fooxx @((#i)FOOX)X 98f BAR @(bar|(#i)foo) 99t FOO @(bar|(#i)foo) 100t Modules (#i)*m* 101EOT 102print "$failed tests failed." 103