1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21: #include <regex.h>
22: #include <stdio.h>
23: #include <string.h>
24:
25: struct tests
26: {
27: const char *regex;
28: const char *string;
29: int cflags;
30: int retval;
31: } tests[] = {
32: { "a.b", "a\nb", REG_EXTENDED | REG_NEWLINE, REG_NOMATCH },
33: { "a.b", "a\nb", REG_EXTENDED, 0 },
34: { "a[^x]b", "a\nb", REG_EXTENDED | REG_NEWLINE, REG_NOMATCH },
35: { "a[^x]b", "a\nb", REG_EXTENDED, 0 }
36: };
37:
38: int
39: main (void)
40: {
41: regex_t r;
42: size_t i;
43: int ret = 0;
44:
45: for (i = 0; i < sizeof (tests) / sizeof (tests[i]); ++i)
46: {
47: memset (&r, 0, sizeof (r));
48: if (regcomp (&r, tests[i].regex, tests[i].cflags))
49: {
50: printf ("regcomp %zd failed\n", i);
51: ret = 1;
52: continue;
53: }
54: int rv = regexec (&r, tests[i].string, 0, NULL, 0);
55: if (rv != tests[i].retval)
56: {
57: printf ("regexec %zd unexpected value %d != %d\n",
58: i, rv, tests[i].retval);
59: ret = 1;
60: }
61: regfree (&r);
62: }
63: return ret;
64: }