mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-02 23:21:45 +01:00
More locale support
This commit is contained in:
@@ -8,14 +8,27 @@
|
||||
#include "fmt/locale.h"
|
||||
#include "gmock.h"
|
||||
|
||||
struct numpunct : std::numpunct<char> {
|
||||
template <typename Char>
|
||||
struct numpunct : std::numpunct<Char> {
|
||||
protected:
|
||||
char do_thousands_sep() const FMT_OVERRIDE { return '~'; }
|
||||
Char do_thousands_sep() const FMT_OVERRIDE { return '~'; }
|
||||
};
|
||||
|
||||
TEST(LocaleTest, Format) {
|
||||
std::locale loc;
|
||||
EXPECT_EQ("1~234~567",
|
||||
fmt::format(std::locale(loc, new numpunct()), "{:n}", 1234567));
|
||||
EXPECT_EQ("1,234,567", fmt::format(loc, "{:n}", 1234567));
|
||||
std::locale loc(std::locale(), new numpunct<char>());
|
||||
EXPECT_EQ("1,234,567", fmt::format(std::locale(), "{:n}", 1234567));
|
||||
EXPECT_EQ("1~234~567", fmt::format(loc, "{:n}", 1234567));
|
||||
fmt::format_arg_store<fmt::format_context, int> as{1234567};
|
||||
EXPECT_EQ("1~234~567", fmt::vformat(loc, "{:n}", fmt::format_args(as)));
|
||||
std::string s;
|
||||
fmt::format_to(std::back_inserter(s), loc, "{:n}", 1234567);
|
||||
EXPECT_EQ("1~234~567", s);
|
||||
}
|
||||
|
||||
TEST(LocaleTest, WFormat) {
|
||||
std::locale loc(std::locale(), new numpunct<wchar_t>());
|
||||
EXPECT_EQ(L"1,234,567", fmt::format(std::locale(), L"{:n}", 1234567));
|
||||
EXPECT_EQ(L"1~234~567", fmt::format(loc, L"{:n}", 1234567));
|
||||
fmt::format_arg_store<fmt::wformat_context, int> as{1234567};
|
||||
EXPECT_EQ(L"1~234~567", fmt::vformat(loc, L"{:n}", fmt::wformat_args(as)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user