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