1 /* Test RE_HAT_LISTS_NOT_NEWLINE and RE_DOT_NEWLINE.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
23 #include <support/test-driver.h>
24 #include <support/check.h>
33 static const struct tests tests
[] = {
34 #define EGREP RE_SYNTAX_EGREP
35 #define EGREP_NL (RE_SYNTAX_EGREP | RE_DOT_NEWLINE) & ~RE_HAT_LISTS_NOT_NEWLINE
36 { "a.b", "a\nb", EGREP
, 0 },
37 { "a.b", "a\nb", EGREP_NL
, 0 },
38 { "a[^x]b", "a\nb", EGREP
, 0 },
39 { "a[^x]b", "a\nb", EGREP_NL
, 0 },
40 /* While \S and \W are internally handled as [^[:space:]] and [^[:alnum:]_],
41 RE_HAT_LISTS_NOT_NEWLINE did not make any difference, so ensure
43 { "a\\Sb", "a\nb", EGREP
, -1 },
44 { "a\\Sb", "a\nb", EGREP_NL
, -1 },
45 { "a\\Wb", "a\nb", EGREP
, 0 },
46 { "a\\Wb", "a\nb", EGREP_NL
, 0 }
48 static const size_t tests_size
= sizeof (tests
) / sizeof (tests
[0]);
53 struct re_pattern_buffer r
;
55 for (size_t i
= 0; i
< tests_size
; i
++)
57 re_set_syntax (tests
[i
].syntax
);
58 memset (&r
, 0, sizeof (r
));
59 const char *re
= re_compile_pattern (tests
[i
].regex
,
60 strlen (tests
[i
].regex
), &r
);
61 TEST_VERIFY (re
== NULL
);
65 size_t len
= strlen (tests
[i
].string
);
66 int rv
= re_search (&r
, tests
[i
].string
, len
, 0, len
, NULL
);
67 TEST_VERIFY (rv
== tests
[i
].retval
);
69 printf ("info: i=%zu rv=%d expected=%d\n", i
, rv
, tests
[i
].retval
);
77 #include <support/test-driver.c>