Skip to content

Commit

Permalink
Use a more sensible locale in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Oct 8, 2023
1 parent bf497ac commit 8e0ca05
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
17 changes: 8 additions & 9 deletions test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -743,21 +743,20 @@ TEST(chrono_test, unsigned_duration) {
}

TEST(chrono_test, weekday) {
auto loc = get_locale("ru_RU.UTF-8");
auto loc = get_locale("es_ES.UTF-8");
std::locale::global(loc);
auto mon = fmt::weekday(1);
auto sat = fmt::weekday(6);

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("{:%a}", tm), "Mon");
EXPECT_EQ(fmt::format("{}", sat), "Sat");
EXPECT_EQ(fmt::format("{:%a}", tm), "Sat");

if (loc != std::locale::classic()) {
EXPECT_THAT((std::vector<std::string>{"пн", "Пн", "пнд", "Пнд"}),
Contains(fmt::format(loc, "{:L}", mon)));
EXPECT_THAT((std::vector<std::string>{"пн", "Пн", "пнд", "Пнд"}),
Contains(fmt::format(loc, "{:%a}", tm)));
auto saturdays = std::vector<std::string>{"sáb", "sá."};
EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:L}", sat)));
EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:%a}", tm)));
}
}

Expand Down
3 changes: 1 addition & 2 deletions test/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ std::locale do_get_locale(const char* name) {

std::locale get_locale(const char* name, const char* alt_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);
}
if (loc == std::locale::classic())
fmt::print(stderr, "{} locale is missing.\n", name);
return loc;
Expand Down

0 comments on commit 8e0ca05

Please sign in to comment.