summaryrefslogtreecommitdiff
path: root/tests/unit/core
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2024-05-08 09:30:20 +0200
committerSébastien Helleu <flashcode@flashtux.org>2024-05-08 09:30:20 +0200
commit9f536d3dc7500611819d3180d5794c787c06e469 (patch)
treecfae7c5c648af7b11f95e2f47a3a569f35f39ce6 /tests/unit/core
parent4d0458afdd0329d0329ef4ec7e8ae7ec1aa6ee40 (diff)
downloadweechat-9f536d3dc7500611819d3180d5794c787c06e469.zip
api: return `-1` or `1` if one input string is NULL and not the other in string comparison functions
Diffstat (limited to 'tests/unit/core')
-rw-r--r--tests/unit/core/test-core-string.cpp56
1 files changed, 42 insertions, 14 deletions
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 73750c0ab..fe4c2eccd 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -607,8 +607,12 @@ TEST(CoreString, StringComparison)
{
/* case-sensitive comparison */
LONGS_EQUAL(0, string_strcmp (NULL, NULL));
- LONGS_EQUAL(-97, string_strcmp (NULL, "abc"));
- LONGS_EQUAL(97, string_strcmp ("abc", NULL));
+ LONGS_EQUAL(-1, string_strcmp (NULL, ""));
+ LONGS_EQUAL(1, string_strcmp ("", NULL));
+ LONGS_EQUAL(-1, string_strcmp (NULL, "abc"));
+ LONGS_EQUAL(1, string_strcmp ("abc", NULL));
+ LONGS_EQUAL(-97, string_strcmp ("", "abc"));
+ LONGS_EQUAL(97, string_strcmp ("abc", ""));
LONGS_EQUAL(-98, string_strcmp ("", "b"));
LONGS_EQUAL(98, string_strcmp ("b", ""));
LONGS_EQUAL(0, string_strcmp ("abc", "abc"));
@@ -627,8 +631,12 @@ TEST(CoreString, StringComparison)
/* case-sensitive comparison with max length */
LONGS_EQUAL(0, string_strncmp (NULL, NULL, 3));
- LONGS_EQUAL(-97, string_strncmp (NULL, "abc", 3));
- LONGS_EQUAL(97, string_strncmp ("abc", NULL, 3));
+ LONGS_EQUAL(-1, string_strncmp (NULL, "", 3));
+ LONGS_EQUAL(1, string_strncmp ("", NULL, 3));
+ LONGS_EQUAL(-1, string_strncmp (NULL, "abc", 3));
+ LONGS_EQUAL(1, string_strncmp ("abc", NULL, 3));
+ LONGS_EQUAL(-97, string_strncmp ("", "abc", 3));
+ LONGS_EQUAL(97, string_strncmp ("abc", "", 3));
LONGS_EQUAL(-98, string_strncmp ("", "b", 3));
LONGS_EQUAL(98, string_strncmp ("b", "", 3));
LONGS_EQUAL(0, string_strncmp ("abc", "abc", 3));
@@ -653,8 +661,12 @@ TEST(CoreString, StringComparison)
/* case-insensitive comparison */
LONGS_EQUAL(0, string_strcasecmp (NULL, NULL));
- LONGS_EQUAL(-97, string_strcasecmp (NULL, "abc"));
- LONGS_EQUAL(97, string_strcasecmp ("abc", NULL));
+ LONGS_EQUAL(-1, string_strcasecmp (NULL, ""));
+ LONGS_EQUAL(1, string_strcasecmp ("", NULL));
+ LONGS_EQUAL(-1, string_strcasecmp (NULL, "abc"));
+ LONGS_EQUAL(1, string_strcasecmp ("abc", NULL));
+ LONGS_EQUAL(-97, string_strcasecmp ("", "abc"));
+ LONGS_EQUAL(97, string_strcasecmp ("abc", ""));
LONGS_EQUAL(-98, string_strcasecmp ("", "b"));
LONGS_EQUAL(98, string_strcasecmp ("b", ""));
LONGS_EQUAL(0, string_strcasecmp ("abc", "abc"));
@@ -673,8 +685,12 @@ TEST(CoreString, StringComparison)
/* case-insensitive comparison with max length */
LONGS_EQUAL(0, string_strncasecmp (NULL, NULL, 3));
- LONGS_EQUAL(-97, string_strncasecmp (NULL, "abc", 3));
- LONGS_EQUAL(97, string_strncasecmp ("abc", NULL, 3));
+ LONGS_EQUAL(-1, string_strncasecmp (NULL, "", 3));
+ LONGS_EQUAL(1, string_strncasecmp ("", NULL, 3));
+ LONGS_EQUAL(-1, string_strncasecmp (NULL, "abc", 3));
+ LONGS_EQUAL(1, string_strncasecmp ("abc", NULL, 3));
+ LONGS_EQUAL(-97, string_strncasecmp ("", "abc", 3));
+ LONGS_EQUAL(97, string_strncasecmp ("abc", "", 3));
LONGS_EQUAL(-98, string_strncasecmp ("", "b", 3));
LONGS_EQUAL(98, string_strncasecmp ("b", "", 3));
LONGS_EQUAL(0, string_strncasecmp ("abc", "abc", 3));
@@ -699,8 +715,12 @@ TEST(CoreString, StringComparison)
/* case-insensitive comparison with a range */
LONGS_EQUAL(0, string_strcasecmp_range (NULL, NULL, 30));
- LONGS_EQUAL(-97, string_strcasecmp_range (NULL, "abc", 30));
- LONGS_EQUAL(97, string_strcasecmp_range ("abc", NULL, 30));
+ LONGS_EQUAL(-1, string_strcasecmp_range (NULL, "", 30));
+ LONGS_EQUAL(1, string_strcasecmp_range ("", NULL, 30));
+ LONGS_EQUAL(-1, string_strcasecmp_range (NULL, "abc", 30));
+ LONGS_EQUAL(1, string_strcasecmp_range ("abc", NULL, 30));
+ LONGS_EQUAL(-97, string_strcasecmp_range ("", "abc", 30));
+ LONGS_EQUAL(97, string_strcasecmp_range ("abc", "", 30));
LONGS_EQUAL(-98, string_strcasecmp_range ("", "b", 30));
LONGS_EQUAL(98, string_strcasecmp_range ("b", "", 30));
LONGS_EQUAL(-2, string_strcasecmp_range ("A", "C", 30));
@@ -727,8 +747,12 @@ TEST(CoreString, StringComparison)
/* case-insensitive comparison with max length and a range */
LONGS_EQUAL(0, string_strncasecmp_range (NULL, NULL, 3, 30));
- LONGS_EQUAL(-97, string_strncasecmp_range (NULL, "abc", 3, 30));
- LONGS_EQUAL(97, string_strncasecmp_range ("abc", NULL, 3, 30));
+ LONGS_EQUAL(-1, string_strncasecmp_range (NULL, "", 3, 30));
+ LONGS_EQUAL(1, string_strncasecmp_range ("", NULL, 3, 30));
+ LONGS_EQUAL(-1, string_strncasecmp_range (NULL, "abc", 3, 30));
+ LONGS_EQUAL(1, string_strncasecmp_range ("abc", NULL, 3, 30));
+ LONGS_EQUAL(-97, string_strncasecmp_range ("", "abc", 3, 30));
+ LONGS_EQUAL(97, string_strncasecmp_range ("abc", "", 3, 30));
LONGS_EQUAL(-98, string_strncasecmp_range ("", "b", 3, 30));
LONGS_EQUAL(98, string_strncasecmp_range ("b", "", 3, 30));
LONGS_EQUAL(-2, string_strncasecmp_range ("ABC", "CCC", 3, 30));
@@ -761,8 +785,12 @@ TEST(CoreString, StringComparison)
/* comparison with chars ignored */
LONGS_EQUAL(0, string_strcmp_ignore_chars (NULL, NULL, "", 0));
- LONGS_EQUAL(-97, string_strcmp_ignore_chars (NULL, "abc", "", 0));
- LONGS_EQUAL(97, string_strcmp_ignore_chars ("abc", NULL, "", 0));
+ LONGS_EQUAL(-1, string_strcmp_ignore_chars (NULL, "", "", 0));
+ LONGS_EQUAL(1, string_strcmp_ignore_chars ("", NULL, "", 0));
+ LONGS_EQUAL(-1, string_strcmp_ignore_chars (NULL, "abc", "", 0));
+ LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc", NULL, "", 0));
+ LONGS_EQUAL(-97, string_strcmp_ignore_chars ("", "abc", "", 0));
+ LONGS_EQUAL(97, string_strcmp_ignore_chars ("abc", "", "", 0));
LONGS_EQUAL(-98, string_strcmp_ignore_chars ("", "b", "", 0));
LONGS_EQUAL(98, string_strcmp_ignore_chars ("b", "", "", 0));
LONGS_EQUAL(-2, string_strcmp_ignore_chars ("ABC", "CCC", "", 0));