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