[Lldb-commits] [PATCH] D50334: Add ConstString test FromMidOfBufferStringRef
Stefan Gränitz via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 6 07:25:00 PDT 2018
sgraenitz created this revision.
sgraenitz added a reviewer: labath.
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?
https://reviews.llvm.org/D50334
Files:
unittests/Utility/ConstStringTest.cpp
Index: unittests/Utility/ConstStringTest.cpp
===================================================================
--- unittests/Utility/ConstStringTest.cpp
+++ unittests/Utility/ConstStringTest.cpp
@@ -34,6 +34,26 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50334.159298.patch
Type: text/x-patch
Size: 988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180806/f6126928/attachment-0001.bin>
More information about the lldb-commits
mailing list