diff options
author | Talin <viridia@gmail.com> | 2012-01-24 23:43:59 +0000 |
---|---|---|
committer | Talin <viridia@gmail.com> | 2012-01-24 23:43:59 +0000 |
commit | 2527188a42b3250671b69dc979102565be1f910f (patch) | |
tree | a5fae26db6d50470aa74f211ad481d912c7fb44f /unittests/ADT | |
parent | d36f5af224594719a10d8b190daf4b56cdb7377f (diff) |
Additional methods for SmallString.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148881 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT')
-rw-r--r-- | unittests/ADT/SmallStringTest.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/unittests/ADT/SmallStringTest.cpp b/unittests/ADT/SmallStringTest.cpp index 099d8159c9..660ac44a8b 100644 --- a/unittests/ADT/SmallStringTest.cpp +++ b/unittests/ADT/SmallStringTest.cpp @@ -44,5 +44,153 @@ TEST_F(SmallStringTest, EmptyStringTest) { EXPECT_TRUE(theString.rbegin() == theString.rend()); } +TEST_F(SmallStringTest, AssignRepeated) { + theString.assign(3, 'a'); + EXPECT_EQ(3u, theString.size()); + EXPECT_STREQ("aaa", theString.c_str()); } +TEST_F(SmallStringTest, AssignIterPair) { + StringRef abc = "abc"; + theString.assign(abc.begin(), abc.end()); + EXPECT_EQ(3u, theString.size()); + EXPECT_STREQ("abc", theString.c_str()); +} + +TEST_F(SmallStringTest, AssignStringRef) { + StringRef abc = "abc"; + theString.assign(abc); + EXPECT_EQ(3u, theString.size()); + EXPECT_STREQ("abc", theString.c_str()); +} + +TEST_F(SmallStringTest, AssignSmallVector) { + StringRef abc = "abc"; + SmallVector<char, 10> abcVec(abc.begin(), abc.end()); + theString.assign(abcVec); + EXPECT_EQ(3u, theString.size()); + EXPECT_STREQ("abc", theString.c_str()); +} + +TEST_F(SmallStringTest, AppendIterPair) { + StringRef abc = "abc"; + theString.append(abc.begin(), abc.end()); + theString.append(abc.begin(), abc.end()); + EXPECT_EQ(6u, theString.size()); + EXPECT_STREQ("abcabc", theString.c_str()); +} + +TEST_F(SmallStringTest, AppendStringRef) { + StringRef abc = "abc"; + theString.append(abc); + theString.append(abc); + EXPECT_EQ(6u, theString.size()); + EXPECT_STREQ("abcabc", theString.c_str()); +} + +TEST_F(SmallStringTest, AppendSmallVector) { + StringRef abc = "abc"; + SmallVector<char, 10> abcVec(abc.begin(), abc.end()); + theString.append(abcVec); + theString.append(abcVec); + EXPECT_EQ(6u, theString.size()); + EXPECT_STREQ("abcabc", theString.c_str()); +} + +TEST_F(SmallStringTest, Substr) { + theString = "hello"; + EXPECT_EQ("lo", theString.substr(3)); + EXPECT_EQ("", theString.substr(100)); + EXPECT_EQ("hello", theString.substr(0, 100)); + EXPECT_EQ("o", theString.substr(4, 10)); +} + +TEST_F(SmallStringTest, Slice) { + theString = "hello"; + EXPECT_EQ("l", theString.slice(2, 3)); + EXPECT_EQ("ell", theString.slice(1, 4)); + EXPECT_EQ("llo", theString.slice(2, 100)); + EXPECT_EQ("", theString.slice(2, 1)); + EXPECT_EQ("", theString.slice(10, 20)); +} + +TEST_F(SmallStringTest, Find) { + theString = "hello"; + EXPECT_EQ(2U, theString.find('l')); + EXPECT_EQ(StringRef::npos, theString.find('z')); + EXPECT_EQ(StringRef::npos, theString.find("helloworld")); + EXPECT_EQ(0U, theString.find("hello")); + EXPECT_EQ(1U, theString.find("ello")); + EXPECT_EQ(StringRef::npos, theString.find("zz")); + EXPECT_EQ(2U, theString.find("ll", 2)); + EXPECT_EQ(StringRef::npos, theString.find("ll", 3)); + EXPECT_EQ(0U, theString.find("")); + + EXPECT_EQ(3U, theString.rfind('l')); + EXPECT_EQ(StringRef::npos, theString.rfind('z')); + EXPECT_EQ(StringRef::npos, theString.rfind("helloworld")); + EXPECT_EQ(0U, theString.rfind("hello")); + EXPECT_EQ(1U, theString.rfind("ello")); + EXPECT_EQ(StringRef::npos, theString.rfind("zz")); + + EXPECT_EQ(2U, theString.find_first_of('l')); + EXPECT_EQ(1U, theString.find_first_of("el")); + EXPECT_EQ(StringRef::npos, theString.find_first_of("xyz")); + + EXPECT_EQ(1U, theString.find_first_not_of('h')); + EXPECT_EQ(4U, theString.find_first_not_of("hel")); + EXPECT_EQ(StringRef::npos, theString.find_first_not_of("hello")); + + theString = "hellx xello hell ello world foo bar hello"; + EXPECT_EQ(36U, theString.find("hello")); + EXPECT_EQ(28U, theString.find("foo")); + EXPECT_EQ(12U, theString.find("hell", 2)); + EXPECT_EQ(0U, theString.find("")); +} + +TEST_F(SmallStringTest, Count) { + theString = "hello"; + EXPECT_EQ(2U, theString.count('l')); + EXPECT_EQ(1U, theString.count('o')); + EXPECT_EQ(0U, theString.count('z')); + EXPECT_EQ(0U, theString.count("helloworld")); + EXPECT_EQ(1U, theString.count("hello")); + EXPECT_EQ(1U, theString.count("ello")); + EXPECT_EQ(0U, theString.count("zz")); +} + +TEST(StringRefTest, Comparisons) { + EXPECT_EQ(-1, SmallString<10>("aab").compare("aad")); + EXPECT_EQ( 0, SmallString<10>("aab").compare("aab")); + EXPECT_EQ( 1, SmallString<10>("aab").compare("aaa")); + EXPECT_EQ(-1, SmallString<10>("aab").compare("aabb")); + EXPECT_EQ( 1, SmallString<10>("aab").compare("aa")); + EXPECT_EQ( 1, SmallString<10>("\xFF").compare("\1")); + + EXPECT_EQ(-1, SmallString<10>("AaB").compare_lower("aAd")); + EXPECT_EQ( 0, SmallString<10>("AaB").compare_lower("aab")); + EXPECT_EQ( 1, SmallString<10>("AaB").compare_lower("AAA")); + EXPECT_EQ(-1, SmallString<10>("AaB").compare_lower("aaBb")); + EXPECT_EQ( 1, SmallString<10>("AaB").compare_lower("aA")); + EXPECT_EQ( 1, SmallString<10>("\xFF").compare_lower("\1")); + + EXPECT_EQ(-1, SmallString<10>("aab").compare_numeric("aad")); + EXPECT_EQ( 0, SmallString<10>("aab").compare_numeric("aab")); + EXPECT_EQ( 1, SmallString<10>("aab").compare_numeric("aaa")); + EXPECT_EQ(-1, SmallString<10>("aab").compare_numeric("aabb")); + EXPECT_EQ( 1, SmallString<10>("aab").compare_numeric("aa")); + EXPECT_EQ(-1, SmallString<10>("1").compare_numeric("10")); + EXPECT_EQ( 0, SmallString<10>("10").compare_numeric("10")); + EXPECT_EQ( 0, SmallString<10>("10a").compare_numeric("10a")); + EXPECT_EQ( 1, SmallString<10>("2").compare_numeric("1")); + EXPECT_EQ( 0, SmallString<10>("llvm_v1i64_ty").compare_numeric("llvm_v1i64_ty")); + EXPECT_EQ( 1, SmallString<10>("\xFF").compare_numeric("\1")); + EXPECT_EQ( 1, SmallString<10>("V16").compare_numeric("V1_q0")); + EXPECT_EQ(-1, SmallString<10>("V1_q0").compare_numeric("V16")); + EXPECT_EQ(-1, SmallString<10>("V8_q0").compare_numeric("V16")); + EXPECT_EQ( 1, SmallString<10>("V16").compare_numeric("V8_q0")); + EXPECT_EQ(-1, SmallString<10>("V1_q0").compare_numeric("V8_q0")); + EXPECT_EQ( 1, SmallString<10>("V8_q0").compare_numeric("V1_q0")); +} + +} |