diff --git a/test/printf-test.cc b/test/printf-test.cc index f31e21df..616afc55 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -300,12 +300,16 @@ template std::string sprintf_int(std::string format, U value) { char buffer[BUFFER_SIZE]; char type = format[format.size() - 1]; - if (type == 'd' || type == 'i') { - typedef typename MakeSigned::Type Signed; - safe_sprintf(buffer, format.c_str(), static_cast(value)); + if (sizeof(T) < sizeof(U)) { + if (type == 'd' || type == 'i') { + typedef typename MakeSigned::Type Signed; + safe_sprintf(buffer, format.c_str(), static_cast(value)); + } else { + typedef typename fmt::internal::MakeUnsigned::Type Unsigned; + safe_sprintf(buffer, format.c_str(), static_cast(value)); + } } else { - typedef typename fmt::internal::MakeUnsigned::Type Unsigned; - safe_sprintf(buffer, format.c_str(), static_cast(value)); + safe_sprintf(buffer, format.c_str(), value); } return buffer; } @@ -348,11 +352,11 @@ TEST(PrintfTest, Length) { TestLength("hh"); TestLength("h"); TestLength("h"); - EXPECT_EQ("-1", sprintf_int("%hhd", UCHAR_MAX)); - EXPECT_EQ("255", sprintf_int("%hhu", UCHAR_MAX)); - //TestLength("l"); + TestLength("l"); //TestLength("l"); // TODO: more tests + EXPECT_EQ("-1", sprintf_int("%hhd", UCHAR_MAX)); + EXPECT_EQ("255", sprintf_int("%hhu", UCHAR_MAX)); } // TODO: test type specifier