diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/seastar/fmt/test/locale-test.cc | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/seastar/fmt/test/locale-test.cc')
-rw-r--r-- | src/seastar/fmt/test/locale-test.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/seastar/fmt/test/locale-test.cc b/src/seastar/fmt/test/locale-test.cc new file mode 100644 index 00000000..83b0f316 --- /dev/null +++ b/src/seastar/fmt/test/locale-test.cc @@ -0,0 +1,34 @@ +// Formatting library for C++ - locale 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" + +template <typename Char> +struct numpunct : std::numpunct<Char> { + protected: + Char do_thousands_sep() const FMT_OVERRIDE { return '~'; } +}; + +TEST(LocaleTest, Format) { + 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))); +} |