1 /* Russian regular expression tests.
2 Copyright (C) 2009-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 #include <sys/types.h>
20 #include <mcheck.h>
21 #include <regex.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <locale.h>
25
26 /* Tests supposed to match. */
27 struct
28 {
29 const char *pattern;
30 const char *string;
31 int flags, nmatch;
32 regmatch_t rm[5];
33 } tests[] = {
34 /* U+0413 \xd0\x93 CYRILLIC CAPITAL LETTER GHE
35 U+0420 \xd0\xa0 CYRILLIC CAPITAL LETTER ER
36 U+0430 \xd0\xb0 CYRILLIC SMALL LETTER A
37 U+0433 \xd0\xb3 CYRILLIC SMALL LETTER GHE
38 U+0440 \xd1\x80 CYRILLIC SMALL LETTER ER
39 U+044F \xd1\x8f CYRILLIC SMALL LETTER YA */
40 { "[\xd0\xb0-\xd1\x8f]", "\xd0\xb3", 0, 1,
41 { { 0, 2 } } },
42 { "[\xd0\xb0-\xd1\x8f]", "\xd0\x93", REG_ICASE, 1,
43 { { 0, 2 } } },
44 { "[\xd1\x80-\xd1\x8f]", "\xd0\xa0", REG_ICASE, 1,
45 { { 0, 2 } } },
46 };
47
48
49 static int
do_test(void)50 do_test (void)
51 {
52 if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
53 {
54 puts ("setlocale failed");
55 return 1;
56 }
57
58 int ret = 0;
59
60 for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
61 {
62 regex_t re;
63 regmatch_t rm[5];
64 int n = regcomp (&re, tests[i].pattern, tests[i].flags);
65 if (n != 0)
66 {
67 char buf[500];
68 regerror (n, &re, buf, sizeof (buf));
69 printf ("regcomp %zd failed: %s\n", i, buf);
70 ret = 1;
71 continue;
72 }
73
74 if (regexec (&re, tests[i].string, tests[i].nmatch, rm, 0))
75 {
76 printf ("regexec %zd failed\n", i);
77 ret = 1;
78 regfree (&re);
79 continue;
80 }
81
82 for (n = 0; n < tests[i].nmatch; ++n)
83 if (rm[n].rm_so != tests[i].rm[n].rm_so
84 || rm[n].rm_eo != tests[i].rm[n].rm_eo)
85 {
86 if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
87 break;
88 printf ("regexec match failure rm[%d] %d..%d\n",
89 n, rm[n].rm_so, rm[n].rm_eo);
90 ret = 1;
91 break;
92 }
93
94 regfree (&re);
95 }
96
97 return ret;
98 }
99
100 #define TEST_FUNCTION do_test ()
101 #include "../test-skeleton.c"
102