diff options
author | Jacques Lucke <jacques@blender.org> | 2020-03-21 16:04:08 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-03-21 16:04:08 +0300 |
commit | c7d9070ccb1663e904eff0a968853137064fbb8e (patch) | |
tree | fc3b7f80e050d156d6300e07106c16f316be8bfe | |
parent | 3512be55e972b167882ff2ea2490d35b3aa628e6 (diff) |
tests for new stringref functions
-rw-r--r-- | source/blender/blenlib/BLI_string_ref.h | 2 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_string_ref_test.cc | 51 |
2 files changed, 52 insertions, 1 deletions
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, ""); +} |