mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-11 05:30:05 +00:00
Add support for long double in Writer.
This commit is contained in:
parent
1e724a9d33
commit
bcef11c0d1
16
format.h
16
format.h
@ -552,28 +552,32 @@ class BasicWriter {
|
||||
BasicWriter &operator<<(unsigned value) {
|
||||
return *this << IntFormatter<unsigned, TypeSpec<0> >(value, TypeSpec<0>());
|
||||
}
|
||||
|
||||
BasicWriter &operator<<(long value) {
|
||||
return *this << IntFormatter<long, TypeSpec<0> >(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<unsigned long, TypeSpec<0> >(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;
|
||||
|
@ -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<short>(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:
|
||||
|
Loading…
Reference in New Issue
Block a user