| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <stdio.h> |
| 7 |
|
| 8 |
extern int iwildmatch(const char *pattern, const char *text); |
| 9 |
|
| 10 |
static const struct { const char *p, *t; int exp; } cases[] = { |
| 11 |
{ "abc", "ABC", 1 }, |
| 12 |
{ "ABC", "abc", 1 }, |
| 13 |
{ "ABC", "abd", 0 }, |
| 14 |
{ "*.EXAMPLE.COM", "foo.example.com", 1 }, |
| 15 |
{ "*.example.com", "FOO.EXAMPLE.COM", 1 }, |
| 16 |
{ "*.BADDOMAIN.COM", "x.baddomain.com", 1 }, |
| 17 |
{ "[A-Z]bc", "abc", 1 }, |
| 18 |
{ "[ABC]xy", "bxy", 1 }, |
| 19 |
{ "x[A-Z]z", "xyz", 1 }, |
| 20 |
{ "[a-z]BC", "abc", 1 }, |
| 21 |
{ "[\\A]bc", "abc", 1 }, |
| 22 |
{ "[A-Z]bc", "5bc", 0 }, |
| 23 |
}; |
| 24 |
|
| 25 |
int main(int argc, char *argv[]) |
| 26 |
{ |
| 27 |
(void)argc; (void)argv; |
| 28 |
int i, fails = 0, n = (int)(sizeof cases / sizeof cases[0]); |
| 29 |
for (i = 0; i < n; i++) { |
| 30 |
int r = iwildmatch(cases[i].p, cases[i].t); |
| 31 |
if (r != cases[i].exp) { |
| 32 |
printf("FAIL: iwildmatch(%s, %s) = %d, expected %d\n", |
| 33 |
cases[i].p, cases[i].t, r, cases[i].exp); |
| 34 |
fails++; |
| 35 |
} |
| 36 |
} |
| 37 |
if (fails) { |
| 38 |
printf("iwildmatch: %d case(s) wrong -- the pattern is not folded " |
| 39 |
"(asymmetric case handling)\n", fails); |
| 40 |
return 1; |
| 41 |
} |
| 42 |
printf("iwildmatch: case-insensitive on both text and pattern\n"); |
| 43 |
return 0; |
| 44 |
} |