[Bf-blender-cvs] [c7d9070ccb1] obj-import-experiments: tests for new stringref functions
Jacques Lucke
noreply at git.blender.org
Sun Mar 22 16:17:38 CET 2020
Commit: c7d9070ccb1663e904eff0a968853137064fbb8e
Author: Jacques Lucke
Date: Sat Mar 21 14:04:08 2020 +0100
Branches: obj-import-experiments
https://developer.blender.org/rBc7d9070ccb1663e904eff0a968853137064fbb8e
tests for new stringref functions
===================================================================
M source/blender/blenlib/BLI_string_ref.h
M tests/gtests/blenlib/BLI_string_ref_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_string_ref.h b/source/blender/blenlib/BLI_string_ref.h
index 8936ed198a6..92f31bbfe21 100644
--- a/source/blender/blenlib/BLI_string_ref.h
+++ b/source/blender/blenlib/BLI_string_ref.h
@@ -189,7 +189,7 @@ class StringRef : public StringRefBase {
StringRef drop_suffix(uint n) const
{
- BLI_assert(n < m_size);
+ BLI_assert(n <= m_size);
return StringRef(m_data, m_size - n);
}
diff --git a/tests/gtests/blenlib/BLI_string_ref_test.cc b/tests/gtests/blenlib/BLI_string_ref_test.cc
index a268bf3215a..2f1174e93b1 100644
--- a/tests/gtests/blenlib/BLI_string_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_string_ref_test.cc
@@ -237,3 +237,54 @@ TEST(string_ref, Substr)
EXPECT_EQ(ref.substr(3, 4), "lo w");
EXPECT_EQ(ref.substr(6, 5), "world");
}
+
+TEST(string_ref, StartsWithChar)
+{
+ StringRef ref("hello world");
+ EXPECT_TRUE(ref.startswith('h'));
+ EXPECT_FALSE(ref.startswith('a'));
+}
+
+TEST(string_ref, EndsWithChar)
+{
+ StringRef ref("hello world");
+ EXPECT_TRUE(ref.endswith('d'));
+ EXPECT_FALSE(ref.endswith('a'));
+}
+
+TEST(string_ref, StartsWithLowerAscii)
+{
+ {
+ StringRef ref("hello");
+ EXPECT_TRUE(ref.startswith_lower_ascii("hel"));
+ EXPECT_FALSE(ref.startswith_lower_ascii("el"));
+ }
+ {
+ StringRef ref("HELLO");
+ EXPECT_TRUE(ref.startswith_lower_ascii("hel"));
+ EXPECT_FALSE(ref.startswith_lower_ascii("el"));
+ }
+ {
+ StringRef ref("Hello");
+ EXPECT_TRUE(ref.startswith_lower_ascii("hel"));
+ EXPECT_FALSE(ref.startswith_lower_ascii("el"));
+ }
+}
+
+TEST(string_ref, DropSuffixN)
+{
+ StringRef ref1("hello world");
+ StringRef ref2 = ref1.drop_suffix(4);
+ StringRef ref3 = ref2.drop_suffix(7);
+ EXPECT_EQ(ref2, "hello w");
+ EXPECT_EQ(ref3, "");
+}
+
+TEST(string_ref, DropSuffix)
+{
+ StringRef ref1("hello world");
+ StringRef ref2 = ref1.drop_suffix("orld");
+ StringRef ref3 = ref2.drop_suffix("hello w");
+ EXPECT_EQ(ref2, "hello w");
+ EXPECT_EQ(ref3, "");
+}
More information about the Bf-blender-cvs
mailing list