Format null pointer as (nil) and null string as (null) in printf (#226)

This commit is contained in:
vitaut
2015-11-11 07:57:19 -08:00
parent e61c8d4cba
commit b5fda1c90d
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -418,6 +418,8 @@ TEST(PrintfTest, Char) {
TEST(PrintfTest, String) {
EXPECT_PRINTF("abc", "%s", "abc");
const char *null_str = 0;
EXPECT_PRINTF("(null)", "%s", null_str);
// TODO: wide string
}
@@ -425,6 +427,8 @@ TEST(PrintfTest, Pointer) {
int n;
void *p = &n;
EXPECT_PRINTF(fmt::format("{}", p), "%p", p);
p = 0;
EXPECT_PRINTF("(nil)", "%p", p);
const char *s = "test";
EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s);
}