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