]>
Commit | Line | Data |
---|---|---|
784aacea | 1 | /* Test RE_HAT_LISTS_NOT_NEWLINE and RE_DOT_NEWLINE. |
04277e02 | 2 | Copyright (C) 2007-2019 Free Software Foundation, Inc. |
784aacea UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Jakub Jelinek <jakub@redhat.com>, 2007. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
784aacea UD |
19 | |
20 | #include <regex.h> | |
21 | #include <stdio.h> | |
22 | #include <string.h> | |
23 | ||
eb04c213 AZ |
24 | #include <support/test-driver.h> |
25 | #include <support/check.h> | |
26 | ||
784aacea UD |
27 | struct tests |
28 | { | |
29 | const char *regex; | |
30 | const char *string; | |
31 | reg_syntax_t syntax; | |
32 | int retval; | |
eb04c213 AZ |
33 | }; |
34 | static const struct tests tests[] = { | |
784aacea UD |
35 | #define EGREP RE_SYNTAX_EGREP |
36 | #define EGREP_NL (RE_SYNTAX_EGREP | RE_DOT_NEWLINE) & ~RE_HAT_LISTS_NOT_NEWLINE | |
eb04c213 | 37 | { "a.b", "a\nb", EGREP, 0 }, |
784aacea | 38 | { "a.b", "a\nb", EGREP_NL, 0 }, |
eb04c213 | 39 | { "a[^x]b", "a\nb", EGREP, 0 }, |
784aacea UD |
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 } | |
48 | }; | |
eb04c213 | 49 | static const size_t tests_size = sizeof (tests) / sizeof (tests[0]); |
784aacea | 50 | |
eb04c213 AZ |
51 | static int |
52 | do_test (void) | |
784aacea UD |
53 | { |
54 | struct re_pattern_buffer r; | |
784aacea | 55 | |
eb04c213 | 56 | for (size_t i = 0; i < tests_size; i++) |
784aacea UD |
57 | { |
58 | re_set_syntax (tests[i].syntax); | |
59 | memset (&r, 0, sizeof (r)); | |
eb04c213 AZ |
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; | |
65 | ||
784aacea UD |
66 | size_t len = strlen (tests[i].string); |
67 | int rv = re_search (&r, tests[i].string, len, 0, len, NULL); | |
eb04c213 AZ |
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); | |
71 | ||
784aacea UD |
72 | regfree (&r); |
73 | } | |
eb04c213 AZ |
74 | |
75 | return 0; | |
784aacea | 76 | } |
eb04c213 AZ |
77 | |
78 | #include <support/test-driver.c> |