Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-08-10 19:13:28 +0300
committerJacques Lucke <jacques@blender.org>2020-08-10 19:17:07 +0300
commitc521b69ffb68df17d6b8e1c71d23924a8b9b9cf3 (patch)
tree69f9505c110e7f1ce7769e0036f51eb439f20635 /source/blender/blenlib/tests/BLI_string_ref_test.cc
parent53d203dea8230da4e80f3cc61468a4e24ff6759c (diff)
BLI: improve StringRef for C++17
Since C++17 there is also std::string_view, which is similar to StringRef. This commit does a couple of things: * New implicit conversions between StringRef and std::string_view. * Support std::string_view in blender::DefaultHash. * Support most of the methods that std::string_view has. * Add StringRef::not_found which can be used instead of -1 in some places. * Improve/fix the description at the top of BLI_string_ref.hh.
Diffstat (limited to 'source/blender/blenlib/tests/BLI_string_ref_test.cc')
-rw-r--r--source/blender/blenlib/tests/BLI_string_ref_test.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_string_ref_test.cc b/source/blender/blenlib/tests/BLI_string_ref_test.cc
index d08c8a77455..2d488feff71 100644
--- a/source/blender/blenlib/tests/BLI_string_ref_test.cc
+++ b/source/blender/blenlib/tests/BLI_string_ref_test.cc
@@ -254,6 +254,14 @@ TEST(string_ref, DropPrefix)
EXPECT_EQ(ref2, "t");
}
+TEST(string_ref, DropSuffix)
+{
+ StringRef ref("test");
+ StringRef ref2 = ref.drop_suffix(1);
+ EXPECT_EQ(ref2.size(), 3);
+ EXPECT_EQ(ref2, "tes");
+}
+
TEST(string_ref, Substr)
{
StringRef ref("hello world");
@@ -261,6 +269,8 @@ TEST(string_ref, Substr)
EXPECT_EQ(ref.substr(4, 0), "");
EXPECT_EQ(ref.substr(3, 4), "lo w");
EXPECT_EQ(ref.substr(6, 5), "world");
+ EXPECT_EQ(ref.substr(8), "rld");
+ EXPECT_EQ(ref.substr(8, 100), "rld");
}
TEST(string_ref, Copy)
@@ -274,4 +284,18 @@ TEST(string_ref, Copy)
EXPECT_EQ(ref, dst);
}
+TEST(string_ref, FromStringView)
+{
+ std::string_view view = "hello";
+ StringRef ref = view;
+ EXPECT_EQ(ref, "hello");
+}
+
+TEST(string_ref, ToStringView)
+{
+ StringRef ref = "hello";
+ std::string_view view = ref;
+ EXPECT_EQ(view, "hello");
+}
+
} // namespace blender::tests