Use a more sensible locale in tests

This commit is contained in:
Victor Zverovich
2023-10-08 08:45:37 -07:00
parent bf497ac068
commit 8e0ca0589f
2 changed files with 9 additions and 11 deletions

View File

@ -743,21 +743,20 @@ TEST(chrono_test, unsigned_duration) {
} }
TEST(chrono_test, weekday) { TEST(chrono_test, weekday) {
auto loc = get_locale("ru_RU.UTF-8"); auto loc = get_locale("es_ES.UTF-8");
std::locale::global(loc); std::locale::global(loc);
auto mon = fmt::weekday(1); auto sat = fmt::weekday(6);
auto tm = std::tm(); auto tm = std::tm();
tm.tm_wday = static_cast<int>(mon.c_encoding()); tm.tm_wday = static_cast<int>(sat.c_encoding());
EXPECT_EQ(fmt::format("{}", mon), "Mon"); EXPECT_EQ(fmt::format("{}", sat), "Sat");
EXPECT_EQ(fmt::format("{:%a}", tm), "Mon"); EXPECT_EQ(fmt::format("{:%a}", tm), "Sat");
if (loc != std::locale::classic()) { if (loc != std::locale::classic()) {
EXPECT_THAT((std::vector<std::string>{"пн", "Пн", "пнд", "Пнд"}), auto saturdays = std::vector<std::string>{"sáb", "sá."};
Contains(fmt::format(loc, "{:L}", mon))); EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:L}", sat)));
EXPECT_THAT((std::vector<std::string>{"пн", "Пн", "пнд", "Пнд"}), EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:%a}", tm)));
Contains(fmt::format(loc, "{:%a}", tm)));
} }
} }

View File

@ -37,9 +37,8 @@ std::locale do_get_locale(const char* name) {
std::locale get_locale(const char* name, const char* alt_name) { std::locale get_locale(const char* name, const char* alt_name) {
auto loc = do_get_locale(name); auto loc = do_get_locale(name);
if (loc == std::locale::classic() && alt_name) { if (loc == std::locale::classic() && alt_name)
loc = do_get_locale(alt_name); loc = do_get_locale(alt_name);
}
if (loc == std::locale::classic()) if (loc == std::locale::classic())
fmt::print(stderr, "{} locale is missing.\n", name); fmt::print(stderr, "{} locale is missing.\n", name);
return loc; return loc;