add regex REG_ICASE test for austingroupbug #872
authorSzabolcs Nagy <nsz@port70.net>
Thu, 18 Jun 2015 21:46:13 +0000 (21:46 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Thu, 18 Jun 2015 21:46:13 +0000 (21:46 +0000)
src/regression/regex-bracket-icase.c [new file with mode: 0644]

diff --git a/src/regression/regex-bracket-icase.c b/src/regression/regex-bracket-icase.c
new file mode 100644 (file)
index 0000000..82b9287
--- /dev/null
@@ -0,0 +1,46 @@
+// [^aBcC] with REG_ICASE should match d,D but not a,A,b,B,c,C according to
+// http://austingroupbugs.net/view.php?id=872
+#include <regex.h>
+#include <limits.h>
+#include <stdio.h>
+#include "test.h"
+
+int main(void)
+{
+       char buf[100];
+       char *pat;
+       regex_t re;
+       int n, i;
+       struct {
+               char *s;
+               int n;
+       } t[] = {
+               {"a", REG_NOMATCH},
+               {"A", REG_NOMATCH},
+               {"b", REG_NOMATCH},
+               {"B", REG_NOMATCH},
+               {"c", REG_NOMATCH},
+               {"C", REG_NOMATCH},
+               {"d", 0},
+               {"D", 0},
+               {0,0}
+       };
+
+       pat = "[^aBcC]";
+       n = regcomp(&re, pat, REG_ICASE);
+       if (n) {
+               regerror(n, &re, buf, sizeof buf);
+               t_error("regcomp(\"%s\") failed: %d (%s)\n", pat, n, buf);
+       }
+
+       for (i = 0; t[i].s; i++) {
+               n = regexec(&re, t[i].s, 0, 0, 0);
+               if (n != t[i].n) {
+                       regerror(n, &re, buf, sizeof buf);
+                       t_error("regexec(/%s/, \"%s\") returned %d (%s), wanted %d\n",
+                               pat, t[i].s, n, buf, t[i].n);
+               }
+       }
+
+       return t_status;
+}