10 auto check = [](
const std::vector<std::string_view>& v,
const std::string& expected) {
11 std::string result =
join(v,
'-');
12 CHECK(result == expected);
17 check({
"foo"},
"foo");
19 check({
"foo",
""},
"foo-");
20 check({
"",
"foo"},
"-foo");
21 check({
"foo",
"bar"},
"foo-bar");
22 check({
"foo",
"bar",
"qux"},
"foo-bar-qux");
23 check({
"",
"bar",
"qux"},
"-bar-qux");
24 check({
"foo",
"bar",
""},
"foo-bar-");
29 std::vector<std::string> vs = {
"foo",
"bar",
"qux"};
30 std::vector<int> vi = {1, -89, 673, 0};
31 const char* ac[] = {
"blabla",
"xyz",
"4567"};
34 const char* sep2 =
", ";
35 std::string sep3 =
"<-->";
38 auto check = [](
const auto& range,
const auto& sep,
const std::string& expected) {
39 std::string result1 =
join(range, sep);
40 CHECK(result1 == expected);
42 std::ostringstream ss;
43 ss <<
join(range, sep);
44 std::string result2 = ss.str();
45 CHECK(result2 == expected);
48 check(vs, sep1,
"foo-bar-qux");
49 check(vs, sep2,
"foo, bar, qux");
50 check(vs, sep3,
"foo<-->bar<-->qux");
51 check(vs, sep4,
"foo123bar123qux");
53 check(vi, sep1,
"1--89-673-0");
54 check(vi, sep2,
"1, -89, 673, 0");
55 check(vi, sep3,
"1<-->-89<-->673<-->0");
56 check(vi, sep4,
"1123-891236731230");
58 check(ac, sep1,
"blabla-xyz-4567");
59 check(ac, sep2,
"blabla, xyz, 4567");
60 check(ac, sep3,
"blabla<-->xyz<-->4567");
61 check(ac, sep4,
"blabla123xyz1234567");
63 auto quote = [](
auto& s) {
return strCat(
'\'', s,
'\''); };
detail::Joiner< Collection, Separator > join(Collection &&col, Separator &&sep)
TEST_CASE("join: vector<string_view>, char")
constexpr auto transform(Range &&range, UnaryOp op)
std::string strCat(Ts &&...ts)