mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Add test for StringFormat and string_view
Bug: none Change-Id: Ibc366dc30f0fc8ef098e66b8ffd982c0046db6d2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261449 Commit-Queue: Harald Alvestrand <hta@webrtc.org> Auto-Submit: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36805}
This commit is contained in:
parent
89e017dd72
commit
624340b32f
1 changed files with 17 additions and 0 deletions
|
@ -10,7 +10,11 @@
|
|||
|
||||
#include "rtc_base/strings/string_format.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/string_encode.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace rtc {
|
||||
|
@ -32,4 +36,17 @@ TEST(StringFormatTest, MaxSizeShouldWork) {
|
|||
EXPECT_EQ(str, StringFormat("%s", str));
|
||||
}
|
||||
|
||||
// Test that formating a string using `absl::string_view` works as expected
|
||||
// whe using `%.*s`.
|
||||
TEST(StringFormatTest, FormatStringView) {
|
||||
const std::string main_string("This is a substring test.");
|
||||
std::vector<absl::string_view> string_views = rtc::split(main_string, ' ');
|
||||
ASSERT_EQ(string_views.size(), 5u);
|
||||
|
||||
const absl::string_view& sv = string_views[3];
|
||||
std::string formatted =
|
||||
StringFormat("We have a %.*s.", static_cast<int>(sv.size()), sv.data());
|
||||
EXPECT_EQ(formatted.compare("We have a substring."), 0);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
|
Loading…
Reference in a new issue