diff --git a/format.h b/format.h index 2d18b992..ed2eb6ae 100644 --- a/format.h +++ b/format.h @@ -552,28 +552,32 @@ class BasicWriter { BasicWriter &operator<<(unsigned value) { return *this << IntFormatter >(value, TypeSpec<0>()); } - BasicWriter &operator<<(long value) { return *this << IntFormatter >(value, TypeSpec<0>()); } /** - Formats *value* and writes it to the stream. + Formats *value* and writes it to the stream. */ BasicWriter &operator<<(unsigned long value) { return *this << IntFormatter >(value, TypeSpec<0>()); } - /** - Formats *value* using the general format for floating-point numbers - (``'g'``) and writes it to the stream. - */ BasicWriter &operator<<(double value) { FormatDouble(value, FormatSpec(), -1); return *this; } + /** + Formats *value* using the general format for floating-point numbers + (``'g'``) and writes it to the stream. + */ + BasicWriter &operator<<(long double value) { + FormatDouble(value, FormatSpec(), -1); + return *this; + } + BasicWriter &operator<<(Char value) { *GrowBuffer(1) = value; return *this; diff --git a/format_test.cc b/format_test.cc index 74fe3266..86362844 100644 --- a/format_test.cc +++ b/format_test.cc @@ -213,14 +213,14 @@ TEST(ArrayTest, Append) { EXPECT_EQ(15u, array.capacity()); } -TEST(WriterTest, WriterCtor) { +TEST(WriterTest, Ctor) { Writer w; EXPECT_EQ(0u, w.size()); EXPECT_STREQ("", w.c_str()); EXPECT_EQ("", w.str()); } -TEST(WriterTest, WriterData) { +TEST(WriterTest, Data) { Writer w; w << 42; EXPECT_EQ("42", std::string(w.data(), w.size())); @@ -249,6 +249,17 @@ TEST(WriterTest, WriteInt) { EXPECT_EQ(buffer, str(Writer() << ULONG_MAX)); } + +TEST(WriterTest, WriteDouble) { + EXPECT_EQ("4.2", str(Writer() << 4.2)); + EXPECT_EQ("-4.2", str(Writer() << -4.2)); + EXPECT_EQ("4.2", str(Writer() << 4.2l)); +} + +TEST(WriterTest, WriteString) { + EXPECT_EQ("abc", str(Writer() << "abc")); +} + TEST(WriterTest, oct) { using fmt::oct; EXPECT_EQ("12", str(Writer() << oct(static_cast(012)))); @@ -279,15 +290,6 @@ TEST(WriterTest, hexu) { EXPECT_EQ("BEEF", str(Writer() << hexu(0xbeeful))); } -TEST(WriterTest, WriteDouble) { - EXPECT_EQ("4.2", str(Writer() << 4.2)); - EXPECT_EQ("-4.2", str(Writer() << -4.2)); -} - -TEST(WriterTest, WriteString) { - EXPECT_EQ("abc", str(Writer() << "abc")); -} - class Date { int year_, month_, day_; public: