Handle short and float arguments
This commit is contained in:
parent
aa9a94c8df
commit
d3be932534
3
format.h
3
format.h
@ -918,10 +918,13 @@ class BasicFormatter : public BasicWriter<Char> {
|
|||||||
};
|
};
|
||||||
mutable BasicFormatter *formatter;
|
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(int value) : type(INT), int_value(value), formatter(0) {}
|
||||||
Arg(unsigned value) : type(UINT), uint_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(long value) : type(LONG), long_value(value), formatter(0) {}
|
||||||
Arg(unsigned long value) : type(ULONG), ulong_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(double value) : type(DOUBLE), double_value(value), formatter(0) {}
|
||||||
Arg(long double value)
|
Arg(long double value)
|
||||||
: type(LONG_DOUBLE), long_double_value(value), formatter(0) {}
|
: type(LONG_DOUBLE), long_double_value(value), formatter(0) {}
|
||||||
|
@ -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) {
|
TEST(FormatterTest, FormatInt) {
|
||||||
EXPECT_THROW_MSG(Format("{0:v") << 42,
|
EXPECT_THROW_MSG(Format("{0:v") << 42,
|
||||||
FormatError, "unmatched '{' in format");
|
FormatError, "unmatched '{' in format");
|
||||||
@ -883,6 +890,10 @@ TEST(FormatterTest, FormatOct) {
|
|||||||
EXPECT_EQ(buffer, str(Format("{0:o}") << ULONG_MAX));
|
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) {
|
TEST(FormatterTest, FormatDouble) {
|
||||||
CheckUnknownTypes(1.2, "eEfFgG", "double");
|
CheckUnknownTypes(1.2, "eEfFgG", "double");
|
||||||
EXPECT_EQ("0", str(Format("{0:}") << 0.0));
|
EXPECT_EQ("0", str(Format("{0:}") << 0.0));
|
||||||
|
Loading…
Reference in New Issue
Block a user