diff --git a/format.h b/format.h index a433f6b9..c80ec50a 100644 --- a/format.h +++ b/format.h @@ -918,10 +918,13 @@ class BasicFormatter : public BasicWriter { }; 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) {} diff --git a/format_test.cc b/format_test.cc index c7c0b15a..c8cb182e 100644 --- a/format_test.cc +++ b/format_test.cc @@ -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));