1 /* POSIX regex testsuite from IEEE 2003.2.
2 Copyright (C) 1998-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <sys/types.h>
25 /* Data structure to describe the tests. */
35 #include "ptestcases.h"
40 main (int argc, char *argv[])
45 for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
46 if (tests[cnt].str == NULL)
48 printf ("\n%s\n%.*s\n", tests[cnt].reg,
49 (int) strlen (tests[cnt].reg),
50 "-----------------------------------------------------");
52 else if (tests[cnt].reg == NULL)
53 printf ("!!! %s\n", tests[cnt].str);
60 printf ("regexp: \"%s\", string: \"%s\" -> ", tests[cnt].reg,
63 /* Compile the expression. */
64 err = regcomp (&re, tests[cnt].reg, tests[cnt].options);
67 if (tests[cnt].start == -2)
68 puts ("compiling failed, OK");
72 regerror (err, &re, buf, sizeof (buf));
73 printf ("FAIL: %s\n", buf);
79 else if (tests[cnt].start == -2)
81 puts ("compiling suceeds, FAIL");
86 /* Run the actual test. */
87 err = regexec (&re, tests[cnt].str, 20, match, 0);
91 if (tests[cnt].start == -1)
92 puts ("no match, OK");
95 puts ("no match, FAIL");
101 if (match[0].rm_so == 0 && tests[cnt].start == 0
102 && match[0].rm_eo == 0 && tests[cnt].end == 0)
104 else if (match[0].rm_so + 1 == tests[cnt].start
105 && match[0].rm_eo == tests[cnt].end)
109 printf ("wrong match (%d to %d): FAIL\n",
110 match[0].rm_so, match[0].rm_eo);
115 /* Free all resources. */
119 printf ("\n%Zu tests, %d errors\n", cnt, errors);