aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/StringRefTest.cpp
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2021-06-14 14:43:46 +0300
committerMartin Storsjö <martin@martin.st>2021-06-22 12:38:08 +0300
commit703b0ed8e208e5e6cf001689ea0a92296552f032 (patch)
tree7782408c0d799f8a6e99d2ae9adf11ab2b3c98ca /llvm/unittests/ADT/StringRefTest.cpp
parentc6a91ee6aaaacbda0c37973112b2e0d609c82321 (diff)
downloadllvm-703b0ed8e208e5e6cf001689ea0a92296552f032.zip
llvm-703b0ed8e208e5e6cf001689ea0a92296552f032.tar.gz
llvm-703b0ed8e208e5e6cf001689ea0a92296552f032.tar.bz2
[ADT] Add StringRef consume_front_lower and consume_back_lower
These serve as a convenient combination of consume_front/back and startswith_lower/endswith_lower, consistent with other existing case insensitive methods named <operation>_lower. Differential Revision: https://reviews.llvm.org/D104218
Diffstat (limited to 'llvm/unittests/ADT/StringRefTest.cpp')
-rw-r--r--llvm/unittests/ADT/StringRefTest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp
index e3f943b..ed11a2a 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/unittests/ADT/StringRefTest.cpp
@@ -392,6 +392,24 @@ TEST(StringRefTest, ConsumeFront) {
EXPECT_TRUE(Str.consume_front(""));
}
+TEST(StringRefTest, ConsumeFrontLower) {
+ StringRef Str("heLLo");
+ EXPECT_TRUE(Str.consume_front_lower(""));
+ EXPECT_EQ("heLLo", Str);
+ EXPECT_FALSE(Str.consume_front("HEl"));
+ EXPECT_EQ("heLLo", Str);
+ EXPECT_TRUE(Str.consume_front_lower("HEl"));
+ EXPECT_EQ("Lo", Str);
+ EXPECT_FALSE(Str.consume_front_lower("loworld"));
+ EXPECT_EQ("Lo", Str);
+ EXPECT_FALSE(Str.consume_front_lower("ol"));
+ EXPECT_EQ("Lo", Str);
+ EXPECT_TRUE(Str.consume_front_lower("lo"));
+ EXPECT_EQ("", Str);
+ EXPECT_FALSE(Str.consume_front_lower("o"));
+ EXPECT_TRUE(Str.consume_front_lower(""));
+}
+
TEST(StringRefTest, EndsWith) {
StringRef Str("hello");
EXPECT_TRUE(Str.endswith(""));
@@ -427,6 +445,24 @@ TEST(StringRefTest, ConsumeBack) {
EXPECT_TRUE(Str.consume_back(""));
}
+TEST(StringRefTest, ConsumeBackLower) {
+ StringRef Str("heLLo");
+ EXPECT_TRUE(Str.consume_back_lower(""));
+ EXPECT_EQ("heLLo", Str);
+ EXPECT_FALSE(Str.consume_back("lO"));
+ EXPECT_EQ("heLLo", Str);
+ EXPECT_TRUE(Str.consume_back_lower("lO"));
+ EXPECT_EQ("heL", Str);
+ EXPECT_FALSE(Str.consume_back_lower("helhel"));
+ EXPECT_EQ("heL", Str);
+ EXPECT_FALSE(Str.consume_back_lower("hle"));
+ EXPECT_EQ("heL", Str);
+ EXPECT_TRUE(Str.consume_back_lower("hEl"));
+ EXPECT_EQ("", Str);
+ EXPECT_FALSE(Str.consume_back_lower("h"));
+ EXPECT_TRUE(Str.consume_back_lower(""));
+}
+
TEST(StringRefTest, Find) {
StringRef Str("helloHELLO");
StringRef LongStr("hellx xello hell ello world foo bar hello HELLO");