3 test_description
='wildmatch tests'
7 match_with_function
() {
13 if test "$match_expect" = 1
15 test_expect_success
"$match_function: match '$text' '$pattern'" "
16 test-wildmatch $match_function '$text' '$pattern'
18 elif test "$match_expect" = 0
20 test_expect_success
"$match_function: no match '$text' '$pattern'" "
21 test_must_fail test-wildmatch $match_function '$text' '$pattern'
24 test_expect_success
"PANIC: Test framework error. Unknown matches value $match_expect" 'false'
37 # $1: Case sensitive glob match: test-wildmatch & ls-files
38 match_with_function
"$text" "$pattern" $match_glob "wildmatch"
40 # $2: Case insensitive glob match: test-wildmatch & ls-files
41 match_with_function
"$text" "$pattern" $match_iglob "iwildmatch"
43 # $3: Case sensitive path match: test-wildmatch & ls-files
44 match_with_function
"$text" "$pattern" $match_pathmatch "pathmatch"
46 # $4: Case insensitive path match: test-wildmatch & ls-files
47 match_with_function
"$text" "$pattern" $match_pathmatchi "ipathmatch"
50 # Basic wildmatch features
54 match
1 1 1 1 foo
'???'
55 match
0 0 0 0 foo
'??'
57 match
1 1 1 1 foo
'f*'
58 match
0 0 0 0 foo
'*f'
59 match
1 1 1 1 foo
'*foo*'
60 match
1 1 1 1 foobar
'*ob*a*r*'
61 match
1 1 1 1 aaaaaaabababab
'*ab'
62 match
1 1 1 1 'foo*' 'foo\*'
63 match
0 0 0 0 foobar
'foo\*bar'
64 match
1 1 1 1 'f\oo' 'f\\oo'
65 match
1 1 1 1 ball
'*[al]?'
66 match
0 0 0 0 ten
'[ten]'
67 match
0 0 1 1 ten
'**[!te]'
68 match
0 0 0 0 ten
'**[!ten]'
69 match
1 1 1 1 ten
't[a-g]n'
70 match
0 0 0 0 ten
't[!a-g]n'
71 match
1 1 1 1 ton
't[!a-g]n'
72 match
1 1 1 1 ton
't[^a-g]n'
73 match
1 1 1 1 'a]b' 'a[]]b'
74 match
1 1 1 1 a-b
'a[]-]b'
75 match
1 1 1 1 'a]b' 'a[]-]b'
76 match
0 0 0 0 aab
'a[]-]b'
77 match
1 1 1 1 aab
'a[]a-]b'
80 # Extended slash-matching features
81 match
0 0 1 1 'foo/baz/bar' 'foo*bar'
82 match
0 0 1 1 'foo/baz/bar' 'foo**bar'
83 match
0 0 1 1 'foobazbar' 'foo**bar'
84 match
1 1 1 1 'foo/baz/bar' 'foo/**/bar'
85 match
1 1 0 0 'foo/baz/bar' 'foo/**/**/bar'
86 match
1 1 1 1 'foo/b/a/z/bar' 'foo/**/bar'
87 match
1 1 1 1 'foo/b/a/z/bar' 'foo/**/**/bar'
88 match
1 1 0 0 'foo/bar' 'foo/**/bar'
89 match
1 1 0 0 'foo/bar' 'foo/**/**/bar'
90 match
0 0 1 1 'foo/bar' 'foo?bar'
91 match
0 0 1 1 'foo/bar' 'foo[/]bar'
92 match
0 0 1 1 'foo/bar' 'foo[^a-z]bar'
93 match
0 0 1 1 'foo/bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
94 match
1 1 1 1 'foo-bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
95 match
1 1 0 0 'foo' '**/foo'
96 match
1 1 1 1 'XXX/foo' '**/foo'
97 match
1 1 1 1 'bar/baz/foo' '**/foo'
98 match
0 0 1 1 'bar/baz/foo' '*/foo'
99 match
0 0 1 1 'foo/bar/baz' '**/bar*'
100 match
1 1 1 1 'deep/foo/bar/baz' '**/bar/*'
101 match
0 0 1 1 'deep/foo/bar/baz/' '**/bar/*'
102 match
1 1 1 1 'deep/foo/bar/baz/' '**/bar/**'
103 match
0 0 0 0 'deep/foo/bar' '**/bar/*'
104 match
1 1 1 1 'deep/foo/bar/' '**/bar/**'
105 match
0 0 1 1 'foo/bar/baz' '**/bar**'
106 match
1 1 1 1 'foo/bar/baz/x' '*/bar/**'
107 match
0 0 1 1 'deep/foo/bar/baz/x' '*/bar/**'
108 match
1 1 1 1 'deep/foo/bar/baz/x' '**/bar/*/*'
110 # Various additional tests
111 match
0 0 0 0 'acrt' 'a[c-c]st'
112 match
1 1 1 1 'acrt' 'a[c-c]rt'
113 match
0 0 0 0 ']' '[!]-]'
114 match
1 1 1 1 'a' '[!]-]'
116 match 0 0 0 0 '\' '\'
117 match 0 0 0 0 'XXX
/\' '*/\'
118 match 1 1 1 1 'XXX
/\' '*/\\'
119 match
1 1 1 1 'foo' 'foo'
120 match
1 1 1 1 '@foo' '@foo'
121 match
0 0 0 0 'foo' '@foo'
122 match
1 1 1 1 '[ab]' '\[ab]'
123 match
1 1 1 1 '[ab]' '[[]ab]'
124 match
1 1 1 1 '[ab]' '[[:]ab]'
125 match
0 0 0 0 '[ab]' '[[::]ab]'
126 match
1 1 1 1 '[ab]' '[[:digit]ab]'
127 match
1 1 1 1 '[ab]' '[\[:]ab]'
128 match
1 1 1 1 '?a?b' '\??\?b'
129 match
1 1 1 1 'abc' '\a\b\c'
130 match
0 0 0 0 'foo' ''
131 match
1 1 1 1 'foo/bar/baz/to' '**/t[o]'
133 # Character class tests
134 match
1 1 1 1 'a1B' '[[:alpha:]][[:digit:]][[:upper:]]'
135 match
0 1 0 1 'a' '[[:digit:][:upper:][:space:]]'
136 match
1 1 1 1 'A' '[[:digit:][:upper:][:space:]]'
137 match
1 1 1 1 '1' '[[:digit:][:upper:][:space:]]'
138 match
0 0 0 0 '1' '[[:digit:][:upper:][:spaci:]]'
139 match
1 1 1 1 ' ' '[[:digit:][:upper:][:space:]]'
140 match
0 0 0 0 '.' '[[:digit:][:upper:][:space:]]'
141 match
1 1 1 1 '.' '[[:digit:][:punct:][:space:]]'
142 match
1 1 1 1 '5' '[[:xdigit:]]'
143 match
1 1 1 1 'f' '[[:xdigit:]]'
144 match
1 1 1 1 'D' '[[:xdigit:]]'
145 match
1 1 1 1 '_' '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'
146 match
1 1 1 1 '.' '[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'
147 match
1 1 1 1 '5' '[a-c[:digit:]x-z]'
148 match
1 1 1 1 'b' '[a-c[:digit:]x-z]'
149 match
1 1 1 1 'y' '[a-c[:digit:]x-z]'
150 match
0 0 0 0 'q' '[a-c[:digit:]x-z]'
152 # Additional tests, including some malformed wildmatch patterns
153 match
1 1 1 1 ']' '[\\-^]'
154 match
0 0 0 0 '[' '[\\-^]'
155 match
1 1 1 1 '-' '[\-_]'
156 match
1 1 1 1 ']' '[\]]'
157 match
0 0 0 0 '\]' '[\]]'
158 match
0 0 0 0 '\' '[\
]]'
159 match 0 0 0 0 'ab
' 'a
[]b
'
160 match 0 0 0 0 'a
[]b
' 'a
[]b
'
161 match 0 0 0 0 'ab
[' 'ab
['
162 match 0 0 0 0 'ab
' '[!'
163 match 0 0 0 0 'ab
' '[-'
164 match 1 1 1 1 '-' '[-]'
165 match 0 0 0 0 '-' '[a-
'
166 match 0 0 0 0 '-' '[!a-
'
167 match 1 1 1 1 '-' '[--A]'
168 match 1 1 1 1 '5' '[--A]'
169 match 1 1 1 1 ' ' '[ --]'
170 match 1 1 1 1 '$
' '[ --]'
171 match 1 1 1 1 '-' '[ --]'
172 match 0 0 0 0 '0' '[ --]'
173 match 1 1 1 1 '-' '[---]'
174 match 1 1 1 1 '-' '[------]'
175 match 0 0 0 0 'j
' '[a-e-n
]'
176 match 1 1 1 1 '-' '[a-e-n
]'
177 match 1 1 1 1 'a
' '[!------]'
178 match 0 0 0 0 '[' '[]-a]'
179 match 1 1 1 1 '^
' '[]-a]'
180 match 0 0 0 0 '^
' '[!]-a]'
181 match 1 1 1 1 '[' '[!]-a]'
182 match 1 1 1 1 '^
' '[a^
bc]'
183 match 1 1 1 1 '-b]' '[a-
]b
]'
184 match 0 0 0 0 '\' '[\]'
185 match
1 1 1 1 '\' '[\\]'
186 match 0 0 0 0 '\' '[!\\]'
187 match
1 1 1 1 'G' '[A-\\]'
188 match
0 0 0 0 'aaabbb' 'b*a'
189 match
0 0 0 0 'aabcaa' '*ba*'
190 match
1 1 1 1 ',' '[,]'
191 match
1 1 1 1 ',' '[\\,]'
192 match
1 1 1 1 '\' '[\\,]'
193 match 1 1 1 1 '-' '[,-.
]'
194 match 0 0 0 0 '+' '[,-.
]'
195 match 0 0 0 0 '-.
]' '[,-.
]'
196 match 1 1 1 1 '2' '[\
1-\
3]'
197 match 1 1 1 1 '3' '[\
1-\
3]'
198 match 0 0 0 0 '4' '[\
1-\
3]'
199 match 1 1 1 1 '\' '[[-\]]'
200 match
1 1 1 1 '[' '[[-\]]'
201 match
1 1 1 1 ']' '[[-\]]'
202 match
0 0 0 0 '-' '[[-\]]'
205 match
1 1 1 1 '-adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
206 match
0 0 0 0 '-adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
207 match
0 0 0 0 '-adobe-courier-bold-o-normal--12-120-75-75-/-70-iso8859-1' '-*-*-*-*-*-*-12-*-*-*-m-*-*-*'
208 match
1 1 1 1 'XXX/adobe/courier/bold/o/normal//12/120/75/75/m/70/iso8859/1' 'XXX/*/*/*/*/*/*/12/*/*/*/m/*/*/*'
209 match
0 0 0 0 'XXX/adobe/courier/bold/o/normal//12/120/75/75/X/70/iso8859/1' 'XXX/*/*/*/*/*/*/12/*/*/*/m/*/*/*'
210 match
1 1 1 1 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt' '**/*a*b*g*n*t'
211 match
0 0 0 0 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txtz' '**/*a*b*g*n*t'
212 match
0 0 0 0 foo
'*/*/*'
213 match
0 0 0 0 foo
/bar
'*/*/*'
214 match
1 1 1 1 foo
/bba
/arr
'*/*/*'
215 match
0 0 1 1 foo
/bb
/aa
/rr
'*/*/*'
216 match
1 1 1 1 foo
/bb
/aa
/rr
'**/**/**'
217 match
1 1 1 1 abcXdefXghi
'*X*i'
218 match
0 0 1 1 ab
/cXd
/efXg
/hi
'*X*i'
219 match
1 1 1 1 ab
/cXd
/efXg
/hi
'*/*X*/*/*i'
220 match
1 1 1 1 ab
/cXd
/efXg
/hi
'**/*X*/**/*i'
222 # Extra pathmatch tests
224 match
1 1 1 1 foo
/bar foo
/bar
225 match
1 1 1 1 foo
/bar
'foo/*'
226 match
0 0 1 1 foo
/bba
/arr
'foo/*'
227 match
1 1 1 1 foo
/bba
/arr
'foo/**'
228 match
0 0 1 1 foo
/bba
/arr
'foo*'
229 match
0 0 1 1 foo
/bba
/arr
'foo**'
230 match
0 0 1 1 foo
/bba
/arr
'foo/*arr'
231 match
0 0 1 1 foo
/bba
/arr
'foo/**arr'
232 match
0 0 0 0 foo
/bba
/arr
'foo/*z'
233 match
0 0 0 0 foo
/bba
/arr
'foo/**z'
234 match
0 0 1 1 foo
/bar
'foo?bar'
235 match
0 0 1 1 foo
/bar
'foo[/]bar'
236 match
0 0 1 1 foo
/bar
'foo[^a-z]bar'
237 match
0 0 1 1 ab
/cXd
/efXg
/hi
'*Xg*i'
239 # Extra case-sensitivity tests
240 match
0 1 0 1 'a' '[A-Z]'
241 match
1 1 1 1 'A' '[A-Z]'
242 match
0 1 0 1 'A' '[a-z]'
243 match
1 1 1 1 'a' '[a-z]'
244 match
0 1 0 1 'a' '[[:upper:]]'
245 match
1 1 1 1 'A' '[[:upper:]]'
246 match
0 1 0 1 'A' '[[:lower:]]'
247 match
1 1 1 1 'a' '[[:lower:]]'
248 match
0 1 0 1 'A' '[B-Za]'
249 match
1 1 1 1 'a' '[B-Za]'
250 match
0 1 0 1 'A' '[B-a]'
251 match
1 1 1 1 'a' '[B-a]'
252 match
0 1 0 1 'z' '[Z-y]'
253 match
1 1 1 1 'Z' '[Z-y]'