summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-01-13 01:24:39 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2019-05-19 11:12:13 +0100
commitb055a6b5e84c046e1a6698e231d79fae359ba084 (patch)
tree10a413093bbfa6dd25ed48a9224fa368acff3c67
parentad4ede91e96b810e7d792c7ca47d8f5321caef9a (diff)
downloadlibgit2-b055a6b5e84c046e1a6698e231d79fae359ba084.tar.gz
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.
-rw-r--r--tests/core/posix.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/core/posix.c b/tests/core/posix.c
index e8b81f842..40eab0a68 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;