1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-23 21:13:02 +02:00
llvm-mirror/unittests/ADT/StringExtrasTest.cpp
Zachary Turner a5137ef9a9 Add llvm::join_items to StringExtras.
llvm::join_items is similar to llvm::join, which produces a string
by concatenating a sequence of values together separated by a
given separator.  But it differs in that the arguments to
llvm::join() are same-type members of a container, whereas the
arguments to llvm::join_items are arbitrary types passed into
a variadic template.  The only requirement on parameters to
llvm::join_items (including for the separator themselves) is
that they be implicitly convertible to std::string or have
an overload of std::string::operator+

Differential Revision: https://reviews.llvm.org/D24880

llvm-svn: 282502
2016-09-27 16:37:30 +00:00

53 lines
1.6 KiB
C++

//===- StringExtrasTest.cpp - Unit tests for String extras ----------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringExtras.h"
#include "gtest/gtest.h"
using namespace llvm;
TEST(StringExtrasTest, Join) {
std::vector<std::string> Items;
EXPECT_EQ("", join(Items.begin(), Items.end(), " <sep> "));
Items = {"foo"};
EXPECT_EQ("foo", join(Items.begin(), Items.end(), " <sep> "));
Items = {"foo", "bar"};
EXPECT_EQ("foo <sep> bar", join(Items.begin(), Items.end(), " <sep> "));
Items = {"foo", "bar", "baz"};
EXPECT_EQ("foo <sep> bar <sep> baz",
join(Items.begin(), Items.end(), " <sep> "));
}
TEST(StringExtrasTest, JoinItems) {
const char *Foo = "foo";
std::string Bar = "bar";
llvm::StringRef Baz = "baz";
char X = 'x';
EXPECT_EQ("", join_items(" <sep> "));
EXPECT_EQ("", join_items('/'));
EXPECT_EQ("foo", join_items(" <sep> ", Foo));
EXPECT_EQ("foo", join_items('/', Foo));
EXPECT_EQ("foo <sep> bar", join_items(" <sep> ", Foo, Bar));
EXPECT_EQ("foo/bar", join_items('/', Foo, Bar));
EXPECT_EQ("foo <sep> bar <sep> baz", join_items(" <sep> ", Foo, Bar, Baz));
EXPECT_EQ("foo/bar/baz", join_items('/', Foo, Bar, Baz));
EXPECT_EQ("foo <sep> bar <sep> baz <sep> x",
join_items(" <sep> ", Foo, Bar, Baz, X));
EXPECT_EQ("foo/bar/baz/x", join_items('/', Foo, Bar, Baz, X));
}