Add ConstString test FromMidOfBufferStringRef

Summary: It was not immediately clear to me whether or not non-null-terminated StringRef's are supported in ConstString and/or the counterpart mechanism. From this test it seems to be fine. Maybe useful to keep?

Reviewers: labath

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D50334

llvm-svn: 339292
This commit is contained in:
Stefan Granitz 2018-08-08 21:57:42 +00:00
parent f1a98df6ee
commit 4c01eccba2
1 changed files with 20 additions and 0 deletions

View File

@ -34,6 +34,26 @@ TEST(ConstStringTest, MangledCounterpart) {
EXPECT_EQ("bar", counterpart.GetStringRef());
}
TEST(ConstStringTest, FromMidOfBufferStringRef) {
// StringRef's into bigger buffer: no null termination
const char *buffer = "foobarbaz";
llvm::StringRef foo_ref(buffer, 3);
llvm::StringRef bar_ref(buffer + 3, 3);
ConstString foo(foo_ref);
ConstString bar;
bar.SetStringWithMangledCounterpart(bar_ref, foo);
EXPECT_EQ("bar", bar.GetStringRef());
ConstString counterpart;
EXPECT_TRUE(bar.GetMangledCounterpart(counterpart));
EXPECT_EQ("foo", counterpart.GetStringRef());
EXPECT_TRUE(foo.GetMangledCounterpart(counterpart));
EXPECT_EQ("bar", counterpart.GetStringRef());
}
TEST(ConstStringTest, NullAndEmptyStates) {
ConstString foo("foo");
EXPECT_FALSE(!foo);