|
17 | 17 | #include "Firestore/core/src/util/string_format.h" |
18 | 18 |
|
19 | 19 | #include "absl/strings/string_view.h" |
| 20 | +#include "gmock/gmock.h" |
20 | 21 | #include "gtest/gtest.h" |
21 | 22 |
|
22 | 23 | namespace firebase { |
@@ -72,14 +73,18 @@ TEST(StringFormatTest, Bool) { |
72 | 73 | EXPECT_EQ("Hello false", StringFormat("Hello %s", false)); |
73 | 74 | } |
74 | 75 |
|
75 | | -TEST(StringFormatTest, Pointer) { |
76 | | - // pointers implicitly convert to bool. Make sure this doesn't happen in |
77 | | - // this API. |
78 | | - int value = 4; |
79 | | - EXPECT_NE("Hello true", StringFormat("Hello %s", &value)); |
| 76 | +TEST(StringFormatTest, NullPointer) { |
| 77 | + // pointers implicitly convert to bool. Make sure this doesn't happen here. |
80 | 78 | EXPECT_EQ("Hello null", StringFormat("Hello %s", nullptr)); |
81 | 79 | } |
82 | 80 |
|
| 81 | +TEST(StringFormatTest, NonNullPointer) { |
| 82 | + // pointers implicitly convert to bool. Make sure this doesn't happen here. |
| 83 | + int value = 4; |
| 84 | + EXPECT_THAT(StringFormat("Hello %s", &value), |
| 85 | + testing::MatchesRegex("Hello (0x)?[0123456789abcdefABCDEF]+")); |
| 86 | +} |
| 87 | + |
83 | 88 | TEST(StringFormatTest, Mixed) { |
84 | 89 | EXPECT_EQ("string=World, bool=true, int=42, float=1.5", |
85 | 90 | StringFormat("string=%s, bool=%s, int=%s, float=%s", "World", true, |
|
0 commit comments