blob: a4ac02125f7cee2fb8f79a85fe323a4c80817ff0 [file] [log] [blame]
Victor Boiviea4d5e242021-03-30 08:03:511/*
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 Silkinebc4d3e2023-11-15 10:04:4810#include "rtc_base/strings/str_join.h"
Victor Boiviea4d5e242021-03-30 08:03:5111
12#include <string>
13#include <utility>
14#include <vector>
15
Sergey Silkinebc4d3e2023-11-15 10:04:4816#include "test/gtest.h"
Victor Boiviea4d5e242021-03-30 08:03:5117
Sergey Silkinebc4d3e2023-11-15 10:04:4818namespace webrtc {
Victor Boiviea4d5e242021-03-30 08:03:5119namespace {
20
21TEST(StrJoinTest, CanJoinStringsFromVector) {
22 std::vector<std::string> strings = {"Hello", "World"};
23 std::string s = StrJoin(strings, " ");
24 EXPECT_EQ(s, "Hello World");
25}
26
27TEST(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
33TEST(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 Silkinebc4d3e2023-11-15 10:04:4845} // namespace webrtc