summaryrefslogtreecommitdiff
path: root/absl/strings/str_format_test.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-09-20 14:20:55 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-09-20 14:21:52 -0700
commit9398fa76a3436bfb89f7a6ec5c74a21f1e4d6029 (patch)
treef25eb0625f95a73d57d1f960383bf3a40eeb96ef /absl/strings/str_format_test.cc
parentd54fd91c4e2cf8d9c843e320fd1de4eb1723af3c (diff)
Adds support for "%v" in absl::StrFormat and related functions for bool values. Note that %v prints bool values as "true" and "false" rather than "1" and "0".
PiperOrigin-RevId: 475651689 Change-Id: I24b3749d85b5bb7cbc18653d629271a8b2b07d08
Diffstat (limited to 'absl/strings/str_format_test.cc')
-rw-r--r--absl/strings/str_format_test.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/absl/strings/str_format_test.cc b/absl/strings/str_format_test.cc
index 2774cfed..4b778056 100644
--- a/absl/strings/str_format_test.cc
+++ b/absl/strings/str_format_test.cc
@@ -265,7 +265,7 @@ TEST_F(FormatEntryPointTest, Stream) {
std::ostringstream oss;
oss << StreamFormat(*parsed, 123, 3, 49, "multistreaming!!!", 1.01, 1.01);
int fmt_result = snprintf(&*buf.begin(), buf.size(), fmt.c_str(), //
- 123, 3, 49, "multistreaming!!!", 1.01, 1.01);
+ 123, 3, 49, "multistreaming!!!", 1.01, 1.01);
ASSERT_TRUE(oss) << fmt;
ASSERT_TRUE(fmt_result >= 0 && static_cast<size_t>(fmt_result) < buf.size())
<< fmt_result;
@@ -644,6 +644,11 @@ TEST(StrFormat, BehavesAsDocumented) {
EXPECT_EQ(StrFormat("%zd", int{1}), "1");
EXPECT_EQ(StrFormat("%td", int{1}), "1");
EXPECT_EQ(StrFormat("%qd", int{1}), "1");
+
+ // Bool is handled correctly depending on whether %v is used
+ EXPECT_EQ(StrFormat("%v", true), "true");
+ EXPECT_EQ(StrFormat("%v", false), "false");
+ EXPECT_EQ(StrFormat("%d", true), "1");
}
using str_format_internal::ExtendedParsedFormat;