Victor Boivie | a4d5e24 | 2021-03-30 08:03:51 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Sergey Silkin | ebc4d3e | 2023-11-15 10:04:48 | [diff] [blame] | 10 | #include "rtc_base/strings/str_join.h" |
Victor Boivie | a4d5e24 | 2021-03-30 08:03:51 | [diff] [blame] | 11 | |
| 12 | #include <string> |
| 13 | #include <utility> |
| 14 | #include <vector> |
| 15 | |
Sergey Silkin | ebc4d3e | 2023-11-15 10:04:48 | [diff] [blame] | 16 | #include "test/gtest.h" |
Victor Boivie | a4d5e24 | 2021-03-30 08:03:51 | [diff] [blame] | 17 | |
Sergey Silkin | ebc4d3e | 2023-11-15 10:04:48 | [diff] [blame] | 18 | namespace webrtc { |
Victor Boivie | a4d5e24 | 2021-03-30 08:03:51 | [diff] [blame] | 19 | namespace { |
| 20 | |
| 21 | TEST(StrJoinTest, CanJoinStringsFromVector) { |
| 22 | std::vector<std::string> strings = {"Hello", "World"}; |
| 23 | std::string s = StrJoin(strings, " "); |
| 24 | EXPECT_EQ(s, "Hello World"); |
| 25 | } |
| 26 | |
| 27 | TEST(StrJoinTest, CanJoinNumbersFromArray) { |
| 28 | std::array<int, 3> numbers = {1, 2, 3}; |
| 29 | std::string s = StrJoin(numbers, ","); |
| 30 | EXPECT_EQ(s, "1,2,3"); |
| 31 | } |
| 32 | |
| 33 | TEST(StrJoinTest, CanFormatElementsWhileJoining) { |
| 34 | std::vector<std::pair<std::string, std::string>> pairs = { |
| 35 | {"hello", "world"}, {"foo", "bar"}, {"fum", "gazonk"}}; |
| 36 | std::string s = StrJoin(pairs, ",", |
| 37 | [&](rtc::StringBuilder& sb, |
| 38 | const std::pair<std::string, std::string>& p) { |
| 39 | sb << p.first << "=" << p.second; |
| 40 | }); |
| 41 | EXPECT_EQ(s, "hello=world,foo=bar,fum=gazonk"); |
| 42 | } |
| 43 | |
| 44 | } // namespace |
Sergey Silkin | ebc4d3e | 2023-11-15 10:04:48 | [diff] [blame] | 45 | } // namespace webrtc |