From f34c3ca3046378bdb7e49b7366bafca0e0bafb9a Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 30 Oct 2013 18:32:26 +0000 Subject: Add {start,end}with_lower methods to StringRef. startswith_lower is ocassionally useful and I think worth adding. endwith_lower is added for completeness. Differential Revision: http://llvm-reviews.chandlerc.com/D2041 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193706 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/ADT/StringRefTest.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'unittests') diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index 07fba49..88691ae 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -61,6 +61,9 @@ TEST(StringRefTest, StringOps) { EXPECT_EQ( 0, StringRef("AaB").compare_lower("aab")); EXPECT_EQ( 1, StringRef("AaB").compare_lower("AAA")); EXPECT_EQ(-1, StringRef("AaB").compare_lower("aaBb")); + EXPECT_EQ(-1, StringRef("AaB").compare_lower("bb")); + EXPECT_EQ( 1, StringRef("aaBb").compare_lower("AaB")); + EXPECT_EQ( 1, StringRef("bb").compare_lower("AaB")); EXPECT_EQ( 1, StringRef("AaB").compare_lower("aA")); EXPECT_EQ( 1, StringRef("\xFF").compare_lower("\1")); @@ -254,6 +257,16 @@ TEST(StringRefTest, StartsWith) { EXPECT_FALSE(Str.startswith("hi")); } +TEST(StringRefTest, StartsWithLower) { + StringRef Str("heLLo"); + EXPECT_TRUE(Str.startswith_lower("")); + EXPECT_TRUE(Str.startswith_lower("he")); + EXPECT_TRUE(Str.startswith_lower("hell")); + EXPECT_TRUE(Str.startswith_lower("HELlo")); + EXPECT_FALSE(Str.startswith_lower("helloworld")); + EXPECT_FALSE(Str.startswith_lower("hi")); +} + TEST(StringRefTest, EndsWith) { StringRef Str("hello"); EXPECT_TRUE(Str.endswith("")); @@ -263,6 +276,16 @@ TEST(StringRefTest, EndsWith) { EXPECT_FALSE(Str.endswith("so")); } +TEST(StringRefTest, EndsWithLower) { + StringRef Str("heLLo"); + EXPECT_TRUE(Str.endswith_lower("")); + EXPECT_TRUE(Str.endswith_lower("lo")); + EXPECT_TRUE(Str.endswith_lower("LO")); + EXPECT_TRUE(Str.endswith_lower("ELlo")); + EXPECT_FALSE(Str.endswith_lower("helloworld")); + EXPECT_FALSE(Str.endswith_lower("hi")); +} + TEST(StringRefTest, Find) { StringRef Str("hello"); EXPECT_EQ(2U, Str.find('l')); -- cgit v1.1