#include "llvm/Support/raw_ostream.h"
using namespace llvm;
-namespace {
+namespace llvm {
std::ostream &operator<<(std::ostream &OS, const StringRef &S) {
OS << S;
return OS;
}
+}
+
+namespace {
TEST(StringRefTest, Construction) {
EXPECT_EQ("", StringRef());
EXPECT_EQ("hello", StringRef("hello"));
StringRef(",").split(parts, ",", -1, true);
EXPECT_TRUE(parts == expected);
+ expected.clear(); parts.clear();
+ expected.push_back("a"); expected.push_back("b");
+ StringRef("a,b").split(parts, ",", -1, true);
+ EXPECT_TRUE(parts == expected);
+
// Test MaxSplit
expected.clear(); parts.clear();
expected.push_back("a,,b,c");
EXPECT_FALSE(Str.startswith("hi"));
}
+TEST(StringRefTest, EndsWith) {
+ StringRef Str("hello");
+ EXPECT_TRUE(Str.endswith("lo"));
+ EXPECT_FALSE(Str.endswith("helloworld"));
+ EXPECT_FALSE(Str.endswith("worldhello"));
+ EXPECT_FALSE(Str.endswith("so"));
+}
+
TEST(StringRefTest, Find) {
StringRef Str("hello");
EXPECT_EQ(2U, Str.find('l'));
EXPECT_EQ(0U, Str.count("zz"));
}
+TEST(StringRefTest, EditDistance) {
+ StringRef Str("hello");
+ EXPECT_EQ(2U, Str.edit_distance("hill"));
+}
+
TEST(StringRefTest, Misc) {
std::string Storage;
raw_string_ostream OS(Storage);