summaryrefslogtreecommitdiff
path: root/tests/unit/core
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-12-24 16:25:20 +0100
committerSébastien Helleu <flashcode@flashtux.org>2022-12-24 16:25:20 +0100
commit083032972dc75ffde841ac77dce4d49093c9ead7 (patch)
tree7acac69f900ac8b6514ad979301e5562fd9d2dd6 /tests/unit/core
parent5fc656a1b8acd8e1207bd64dfbb5d1bdcde81ec8 (diff)
downloadweechat-083032972dc75ffde841ac77dce4d49093c9ead7.zip
api: return arithmetic difference between chars in string comparison functions
Return code is changed for the following functions: - string_strcasecmp - string_strcasecmp_range - string_strncasecmp - string_strncasecmp_range - string_strcmp_ignore_chars - utf8_charcmp - utf8_charcasecmp - utf8_charcasecmp_range
Diffstat (limited to 'tests/unit/core')
-rw-r--r--tests/unit/core/test-core-string.cpp132
-rw-r--r--tests/unit/core/test-core-utf8.cpp48
2 files changed, 99 insertions, 81 deletions
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 3dbcfbc78..540e241b5 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -468,107 +468,121 @@ TEST(CoreString, Comparison)
{
/* case-insensitive comparison */
LONGS_EQUAL(0, string_strcasecmp (NULL, NULL));
- LONGS_EQUAL(-1, string_strcasecmp (NULL, "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("abc", NULL));
+ LONGS_EQUAL(-97, string_strcasecmp (NULL, "abc"));
+ LONGS_EQUAL(97, string_strcasecmp ("abc", NULL));
+ LONGS_EQUAL(-98, string_strcasecmp ("", "b"));
+ LONGS_EQUAL(98, string_strcasecmp ("b", ""));
LONGS_EQUAL(0, string_strcasecmp ("abc", "abc"));
LONGS_EQUAL(0, string_strcasecmp ("abc", "ABC"));
LONGS_EQUAL(0, string_strcasecmp ("ABC", "ABC"));
- LONGS_EQUAL(-1, string_strcasecmp ("abc", "def"));
- LONGS_EQUAL(-1, string_strcasecmp ("abc", "DEF"));
- LONGS_EQUAL(-1, string_strcasecmp ("ABC", "def"));
- LONGS_EQUAL(-1, string_strcasecmp ("ABC", "DEF"));
- LONGS_EQUAL(1, string_strcasecmp ("def", "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("def", "ABC"));
- LONGS_EQUAL(1, string_strcasecmp ("DEF", "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("DEF", "ABC"));
+ LONGS_EQUAL(-3, string_strcasecmp ("abc", "def"));
+ LONGS_EQUAL(-3, string_strcasecmp ("abc", "DEF"));
+ LONGS_EQUAL(-3, string_strcasecmp ("ABC", "def"));
+ LONGS_EQUAL(-3, string_strcasecmp ("ABC", "DEF"));
+ LONGS_EQUAL(3, string_strcasecmp ("def", "abc"));
+ LONGS_EQUAL(3, string_strcasecmp ("def", "ABC"));
+ LONGS_EQUAL(3, string_strcasecmp ("DEF", "abc"));
+ LONGS_EQUAL(3, string_strcasecmp ("DEF", "ABC"));
/* case-insensitive comparison with max length */
LONGS_EQUAL(0, string_strncasecmp (NULL, NULL, 3));
- LONGS_EQUAL(-1, string_strncasecmp (NULL, "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("abc", NULL, 3));
+ LONGS_EQUAL(-97, string_strncasecmp (NULL, "abc", 3));
+ LONGS_EQUAL(97, string_strncasecmp ("abc", NULL, 3));
+ LONGS_EQUAL(-98, string_strncasecmp ("", "b", 3));
+ LONGS_EQUAL(98, string_strncasecmp ("b", "", 3));
LONGS_EQUAL(0, string_strncasecmp ("abc", "abc", 3));
LONGS_EQUAL(0, string_strncasecmp ("abcabc", "abcdef", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abcabc", "abcdef", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abcabc", "abcdef", 6));
LONGS_EQUAL(0, string_strncasecmp ("abc", "ABC", 3));
LONGS_EQUAL(0, string_strncasecmp ("abcabc", "ABCDEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abcabc", "ABCDEF", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abcabc", "ABCDEF", 6));
LONGS_EQUAL(0, string_strncasecmp ("ABC", "ABC", 3));
LONGS_EQUAL(0, string_strncasecmp ("ABCABC", "ABCDEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABCABC", "ABCDEF", 6));
- LONGS_EQUAL(-1, string_strncasecmp ("abc", "def", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abc", "DEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABC", "def", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABC", "DEF", 3));
- LONGS_EQUAL(1, string_strncasecmp ("def", "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("def", "ABC", 3));
- LONGS_EQUAL(1, string_strncasecmp ("DEF", "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("DEF", "ABC", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABCABC", "ABCDEF", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abc", "def", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("abc", "DEF", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABC", "def", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABC", "DEF", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("def", "abc", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("def", "ABC", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("DEF", "abc", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("DEF", "ABC", 3));
/* case-insensitive comparison with a range */
LONGS_EQUAL(0, string_strcasecmp_range (NULL, NULL, 30));
- LONGS_EQUAL(-1, string_strcasecmp_range (NULL, "abc", 30));
- LONGS_EQUAL(1, string_strcasecmp_range ("abc", NULL, 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("A", "Z", 30));
- LONGS_EQUAL(1, string_strcasecmp_range ("Z", "A", 30));
+ LONGS_EQUAL(-97, string_strcasecmp_range (NULL, "abc", 30));
+ LONGS_EQUAL(97, string_strcasecmp_range ("abc", NULL, 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));
+ LONGS_EQUAL(2, string_strcasecmp_range ("C", "A", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("A", "a", 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("ë", "€", 30));
+ LONGS_EQUAL(-8129, string_strcasecmp_range ("ë", "€", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("[", "{", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("]", "}", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("\\", "|", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("^", "~", 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("[", "{", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("]", "}", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("\\", "|", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("[", "{", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("{", "[", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("]", "}", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("}", "]", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("\\", "|", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("|", "\\", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("~", "^", 26));
/* case-insensitive comparison with max length and a range */
LONGS_EQUAL(0, string_strncasecmp_range (NULL, 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(-1, string_strncasecmp_range ("ABC", "ZZZ", 3, 30));
- LONGS_EQUAL(1, string_strncasecmp_range ("ZZZ", "ABC", 3, 30));
+ LONGS_EQUAL(-97, string_strncasecmp_range (NULL, "abc", 3, 30));
+ LONGS_EQUAL(97, string_strncasecmp_range ("abc", NULL, 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));
+ LONGS_EQUAL(2, string_strncasecmp_range ("CCC", "ABC", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("ABC", "abc", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("ABCABC", "abcdef", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("ABCABC", "abcdef", 6, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("ëëë", "€€€", 3, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("ABCABC", "abcdef", 6, 30));
+ LONGS_EQUAL(-8129, string_strncasecmp_range ("ëëë", "€€€", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("[[[", "{{{", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("[[[abc", "{{{def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("[[[abc", "{{{def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("[[[abc", "{{{def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("]]]", "}}}", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("]]]abc", "}}}def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("]]]abc", "}}}def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("]]]abc", "}}}def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("\\\\\\", "|||", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("\\\\\\abc", "|||def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("\\\\\\abc", "|||def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("\\\\\\abc", "|||def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("^^^", "~~~", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("^^^abc", "~~~def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("^^^abc", "~~~def", 6, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("[[[", "{{{", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("]]]", "}}}", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("\\\\\\", "|||", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("^^^", "~~~", 3, 26));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("^^^abc", "~~~def", 6, 30));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("[[[", "{{{", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("]]]", "}}}", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("\\\\\\", "|||", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("^^^", "~~~", 3, 26));
/* comparison with chars ignored */
LONGS_EQUAL(0, string_strcmp_ignore_chars (NULL, NULL, "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars (NULL, "abc", "", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc", NULL, "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("ABC", "ZZZ", "", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("ZZZ", "ABC", "", 0));
+ LONGS_EQUAL(-97, string_strcmp_ignore_chars (NULL, "abc", "", 0));
+ LONGS_EQUAL(97, string_strcmp_ignore_chars ("abc", NULL, "", 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));
+ LONGS_EQUAL(2, string_strcmp_ignore_chars ("CCC", "ABC", "", 0));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("ABC", "abc", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("ABC", "abc", "", 1));
+ LONGS_EQUAL(-32, string_strcmp_ignore_chars ("ABC", "abc", "", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("abc..abc", "abcabc", ".", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc..abc", "ABCABC", ".", 1));
+ LONGS_EQUAL(32, string_strcmp_ignore_chars ("abc..abc", "ABCABC", ".", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("abc..abc", "abc-.-.abc",
".-", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc..abc", "ABC-.-.ABC",
- ".-", 1));
+ LONGS_EQUAL(32, string_strcmp_ignore_chars ("abc..abc", "ABC-.-.ABC",
+ ".-", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars (".abc..abc", "..abcabc", ".", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars (".abc..abc", "..", ".", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars (".", "..abcabc", ".", 0));
+ LONGS_EQUAL(97, string_strcmp_ignore_chars (".abc..abc", "..", ".", 0));
+ LONGS_EQUAL(-97, string_strcmp_ignore_chars (".", "..abcabc", ".", 0));
LONGS_EQUAL(0, string_strcmp_ignore_chars (".", ".", ".", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "é", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "É", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "é", "", 1));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "ê", "", 0));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "Ê", "", 0));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "ê", "", 1));
}
/*
diff --git a/tests/unit/core/test-core-utf8.cpp b/tests/unit/core/test-core-utf8.cpp
index 7da5482b1..cd330eadf 100644
--- a/tests/unit/core/test-core-utf8.cpp
+++ b/tests/unit/core/test-core-utf8.cpp
@@ -602,43 +602,47 @@ TEST(CoreUtf8, Comparison)
{
/* case-sensitive comparison */
LONGS_EQUAL(0, utf8_charcmp (NULL, NULL));
- LONGS_EQUAL(-1, utf8_charcmp (NULL, "abc"));
- LONGS_EQUAL(1, utf8_charcmp ("abc", NULL));
+ LONGS_EQUAL(-97, utf8_charcmp (NULL, "abc"));
+ LONGS_EQUAL(97, utf8_charcmp ("abc", NULL));
LONGS_EQUAL(0, utf8_charcmp ("axx", "azz"));
- LONGS_EQUAL(-1, utf8_charcmp ("A", "Z"));
- LONGS_EQUAL(1, utf8_charcmp ("Z", "A"));
- LONGS_EQUAL(-1, utf8_charcmp ("A", "a"));
- LONGS_EQUAL(-1, utf8_charcmp ("ë", "€"));
- LONGS_EQUAL(1, utf8_charcmp ("ë", ""));
- LONGS_EQUAL(-1, utf8_charcmp ("", "ë"));
+ LONGS_EQUAL(-2, utf8_charcmp ("A", "C"));
+ LONGS_EQUAL(2, utf8_charcmp ("C", "A"));
+ LONGS_EQUAL(-32, utf8_charcmp ("A", "a"));
+ LONGS_EQUAL(-8129, utf8_charcmp ("ë", "€"));
+ LONGS_EQUAL(235, utf8_charcmp ("ë", ""));
+ LONGS_EQUAL(-235, utf8_charcmp ("", "ë"));
/* case-insensitive comparison */
LONGS_EQUAL(0, utf8_charcasecmp (NULL, NULL));
- LONGS_EQUAL(-1, utf8_charcasecmp (NULL, "abc"));
- LONGS_EQUAL(1, utf8_charcasecmp ("abc", NULL));
+ LONGS_EQUAL(-97, utf8_charcasecmp (NULL, "abc"));
+ LONGS_EQUAL(97, utf8_charcasecmp ("abc", NULL));
LONGS_EQUAL(0, utf8_charcasecmp ("axx", "azz"));
- LONGS_EQUAL(-1, utf8_charcasecmp ("A", "Z"));
- LONGS_EQUAL(1, utf8_charcasecmp ("Z", "A"));
+ LONGS_EQUAL(-2, utf8_charcasecmp ("A", "C"));
+ LONGS_EQUAL(2, utf8_charcasecmp ("C", "A"));
LONGS_EQUAL(0, utf8_charcasecmp ("A", "a"));
- LONGS_EQUAL(-1, utf8_charcasecmp ("ë", "€"));
+ LONGS_EQUAL(-8129, utf8_charcasecmp ("ë", "€"));
/* case-insensitive comparison with a range */
LONGS_EQUAL(0, utf8_charcasecmp_range (NULL, NULL, 30));
- LONGS_EQUAL(-1, utf8_charcasecmp_range (NULL, "abc", 30));
- LONGS_EQUAL(1, utf8_charcasecmp_range ("abc", NULL, 30));
+ LONGS_EQUAL(-97, utf8_charcasecmp_range (NULL, "abc", 30));
+ LONGS_EQUAL(97, utf8_charcasecmp_range ("abc", NULL, 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("axx", "azz", 30));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("A", "Z", 30));
- LONGS_EQUAL(1, utf8_charcasecmp_range ("Z", "A", 30));
+ LONGS_EQUAL(-2, utf8_charcasecmp_range ("A", "C", 30));
+ LONGS_EQUAL(2, utf8_charcasecmp_range ("C", "A", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("A", "a", 30));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("ë", "€", 30));
+ LONGS_EQUAL(-8129, utf8_charcasecmp_range ("ë", "€", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("[", "{", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("]", "}", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("\\", "|", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("^", "~", 30));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("[", "{", 26));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("]", "}", 26));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("\\", "|", 26));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(-32, utf8_charcasecmp_range ("[", "{", 26));
+ LONGS_EQUAL(32, utf8_charcasecmp_range ("{", "[", 26));
+ LONGS_EQUAL(-32, utf8_charcasecmp_range ("]", "}", 26));
+ LONGS_EQUAL(32, utf8_charcasecmp_range ("}", "]", 26));
+ LONGS_EQUAL(-32, utf8_charcasecmp_range ("\\", "|", 26));
+ LONGS_EQUAL(32, utf8_charcasecmp_range ("|", "\\", 26));
+ LONGS_EQUAL(-32, utf8_charcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(32, utf8_charcasecmp_range ("~", "^", 26));
}
/*