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