Improve locale support

This commit is contained in:
Victor Zverovich
2018-11-14 09:39:37 -08:00
parent 1385050e26
commit f2ee988105
11 changed files with 141 additions and 65 deletions

View File

@@ -89,6 +89,7 @@ add_fmt_test(core-test)
add_fmt_test(gtest-extra-test)
add_fmt_test(format-test mock-allocator.h)
add_fmt_test(format-impl-test)
add_fmt_test(locale-test)
add_fmt_test(ostream-test)
add_fmt_test(printf-test)
add_fmt_test(time-test)

View File

@@ -603,17 +603,6 @@ TEST(StringViewTest, Ctor) {
EXPECT_EQ(4u, string_view(std::string("defg")).size());
}
// GCC 4.6 doesn't have std::is_copy_*.
#if FMT_GCC_VERSION && FMT_GCC_VERSION >= 407
TEST(WriterTest, NotCopyConstructible) {
EXPECT_FALSE(std::is_copy_constructible<fmt::writer>::value);
}
TEST(WriterTest, NotCopyAssignable) {
EXPECT_FALSE(std::is_copy_assignable<fmt::writer>::value);
}
#endif
TEST(WriterTest, Data) {
memory_buffer buf;
fmt::writer w(buf);
@@ -1947,7 +1936,7 @@ class mock_arg_formatter:
typedef buffer_range range;
mock_arg_formatter(fmt::format_context &ctx, fmt::format_specs *s = FMT_NULL)
: base(fmt::internal::get_container(ctx.out()), s) {
: base(fmt::internal::get_container(ctx.out()), s, ctx.locale()) {
EXPECT_CALL(*this, call(42));
}

21
test/locale-test.cc Normal file
View File

@@ -0,0 +1,21 @@
// Formatting library for C++ - core tests
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
#include "fmt/locale.h"
#include "gmock.h"
struct numpunct : std::numpunct<char> {
protected:
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));
}