From 26e16fdea74dcb3c4e1f75ff030f42a4bf7c78d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 20 Oct 2024 21:47:23 +0200 Subject: [PATCH] tests: add extra tests on function string_split New tests: - split empty string - standard split with only separators in string - standard split with only separators in string and strip separators --- tests/unit/core/test-core-string.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index e0f31e68a..4580f0eb2 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -1588,6 +1588,9 @@ TEST(CoreString, Split) POINTERS_EQUAL(NULL, string_split ("", "", NULL, flags, 0, &argc)); LONGS_EQUAL(0, argc); argc = -1; + POINTERS_EQUAL(NULL, string_split ("", ",", NULL, flags, 0, &argc)); + LONGS_EQUAL(0, argc); + argc = -1; POINTERS_EQUAL(NULL, string_split (" ", " ", NULL, flags, 0, &argc)); LONGS_EQUAL(0, argc); @@ -1840,6 +1843,25 @@ TEST(CoreString, Split) STRCMP_EQUAL("fghi", argv[3]); STRCMP_EQUAL(NULL, argv[4]); string_free_split (argv); + + /* standard split with only separators in string */ + flags = 0; + argc = -1; + argv = string_split (",,", ",", NULL, flags, 0, &argc); + LONGS_EQUAL(3, argc); + CHECK(argv); + STRCMP_EQUAL("", argv[0]); + STRCMP_EQUAL("", argv[1]); + STRCMP_EQUAL("", argv[2]); + STRCMP_EQUAL(NULL, argv[3]); + string_free_split (argv); + + /* standard split with only separators in string and strip separators */ + flags = WEECHAT_STRING_SPLIT_STRIP_LEFT + | WEECHAT_STRING_SPLIT_STRIP_RIGHT; + argc = -1; + POINTERS_EQUAL(NULL, string_split (",,", ",", NULL, flags, 0, &argc)); + LONGS_EQUAL(0, argc); } /*