Handle short and float arguments

This commit is contained in:
Victor Zverovich 2013-03-31 07:01:09 -07:00
parent aa9a94c8df
commit d3be932534
2 changed files with 14 additions and 0 deletions

View File

@ -918,10 +918,13 @@ class BasicFormatter : public BasicWriter<Char> {
};
mutable BasicFormatter *formatter;
Arg(short value) : type(INT), int_value(value), formatter(0) {}
Arg(unsigned short value) : type(UINT), int_value(value), formatter(0) {}
Arg(int value) : type(INT), int_value(value), formatter(0) {}
Arg(unsigned value) : type(UINT), uint_value(value), formatter(0) {}
Arg(long value) : type(LONG), long_value(value), formatter(0) {}
Arg(unsigned long value) : type(ULONG), ulong_value(value), formatter(0) {}
Arg(float value) : type(DOUBLE), double_value(value), formatter(0) {}
Arg(double value) : type(DOUBLE), double_value(value), formatter(0) {}
Arg(long double value)
: type(LONG_DOUBLE), long_double_value(value), formatter(0) {}

View File

@ -809,6 +809,13 @@ void CheckUnknownTypes(
}
}
TEST(FormatterTest, FormatShort) {
short s = 42;
EXPECT_EQ("42", str(Format("{0:d}") << s));
unsigned short us = 42;
EXPECT_EQ("42", str(Format("{0:d}") << us));
}
TEST(FormatterTest, FormatInt) {
EXPECT_THROW_MSG(Format("{0:v") << 42,
FormatError, "unmatched '{' in format");
@ -883,6 +890,10 @@ TEST(FormatterTest, FormatOct) {
EXPECT_EQ(buffer, str(Format("{0:o}") << ULONG_MAX));
}
TEST(FormatterTest, FormatFloat) {
EXPECT_EQ("392.500000", str(Format("{0:f}") << 392.5f));
}
TEST(FormatterTest, FormatDouble) {
CheckUnknownTypes(1.2, "eEfFgG", "double");
EXPECT_EQ("0", str(Format("{0:}") << 0.0));