Skip to content

Commit

Permalink
Format (un)signed char as integer by default (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Nov 6, 2015
1 parent 9beb01d commit 7c24973
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,8 @@ class MakeValue : public Arg {
FMT_MAKE_VALUE(float, double_value, DOUBLE)
FMT_MAKE_VALUE(double, double_value, DOUBLE)
FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE)
FMT_MAKE_VALUE(signed char, int_value, CHAR)
FMT_MAKE_VALUE(unsigned char, int_value, CHAR)
FMT_MAKE_VALUE(signed char, int_value, INT)
FMT_MAKE_VALUE(unsigned char, int_value, UINT)
FMT_MAKE_VALUE(char, int_value, CHAR)

#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
Expand Down
5 changes: 5 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,11 @@ TEST(FormatterTest, FormatChar) {
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) {
EXPECT_EQ(L"a", format(L"{0}", L'a'));
// This shouldn't compile:
Expand Down
12 changes: 7 additions & 5 deletions test/util-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,6 @@ TEST(ArgTest, MakeArg) {
EXPECT_ARG_(wchar_t, BOOL, bool, int, true);

// 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, CHAR_MIN);
EXPECT_ARG(CHAR, char, CHAR_MAX);
Expand All @@ -485,6 +480,13 @@ TEST(ArgTest, MakeArg) {
EXPECT_ARGW(CHAR, wchar_t, WCHAR_MIN);
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.
EXPECT_ARG(INT, short, 42);
EXPECT_ARG(INT, short, SHRT_MIN);
Expand Down

0 comments on commit 7c24973

Please sign in to comment.