Lines Matching refs:StringRef
1 //===- llvm/unittest/ADT/StringRefTest.cpp - StringRef unit tests ---------===//
11 #include "llvm/ADT/StringRef.h"
18 std::ostream &operator<<(std::ostream &OS, const StringRef &S) {
24 const std::pair<StringRef, StringRef> &P) {
33 EXPECT_EQ("", StringRef());
34 EXPECT_EQ("hello", StringRef("hello"));
35 EXPECT_EQ("hello", StringRef("hello world", 5));
36 EXPECT_EQ("hello", StringRef(std::string("hello")));
40 StringRef S("hello");
48 EXPECT_EQ(p, StringRef(p, 0).data());
49 EXPECT_TRUE(StringRef().empty());
50 EXPECT_EQ((size_t) 5, StringRef("hello").size());
51 EXPECT_EQ(-1, StringRef("aab").compare("aad"));
52 EXPECT_EQ( 0, StringRef("aab").compare("aab"));
53 EXPECT_EQ( 1, StringRef("aab").compare("aaa"));
54 EXPECT_EQ(-1, StringRef("aab").compare("aabb"));
55 EXPECT_EQ( 1, StringRef("aab").compare("aa"));
56 EXPECT_EQ( 1, StringRef("\xFF").compare("\1"));
58 EXPECT_EQ(-1, StringRef("AaB").compare_lower("aAd"));
59 EXPECT_EQ( 0, StringRef("AaB").compare_lower("aab"));
60 EXPECT_EQ( 1, StringRef("AaB").compare_lower("AAA"));
61 EXPECT_EQ(-1, StringRef("AaB").compare_lower("aaBb"));
62 EXPECT_EQ( 1, StringRef("AaB").compare_lower("aA"));
63 EXPECT_EQ( 1, StringRef("\xFF").compare_lower("\1"));
65 EXPECT_EQ(-1, StringRef("aab").compare_numeric("aad"));
66 EXPECT_EQ( 0, StringRef("aab").compare_numeric("aab"));
67 EXPECT_EQ( 1, StringRef("aab").compare_numeric("aaa"));
68 EXPECT_EQ(-1, StringRef("aab").compare_numeric("aabb"));
69 EXPECT_EQ( 1, StringRef("aab").compare_numeric("aa"));
70 EXPECT_EQ(-1, StringRef("1").compare_numeric("10"));
71 EXPECT_EQ( 0, StringRef("10").compare_numeric("10"));
72 EXPECT_EQ( 0, StringRef("10a").compare_numeric("10a"));
73 EXPECT_EQ( 1, StringRef("2").compare_numeric("1"));
74 EXPECT_EQ( 0, StringRef("llvm_v1i64_ty").compare_numeric("llvm_v1i64_ty"));
75 EXPECT_EQ( 1, StringRef("\xFF").compare_numeric("\1"));
79 EXPECT_EQ("", StringRef());
80 EXPECT_TRUE(StringRef("aab") < StringRef("aad"));
81 EXPECT_FALSE(StringRef("aab") < StringRef("aab"));
82 EXPECT_TRUE(StringRef("aab") <= StringRef("aab"));
83 EXPECT_FALSE(StringRef("aab") <= StringRef("aaa"));
84 EXPECT_TRUE(StringRef("aad") > StringRef("aab"));
85 EXPECT_FALSE(StringRef("aab") > StringRef("aab"));
86 EXPECT_TRUE(StringRef("aab") >= StringRef("aab"));
87 EXPECT_FALSE(StringRef("aaa") >= StringRef("aab"));
88 EXPECT_EQ(StringRef("aab"), StringRef("aab"));
89 EXPECT_FALSE(StringRef("aab") == StringRef("aac"));
90 EXPECT_FALSE(StringRef("aab") != StringRef("aab"));
91 EXPECT_TRUE(StringRef("aab") != StringRef("aac"));
92 EXPECT_EQ('a', StringRef("aab")[1]);
96 StringRef Str("hello");
104 StringRef Str("hello");
113 StringRef Str("hello");
114 EXPECT_EQ(std::make_pair(StringRef("hello"), StringRef("")),
116 EXPECT_EQ(std::make_pair(StringRef("h"), StringRef("llo")),
118 EXPECT_EQ(std::make_pair(StringRef(""), StringRef("ello")),
120 EXPECT_EQ(std::make_pair(StringRef("he"), StringRef("lo")),
122 EXPECT_EQ(std::make_pair(StringRef("hell"), StringRef("")),
125 EXPECT_EQ(std::make_pair(StringRef("hello"), StringRef("")),
127 EXPECT_EQ(std::make_pair(StringRef("h"), StringRef("llo")),
129 EXPECT_EQ(std::make_pair(StringRef(""), StringRef("ello")),
131 EXPECT_EQ(std::make_pair(StringRef("hel"), StringRef("o")),
133 EXPECT_EQ(std::make_pair(StringRef("hell"), StringRef("")),
138 SmallVector<StringRef, 5> parts;
139 SmallVector<StringRef, 5> expected;
142 StringRef(",ab,,c,").split(parts, ",", -1, false);
148 StringRef(",ab,,c,").split(parts, ",", -1, true);
153 StringRef("").split(parts, ",", -1, true);
157 StringRef("").split(parts, ",", -1, false);
161 StringRef(",").split(parts, ",", -1, false);
166 StringRef(",").split(parts, ",", -1, true);
171 StringRef("a,b").split(parts, ",", -1, true);
177 StringRef("a,,b,c").split(parts, ",", 0, true);
182 StringRef("a,,b,c").split(parts, ",", 0, false);
187 StringRef("a,,b,c").split(parts, ",", 1, true);
192 StringRef("a,,b,c").split(parts, ",", 1, false);
197 StringRef("a,,b,c").split(parts, ",", 2, true);
202 StringRef("a,,b,c").split(parts, ",", 2, false);
208 StringRef("a,,b,c").split(parts, ",", 3, true);
213 StringRef("a,,b,c").split(parts, ",", 3, false);
218 StringRef Str("hello");
225 StringRef Str("hello");
233 StringRef Str("hello");
235 EXPECT_EQ(StringRef::npos, Str.find('z'));
236 EXPECT_EQ(StringRef::npos, Str.find("helloworld"));
239 EXPECT_EQ(StringRef::npos, Str.find("zz"));
241 EXPECT_EQ(StringRef::npos, Str.find("ll", 3));
244 EXPECT_EQ(StringRef::npos, Str.rfind('z'));
245 EXPECT_EQ(StringRef::npos, Str.rfind("helloworld"));
248 EXPECT_EQ(StringRef::npos, Str.rfind("zz"));
252 EXPECT_EQ(StringRef::npos, Str.find_first_of("xyz"));
256 EXPECT_EQ(StringRef::npos, Str.find_first_not_of("hello"));
260 StringRef Str("hello");
271 StringRef Str("hello");
278 OS << StringRef("hello");