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