Skip to content

Commit aea9a71

Browse files
pks-tethomson
authored andcommitted
tests: regcomp: assert character groups do match normal alphabet
In order to avoid us being unable to match characters which are part of the normal US alphabet in certain weird languages, add two tests to catch this behavior.
1 parent e207b2a commit aea9a71

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/core/posix.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,48 @@ void test_core_posix__p_regcomp_ignores_global_locale_collate(void)
197197
p_regfree(&preg);
198198
}
199199

200+
void test_core_posix__p_regcomp_matches_digits_with_locale(void)
201+
{
202+
p_regex_t preg;
203+
char c, str[2];
204+
205+
try_set_locale(LC_COLLATE);
206+
try_set_locale(LC_CTYPE);
207+
208+
cl_must_pass(p_regcomp(&preg, "[:digit:]", P_REG_EXTENDED));
209+
210+
str[1] = '\0';
211+
for (c = '0'; c <= '9'; c++) {
212+
str[0] = c;
213+
cl_must_pass(p_regexec(&preg, str, 0, NULL, 0));
214+
}
215+
216+
p_regfree(&preg);
217+
}
218+
219+
void test_core_posix__p_regcomp_matches_alphabet_with_locale(void)
220+
{
221+
p_regex_t preg;
222+
char c, str[2];
223+
224+
try_set_locale(LC_COLLATE);
225+
try_set_locale(LC_CTYPE);
226+
227+
cl_must_pass(p_regcomp(&preg, "[:alpha:]", REG_EXTENDED));
228+
229+
str[1] = '\0';
230+
for (c = 'a'; c <= 'z'; c++) {
231+
str[0] = c;
232+
cl_must_pass(p_regexec(&preg, str, 0, NULL, 0));
233+
}
234+
for (c = 'A'; c <= 'Z'; c++) {
235+
str[0] = c;
236+
cl_must_pass(p_regexec(&preg, str, 0, NULL, 0));
237+
}
238+
239+
p_regfree(&preg);
240+
}
241+
200242
void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
201243
{
202244
size_t idx;

0 commit comments

Comments
 (0)