summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-06-15 20:47:14 +0200
committerSébastien Helleu <flashcode@flashtux.org>2019-06-15 20:47:14 +0200
commit917815635415b523eaf58ed4c65757247d5cca99 (patch)
treeabac3f1894ed07cbf2caed70cc285bde87b3263c /tests
parent866a29c7e63bbda24e04fc36b34bbd798a8c98db (diff)
downloadweechat-917815635415b523eaf58ed4c65757247d5cca99.zip
api: add argument "strip_items" in function string_split
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/core/test-core-hook.cpp2
-rw-r--r--tests/unit/core/test-core-string.cpp114
2 files changed, 86 insertions, 30 deletions
diff --git a/tests/unit/core/test-core-hook.cpp b/tests/unit/core/test-core-hook.cpp
index 8875912ba..572323bc1 100644
--- a/tests/unit/core/test-core-hook.cpp
+++ b/tests/unit/core/test-core-hook.cpp
@@ -183,7 +183,7 @@ test_modifier_cb (const void *pointer, void *data,
(void) modifier;
/* split modifier_data, which is: "plugin;name;tags" */
- items = string_split (modifier_data, ";",
+ items = string_split (modifier_data, ";", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 1f8938091..11ec19b4d 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -1011,29 +1011,29 @@ TEST(CoreString, Split)
char **argv;
int argc, flags;
- POINTERS_EQUAL(NULL, string_split (NULL, NULL, 0, 0, NULL));
- POINTERS_EQUAL(NULL, string_split (NULL, "", 0, 0, NULL));
- POINTERS_EQUAL(NULL, string_split ("", NULL, 0, 0, NULL));
- POINTERS_EQUAL(NULL, string_split ("", "", 0, 0, NULL));
+ POINTERS_EQUAL(NULL, string_split (NULL, NULL, NULL, 0, 0, NULL));
+ POINTERS_EQUAL(NULL, string_split (NULL, "", NULL, 0, 0, NULL));
+ POINTERS_EQUAL(NULL, string_split ("", NULL, NULL, 0, 0, NULL));
+ POINTERS_EQUAL(NULL, string_split ("", "", NULL, 0, 0, NULL));
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
argc = -1;
- POINTERS_EQUAL(NULL, string_split (NULL, NULL, flags, 0, &argc));
+ POINTERS_EQUAL(NULL, string_split (NULL, NULL, NULL, flags, 0, &argc));
LONGS_EQUAL(0, argc);
argc = -1;
- POINTERS_EQUAL(NULL, string_split (NULL, "", flags, 0, &argc));
+ POINTERS_EQUAL(NULL, string_split (NULL, "", NULL, flags, 0, &argc));
LONGS_EQUAL(0, argc);
argc = -1;
- POINTERS_EQUAL(NULL, string_split ("", NULL, flags, 0, &argc));
+ POINTERS_EQUAL(NULL, string_split ("", NULL, NULL, flags, 0, &argc));
LONGS_EQUAL(0, argc);
argc = -1;
- POINTERS_EQUAL(NULL, string_split ("", "", flags, 0, &argc));
+ POINTERS_EQUAL(NULL, string_split ("", "", NULL, flags, 0, &argc));
LONGS_EQUAL(0, argc);
argc = -1;
- POINTERS_EQUAL(NULL, string_split (" ", " ", flags, 0, &argc));
+ POINTERS_EQUAL(NULL, string_split (" ", " ", NULL, flags, 0, &argc));
LONGS_EQUAL(0, argc);
/* free split with NULL */
@@ -1044,7 +1044,7 @@ TEST(CoreString, Split)
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
argc = -1;
- argv = string_split ("abc de fghi", " ", flags, 0, &argc);
+ argv = string_split ("abc de fghi", " ", NULL, flags, 0, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
STRCMP_EQUAL("abc", argv[0]);
@@ -1058,7 +1058,7 @@ TEST(CoreString, Split)
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
argc = -1;
- argv = string_split (" abc de fghi ", " ", flags, 0, &argc);
+ argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
STRCMP_EQUAL("abc", argv[0]);
@@ -1072,7 +1072,7 @@ TEST(CoreString, Split)
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
argc = -1;
- argv = string_split (" abc de fghi ", " ", flags, 2, &argc);
+ argv = string_split (" abc de fghi ", " ", NULL, flags, 2, &argc);
LONGS_EQUAL(2, argc);
CHECK(argv);
STRCMP_EQUAL("abc", argv[0]);
@@ -1086,7 +1086,7 @@ TEST(CoreString, Split)
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
| WEECHAT_STRING_SPLIT_KEEP_EOL;
argc = -1;
- argv = string_split (" abc de fghi ", " ", flags, 0, &argc);
+ argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
STRCMP_EQUAL("abc de fghi", argv[0]);
@@ -1101,7 +1101,7 @@ TEST(CoreString, Split)
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
| WEECHAT_STRING_SPLIT_KEEP_EOL;
argc = -1;
- argv = string_split (" abc de fghi ", " ", flags, 2, &argc);
+ argv = string_split (" abc de fghi ", " ", NULL, flags, 2, &argc);
LONGS_EQUAL(2, argc);
CHECK(argv);
STRCMP_EQUAL("abc de fghi", argv[0]);
@@ -1114,7 +1114,7 @@ TEST(CoreString, Split)
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
| WEECHAT_STRING_SPLIT_KEEP_EOL;
argc = -1;
- argv = string_split (" abc de fghi ", " ", flags, 0, &argc);
+ argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
STRCMP_EQUAL("abc de fghi ", argv[0]);
@@ -1128,7 +1128,7 @@ TEST(CoreString, Split)
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
| WEECHAT_STRING_SPLIT_KEEP_EOL;
argc = -1;
- argv = string_split (" abc de fghi ", " ", flags, 2, &argc);
+ argv = string_split (" abc de fghi ", " ", NULL, flags, 2, &argc);
LONGS_EQUAL(2, argc);
CHECK(argv);
STRCMP_EQUAL("abc de fghi ", argv[0]);
@@ -1141,7 +1141,7 @@ TEST(CoreString, Split)
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
argc = -1;
- argv = string_split ("abc,de,fghi", ",", flags, 0, &argc);
+ argv = string_split ("abc,de,fghi", ",", NULL, flags, 0, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
STRCMP_EQUAL("abc", argv[0]);
@@ -1150,12 +1150,64 @@ TEST(CoreString, Split)
POINTERS_EQUAL(NULL, argv[3]);
string_free_split (argv);
+ /*
+ * standard split with comma separator,
+ * strip_items set to empty string (ignored)
+ */
+ flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
+ | WEECHAT_STRING_SPLIT_STRIP_RIGHT
+ | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
+ argc = -1;
+ argv = string_split (" abc ,, de ,fghi ,,", ",", "", flags, 0, &argc);
+ LONGS_EQUAL(3, argc);
+ CHECK(argv);
+ STRCMP_EQUAL(" abc ", argv[0]);
+ STRCMP_EQUAL(" de ", argv[1]);
+ STRCMP_EQUAL("fghi ", argv[2]);
+ POINTERS_EQUAL(NULL, argv[3]);
+ string_free_split (argv);
+
+ /*
+ * standard split with comma separator,
+ * strip spaces in items (left/right)
+ */
+ flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
+ | WEECHAT_STRING_SPLIT_STRIP_RIGHT
+ | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
+ argc = -1;
+ argv = string_split (" abc ,, de ,fghi ,,", ",", " ", flags, 0, &argc);
+ LONGS_EQUAL(3, argc);
+ CHECK(argv);
+ STRCMP_EQUAL("abc", argv[0]);
+ STRCMP_EQUAL("de", argv[1]);
+ STRCMP_EQUAL("fghi", argv[2]);
+ POINTERS_EQUAL(NULL, argv[3]);
+ string_free_split (argv);
+
+ /*
+ * standard split with comma separator,
+ * strip spaces and parentheses in items (left/right)
+ */
+ flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
+ | WEECHAT_STRING_SPLIT_STRIP_RIGHT
+ | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
+ argc = -1;
+ argv = string_split (" abc ,, (de) ,(f(g)hi) ,,", ",", " ()",
+ flags, 0, &argc);
+ LONGS_EQUAL(3, argc);
+ CHECK(argv);
+ STRCMP_EQUAL("abc", argv[0]);
+ STRCMP_EQUAL("de", argv[1]);
+ STRCMP_EQUAL("f(g)hi", argv[2]);
+ POINTERS_EQUAL(NULL, argv[3]);
+ string_free_split (argv);
+
/* standard split with comma separator and empty item (ignore this item) */
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
argc = -1;
- argv = string_split ("abc,,fghi", ",", flags, 0, &argc);
+ argv = string_split ("abc,,fghi", ",", NULL, flags, 0, &argc);
LONGS_EQUAL(2, argc);
CHECK(argv);
STRCMP_EQUAL("abc", argv[0]);
@@ -1166,7 +1218,7 @@ TEST(CoreString, Split)
/* standard split with comma separtor and empty item (keep this item) */
flags = 0;
argc = -1;
- argv = string_split ("abc,,fghi", ",", flags, 0, &argc);
+ argv = string_split ("abc,,fghi", ",", NULL, flags, 0, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
STRCMP_EQUAL("abc", argv[0]);
@@ -1178,7 +1230,7 @@ TEST(CoreString, Split)
/* standard split with comma separtor and empty items (keep them) */
flags = 0;
argc = -1;
- argv = string_split (",abc,,fghi,", ",", flags, 0, &argc);
+ argv = string_split (",abc,,fghi,", ",", NULL, flags, 0, &argc);
LONGS_EQUAL(5, argc);
CHECK(argv);
STRCMP_EQUAL("", argv[0]);
@@ -1195,7 +1247,7 @@ TEST(CoreString, Split)
*/
flags = 0;
argc = -1;
- argv = string_split (",abc,,fghi,", ",", flags, 2, &argc);
+ argv = string_split (",abc,,fghi,", ",", NULL, flags, 2, &argc);
LONGS_EQUAL(2, argc);
CHECK(argv);
STRCMP_EQUAL("", argv[0]);
@@ -1209,7 +1261,7 @@ TEST(CoreString, Split)
*/
flags = 0;
argc = -1;
- argv = string_split (",abc,,fghi,", ",", flags, 3, &argc);
+ argv = string_split (",abc,,fghi,", ",", NULL, flags, 3, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
STRCMP_EQUAL("", argv[0]);
@@ -1224,7 +1276,7 @@ TEST(CoreString, Split)
*/
flags = 0;
argc = -1;
- argv = string_split (",abc,,fghi,", ",", flags, 4, &argc);
+ argv = string_split (",abc,,fghi,", ",", NULL, flags, 4, &argc);
LONGS_EQUAL(4, argc);
CHECK(argv);
STRCMP_EQUAL("", argv[0]);
@@ -1250,15 +1302,19 @@ TEST(CoreString, SplitShared)
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
- POINTERS_EQUAL(NULL, string_split_shared (NULL, NULL, flags, 0, NULL));
- POINTERS_EQUAL(NULL, string_split_shared (NULL, "", flags, 0, NULL));
- POINTERS_EQUAL(NULL, string_split_shared ("", NULL, flags, 0, NULL));
- POINTERS_EQUAL(NULL, string_split_shared ("", "", flags, 0, NULL));
+ POINTERS_EQUAL(NULL, string_split_shared (NULL, NULL, NULL,
+ flags, 0, NULL));
+ POINTERS_EQUAL(NULL, string_split_shared (NULL, "", NULL,
+ flags, 0, NULL));
+ POINTERS_EQUAL(NULL, string_split_shared ("", NULL, NULL,
+ flags, 0, NULL));
+ POINTERS_EQUAL(NULL, string_split_shared ("", "", NULL,
+ flags, 0, NULL));
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
- argv = string_split_shared (" abc de abc ", " ", flags, 0, &argc);
+ argv = string_split_shared (" abc de abc ", " ", NULL, flags, 0, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
STRCMP_EQUAL("abc", argv[0]);
@@ -1441,7 +1497,7 @@ TEST(CoreString, SplitBuildWithSplitString)
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
- argv = string_split (" abc de fghi ", " ", flags, 0, &argc);
+ argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
str = string_build_with_split_string ((const char **)argv, NULL);
STRCMP_EQUAL("abcdefghi", str);