Format (un)signed char as integer by default (#217)

This commit is contained in:
vitaut 2015-11-05 20:46:22 -05:00
parent 9beb01d8e5
commit 7c24973637
3 changed files with 14 additions and 7 deletions

View File

@ -1045,8 +1045,8 @@ class MakeValue : public Arg {
FMT_MAKE_VALUE(float, double_value, DOUBLE) FMT_MAKE_VALUE(float, double_value, DOUBLE)
FMT_MAKE_VALUE(double, double_value, DOUBLE) FMT_MAKE_VALUE(double, double_value, DOUBLE)
FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE) FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE)
FMT_MAKE_VALUE(signed char, int_value, CHAR) FMT_MAKE_VALUE(signed char, int_value, INT)
FMT_MAKE_VALUE(unsigned char, int_value, CHAR) FMT_MAKE_VALUE(unsigned char, int_value, UINT)
FMT_MAKE_VALUE(char, int_value, CHAR) FMT_MAKE_VALUE(char, int_value, CHAR)
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)

View File

@ -1324,6 +1324,11 @@ TEST(FormatterTest, FormatChar) {
EXPECT_EQ(fmt::format("{:02X}", n), fmt::format("{:02X}", 'x')); EXPECT_EQ(fmt::format("{:02X}", n), fmt::format("{:02X}", 'x'));
} }
TEST(FormatterTest, FormatUnsignedChar) {
EXPECT_EQ("42", format("{}", static_cast<unsigned char>(42)));
EXPECT_EQ("42", format("{}", static_cast<uint8_t>(42)));
}
TEST(FormatterTest, FormatWChar) { TEST(FormatterTest, FormatWChar) {
EXPECT_EQ(L"a", format(L"{0}", L'a')); EXPECT_EQ(L"a", format(L"{0}", L'a'));
// This shouldn't compile: // This shouldn't compile:

View File

@ -471,11 +471,6 @@ TEST(ArgTest, MakeArg) {
EXPECT_ARG_(wchar_t, BOOL, bool, int, true); EXPECT_ARG_(wchar_t, BOOL, bool, int, true);
// Test char. // Test char.
EXPECT_ARG(CHAR, signed char, 'a');
EXPECT_ARG(CHAR, signed char, SCHAR_MIN);
EXPECT_ARG(CHAR, signed char, SCHAR_MAX);
EXPECT_ARG(CHAR, unsigned char, 'a');
EXPECT_ARG(CHAR, unsigned char, UCHAR_MAX );
EXPECT_ARG(CHAR, char, 'a'); EXPECT_ARG(CHAR, char, 'a');
EXPECT_ARG(CHAR, char, CHAR_MIN); EXPECT_ARG(CHAR, char, CHAR_MIN);
EXPECT_ARG(CHAR, char, CHAR_MAX); EXPECT_ARG(CHAR, char, CHAR_MAX);
@ -485,6 +480,13 @@ TEST(ArgTest, MakeArg) {
EXPECT_ARGW(CHAR, wchar_t, WCHAR_MIN); EXPECT_ARGW(CHAR, wchar_t, WCHAR_MIN);
EXPECT_ARGW(CHAR, wchar_t, WCHAR_MAX); EXPECT_ARGW(CHAR, wchar_t, WCHAR_MAX);
// Test signed/unsigned char.
EXPECT_ARG(INT, signed char, 42);
EXPECT_ARG(INT, signed char, SCHAR_MIN);
EXPECT_ARG(INT, signed char, SCHAR_MAX);
EXPECT_ARG(UINT, unsigned char, 42);
EXPECT_ARG(UINT, unsigned char, UCHAR_MAX );
// Test short. // Test short.
EXPECT_ARG(INT, short, 42); EXPECT_ARG(INT, short, 42);
EXPECT_ARG(INT, short, SHRT_MIN); EXPECT_ARG(INT, short, SHRT_MIN);