mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 19:24:48 +02:00
Fix 'l' specifier test.
This commit is contained in:
@@ -300,12 +300,16 @@ template <typename T, typename U>
|
|||||||
std::string sprintf_int(std::string format, U value) {
|
std::string sprintf_int(std::string format, U value) {
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
char type = format[format.size() - 1];
|
char type = format[format.size() - 1];
|
||||||
if (type == 'd' || type == 'i') {
|
if (sizeof(T) < sizeof(U)) {
|
||||||
typedef typename MakeSigned<T>::Type Signed;
|
if (type == 'd' || type == 'i') {
|
||||||
safe_sprintf(buffer, format.c_str(), static_cast<Signed>(value));
|
typedef typename MakeSigned<T>::Type Signed;
|
||||||
|
safe_sprintf(buffer, format.c_str(), static_cast<Signed>(value));
|
||||||
|
} else {
|
||||||
|
typedef typename fmt::internal::MakeUnsigned<T>::Type Unsigned;
|
||||||
|
safe_sprintf(buffer, format.c_str(), static_cast<Unsigned>(value));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
typedef typename fmt::internal::MakeUnsigned<T>::Type Unsigned;
|
safe_sprintf(buffer, format.c_str(), value);
|
||||||
safe_sprintf(buffer, format.c_str(), static_cast<Unsigned>(value));
|
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@@ -348,11 +352,11 @@ TEST(PrintfTest, Length) {
|
|||||||
TestLength<unsigned char>("hh");
|
TestLength<unsigned char>("hh");
|
||||||
TestLength<short>("h");
|
TestLength<short>("h");
|
||||||
TestLength<unsigned short>("h");
|
TestLength<unsigned short>("h");
|
||||||
EXPECT_EQ("-1", sprintf_int<unsigned char>("%hhd", UCHAR_MAX));
|
TestLength<long>("l");
|
||||||
EXPECT_EQ("255", sprintf_int<unsigned char>("%hhu", UCHAR_MAX));
|
|
||||||
//TestLength<long>("l");
|
|
||||||
//TestLength<unsigned long>("l");
|
//TestLength<unsigned long>("l");
|
||||||
// TODO: more tests
|
// TODO: more tests
|
||||||
|
EXPECT_EQ("-1", sprintf_int<unsigned char>("%hhd", UCHAR_MAX));
|
||||||
|
EXPECT_EQ("255", sprintf_int<unsigned char>("%hhu", UCHAR_MAX));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test type specifier
|
// TODO: test type specifier
|
||||||
|
Reference in New Issue
Block a user