1 | /* Turkish regular expression tests. |
2 | Copyright (C) 2002-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 | /* \xc4\xb0 LATIN CAPITAL LETTER I WITH DOT ABOVE |
35 | \xc4\xb1 LATIN SMALL LETTER DOTLESS I |
36 | \xe2\x80\x94 EM DASH */ |
37 | { "\xc4\xb0I*\xc4\xb1$" , "aBi\xc4\xb1\xc4\xb1I" , REG_ICASE, 2, |
38 | { { .rm_so: 2, .rm_eo: 8 }, { -1, -1 } } }, |
39 | { "[\xc4\xb0x]I*\xc4\xb1$" , "aBi\xc4\xb1\xc4\xb1I" , REG_ICASE, 2, |
40 | { { 2, 8 }, { -1, -1 } } }, |
41 | { "[^x]I*\xc4\xb1$" , "aBi\xc4\xb1\xc4\xb1I" , REG_ICASE, 2, |
42 | { { 2, 8 }, { -1, -1 } } }, |
43 | { "([[:alpha:]]i[[:xdigit:]])(\xc4\xb1*)(\xc4\xb0{2})" , |
44 | "\xe2\x80\x94\xc4\xb1\xc4\xb0" "fIi\xc4\xb0ii" , REG_ICASE | REG_EXTENDED, |
45 | 4, { { 3, 12 }, { 3, 8 }, { 8, 9 }, { 9, 12 } } }, |
46 | { "\xc4\xb1i(i)*()(\\s\xc4\xb0|\\SI)" , "SIi\xc4\xb0\xc4\xb0 is" , |
47 | REG_ICASE | REG_EXTENDED, 4, { { 1, 9 }, { 5, 7 }, { 7, 7 }, { 7, 9 } } }, |
48 | { "\xc4\xb1i(i)*()(\\s\xc4\xb0|\\SI)" , "\xc4\xb1\xc4\xb0\xc4\xb0iJ\xc4\xb1" , |
49 | REG_ICASE | REG_EXTENDED, 4, |
50 | { { 0, 10 }, { 6, 7 }, { 7, 7 }, { 7, 10 } } }, |
51 | }; |
52 | |
53 | int |
54 | main (void) |
55 | { |
56 | regex_t re; |
57 | regmatch_t rm[5]; |
58 | size_t i; |
59 | int n, ret = 0; |
60 | |
61 | setlocale (LC_ALL, "tr_TR.UTF-8" ); |
62 | for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) |
63 | { |
64 | n = regcomp (preg: &re, pattern: tests[i].pattern, cflags: tests[i].flags); |
65 | if (n != 0) |
66 | { |
67 | char buf[500]; |
68 | regerror (errcode: n, preg: &re, errbuf: buf, errbuf_size: sizeof (buf)); |
69 | printf (format: "regcomp %zd failed: %s\n" , i, buf); |
70 | ret = 1; |
71 | continue; |
72 | } |
73 | |
74 | if (regexec (preg: &re, String: tests[i].string, nmatch: tests[i].nmatch, pmatch: rm, eflags: 0)) |
75 | { |
76 | printf (format: "regexec %zd failed\n" , i); |
77 | ret = 1; |
78 | regfree (preg: &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 (format: "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 (preg: &re); |
95 | } |
96 | |
97 | return ret; |
98 | } |
99 | |