2021-05-24 13:20:51 +00:00
|
|
|
// Formatting library for C++ - Unicode tests
|
|
|
|
//
|
|
|
|
// Copyright (c) 2012 - present, Victor Zverovich
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// For the license information refer to format.h.
|
|
|
|
|
2021-05-24 19:22:52 +00:00
|
|
|
#include <iomanip>
|
|
|
|
#include <locale>
|
2021-05-24 14:23:56 +00:00
|
|
|
#include <vector>
|
2021-05-24 13:20:51 +00:00
|
|
|
|
2021-05-24 14:23:56 +00:00
|
|
|
#include "fmt/chrono.h"
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "util.h" // get_locale
|
|
|
|
|
|
|
|
using testing::Contains;
|
|
|
|
|
|
|
|
TEST(unicode_test, is_utf8) { EXPECT_TRUE(fmt::detail::is_utf8()); }
|
|
|
|
|
|
|
|
TEST(unicode_test, legacy_locale) {
|
2022-08-20 14:18:30 +00:00
|
|
|
auto loc = get_locale("be_BY.CP1251", "Belarussian_Belarus.1251");
|
2021-05-24 14:23:56 +00:00
|
|
|
if (loc == std::locale::classic()) return;
|
2021-05-24 19:22:52 +00:00
|
|
|
|
|
|
|
auto s = std::string();
|
2021-05-24 14:23:56 +00:00
|
|
|
try {
|
2022-08-20 14:18:30 +00:00
|
|
|
s = fmt::format(loc, "Дзень тыдня: {:L}", fmt::weekday(1));
|
2021-05-24 14:23:56 +00:00
|
|
|
} catch (const fmt::format_error& e) {
|
2021-05-24 19:22:52 +00:00
|
|
|
// Formatting can fail due to an unsupported encoding.
|
2021-05-24 14:23:56 +00:00
|
|
|
fmt::print("Format error: {}\n", e.what());
|
2021-05-24 19:22:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 500
|
|
|
|
auto&& os = std::ostringstream();
|
|
|
|
os.imbue(loc);
|
|
|
|
auto tm = std::tm();
|
|
|
|
tm.tm_wday = 1;
|
|
|
|
os << std::put_time(&tm, "%a");
|
|
|
|
auto wd = os.str();
|
|
|
|
if (wd == "??") {
|
2022-08-20 14:18:30 +00:00
|
|
|
EXPECT_EQ(s, "Дзень тыдня: ??");
|
2021-05-24 19:22:52 +00:00
|
|
|
fmt::print("std::locale gives ?? as a weekday.\n");
|
|
|
|
return;
|
2021-05-24 14:23:56 +00:00
|
|
|
}
|
2021-05-24 19:22:52 +00:00
|
|
|
#endif
|
2022-08-20 14:18:30 +00:00
|
|
|
EXPECT_THAT((std::vector<std::string>{"Дзень тыдня: пн", "Дзень тыдня: Пан"}),
|
2021-05-24 19:22:52 +00:00
|
|
|
Contains(s));
|
2021-05-24 14:23:56 +00:00
|
|
|
}
|