From 871e2bff992eda54f8192dd4425ebae3539c2e9a Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Tue, 7 May 2019 22:29:54 +0700 Subject: [PATCH] Move `test_count_digits` block from `format-test.cc` --- test/format-impl-test.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 33263aaa..d6f85a37 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -237,3 +237,19 @@ TEST(FormatTest, FormatErrorCode) { TEST(FormatTest, CountCodePoints) { EXPECT_EQ(4, fmt::internal::count_code_points(fmt::u8string_view("ёжик"))); } + +// Tests fmt::internal::count_digits for integer type Int. +template void test_count_digits() { + for (Int i = 0; i < 10; ++i) EXPECT_EQ(1u, fmt::internal::count_digits(i)); + for (Int i = 1, n = 1, end = std::numeric_limits::max() / 10; n <= end; + ++i) { + n *= 10; + EXPECT_EQ(i, fmt::internal::count_digits(n - 1)); + EXPECT_EQ(i + 1, fmt::internal::count_digits(n)); + } +} + +TEST(UtilTest, CountDigits) { + test_count_digits(); + test_count_digits(); +}