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
32# Basic wildmat features
33match 1 1 foo foo
34match 0 0 foo bar
35match 1 1 '' ""
36match 1 1 foo '???'
37match 0 0 foo '??'
38match 1 1 foo '*'
39match 1 1 foo 'f*'
40match 0 0 foo '*f'
41match 1 1 foo '*foo*'
42match 1 1 foobar '*ob*a*r*'
43match 1 1 aaaaaaabababab '*ab'
44match 1 1 'foo*' 'foo\*'
45match 0 0 foobar 'foo\*bar'
46match 1 1 'f\oo' 'f\\oo'
47match 1 1 ball '*[al]?'
48match 0 0 ten '[ten]'
49match 1 1 ten '**[!te]'
50match 0 0 ten '**[!ten]'
51match 1 1 ten 't[a-g]n'
52match 0 0 ten 't[!a-g]n'
53match 1 1 ton 't[!a-g]n'
54match 1 1 ton 't[^a-g]n'
55match 1 x 'a]b' 'a[]]b'
56match 1 x a-b 'a[]-]b'
57match 1 x 'a]b' 'a[]-]b'
58match 0 x aab 'a[]-]b'
59match 1 x aab 'a[]a-]b'
60match 1 1 ']' ']'
61
62# Extended slash-matching features
63match 0 0 'foo/baz/bar' 'foo*bar'
64match 1 0 'foo/baz/bar' 'foo**bar'
65match 0 0 'foo/bar' 'foo?bar'
66match 0 0 'foo/bar' 'foo[/]bar'
67match 0 0 'foo/bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
68match 1 1 'foo-bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
69match 0 0 'foo' '**/foo'
70match 1 x '/foo' '**/foo'
71match 1 0 'bar/baz/foo' '**/foo'
72match 0 0 'bar/baz/foo' '*/foo'
73match 0 0 'foo/bar/baz' '**/bar*'
74match 1 0 'deep/foo/bar/baz' '**/bar/*'
75match 0 0 'deep/foo/bar/baz/' '**/bar/*'
76match 1 0 'deep/foo/bar/baz/' '**/bar/**'
77match 0 0 'deep/foo/bar' '**/bar/*'
78match 1 0 'deep/foo/bar/' '**/bar/**'
79match 1 0 'foo/bar/baz' '**/bar**'
80match 1 0 'foo/bar/baz/x' '*/bar/**'
81match 0 0 'deep/foo/bar/baz/x' '*/bar/**'
82match 1 0 'deep/foo/bar/baz/x' '**/bar/*/*'
83
84# Various additional tests
85match 0 0 'acrt' 'a[c-c]st'
86match 1 1 'acrt' 'a[c-c]rt'
87match 0 0 ']' '[!]-]'
88match 1 x 'a' '[!]-]'
89match 0 0 '' '\'
90match 0 x '\' '\'
91match 0 x '/\' '*/\'
92match 1 x '/\' '*/\\'
93match 1 1 'foo' 'foo'
94match 1 1 '@foo' '@foo'
95match 0 0 'foo' '@foo'
96match 1 1 '[ab]' '\[ab]'
97match 1 1 '[ab]' '[[]ab]'
98match 1 x '[ab]' '[[:]ab]'
99match 0 x '[ab]' '[[::]ab]'
100match 1 x '[ab]' '[[:digit]ab]'
101match 1 x '[ab]' '[\[:]ab]'
102match 1 1 '?a?b' '\??\?b'
103match 1 1 'abc' '\a\b\c'
104match 0 0 'foo' ''
105match 1 0 'foo/bar/baz/to' '**/t[o]'
106
107# Character class tests
108match 1 x 'a1B' '[[:alpha:]][[:digit:]][[:upper:]]'
109match 0 x 'a' '[[:digit:][:upper:][:space:]]'
110match 1 x 'A' '[[:digit:][:upper:][:space:]]'
111match 1 x '1' '[[:digit:][:upper:][:space:]]'
112match 0 x '1' '[[:digit:][:upper:][:spaci:]]'
113match 1 x ' ' '[[:digit:][:upper:][:space:]]'
114match 0 x '.' '[[:digit:][:upper:][:space:]]'
115match 1 x '.' '[[:digit:][:punct:][:space:]]'
116match 1 1 '5' '[[:xdigit:]]'
117match 1 1 'f' '[[:xdigit:]]'
118match 1 1 'D' '[[:xdigit:]]'
119match 1 x '_' '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'
120match 1 x '_' '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'
121match 1 x '.' '[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'
122match 1 x '5' '[a-c[:digit:]x-z]'
123match 1 x 'b' '[a-c[:digit:]x-z]'
124match 1 x 'y' '[a-c[:digit:]x-z]'
125match 0 x 'q' '[a-c[:digit:]x-z]'
126
127# Additional tests, including some malformed wildmats
128match 1 x ']' '[\\-^]'
129match 0 0 '[' '[\\-^]'
130match 1 x '-' '[\-_]'
131match 1 x ']' '[\]]'
132match 0 0 '\]' '[\]]'
133match 0 0 '\' '[\]]'
134match 0 0 'ab' 'a[]b'
135match 0 x 'a[]b' 'a[]b'
136match 0 x 'ab[' 'ab['
137match 0 0 'ab' '[!'
138match 0 0 'ab' '[-'
139match 1 1 '-' '[-]'
140match 0 0 '-' '[a-'
141match 0 0 '-' '[!a-'
142match 1 x '-' '[--A]'
143match 1 x '5' '[--A]'
144match 1 1 ' ' '[ --]'
145match 1 1 '$' '[ --]'
146match 1 1 '-' '[ --]'
147match 0 0 '0' '[ --]'
148match 1 x '-' '[---]'
149match 1 x '-' '[------]'
150match 0 0 'j' '[a-e-n]'
151match 1 x '-' '[a-e-n]'
152match 1 x 'a' '[!------]'
153match 0 0 '[' '[]-a]'
154match 1 x '^' '[]-a]'
155match 0 0 '^' '[!]-a]'
156match 1 x '[' '[!]-a]'
157match 1 1 '^' '[a^bc]'
158match 1 x '-b]' '[a-]b]'
159match 0 0 '\' '[\]'
160match 1 1 '\' '[\\]'
161match 0 0 '\' '[!\\]'
162match 1 1 'G' '[A-\\]'
163match 0 0 'aaabbb' 'b*a'
164match 0 0 'aabcaa' '*ba*'
165match 1 1 ',' '[,]'
166match 1 1 ',' '[\\,]'
167match 1 1 '\' '[\\,]'
168match 1 1 '-' '[,-.]'
169match 0 0 '+' '[,-.]'
170match 0 0 '-.]' '[,-.]'
171match 1 1 '2' '[\1-\3]'
172match 1 1 '3' '[\1-\3]'
173match 0 0 '4' '[\1-\3]'
174match 1 1 '\' '[[-\]]'
175match 1 1 '[' '[[-\]]'
176match 1 1 ']' '[[-\]]'
177match 0 0 '-' '[[-\]]'
178
179# Test recursion and the abort code (use "wildtest -i" to see iteration counts)
180match 1 1 '-adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
181match 0 0 '-adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
182match 0 0 '-adobe-courier-bold-o-normal--12-120-75-75-/-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
183match 1 1 '/adobe/courier/bold/o/normal//12/120/75/75/m/70/iso8859/1' '/*/*/*/*/*/*/12/*/*/*/m/*/*/*'
184match 0 0 '/adobe/courier/bold/o/normal//12/120/75/75/X/70/iso8859/1' '/*/*/*/*/*/*/12/*/*/*/m/*/*/*'
185match 1 0 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt' '**/*a*b*g*n*t'
186match 0 0 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txtz' '**/*a*b*g*n*t'
187
188test_done