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