diff options
Diffstat (limited to 'test/format-test.cc')
-rw-r--r-- | test/format-test.cc | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/test/format-test.cc b/test/format-test.cc index 128b57a2..8ed524cc 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1270,6 +1270,8 @@ TEST(FormatterTest, FormatDouble) { EXPECT_EQ(buffer, format("{:a}", -42.0)); safe_sprintf(buffer, "%A", -42.0); EXPECT_EQ(buffer, format("{:A}", -42.0)); + EXPECT_EQ("9223372036854775808.000000", + format("{:f}", 9223372036854775807.0)); } TEST(FormatterTest, PrecisionRounding) { @@ -1943,10 +1945,12 @@ TEST(FormatTest, FormatToN) { EXPECT_EQ(5u, result.size); EXPECT_EQ(buffer + 3, result.out); EXPECT_EQ("123x", fmt::string_view(buffer, 4)); + result = fmt::format_to_n(buffer, 3, "{:s}", "foobar"); EXPECT_EQ(6u, result.size); EXPECT_EQ(buffer + 3, result.out); EXPECT_EQ("foox", fmt::string_view(buffer, 4)); + buffer[0] = 'x'; buffer[1] = 'x'; buffer[2] = 'x'; @@ -1954,10 +1958,20 @@ TEST(FormatTest, FormatToN) { EXPECT_EQ(1u, result.size); EXPECT_EQ(buffer + 1, result.out); EXPECT_EQ("Axxx", fmt::string_view(buffer, 4)); + result = fmt::format_to_n(buffer, 3, "{}{} ", 'B', 'C'); EXPECT_EQ(3u, result.size); EXPECT_EQ(buffer + 3, result.out); EXPECT_EQ("BC x", fmt::string_view(buffer, 4)); + + result = fmt::format_to_n(buffer, 4, "{}", "ABCDE"); + EXPECT_EQ(5u, result.size); + EXPECT_EQ("ABCD", fmt::string_view(buffer, 4)); + + buffer[3] = 'x'; + result = fmt::format_to_n(buffer, 3, "{}", std::string(1000, '*')); + EXPECT_EQ(1000u, result.size); + EXPECT_EQ("***x", fmt::string_view(buffer, 4)); } TEST(FormatTest, WideFormatToN) { @@ -2414,11 +2428,13 @@ TEST(FormatTest, CharTraitsIsNotAmbiguous) { #endif } +#if __cplusplus > 201103L struct custom_char { int value; custom_char() = default; - template <typename T> custom_char(T val) : value(static_cast<int>(val)) {} + template <typename T> + constexpr custom_char(T val) : value(static_cast<int>(val)) {} operator int() const { return value; } }; @@ -2435,6 +2451,7 @@ TEST(FormatTest, FormatCustomChar) { EXPECT_EQ(result.size(), 1); EXPECT_EQ(result[0], custom_char('x')); } +#endif // Convert a char8_t string to std::string. Otherwise GTest will insist on // inserting `char8_t` NTBS into a `char` stream which is disabled by P1423. |