1 /* Regular expression tests.
2 Copyright (C) 2003-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
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 <https://www.gnu.org/licenses/>. */
20 #include <sys/types.h>
28 frob_escapes (char *src
, int pattern
)
32 for (dst
= src
; *src
!= '\0'; dst
++, src
++)
71 main (int argc
, char **argv
)
78 char *pattern
, *string
;
79 int flags
= REG_EXTENDED
;
88 fprintf (stderr
, "Missing test filename\n");
92 f
= fopen (argv
[1], "r");
95 fprintf (stderr
, "Couldn't open %s\n", argv
[1]);
99 while ((len
= getline (&line
, &line_len
, f
)) > 0)
104 if (line
[len
- 1] == '\n')
117 if (strstr (line
, "REG_BASIC"))
120 flags
= REG_EXTENDED
;
121 if (strstr (line
, "REG_ICASE"))
123 if (strstr (line
, "REG_NEWLINE"))
124 flags
|= REG_NEWLINE
;
126 if (strstr (line
, "REG_NOTBOL"))
127 eflags
|= REG_NOTBOL
;
128 if (strstr (line
, "REG_NOTEOL"))
129 eflags
|= REG_NOTEOL
;
133 pattern
= line
+ strspn (line
, " \t");
134 if (*pattern
== '\0')
136 p
= pattern
+ strcspn (pattern
, " \t");
141 string
= p
+ strspn (p
, " \t");
147 p
= strchr (string
, '"');
154 p
= string
+ strcspn (string
, " \t");
163 frob_escapes (pattern
, 1);
165 frob_escapes (string
, 0);
167 n
= regcomp (&re
, pattern
, flags
);
173 regerror (n
, &re
, buf
, sizeof (buf
));
174 printf ("FAIL regcomp unexpectedly failed: %s\n",
180 else if (string
== NULL
)
183 puts ("FAIL regcomp unpexpectedly succeeded");
188 if (regexec (&re
, string
, 20, rm
, eflags
))
190 for (i
= 0; i
< 20; ++i
)
199 for (i
= 0; i
< 20 && *p
!= '\0'; ++i
)
203 rm_so
= strtol (p
, &q
, 10);
208 rm_eo
= strtol (p
, &q
, 10);
213 if (rm
[i
].rm_so
!= rm_so
|| rm
[i
].rm_eo
!= rm_eo
)
215 printf ("FAIL rm[%d] %d..%d != expected %d..%d\n",
216 i
, rm
[i
].rm_so
, rm
[i
].rm_eo
, rm_so
, rm_eo
);