diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/fmt/test/locale-test.cc | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/fmt/test/locale-test.cc')
-rw-r--r-- | contrib/libs/fmt/test/locale-test.cc | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/contrib/libs/fmt/test/locale-test.cc b/contrib/libs/fmt/test/locale-test.cc index ef346ab6be..7d776b4290 100644 --- a/contrib/libs/fmt/test/locale-test.cc +++ b/contrib/libs/fmt/test/locale-test.cc @@ -1,102 +1,102 @@ -// 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" +// 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 <complex> -#include <gmock/gmock.h> - +#include <gmock/gmock.h> + using fmt::detail::max_value; - -#ifndef FMT_STATIC_THOUSANDS_SEPARATOR -template <typename Char> struct numpunct : std::numpunct<Char> { - protected: - Char do_decimal_point() const FMT_OVERRIDE { return '?'; } - std::string do_grouping() const FMT_OVERRIDE { return "\03"; } - Char do_thousands_sep() const FMT_OVERRIDE { return '~'; } -}; - -template <typename Char> struct no_grouping : std::numpunct<Char> { - protected: - Char do_decimal_point() const FMT_OVERRIDE { return '.'; } - std::string do_grouping() const FMT_OVERRIDE { return ""; } - Char do_thousands_sep() const FMT_OVERRIDE { return ','; } -}; - -template <typename Char> struct special_grouping : std::numpunct<Char> { - protected: - Char do_decimal_point() const FMT_OVERRIDE { return '.'; } - std::string do_grouping() const FMT_OVERRIDE { return "\03\02"; } - Char do_thousands_sep() const FMT_OVERRIDE { return ','; } -}; - -template <typename Char> struct small_grouping : std::numpunct<Char> { - protected: - Char do_decimal_point() const FMT_OVERRIDE { return '.'; } - std::string do_grouping() const FMT_OVERRIDE { return "\01"; } - Char do_thousands_sep() const FMT_OVERRIDE { return ','; } -}; - -TEST(LocaleTest, DoubleDecimalPoint) { - std::locale loc(std::locale(), new numpunct<char>()); + +#ifndef FMT_STATIC_THOUSANDS_SEPARATOR +template <typename Char> struct numpunct : std::numpunct<Char> { + protected: + Char do_decimal_point() const FMT_OVERRIDE { return '?'; } + std::string do_grouping() const FMT_OVERRIDE { return "\03"; } + Char do_thousands_sep() const FMT_OVERRIDE { return '~'; } +}; + +template <typename Char> struct no_grouping : std::numpunct<Char> { + protected: + Char do_decimal_point() const FMT_OVERRIDE { return '.'; } + std::string do_grouping() const FMT_OVERRIDE { return ""; } + Char do_thousands_sep() const FMT_OVERRIDE { return ','; } +}; + +template <typename Char> struct special_grouping : std::numpunct<Char> { + protected: + Char do_decimal_point() const FMT_OVERRIDE { return '.'; } + std::string do_grouping() const FMT_OVERRIDE { return "\03\02"; } + Char do_thousands_sep() const FMT_OVERRIDE { return ','; } +}; + +template <typename Char> struct small_grouping : std::numpunct<Char> { + protected: + Char do_decimal_point() const FMT_OVERRIDE { return '.'; } + std::string do_grouping() const FMT_OVERRIDE { return "\01"; } + Char do_thousands_sep() const FMT_OVERRIDE { return ','; } +}; + +TEST(LocaleTest, DoubleDecimalPoint) { + std::locale loc(std::locale(), new numpunct<char>()); EXPECT_EQ("1?23", fmt::format(loc, "{:L}", 1.23)); -} - -TEST(LocaleTest, Format) { - std::locale loc(std::locale(), new numpunct<char>()); +} + +TEST(LocaleTest, Format) { + std::locale loc(std::locale(), new numpunct<char>()); EXPECT_EQ("1234567", fmt::format(std::locale(), "{:L}", 1234567)); EXPECT_EQ("1~234~567", fmt::format(loc, "{:L}", 1234567)); EXPECT_EQ("-1~234~567", fmt::format(loc, "{:L}", -1234567)); EXPECT_EQ("-256", fmt::format(loc, "{:L}", -256)); - fmt::format_arg_store<fmt::format_context, int> as{1234567}; + fmt::format_arg_store<fmt::format_context, int> as{1234567}; EXPECT_EQ("1~234~567", fmt::vformat(loc, "{:L}", fmt::format_args(as))); - std::string s; + std::string s; fmt::format_to(std::back_inserter(s), loc, "{:L}", 1234567); - EXPECT_EQ("1~234~567", s); - - std::locale no_grouping_loc(std::locale(), new no_grouping<char>()); + EXPECT_EQ("1~234~567", s); + + std::locale no_grouping_loc(std::locale(), new no_grouping<char>()); EXPECT_EQ("1234567", fmt::format(no_grouping_loc, "{:L}", 1234567)); - - std::locale special_grouping_loc(std::locale(), new special_grouping<char>()); + + std::locale special_grouping_loc(std::locale(), new special_grouping<char>()); EXPECT_EQ("1,23,45,678", fmt::format(special_grouping_loc, "{:L}", 12345678)); EXPECT_EQ("12,345", fmt::format(special_grouping_loc, "{:L}", 12345)); - - std::locale small_grouping_loc(std::locale(), new small_grouping<char>()); - EXPECT_EQ("4,2,9,4,9,6,7,2,9,5", + + std::locale small_grouping_loc(std::locale(), new small_grouping<char>()); + EXPECT_EQ("4,2,9,4,9,6,7,2,9,5", fmt::format(small_grouping_loc, "{:L}", max_value<uint32_t>())); -} - +} + TEST(LocaleTest, FormatDetaultAlign) { std::locale special_grouping_loc(std::locale(), new special_grouping<char>()); EXPECT_EQ(" 12,345", fmt::format(special_grouping_loc, "{:8L}", 12345)); } -TEST(LocaleTest, WFormat) { - std::locale loc(std::locale(), new numpunct<wchar_t>()); +TEST(LocaleTest, WFormat) { + std::locale loc(std::locale(), new numpunct<wchar_t>()); EXPECT_EQ(L"1234567", fmt::format(std::locale(), L"{:L}", 1234567)); EXPECT_EQ(L"1~234~567", fmt::format(loc, L"{:L}", 1234567)); - fmt::format_arg_store<fmt::wformat_context, int> as{1234567}; + fmt::format_arg_store<fmt::wformat_context, int> as{1234567}; EXPECT_EQ(L"1~234~567", fmt::vformat(loc, L"{:L}", fmt::wformat_args(as))); EXPECT_EQ(L"1234567", fmt::format(std::locale("C"), L"{:L}", 1234567)); - - std::locale no_grouping_loc(std::locale(), new no_grouping<wchar_t>()); + + std::locale no_grouping_loc(std::locale(), new no_grouping<wchar_t>()); EXPECT_EQ(L"1234567", fmt::format(no_grouping_loc, L"{:L}", 1234567)); - - std::locale special_grouping_loc(std::locale(), - new special_grouping<wchar_t>()); - EXPECT_EQ(L"1,23,45,678", + + std::locale special_grouping_loc(std::locale(), + new special_grouping<wchar_t>()); + EXPECT_EQ(L"1,23,45,678", fmt::format(special_grouping_loc, L"{:L}", 12345678)); - - std::locale small_grouping_loc(std::locale(), new small_grouping<wchar_t>()); - EXPECT_EQ(L"4,2,9,4,9,6,7,2,9,5", + + std::locale small_grouping_loc(std::locale(), new small_grouping<wchar_t>()); + EXPECT_EQ(L"4,2,9,4,9,6,7,2,9,5", fmt::format(small_grouping_loc, L"{:L}", max_value<uint32_t>())); -} - +} + TEST(LocaleTest, DoubleFormatter) { auto loc = std::locale(std::locale(), new special_grouping<char>()); auto f = fmt::formatter<int>(); @@ -157,4 +157,4 @@ TEST(FormatTest, Complex) { EXPECT_EQ(fmt::format("{:8}", std::complex<double>(1, 2)), " (1+2i)"); } -#endif // FMT_STATIC_THOUSANDS_SEPARATOR +#endif // FMT_STATIC_THOUSANDS_SEPARATOR |