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