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