1 /* Regular expression tests.
2 Copyright (C) 2003 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, write to the Free
18 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <sys/types.h>
33 frob_escapes (char *src
, int pattern
)
37 for (dst
= src
; *src
!= '\0'; dst
++, src
++)
76 main (int argc
, char **argv
)
83 char *pattern
, *string
;
84 int flags
= REG_EXTENDED
;
95 fprintf (stderr
, "Missing test filename\n");
99 f
= fopen (argv
[1], "r");
102 fprintf (stderr
, "Couldn't open %s\n", argv
[1]);
106 while ((len
= getline (&line
, &line_len
, f
)) > 0)
111 if (line
[len
- 1] == '\n')
124 if (strstr (line
, "REG_BASIC"))
127 flags
= REG_EXTENDED
;
128 if (strstr (line
, "REG_ICASE"))
130 if (strstr (line
, "REG_NEWLINE"))
131 flags
|= REG_NEWLINE
;
133 if (strstr (line
, "REG_NOTBOL"))
134 eflags
|= REG_NOTBOL
;
135 if (strstr (line
, "REG_NOTEOL"))
136 eflags
|= REG_NOTEOL
;
140 pattern
= line
+ strspn (line
, " \t");
141 if (*pattern
== '\0')
143 p
= pattern
+ strcspn (pattern
, " \t");
148 string
= p
+ strspn (p
, " \t");
154 p
= strchr (string
, '"');
161 p
= string
+ strcspn (string
, " \t");
170 frob_escapes (pattern
, 1);
172 frob_escapes (string
, 0);
174 n
= regcomp (&re
, pattern
, flags
);
180 regerror (n
, &re
, buf
, sizeof (buf
));
181 printf ("FAIL regcomp unexpectedly failed: %s\n",
187 else if (string
== NULL
)
190 puts ("FAIL regcomp unpexpectedly succeeded");
195 if (regexec (&re
, string
, 20, rm
, eflags
))
197 for (i
= 0; i
< 20; ++i
)
206 for (i
= 0; i
< 20 && *p
!= '\0'; ++i
)
210 rm_so
= strtol (p
, &q
, 10);
215 rm_eo
= strtol (p
, &q
, 10);
220 if (rm
[i
].rm_so
!= rm_so
|| rm
[i
].rm_eo
!= rm_eo
)
222 printf ("FAIL rm[%d] %d..%d != expected %d..%d\n",
223 i
, rm
[i
].rm_so
, rm
[i
].rm_eo
, rm_so
, rm_eo
);