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