mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 21:16:56 +00:00
Restore the 'B' type by https://github.com/gcflymoto and add tests.
This commit is contained in:
parent
4f3ae78adb
commit
f184ad0a2c
4
format.h
4
format.h
@ -729,7 +729,7 @@ BasicWriter<Char> &BasicWriter<Char>::operator<<(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'b': {
|
||||
case 'b': case 'B': {
|
||||
UnsignedType n = abs_value;
|
||||
bool print_prefix = f.hash_flag();
|
||||
if (print_prefix) size += 2;
|
||||
@ -742,7 +742,7 @@ BasicWriter<Char> &BasicWriter<Char>::operator<<(
|
||||
*p-- = '0' + (n & 1);
|
||||
} while ((n >>= 1) != 0);
|
||||
if (print_prefix) {
|
||||
*p-- = 'b';
|
||||
*p-- = f.type();
|
||||
*p = '0';
|
||||
}
|
||||
break;
|
||||
|
@ -316,6 +316,14 @@ TEST(WriterTest, WriteWideString) {
|
||||
//fmt::WWriter() << "abc";
|
||||
}
|
||||
|
||||
TEST(WriterTest, bin) {
|
||||
using fmt::bin;
|
||||
EXPECT_EQ("1100101011111110", str(Writer() << bin(0xcafe)));
|
||||
EXPECT_EQ("1011101010111110", str(Writer() << bin(0xbabeu)));
|
||||
EXPECT_EQ("1101111010101101", str(Writer() << bin(0xdeadl)));
|
||||
EXPECT_EQ("1011111011101111", str(Writer() << bin(0xbeeful)));
|
||||
}
|
||||
|
||||
TEST(WriterTest, oct) {
|
||||
using fmt::oct;
|
||||
EXPECT_EQ("12", str(Writer() << oct(static_cast<short>(012))));
|
||||
@ -325,14 +333,6 @@ TEST(WriterTest, oct) {
|
||||
EXPECT_EQ("70", str(Writer() << oct(070ul)));
|
||||
}
|
||||
|
||||
TEST(WriterTest, bin) {
|
||||
using fmt::bin;
|
||||
EXPECT_EQ("1100101011111110", str(Writer() << bin(0xcafe)));
|
||||
EXPECT_EQ("1011101010111110", str(Writer() << bin(0xbabeu)));
|
||||
EXPECT_EQ("1101111010101101", str(Writer() << bin(0xdeadl)));
|
||||
EXPECT_EQ("1011111011101111", str(Writer() << bin(0xbeeful)));
|
||||
}
|
||||
|
||||
TEST(WriterTest, hex) {
|
||||
using fmt::hex;
|
||||
fmt::IntFormatter<int, fmt::TypeSpec<'x'> > (*phex)(int value) = hex;
|
||||
@ -685,6 +685,9 @@ TEST(FormatterTest, SpaceSign) {
|
||||
TEST(FormatterTest, HashFlag) {
|
||||
EXPECT_EQ("42", str(Format("{0:#}") << 42));
|
||||
EXPECT_EQ("-42", str(Format("{0:#}") << -42));
|
||||
EXPECT_EQ("0b101010", str(Format("{0:#b}") << 0x42));
|
||||
EXPECT_EQ("0B101010", str(Format("{0:#B}") << 0x42));
|
||||
EXPECT_EQ("-0b101010", str(Format("{0:#b}") << -0x42));
|
||||
EXPECT_EQ("0x42", str(Format("{0:#x}") << 0x42));
|
||||
EXPECT_EQ("0X42", str(Format("{0:#X}") << 0x42));
|
||||
EXPECT_EQ("-0x42", str(Format("{0:#x}") << -0x42));
|
||||
|
Loading…
Reference in New Issue
Block a user