Use common bits/shm.h for more architectures.
[glibc.git] / posix / bug-regex28.c
blobba263b27c8c7966051dcea078d1ba26fe4de1e3f
1 /* Test RE_HAT_LISTS_NOT_NEWLINE and RE_DOT_NEWLINE.
2 Copyright (C) 2007-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2007.
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 <regex.h>
21 #include <stdio.h>
22 #include <string.h>
24 #include <support/test-driver.h>
25 #include <support/check.h>
27 struct tests
29 const char *regex;
30 const char *string;
31 reg_syntax_t syntax;
32 int retval;
34 static const struct tests tests[] = {
35 #define EGREP RE_SYNTAX_EGREP
36 #define EGREP_NL (RE_SYNTAX_EGREP | RE_DOT_NEWLINE) & ~RE_HAT_LISTS_NOT_NEWLINE
37 { "a.b", "a\nb", EGREP, 0 },
38 { "a.b", "a\nb", EGREP_NL, 0 },
39 { "a[^x]b", "a\nb", EGREP, 0 },
40 { "a[^x]b", "a\nb", EGREP_NL, 0 },
41 /* While \S and \W are internally handled as [^[:space:]] and [^[:alnum:]_],
42 RE_HAT_LISTS_NOT_NEWLINE did not make any difference, so ensure
43 it doesn't change. */
44 { "a\\Sb", "a\nb", EGREP, -1 },
45 { "a\\Sb", "a\nb", EGREP_NL, -1 },
46 { "a\\Wb", "a\nb", EGREP, 0 },
47 { "a\\Wb", "a\nb", EGREP_NL, 0 }
49 static const size_t tests_size = sizeof (tests) / sizeof (tests[0]);
51 static int
52 do_test (void)
54 struct re_pattern_buffer r;
56 for (size_t i = 0; i < tests_size; i++)
58 re_set_syntax (tests[i].syntax);
59 memset (&r, 0, sizeof (r));
60 const char *re = re_compile_pattern (tests[i].regex,
61 strlen (tests[i].regex), &r);
62 TEST_VERIFY (re == NULL);
63 if (re != NULL)
64 continue;
66 size_t len = strlen (tests[i].string);
67 int rv = re_search (&r, tests[i].string, len, 0, len, NULL);
68 TEST_VERIFY (rv == tests[i].retval);
69 if (test_verbose > 0)
70 printf ("info: i=%zu rv=%d expected=%d\n", i, rv, tests[i].retval);
72 regfree (&r);
75 return 0;
78 #include <support/test-driver.c>