diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-12-24 18:29:35 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-12-24 18:29:35 +0100 |
commit | 21f35750163cd64cf323f5070aa9ae158c943b33 (patch) | |
tree | e2da35530697689006219061c1b9c3a45b449a35 /tests/unit/core/test-core-string.cpp | |
parent | 0dd1d4133b1e49646ec4fc7cfb256dc20028f238 (diff) | |
download | weechat-21f35750163cd64cf323f5070aa9ae158c943b33.zip |
api: add functions string_strcmp and string_strncmp
Diffstat (limited to 'tests/unit/core/test-core-string.cpp')
-rw-r--r-- | tests/unit/core/test-core-string.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index 78670cc2c..a06cd9ed9 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -511,6 +511,8 @@ TEST(CoreString, CharComparison) /* * Tests functions: + * string_strcmp + * string_strncmp * string_strcasecmp * string_strncasecmp * string_strcasecmp_range @@ -520,6 +522,48 @@ TEST(CoreString, CharComparison) 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(-98, string_strcmp ("", "b")); + LONGS_EQUAL(98, string_strcmp ("b", "")); + LONGS_EQUAL(0, string_strcmp ("abc", "abc")); + LONGS_EQUAL(32, string_strcmp ("abc", "ABC")); + LONGS_EQUAL(0, string_strcmp ("ABC", "ABC")); + LONGS_EQUAL(-3, string_strcmp ("abc", "def")); + LONGS_EQUAL(29, string_strcmp ("abc", "DEF")); + LONGS_EQUAL(-35, string_strcmp ("ABC", "def")); + LONGS_EQUAL(-3, string_strcmp ("ABC", "DEF")); + LONGS_EQUAL(3, string_strcmp ("def", "abc")); + LONGS_EQUAL(35, string_strcmp ("def", "ABC")); + LONGS_EQUAL(-29, string_strcmp ("DEF", "abc")); + LONGS_EQUAL(3, string_strcmp ("DEF", "ABC")); + + /* 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(-98, string_strncmp ("", "b", 3)); + LONGS_EQUAL(98, string_strncmp ("b", "", 3)); + LONGS_EQUAL(0, string_strncmp ("abc", "abc", 3)); + LONGS_EQUAL(0, string_strncmp ("abcabc", "abcdef", 3)); + LONGS_EQUAL(-3, string_strncmp ("abcabc", "abcdef", 6)); + LONGS_EQUAL(32, string_strncmp ("abc", "ABC", 3)); + LONGS_EQUAL(32, string_strncmp ("abcabc", "ABCDEF", 3)); + LONGS_EQUAL(32, string_strncmp ("abcabc", "ABCDEF", 6)); + LONGS_EQUAL(0, string_strncmp ("ABC", "ABC", 3)); + LONGS_EQUAL(0, string_strncmp ("ABCABC", "ABCDEF", 3)); + LONGS_EQUAL(-3, string_strncmp ("ABCABC", "ABCDEF", 6)); + LONGS_EQUAL(-3, string_strncmp ("abc", "def", 3)); + LONGS_EQUAL(29, string_strncmp ("abc", "DEF", 3)); + LONGS_EQUAL(-35, string_strncmp ("ABC", "def", 3)); + LONGS_EQUAL(-3, string_strncmp ("ABC", "DEF", 3)); + LONGS_EQUAL(3, string_strncmp ("def", "abc", 3)); + LONGS_EQUAL(35, string_strncmp ("def", "ABC", 3)); + LONGS_EQUAL(-29, string_strncmp ("DEF", "abc", 3)); + LONGS_EQUAL(3, string_strncmp ("DEF", "ABC", 3)); + /* case-insensitive comparison */ LONGS_EQUAL(0, string_strcasecmp (NULL, NULL)); LONGS_EQUAL(-97, string_strcasecmp (NULL, "abc")); |