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