footer.kmk: KBUILD_NO_TESTING_PASS_ALIASES.
[kbuild-mirror.git] / src / sed / testsuite / bug-regex13.c
blob9f57e3bcb74413968c3115add1832254e1a32f3a
1 /* Regular expression tests.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>, 2002.
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
19 02110-1301 USA. */
21 #include "config.h"
23 #include <sys/types.h>
24 #ifdef HAVE_MCHECK_H
25 #include <mcheck.h>
26 #endif
27 #include <regex.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 static struct
34 int syntax;
35 const char *pattern;
36 const char *string;
37 int start;
38 } tests[] = {
39 {RE_BACKSLASH_ESCAPE_IN_LISTS, "[0\\-9]", "1", -1}, /* It should not match. */
40 {RE_BACKSLASH_ESCAPE_IN_LISTS, "[0\\-9]", "-", 0}, /* It should match. */
41 {RE_SYNTAX_POSIX_BASIC, "s1\n.*\ns3", "s1\ns2\ns3", 0},
42 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}c", "ac", 0},
43 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}c", "abc", -1},
44 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}c", "abbc", -1},
45 /* Nested duplication. */
46 {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{1}c", "ac", -1},
47 {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{1}c", "abc", 0},
48 {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{1}c", "abbc", -1},
49 {RE_SYNTAX_POSIX_EXTENDED, "ab{2}{2}c", "ac", -1},
50 {RE_SYNTAX_POSIX_EXTENDED, "ab{2}{2}c", "abbc", -1},
51 {RE_SYNTAX_POSIX_EXTENDED, "ab{2}{2}c", "abbbbc", 0},
52 {RE_SYNTAX_POSIX_EXTENDED, "ab{2}{2}c", "abbbbbc", -1},
53 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}{1}c", "ac", 0},
54 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}{1}c", "abc", -1},
55 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}{1}c", "abbc", -1},
56 {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{0}c", "ac", 0},
57 {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{0}c", "abc", -1},
58 {RE_SYNTAX_POSIX_EXTENDED, "ab{1}{0}c", "abbc", -1},
59 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}*c", "ac", 0},
60 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}*c", "abc", -1},
61 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}*c", "abbc", -1},
62 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}?c", "ac", 0},
63 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}?c", "abc", -1},
64 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}?c", "abbc", -1},
65 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}+c", "ac", 0},
66 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}+c", "abc", -1},
67 {RE_SYNTAX_POSIX_EXTENDED, "ab{0}+c", "abbc", -1},
70 int
71 main (void)
73 struct re_pattern_buffer regbuf;
74 const char *err;
75 size_t i;
76 int ret = 0;
78 #ifdef HAVE_MCHECK_H
79 mtrace ();
80 #endif
82 for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
84 int start;
85 re_set_syntax (tests[i].syntax);
86 memset (&regbuf, '\0', sizeof (regbuf));
87 err = re_compile_pattern (tests[i].pattern, strlen (tests[i].pattern),
88 &regbuf);
89 if (err != NULL)
91 printf ("re_compile_pattern failed: %s\n", err);
92 ret = 1;
93 continue;
96 start = re_search (&regbuf, tests[i].string, strlen (tests[i].string),
97 0, strlen (tests[i].string), NULL);
98 if (start != tests[i].start)
100 printf ("re_search failed %d\n", start);
101 ret = 1;
102 regfree (&regbuf);
103 continue;
105 regfree (&regbuf);
108 return ret;