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