t / t3070-wildmatch.shon commit Merge branch 'pe/doc-email-env-is-trumped-by-config' (e928b70)
   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
  32# Basic wildmat features
  33match 1 1 foo foo
  34match 0 0 foo bar
  35match 1 1 '' ""
  36match 1 1 foo '???'
  37match 0 0 foo '??'
  38match 1 1 foo '*'
  39match 1 1 foo 'f*'
  40match 0 0 foo '*f'
  41match 1 1 foo '*foo*'
  42match 1 1 foobar '*ob*a*r*'
  43match 1 1 aaaaaaabababab '*ab'
  44match 1 1 'foo*' 'foo\*'
  45match 0 0 foobar 'foo\*bar'
  46match 1 1 'f\oo' 'f\\oo'
  47match 1 1 ball '*[al]?'
  48match 0 0 ten '[ten]'
  49match 0 1 ten '**[!te]'
  50match 0 0 ten '**[!ten]'
  51match 1 1 ten 't[a-g]n'
  52match 0 0 ten 't[!a-g]n'
  53match 1 1 ton 't[!a-g]n'
  54match 1 1 ton 't[^a-g]n'
  55match 1 x 'a]b' 'a[]]b'
  56match 1 x a-b 'a[]-]b'
  57match 1 x 'a]b' 'a[]-]b'
  58match 0 x aab 'a[]-]b'
  59match 1 x aab 'a[]a-]b'
  60match 1 1 ']' ']'
  61
  62# Extended slash-matching features
  63match 0 0 'foo/baz/bar' 'foo*bar'
  64match 0 0 'foo/baz/bar' 'foo**bar'
  65match 0 1 'foobazbar' 'foo**bar'
  66match 1 1 'foo/baz/bar' 'foo/**/bar'
  67match 1 0 'foo/baz/bar' 'foo/**/**/bar'
  68match 1 0 'foo/b/a/z/bar' 'foo/**/bar'
  69match 1 0 'foo/b/a/z/bar' 'foo/**/**/bar'
  70match 1 0 'foo/bar' 'foo/**/bar'
  71match 1 0 'foo/bar' 'foo/**/**/bar'
  72match 0 0 'foo/bar' 'foo?bar'
  73match 0 0 'foo/bar' 'foo[/]bar'
  74match 0 0 'foo/bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
  75match 1 1 'foo-bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
  76match 1 0 'foo' '**/foo'
  77match 1 x 'XXX/foo' '**/foo'
  78match 1 0 'bar/baz/foo' '**/foo'
  79match 0 0 'bar/baz/foo' '*/foo'
  80match 0 0 'foo/bar/baz' '**/bar*'
  81match 1 0 'deep/foo/bar/baz' '**/bar/*'
  82match 0 0 'deep/foo/bar/baz/' '**/bar/*'
  83match 1 0 'deep/foo/bar/baz/' '**/bar/**'
  84match 0 0 'deep/foo/bar' '**/bar/*'
  85match 1 0 'deep/foo/bar/' '**/bar/**'
  86match 0 0 'foo/bar/baz' '**/bar**'
  87match 1 0 'foo/bar/baz/x' '*/bar/**'
  88match 0 0 'deep/foo/bar/baz/x' '*/bar/**'
  89match 1 0 'deep/foo/bar/baz/x' '**/bar/*/*'
  90
  91# Various additional tests
  92match 0 0 'acrt' 'a[c-c]st'
  93match 1 1 'acrt' 'a[c-c]rt'
  94match 0 0 ']' '[!]-]'
  95match 1 x 'a' '[!]-]'
  96match 0 0 '' '\'
  97match 0 x '\' '\'
  98match 0 x 'XXX/\' '*/\'
  99match 1 x 'XXX/\' '*/\\'
 100match 1 1 'foo' 'foo'
 101match 1 1 '@foo' '@foo'
 102match 0 0 'foo' '@foo'
 103match 1 1 '[ab]' '\[ab]'
 104match 1 1 '[ab]' '[[]ab]'
 105match 1 x '[ab]' '[[:]ab]'
 106match 0 x '[ab]' '[[::]ab]'
 107match 1 x '[ab]' '[[:digit]ab]'
 108match 1 x '[ab]' '[\[:]ab]'
 109match 1 1 '?a?b' '\??\?b'
 110match 1 1 'abc' '\a\b\c'
 111match 0 0 'foo' ''
 112match 1 0 'foo/bar/baz/to' '**/t[o]'
 113
 114# Character class tests
 115match 1 x 'a1B' '[[:alpha:]][[:digit:]][[:upper:]]'
 116match 0 x 'a' '[[:digit:][:upper:][:space:]]'
 117match 1 x 'A' '[[:digit:][:upper:][:space:]]'
 118match 1 x '1' '[[:digit:][:upper:][:space:]]'
 119match 0 x '1' '[[:digit:][:upper:][:spaci:]]'
 120match 1 x ' ' '[[:digit:][:upper:][:space:]]'
 121match 0 x '.' '[[:digit:][:upper:][:space:]]'
 122match 1 x '.' '[[:digit:][:punct:][:space:]]'
 123match 1 x '5' '[[:xdigit:]]'
 124match 1 x 'f' '[[:xdigit:]]'
 125match 1 x 'D' '[[:xdigit:]]'
 126match 1 x '_' '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'
 127match 1 x '_' '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'
 128match 1 x '.' '[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'
 129match 1 x '5' '[a-c[:digit:]x-z]'
 130match 1 x 'b' '[a-c[:digit:]x-z]'
 131match 1 x 'y' '[a-c[:digit:]x-z]'
 132match 0 x 'q' '[a-c[:digit:]x-z]'
 133
 134# Additional tests, including some malformed wildmats
 135match 1 x ']' '[\\-^]'
 136match 0 0 '[' '[\\-^]'
 137match 1 x '-' '[\-_]'
 138match 1 x ']' '[\]]'
 139match 0 0 '\]' '[\]]'
 140match 0 0 '\' '[\]]'
 141match 0 0 'ab' 'a[]b'
 142match 0 x 'a[]b' 'a[]b'
 143match 0 x 'ab[' 'ab['
 144match 0 0 'ab' '[!'
 145match 0 0 'ab' '[-'
 146match 1 1 '-' '[-]'
 147match 0 0 '-' '[a-'
 148match 0 0 '-' '[!a-'
 149match 1 x '-' '[--A]'
 150match 1 x '5' '[--A]'
 151match 1 1 ' ' '[ --]'
 152match 1 1 '$' '[ --]'
 153match 1 1 '-' '[ --]'
 154match 0 0 '0' '[ --]'
 155match 1 x '-' '[---]'
 156match 1 x '-' '[------]'
 157match 0 0 'j' '[a-e-n]'
 158match 1 x '-' '[a-e-n]'
 159match 1 x 'a' '[!------]'
 160match 0 0 '[' '[]-a]'
 161match 1 x '^' '[]-a]'
 162match 0 0 '^' '[!]-a]'
 163match 1 x '[' '[!]-a]'
 164match 1 1 '^' '[a^bc]'
 165match 1 x '-b]' '[a-]b]'
 166match 0 0 '\' '[\]'
 167match 1 1 '\' '[\\]'
 168match 0 0 '\' '[!\\]'
 169match 1 1 'G' '[A-\\]'
 170match 0 0 'aaabbb' 'b*a'
 171match 0 0 'aabcaa' '*ba*'
 172match 1 1 ',' '[,]'
 173match 1 1 ',' '[\\,]'
 174match 1 1 '\' '[\\,]'
 175match 1 1 '-' '[,-.]'
 176match 0 0 '+' '[,-.]'
 177match 0 0 '-.]' '[,-.]'
 178match 1 1 '2' '[\1-\3]'
 179match 1 1 '3' '[\1-\3]'
 180match 0 0 '4' '[\1-\3]'
 181match 1 1 '\' '[[-\]]'
 182match 1 1 '[' '[[-\]]'
 183match 1 1 ']' '[[-\]]'
 184match 0 0 '-' '[[-\]]'
 185
 186# Test recursion and the abort code (use "wildtest -i" to see iteration counts)
 187match 1 1 '-adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
 188match 0 0 '-adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
 189match 0 0 '-adobe-courier-bold-o-normal--12-120-75-75-/-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
 190match 1 1 'XXX/adobe/courier/bold/o/normal//12/120/75/75/m/70/iso8859/1' 'XXX/*/*/*/*/*/*/12/*/*/*/m/*/*/*'
 191match 0 0 'XXX/adobe/courier/bold/o/normal//12/120/75/75/X/70/iso8859/1' 'XXX/*/*/*/*/*/*/12/*/*/*/m/*/*/*'
 192match 1 0 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt' '**/*a*b*g*n*t'
 193match 0 0 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txtz' '**/*a*b*g*n*t'
 194
 195test_done