summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-03-09 21:54:25 +0100
committerSébastien Helleu <flashcode@flashtux.org>2019-03-09 21:56:05 +0100
commit8aa5f5375e2a16d538fdf96babcd52a2f8f7801c (patch)
tree0a78c762c50c3fcf63c4cd57a170a3320d976c81 /tests/unit
parent79d0910c085eac5eb48c0c66e4c8989cc1996554 (diff)
downloadweechat-8aa5f5375e2a16d538fdf96babcd52a2f8f7801c.zip
core: add value -1 for keep_eol in function string_strip (issue #1322)
The value -1 means it's a standard split, but empty items are kept, and separators are not removed at beginning/end of string.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/core/test-core-string.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 1ccb2fe65..c11d63c36 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -1036,6 +1036,17 @@ TEST(CoreString, Split)
/* standard split */
argc = -1;
+ argv = string_split ("abc de fghi", " ", 0, 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 */
+ argc = -1;
argv = string_split (" abc de fghi ", " ", 0, 0, &argc);
LONGS_EQUAL(3, argc);
CHECK(argv);
@@ -1096,6 +1107,93 @@ TEST(CoreString, Split)
STRCMP_EQUAL("de fghi ", argv[1]);
POINTERS_EQUAL(NULL, argv[2]);
string_free_split (argv);
+
+ /* standard split with comma separator */
+ argc = -1;
+ argv = string_split ("abc,de,fghi", ",", 0, 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 and empty item (ignore this item) */
+ argc = -1;
+ argv = string_split ("abc,,fghi", ",", 0, 0, &argc);
+ LONGS_EQUAL(2, argc);
+ CHECK(argv);
+ STRCMP_EQUAL("abc", argv[0]);
+ STRCMP_EQUAL("fghi", argv[1]);
+ POINTERS_EQUAL(NULL, argv[2]);
+ string_free_split (argv);
+
+ /* standard split with comma separtor and empty item (keep this item) */
+ argc = -1;
+ argv = string_split ("abc,,fghi", ",", -1, 0, &argc);
+ LONGS_EQUAL(3, argc);
+ CHECK(argv);
+ STRCMP_EQUAL("abc", argv[0]);
+ STRCMP_EQUAL("", argv[1]);
+ STRCMP_EQUAL("fghi", argv[2]);
+ POINTERS_EQUAL(NULL, argv[3]);
+ string_free_split (argv);
+
+ /* standard split with comma separtor and empty items (keep them) */
+ argc = -1;
+ argv = string_split (",abc,,fghi,", ",", -1, 0, &argc);
+ LONGS_EQUAL(5, argc);
+ CHECK(argv);
+ STRCMP_EQUAL("", argv[0]);
+ STRCMP_EQUAL("abc", argv[1]);
+ STRCMP_EQUAL("", argv[2]);
+ STRCMP_EQUAL("fghi", argv[3]);
+ STRCMP_EQUAL("", argv[4]);
+ POINTERS_EQUAL(NULL, argv[5]);
+ string_free_split (argv);
+
+ /*
+ * standard split with comma separtor and empty items (keep them),
+ * max 2 items
+ */
+ argc = -1;
+ argv = string_split (",abc,,fghi,", ",", -1, 2, &argc);
+ LONGS_EQUAL(2, argc);
+ CHECK(argv);
+ STRCMP_EQUAL("", argv[0]);
+ STRCMP_EQUAL("abc", argv[1]);
+ POINTERS_EQUAL(NULL, argv[2]);
+ string_free_split (argv);
+
+ /*
+ * standard split with comma separtor and empty items (keep them),
+ * max 3 items
+ */
+ argc = -1;
+ argv = string_split (",abc,,fghi,", ",", -1, 3, &argc);
+ LONGS_EQUAL(3, argc);
+ CHECK(argv);
+ STRCMP_EQUAL("", argv[0]);
+ STRCMP_EQUAL("abc", argv[1]);
+ STRCMP_EQUAL("", argv[2]);
+ POINTERS_EQUAL(NULL, argv[3]);
+ string_free_split (argv);
+
+ /*
+ * standard split with comma separtor and empty items (keep them),
+ * max 4 items
+ */
+ argc = -1;
+ argv = string_split (",abc,,fghi,", ",", -1, 4, &argc);
+ LONGS_EQUAL(4, argc);
+ CHECK(argv);
+ STRCMP_EQUAL("", argv[0]);
+ STRCMP_EQUAL("abc", argv[1]);
+ STRCMP_EQUAL("", argv[2]);
+ STRCMP_EQUAL("fghi", argv[3]);
+ POINTERS_EQUAL(NULL, argv[4]);
+ string_free_split (argv);
}
/*