Skip to content

Commit 1911936

Browse files
committed
test-formatter: added %x/%o/%d/%s combination tests
1 parent 5751202 commit 1911936

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test-formatter.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ TEST_CASE("formatter") {
7272
CHECK( stringformat("%s %5d", "xyz", 123) == "xyz 123");
7373
CHECK( stringformat("%s %5s", "xyz", "xyz") == "xyz xyz");
7474
CHECK( stringformat("%s %s", "xyz", "xyz") == "xyz xyz");
75+
76+
CHECK( stringformat("%x %s", 123, 123) == "7b 123"); // problem
77+
CHECK( stringformat("%x %d", 123, 123) == "7b 123");
78+
CHECK( stringformat("%x %o", 123, 123) == "7b 173");
79+
CHECK( stringformat("%x %X", 123, 123) == "7b 7B");
80+
81+
CHECK( stringformat("%d %s", 123, 123) == "123 123");
82+
CHECK( stringformat("%d %d", 123, 123) == "123 123");
83+
CHECK( stringformat("%d %o", 123, 123) == "123 173");
84+
CHECK( stringformat("%d %X", 123, 123) == "123 7B");
85+
86+
CHECK( stringformat("%o %s", 123, 123) == "173 123"); // problem
87+
CHECK( stringformat("%o %d", 123, 123) == "173 123");
88+
CHECK( stringformat("%o %o", 123, 123) == "173 173");
89+
CHECK( stringformat("%o %X", 123, 123) == "173 7B");
90+
91+
7592
}
7693
SECTION("charcv") {
7794
CHECK( stringformat("%c", char(122)) == "z" );
@@ -292,6 +309,19 @@ TEST_CASE("formatter") {
292309

293310
CHECK( stringformat("%s", std::array<double, 4>{{1,2,3,4}}) == "1 2 3 4" );
294311
CHECK( stringformat("%s", std::array<uint8_t, 4>{{1,2,3,4}}) == "1 2 3 4" );
312+
313+
// various hex dumps
314+
//CHECK( stringformat("%0b", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
315+
//CHECK( stringformat("%-0b", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
316+
//CHECK( stringformat("%+0b", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
317+
//CHECK( stringformat("%-b", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
318+
//CHECK( stringformat("%+b", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
319+
320+
//CHECK( stringformat("%0x", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
321+
//CHECK( stringformat("%x", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
322+
//CHECK( stringformat("%-x", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
323+
//CHECK( stringformat("%s", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
324+
//CHECK( stringformat("%-s", std::array<uint8_t, 7>{{1,2,3,4,15,0x90,0xff}}) == "01 02 03 04" );
295325
}
296326
SECTION("custom") {
297327
CHECK( stringformat("%s", mytype()) == "MYTYPE" );

0 commit comments

Comments
 (0)