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:
Diffstat (limited to 'tests/gtests/blenlib/BLI_string_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_string_test.cc70
1 files changed, 66 insertions, 4 deletions
diff --git a/tests/gtests/blenlib/BLI_string_test.cc b/tests/gtests/blenlib/BLI_string_test.cc
index 4c5c410dcb2..fa10e21730b 100644
--- a/tests/gtests/blenlib/BLI_string_test.cc
+++ b/tests/gtests/blenlib/BLI_string_test.cc
@@ -36,7 +36,7 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n)
TEST(string, StrPartition)
{
const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
- char *sep, *suf;
+ const char *sep, *suf;
size_t pre_ln;
{
@@ -95,7 +95,7 @@ TEST(string, StrPartition)
TEST(string, StrRPartition)
{
const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
- char *sep, *suf;
+ const char *sep, *suf;
size_t pre_ln;
{
@@ -150,11 +150,42 @@ TEST(string, StrRPartition)
}
}
+/* BLI_str_partition_ex */
+TEST(string, StrPartitionEx)
+{
+ const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
+ const char *sep, *suf;
+ size_t pre_ln;
+
+ /* Only considering 'from_right' cases here. */
+
+ {
+ const char *str = "mat.e-r_ia.l";
+
+ /* "mat.e-r_ia.l" over "mat.e-r" -> "mat.e", '.', "r_ia.l", 3 */
+ pre_ln = BLI_str_partition_ex(str, str + 6, delim, &sep, &suf, true);
+ EXPECT_EQ(5, pre_ln);
+ EXPECT_EQ(&str[5], sep);
+ EXPECT_STREQ("r_ia.l", suf);
+ }
+
+ /* Corner cases. */
+ {
+ const char *str = "mate.rial";
+
+ /* "mate.rial" over "mate" -> "mate.rial", NULL, NULL, 4 */
+ pre_ln = BLI_str_partition_ex(str, str + 4, delim, &sep, &suf, true);
+ EXPECT_EQ(4, pre_ln);
+ EXPECT_EQ(NULL, sep);
+ EXPECT_EQ(NULL, suf);
+ }
+}
+
/* BLI_str_partition_utf8 */
TEST(string, StrPartitionUtf8)
{
const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
- char *sep, *suf;
+ const char *sep, *suf;
size_t pre_ln;
{
@@ -213,7 +244,7 @@ TEST(string, StrPartitionUtf8)
TEST(string, StrRPartitionUtf8)
{
const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
- char *sep, *suf;
+ const char *sep, *suf;
size_t pre_ln;
{
@@ -268,6 +299,37 @@ TEST(string, StrRPartitionUtf8)
}
}
+/* BLI_str_partition_ex_utf8 */
+TEST(string, StrPartitionExUtf8)
+{
+ const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
+ const char *sep, *suf;
+ size_t pre_ln;
+
+ /* Only considering 'from_right' cases here. */
+
+ {
+ const char *str = "ma\xc3\xb1te-r\xe2\x98\xafial";
+
+ /* "ma\xc3\xb1te-r\xe2\x98\xafial" over "ma\xc3\xb1te" -> "ma", '\xc3\xb1', "te-r\xe2\x98\xafial", 2 */
+ pre_ln = BLI_str_partition_ex_utf8(str, str + 6, delim, &sep, &suf, true);
+ EXPECT_EQ(2, pre_ln);
+ EXPECT_EQ(&str[2], sep);
+ EXPECT_STREQ("te-r\xe2\x98\xafial", suf);
+ }
+
+ /* Corner cases. */
+ {
+ const char *str = "mate\xe2\x98\xafrial";
+
+ /* "mate\xe2\x98\xafrial" over "mate" -> "mate\xe2\x98\xafrial", NULL, NULL, 4 */
+ pre_ln = BLI_str_partition_ex_utf8(str, str + 4, delim, &sep, &suf, true);
+ EXPECT_EQ(4, pre_ln);
+ EXPECT_EQ(NULL, sep);
+ EXPECT_EQ(NULL, suf);
+ }
+}
+
/* BLI_str_format_int_grouped */
TEST(string, StrFormatIntGrouped)
{