tests: regex: add test with LC_COLLATE being set While we already have a test for `p_regexec` with `LC_CTYPE` being modified, `regexec` also alters behavior as soon as `LC_COLLATE` is being modified. Most importantly, `LC_COLLATE` changes the way how ranges are interpreted to just not handling them at all. Thus, ensure that either we use `regcomp_l` to avoid this, or that we've fallen back to our builtin regex functionality which also behaves properly.
diff --git a/tests/core/posix.c b/tests/core/posix.c
index e8b81f8..40eab0a 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -177,6 +177,31 @@ void test_core_posix__p_regcomp_ignores_global_locale_ctype(void)
cl_must_pass(error);
}
+void test_core_posix__p_regcomp_ignores_global_locale_collate(void)
+{
+ regex_t preg;
+ int error = 0;
+
+ const char* oldlocale = setlocale(LC_COLLATE, NULL);
+
+ if (!setlocale(LC_COLLATE, "UTF-8") &&
+ !setlocale(LC_COLLATE, "c.utf8") &&
+ !setlocale(LC_COLLATE, "en_US.UTF-8"))
+ cl_skip();
+
+ if (MB_CUR_MAX == 1) {
+ setlocale(LC_COLLATE, oldlocale);
+ cl_fail("Expected locale to be switched to multibyte");
+ }
+
+ error = p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED);
+ regfree(&preg);
+
+ setlocale(LC_COLLATE, oldlocale);
+
+ cl_must_pass(error);
+}
+
void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
{
size_t idx;