add regex REG_ICASE test for austingroupbug #872
[libc-test] / src / regression / regex-bracket-icase.c
1 // [^aBcC] with REG_ICASE should match d,D but not a,A,b,B,c,C according to
2 // http://austingroupbugs.net/view.php?id=872
3 #include <regex.h>
4 #include <limits.h>
5 #include <stdio.h>
6 #include "test.h"
7
8 int main(void)
9 {
10         char buf[100];
11         char *pat;
12         regex_t re;
13         int n, i;
14         struct {
15                 char *s;
16                 int n;
17         } t[] = {
18                 {"a", REG_NOMATCH},
19                 {"A", REG_NOMATCH},
20                 {"b", REG_NOMATCH},
21                 {"B", REG_NOMATCH},
22                 {"c", REG_NOMATCH},
23                 {"C", REG_NOMATCH},
24                 {"d", 0},
25                 {"D", 0},
26                 {0,0}
27         };
28
29         pat = "[^aBcC]";
30         n = regcomp(&re, pat, REG_ICASE);
31         if (n) {
32                 regerror(n, &re, buf, sizeof buf);
33                 t_error("regcomp(\"%s\") failed: %d (%s)\n", pat, n, buf);
34         }
35
36         for (i = 0; t[i].s; i++) {
37                 n = regexec(&re, t[i].s, 0, 0, 0);
38                 if (n != t[i].n) {
39                         regerror(n, &re, buf, sizeof buf);
40                         t_error("regexec(/%s/, \"%s\") returned %d (%s), wanted %d\n",
41                                 pat, t[i].s, n, buf, t[i].n);
42                 }
43         }
44
45         return t_status;
46 }