t / t3070-wildmatch.shon commit t0001: use test_config_global (2a47241)
   1#!/bin/sh
   2
   3test_description='wildmatch tests'
   4
   5. ./test-lib.sh
   6
   7match() {
   8    if [ $1 = 1 ]; then
   9        test_expect_success "wildmatch:     match '$3' '$4'" "
  10            test-wildmatch wildmatch '$3' '$4'
  11        "
  12    else
  13        test_expect_success "wildmatch:  no match '$3' '$4'" "
  14            ! test-wildmatch wildmatch '$3' '$4'
  15        "
  16    fi
  17    if [ $2 = 1 ]; then
  18        test_expect_success "fnmatch:       match '$3' '$4'" "
  19            test-wildmatch fnmatch '$3' '$4'
  20        "
  21    elif [ $2 = 0 ]; then
  22        test_expect_success "fnmatch:    no match '$3' '$4'" "
  23            ! test-wildmatch fnmatch '$3' '$4'
  24        "
  25#    else
  26#       test_expect_success BROKEN_FNMATCH "fnmatch:       '$3' '$4'" "
  27#           ! test-wildmatch fnmatch '$3' '$4'
  28#       "
  29    fi
  30}
  31
  32imatch() {
  33    if [ $1 = 1 ]; then
  34        test_expect_success "iwildmatch:    match '$2' '$3'" "
  35            test-wildmatch iwildmatch '$2' '$3'
  36        "
  37    else
  38        test_expect_success "iwildmatch: no match '$2' '$3'" "
  39            ! test-wildmatch iwildmatch '$2' '$3'
  40        "
  41    fi
  42}
  43
  44pathmatch() {
  45    if [ $1 = 1 ]; then
  46        test_expect_success "pathmatch:     match '$2' '$3'" "
  47            test-wildmatch pathmatch '$2' '$3'
  48        "
  49    else
  50        test_expect_success "pathmatch:  no match '$2' '$3'" "
  51            ! test-wildmatch pathmatch '$2' '$3'
  52        "
  53    fi
  54}
  55
  56# Basic wildmat features
  57match 1 1 foo foo
  58match 0 0 foo bar
  59match 1 1 '' ""
  60match 1 1 foo '???'
  61match 0 0 foo '??'
  62match 1 1 foo '*'
  63match 1 1 foo 'f*'
  64match 0 0 foo '*f'
  65match 1 1 foo '*foo*'
  66match 1 1 foobar '*ob*a*r*'
  67match 1 1 aaaaaaabababab '*ab'
  68match 1 1 'foo*' 'foo\*'
  69match 0 0 foobar 'foo\*bar'
  70match 1 1 'f\oo' 'f\\oo'
  71match 1 1 ball '*[al]?'
  72match 0 0 ten '[ten]'
  73match 0 1 ten '**[!te]'
  74match 0 0 ten '**[!ten]'
  75match 1 1 ten 't[a-g]n'
  76match 0 0 ten 't[!a-g]n'
  77match 1 1 ton 't[!a-g]n'
  78match 1 1 ton 't[^a-g]n'
  79match 1 x 'a]b' 'a[]]b'
  80match 1 x a-b 'a[]-]b'
  81match 1 x 'a]b' 'a[]-]b'
  82match 0 x aab 'a[]-]b'
  83match 1 x aab 'a[]a-]b'
  84match 1 1 ']' ']'
  85
  86# Extended slash-matching features
  87match 0 0 'foo/baz/bar' 'foo*bar'
  88match 0 0 'foo/baz/bar' 'foo**bar'
  89match 0 1 'foobazbar' 'foo**bar'
  90match 1 1 'foo/baz/bar' 'foo/**/bar'
  91match 1 0 'foo/baz/bar' 'foo/**/**/bar'
  92match 1 0 'foo/b/a/z/bar' 'foo/**/bar'
  93match 1 0 'foo/b/a/z/bar' 'foo/**/**/bar'
  94match 1 0 'foo/bar' 'foo/**/bar'
  95match 1 0 'foo/bar' 'foo/**/**/bar'
  96match 0 0 'foo/bar' 'foo?bar'
  97match 0 0 'foo/bar' 'foo[/]bar'
  98match 0 0 'foo/bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
  99match 1 1 'foo-bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
 100match 1 0 'foo' '**/foo'
 101match 1 x 'XXX/foo' '**/foo'
 102match 1 0 'bar/baz/foo' '**/foo'
 103match 0 0 'bar/baz/foo' '*/foo'
 104match 0 0 'foo/bar/baz' '**/bar*'
 105match 1 0 'deep/foo/bar/baz' '**/bar/*'
 106match 0 0 'deep/foo/bar/baz/' '**/bar/*'
 107match 1 0 'deep/foo/bar/baz/' '**/bar/**'
 108match 0 0 'deep/foo/bar' '**/bar/*'
 109match 1 0 'deep/foo/bar/' '**/bar/**'
 110match 0 0 'foo/bar/baz' '**/bar**'
 111match 1 0 'foo/bar/baz/x' '*/bar/**'
 112match 0 0 'deep/foo/bar/baz/x' '*/bar/**'
 113match 1 0 'deep/foo/bar/baz/x' '**/bar/*/*'
 114
 115# Various additional tests
 116match 0 0 'acrt' 'a[c-c]st'
 117match 1 1 'acrt' 'a[c-c]rt'
 118match 0 0 ']' '[!]-]'
 119match 1 x 'a' '[!]-]'
 120match 0 0 '' '\'
 121match 0 x '\' '\'
 122match 0 x 'XXX/\' '*/\'
 123match 1 x 'XXX/\' '*/\\'
 124match 1 1 'foo' 'foo'
 125match 1 1 '@foo' '@foo'
 126match 0 0 'foo' '@foo'
 127match 1 1 '[ab]' '\[ab]'
 128match 1 1 '[ab]' '[[]ab]'
 129match 1 x '[ab]' '[[:]ab]'
 130match 0 x '[ab]' '[[::]ab]'
 131match 1 x '[ab]' '[[:digit]ab]'
 132match 1 x '[ab]' '[\[:]ab]'
 133match 1 1 '?a?b' '\??\?b'
 134match 1 1 'abc' '\a\b\c'
 135match 0 0 'foo' ''
 136match 1 0 'foo/bar/baz/to' '**/t[o]'
 137
 138# Character class tests
 139match 1 x 'a1B' '[[:alpha:]][[:digit:]][[:upper:]]'
 140match 0 x 'a' '[[:digit:][:upper:][:space:]]'
 141match 1 x 'A' '[[:digit:][:upper:][:space:]]'
 142match 1 x '1' '[[:digit:][:upper:][:space:]]'
 143match 0 x '1' '[[:digit:][:upper:][:spaci:]]'
 144match 1 x ' ' '[[:digit:][:upper:][:space:]]'
 145match 0 x '.' '[[:digit:][:upper:][:space:]]'
 146match 1 x '.' '[[:digit:][:punct:][:space:]]'
 147match 1 x '5' '[[:xdigit:]]'
 148match 1 x 'f' '[[:xdigit:]]'
 149match 1 x 'D' '[[:xdigit:]]'
 150match 1 x '_' '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'
 151match 1 x '_' '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'
 152match 1 x '.' '[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'
 153match 1 x '5' '[a-c[:digit:]x-z]'
 154match 1 x 'b' '[a-c[:digit:]x-z]'
 155match 1 x 'y' '[a-c[:digit:]x-z]'
 156match 0 x 'q' '[a-c[:digit:]x-z]'
 157
 158# Additional tests, including some malformed wildmats
 159match 1 x ']' '[\\-^]'
 160match 0 0 '[' '[\\-^]'
 161match 1 x '-' '[\-_]'
 162match 1 x ']' '[\]]'
 163match 0 0 '\]' '[\]]'
 164match 0 0 '\' '[\]]'
 165match 0 0 'ab' 'a[]b'
 166match 0 x 'a[]b' 'a[]b'
 167match 0 x 'ab[' 'ab['
 168match 0 0 'ab' '[!'
 169match 0 0 'ab' '[-'
 170match 1 1 '-' '[-]'
 171match 0 0 '-' '[a-'
 172match 0 0 '-' '[!a-'
 173match 1 x '-' '[--A]'
 174match 1 x '5' '[--A]'
 175match 1 1 ' ' '[ --]'
 176match 1 1 '$' '[ --]'
 177match 1 1 '-' '[ --]'
 178match 0 0 '0' '[ --]'
 179match 1 x '-' '[---]'
 180match 1 x '-' '[------]'
 181match 0 0 'j' '[a-e-n]'
 182match 1 x '-' '[a-e-n]'
 183match 1 x 'a' '[!------]'
 184match 0 0 '[' '[]-a]'
 185match 1 x '^' '[]-a]'
 186match 0 0 '^' '[!]-a]'
 187match 1 x '[' '[!]-a]'
 188match 1 1 '^' '[a^bc]'
 189match 1 x '-b]' '[a-]b]'
 190match 0 0 '\' '[\]'
 191match 1 1 '\' '[\\]'
 192match 0 0 '\' '[!\\]'
 193match 1 1 'G' '[A-\\]'
 194match 0 0 'aaabbb' 'b*a'
 195match 0 0 'aabcaa' '*ba*'
 196match 1 1 ',' '[,]'
 197match 1 1 ',' '[\\,]'
 198match 1 1 '\' '[\\,]'
 199match 1 1 '-' '[,-.]'
 200match 0 0 '+' '[,-.]'
 201match 0 0 '-.]' '[,-.]'
 202match 1 1 '2' '[\1-\3]'
 203match 1 1 '3' '[\1-\3]'
 204match 0 0 '4' '[\1-\3]'
 205match 1 1 '\' '[[-\]]'
 206match 1 1 '[' '[[-\]]'
 207match 1 1 ']' '[[-\]]'
 208match 0 0 '-' '[[-\]]'
 209
 210# Test recursion and the abort code (use "wildtest -i" to see iteration counts)
 211match 1 1 '-adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
 212match 0 0 '-adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
 213match 0 0 '-adobe-courier-bold-o-normal--12-120-75-75-/-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
 214match 1 1 'XXX/adobe/courier/bold/o/normal//12/120/75/75/m/70/iso8859/1' 'XXX/*/*/*/*/*/*/12/*/*/*/m/*/*/*'
 215match 0 0 'XXX/adobe/courier/bold/o/normal//12/120/75/75/X/70/iso8859/1' 'XXX/*/*/*/*/*/*/12/*/*/*/m/*/*/*'
 216match 1 0 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt' '**/*a*b*g*n*t'
 217match 0 0 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txtz' '**/*a*b*g*n*t'
 218match 0 x foo '*/*/*'
 219match 0 x foo/bar '*/*/*'
 220match 1 x foo/bba/arr '*/*/*'
 221match 0 x foo/bb/aa/rr '*/*/*'
 222match 1 x foo/bb/aa/rr '**/**/**'
 223match 1 x abcXdefXghi '*X*i'
 224match 0 x ab/cXd/efXg/hi '*X*i'
 225match 1 x ab/cXd/efXg/hi '*/*X*/*/*i'
 226match 1 x ab/cXd/efXg/hi '**/*X*/**/*i'
 227
 228pathmatch 1 foo foo
 229pathmatch 0 foo fo
 230pathmatch 1 foo/bar foo/bar
 231pathmatch 1 foo/bar 'foo/*'
 232pathmatch 1 foo/bba/arr 'foo/*'
 233pathmatch 1 foo/bba/arr 'foo/**'
 234pathmatch 1 foo/bba/arr 'foo*'
 235pathmatch 1 foo/bba/arr 'foo**'
 236pathmatch 1 foo/bba/arr 'foo/*arr'
 237pathmatch 1 foo/bba/arr 'foo/**arr'
 238pathmatch 0 foo/bba/arr 'foo/*z'
 239pathmatch 0 foo/bba/arr 'foo/**z'
 240pathmatch 1 foo/bar 'foo?bar'
 241pathmatch 1 foo/bar 'foo[/]bar'
 242pathmatch 0 foo '*/*/*'
 243pathmatch 0 foo/bar '*/*/*'
 244pathmatch 1 foo/bba/arr '*/*/*'
 245pathmatch 1 foo/bb/aa/rr '*/*/*'
 246pathmatch 1 abcXdefXghi '*X*i'
 247pathmatch 1 ab/cXd/efXg/hi '*/*X*/*/*i'
 248pathmatch 1 ab/cXd/efXg/hi '*Xg*i'
 249
 250# Case-sensitivy features
 251match 0 x 'a' '[A-Z]'
 252match 1 x 'A' '[A-Z]'
 253match 0 x 'A' '[a-z]'
 254match 1 x 'a' '[a-z]'
 255match 0 x 'a' '[[:upper:]]'
 256match 1 x 'A' '[[:upper:]]'
 257match 0 x 'A' '[[:lower:]]'
 258match 1 x 'a' '[[:lower:]]'
 259match 0 x 'A' '[B-Za]'
 260match 1 x 'a' '[B-Za]'
 261match 0 x 'A' '[B-a]'
 262match 1 x 'a' '[B-a]'
 263match 0 x 'z' '[Z-y]'
 264match 1 x 'Z' '[Z-y]'
 265
 266imatch 1 'a' '[A-Z]'
 267imatch 1 'A' '[A-Z]'
 268imatch 1 'A' '[a-z]'
 269imatch 1 'a' '[a-z]'
 270imatch 1 'a' '[[:upper:]]'
 271imatch 1 'A' '[[:upper:]]'
 272imatch 1 'A' '[[:lower:]]'
 273imatch 1 'a' '[[:lower:]]'
 274imatch 1 'A' '[B-Za]'
 275imatch 1 'a' '[B-Za]'
 276imatch 1 'A' '[B-a]'
 277imatch 1 'a' '[B-a]'
 278imatch 1 'z' '[Z-y]'
 279imatch 1 'Z' '[Z-y]'
 280
 281test_done