1 /* POSIX regex testsuite from IEEE 2003.2.
2 Copyright (C) 1998-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <sys/types.h>
24 /* Data structure to describe the tests. */
34 #include "ptestcases.h"
39 main (int argc
, char *argv
[])
44 for (cnt
= 0; cnt
< sizeof (tests
) / sizeof (tests
[0]); ++cnt
)
45 if (tests
[cnt
].str
== NULL
)
47 printf ("\n%s\n%.*s\n", tests
[cnt
].reg
,
48 (int) strlen (tests
[cnt
].reg
),
49 "-----------------------------------------------------");
51 else if (tests
[cnt
].reg
== NULL
)
52 printf ("!!! %s\n", tests
[cnt
].str
);
59 printf ("regexp: \"%s\", string: \"%s\" -> ", tests
[cnt
].reg
,
62 /* Compile the expression. */
63 err
= regcomp (&re
, tests
[cnt
].reg
, tests
[cnt
].options
);
66 if (tests
[cnt
].start
== -2)
67 puts ("compiling failed, OK");
71 regerror (err
, &re
, buf
, sizeof (buf
));
72 printf ("FAIL: %s\n", buf
);
78 else if (tests
[cnt
].start
== -2)
80 puts ("compiling suceeds, FAIL");
85 /* Run the actual test. */
86 err
= regexec (&re
, tests
[cnt
].str
, 20, match
, 0);
90 if (tests
[cnt
].start
== -1)
91 puts ("no match, OK");
94 puts ("no match, FAIL");
100 if (match
[0].rm_so
== 0 && tests
[cnt
].start
== 0
101 && match
[0].rm_eo
== 0 && tests
[cnt
].end
== 0)
103 else if (match
[0].rm_so
+ 1 == tests
[cnt
].start
104 && match
[0].rm_eo
== tests
[cnt
].end
)
108 printf ("wrong match (%d to %d): FAIL\n",
109 match
[0].rm_so
, match
[0].rm_eo
);
114 /* Free all resources. */
118 printf ("\n%zu tests, %d errors\n", cnt
, errors
);