xref: /aosp_15_r20/external/webrtc/net/dcsctp/common/str_join_test.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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  */
10 #include "net/dcsctp/common/str_join.h"
11 
12 #include <string>
13 #include <utility>
14 #include <vector>
15 
16 #include "test/gmock.h"
17 
18 namespace dcsctp {
19 namespace {
20 
TEST(StrJoinTest,CanJoinStringsFromVector)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 
TEST(StrJoinTest,CanJoinNumbersFromArray)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 
TEST(StrJoinTest,CanFormatElementsWhileJoining)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
45 }  // namespace dcsctp
46