diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 4d6198b6..eda1f239 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -246,13 +246,6 @@ TEST(format_impl_test, format_error_code) { } } -TEST(format_impl_test, compute_width) { - EXPECT_EQ(4, - fmt::detail::compute_width( - fmt::basic_string_view( - reinterpret_cast("ёжик")))); -} - // Tests fmt::detail::count_digits for integer type Int. template void test_count_digits() { for (Int i = 0; i < 10; ++i) EXPECT_EQ(1u, fmt::detail::count_digits(i)); diff --git a/test/format-test.cc b/test/format-test.cc index 08b4e8c1..34eb28a3 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -173,6 +173,10 @@ TEST(util_test, parse_nonnegative_int) { EXPECT_EQ(fmt::detail::parse_nonnegative_int(begin, end, -1), -1); } +TEST(format_impl_test, compute_width) { + EXPECT_EQ(fmt::detail::compute_width("вожык"), 5); +} + TEST(util_test, utf8_to_utf16) { auto u = fmt::detail::utf8_to_utf16("лошадка"); EXPECT_EQ(L"\x043B\x043E\x0448\x0430\x0434\x043A\x0430", u.str()); @@ -1053,6 +1057,12 @@ TEST(format_test, precision) { EXPECT_EQ("123456", fmt::format("{0:.6}", "123456\xad")); } +TEST(xchar_test, utf8_precision) { + auto result = fmt::format("{:.4}", "caf\u00e9s"); // cafés + EXPECT_EQ(fmt::detail::compute_width(result), 4); + EXPECT_EQ(result, "caf\u00e9"); +} + TEST(format_test, runtime_precision) { char format_str[buffer_size]; safe_sprintf(format_str, "{0:.{%u", UINT_MAX); diff --git a/test/xchar-test.cc b/test/xchar-test.cc index f72e94dc..90ada586 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -187,18 +187,6 @@ template std::string from_u8str(const S& str) { return std::string(str.begin(), str.end()); } -TEST(xchar_test, format_utf8_precision) { - using str_type = std::basic_string; - auto format = - str_type(reinterpret_cast(u8"{:.4}")); - auto str = str_type(reinterpret_cast( - u8"caf\u00e9s")); // cafés - auto result = fmt::format(format, str); - EXPECT_EQ(fmt::detail::compute_width(result), 4); - EXPECT_EQ(result.size(), 5); - EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5))); -} - TEST(xchar_test, format_to) { auto buf = std::vector(); fmt::format_to(std::back_inserter(buf), L"{}{}", 42, L'\0');