Add support for long and unsigned long in Writer.
This commit is contained in:
parent
e89c60d63e
commit
2a9f358d7e
8
format.h
8
format.h
@ -499,6 +499,14 @@ class BasicWriter {
|
||||
return *this << IntFormatter<unsigned, TypeSpec<0> >(value, TypeSpec<0>());
|
||||
}
|
||||
|
||||
BasicWriter &operator<<(long value) {
|
||||
return *this << IntFormatter<long, TypeSpec<0> >(value, TypeSpec<0>());
|
||||
}
|
||||
BasicWriter &operator<<(unsigned long value) {
|
||||
return *this <<
|
||||
IntFormatter<unsigned long, TypeSpec<0> >(value, TypeSpec<0>());
|
||||
}
|
||||
|
||||
BasicWriter &operator<<(double value) {
|
||||
FormatDouble(value, FormatSpec(), -1);
|
||||
return *this;
|
||||
|
@ -220,9 +220,33 @@ TEST(WriterTest, WriterCtor) {
|
||||
EXPECT_EQ("", w.str());
|
||||
}
|
||||
|
||||
TEST(WriterTest, WriterData) {
|
||||
Writer w;
|
||||
w << 42;
|
||||
EXPECT_EQ("42", std::string(w.data(), w.size()));
|
||||
}
|
||||
|
||||
TEST(WriterTest, WriteInt) {
|
||||
EXPECT_EQ("42", str(Writer() << 42));
|
||||
EXPECT_EQ("-42", str(Writer() << -42));
|
||||
EXPECT_EQ("12", str(Writer() << static_cast<short>(12)));
|
||||
EXPECT_EQ("34", str(Writer() << 34u));
|
||||
EXPECT_EQ("56", str(Writer() << 56l));
|
||||
EXPECT_EQ("78", str(Writer() << 78ul));
|
||||
|
||||
char buffer[BUFFER_SIZE];
|
||||
SPrintf(buffer, "%d", INT_MIN);
|
||||
EXPECT_EQ(buffer, str(Writer() << INT_MIN));
|
||||
SPrintf(buffer, "%d", INT_MAX);
|
||||
EXPECT_EQ(buffer, str(Writer() << INT_MAX));
|
||||
SPrintf(buffer, "%u", UINT_MAX);
|
||||
EXPECT_EQ(buffer, str(Writer() << UINT_MAX));
|
||||
SPrintf(buffer, "%ld", 0 - static_cast<unsigned long>(LONG_MIN));
|
||||
EXPECT_EQ(buffer, str(Writer() << LONG_MIN));
|
||||
SPrintf(buffer, "%ld", LONG_MAX);
|
||||
EXPECT_EQ(buffer, str(Writer() << LONG_MAX));
|
||||
SPrintf(buffer, "%lu", ULONG_MAX);
|
||||
EXPECT_EQ(buffer, str(Writer() << ULONG_MAX));
|
||||
}
|
||||
|
||||
TEST(WriterTest, oct) {
|
||||
|
Loading…
Reference in New Issue
Block a user