summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-07-20 13:16:35 +0200
committerSébastien Helleu <flashcode@flashtux.org>2022-07-20 13:16:35 +0200
commitb7441bd7a30e1fdee837fad9923d372b4b283374 (patch)
tree1a27579f0d8bfeed77a2377f9245d6b6d6553238 /tests/unit
parent62e68f965f7bce87eb0bf61bb134de5a3d3b7507 (diff)
downloadweechat-b7441bd7a30e1fdee837fad9923d372b4b283374.zip
api: add arguments "index_start" and "index_end" in function string_rebuild_split_string
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/core/test-core-string.cpp86
1 files changed, 82 insertions, 4 deletions
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index f14e572a6..5639d2aae 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -1708,7 +1708,7 @@ TEST(CoreString, RebuildSplitString)
char **argv, *str;
int argc, flags;
- str = string_rebuild_split_string (NULL, NULL);
+ str = string_rebuild_split_string (NULL, NULL, 0, -1);
POINTERS_EQUAL(NULL, str);
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
@@ -1716,18 +1716,96 @@ TEST(CoreString, RebuildSplitString)
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
- str = string_rebuild_split_string ((const char **)argv, NULL);
+ /* invalid index_end, which is < index_start */
+ str = string_rebuild_split_string ((const char **)argv, NULL, 1, 0);
+ POINTERS_EQUAL(NULL, str);
+ str = string_rebuild_split_string ((const char **)argv, NULL, 2, 1);
+ POINTERS_EQUAL(NULL, str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, -1);
+ STRCMP_EQUAL("abcdefghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, 0);
+ STRCMP_EQUAL("abc", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, 1);
+ STRCMP_EQUAL("abcde", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, 2);
STRCMP_EQUAL("abcdefghi", str);
free (str);
- str = string_rebuild_split_string ((const char **)argv, "");
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, 3);
STRCMP_EQUAL("abcdefghi", str);
free (str);
- str = string_rebuild_split_string ((const char **)argv, ";;");
+ str = string_rebuild_split_string ((const char **)argv, NULL, 1, 1);
+ STRCMP_EQUAL("de", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 1, 2);
+ STRCMP_EQUAL("defghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 1, 3);
+ STRCMP_EQUAL("defghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 2, 2);
+ STRCMP_EQUAL("fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 2, 3);
+ STRCMP_EQUAL("fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, "", 0, -1);
+ STRCMP_EQUAL("abcdefghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, -1);
+ STRCMP_EQUAL("abc;;de;;fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, 0);
+ STRCMP_EQUAL("abc", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, 1);
+ STRCMP_EQUAL("abc;;de", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, 2);
+ STRCMP_EQUAL("abc;;de;;fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, 3);
STRCMP_EQUAL("abc;;de;;fghi", str);
free (str);
+ str = string_rebuild_split_string ((const char **)argv, ";;", 1, 1);
+ STRCMP_EQUAL("de", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 1, 2);
+ STRCMP_EQUAL("de;;fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 1, 3);
+ STRCMP_EQUAL("de;;fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 2, 2);
+ STRCMP_EQUAL("fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 2, 3);
+ STRCMP_EQUAL("fghi", str);
+ free (str);
+
string_free_split (argv);
}