summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-12-21 19:23:29 +0100
committerSébastien Helleu <flashcode@flashtux.org>2022-12-21 20:49:09 +0100
commit68b510517e7a14b2d2457f8437e9291b87e0d1d5 (patch)
treea3fae5b8673ec860f49315bb1b0ec72e74cf54d1 /tests
parent95286c1eb362cedb767597ea23fb29d6455f6b94 (diff)
downloadweechat-68b510517e7a14b2d2457f8437e9291b87e0d1d5.zip
core: improve case convert and insensitive char comparisons (closes #258)
All lowercase letters are now properly converted to uppercase letters (and vice versa), via functions `towupper` and `towlower`. Functions `string_tolower`, `string_toupper` and `utf8_charcasecmp` have been optimized to be faster when there are ASCII chars (< 128); functions are about 25-40% faster with mixed chars (both ASCII and multi-bytes). Function `utf8_wide_char` has been removed, `utf8_char_int` can be used instead.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/core/test-core-eval.cpp4
-rw-r--r--tests/unit/core/test-core-string.cpp10
-rw-r--r--tests/unit/core/test-core-utf8.cpp9
3 files changed, 8 insertions, 15 deletions
diff --git a/tests/unit/core/test-core-eval.cpp b/tests/unit/core/test-core-eval.cpp
index 248c680fe..c6c18e2eb 100644
--- a/tests/unit/core/test-core-eval.cpp
+++ b/tests/unit/core/test-core-eval.cpp
@@ -538,12 +538,12 @@ TEST(CoreEval, EvalExpression)
/* test case conversion: to lower case */
WEE_CHECK_EVAL("", "${lower:}");
WEE_CHECK_EVAL("this is a test", "${lower:This is a TEST}");
- WEE_CHECK_EVAL("testÉ testé", "${lower:TESTÉ Testé}");
+ WEE_CHECK_EVAL("testé testé", "${lower:TESTÉ Testé}");
/* test case conversion: to upper case */
WEE_CHECK_EVAL("", "${upper:}");
WEE_CHECK_EVAL("THIS IS A TEST", "${upper:This is a TEST}");
- WEE_CHECK_EVAL("TESTÉ TESTé", "${upper:TESTÉ Testé}");
+ WEE_CHECK_EVAL("TESTÉ TESTÉ", "${upper:TESTÉ Testé}");
/* test hidden chars */
WEE_CHECK_EVAL("", "${hide:invalid}");
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index ec8dce52c..24a557cb5 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -191,8 +191,9 @@ TEST(CoreString, ToLower)
WEE_TEST_STR(NULL, string_tolower (NULL));
WEE_TEST_STR("", string_tolower (""));
- WEE_TEST_STR("abcd_É", string_tolower ("ABCD_É"));
- WEE_TEST_STR("À É Ï Ô Ü Ÿ Æ Œ Ç", string_tolower ("À É Ï Ô Ü Ÿ Æ Œ Ç"));
+ WEE_TEST_STR("abcd_é", string_tolower ("ABCD_É"));
+ WEE_TEST_STR("àáâãäåæçèéêëìíîïðñòóôõöøœšùúûüýÿ",
+ string_tolower ("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØŒŠÙÚÛÜÝŸ"));
WEE_TEST_STR("€", string_tolower ("€"));
WEE_TEST_STR("[⛄]", string_tolower ("[⛄]"));
}
@@ -209,8 +210,9 @@ TEST(CoreString, ToUpper)
WEE_TEST_STR(NULL, string_tolower (NULL));
WEE_TEST_STR("", string_toupper (""));
- WEE_TEST_STR("ABCD_é", string_toupper ("abcd_é"));
- WEE_TEST_STR("à é ï ô ü ÿ æ œ ç", string_toupper ("à é ï ô ü ÿ æ œ ç"));
+ WEE_TEST_STR("ABCD_É", string_toupper ("abcd_é"));
+ WEE_TEST_STR("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØŒŠÙÚÛÜÝŸ",
+ string_toupper ("àáâãäåæçèéêëìíîïðñòóôõöøœšùúûüýÿ"));
WEE_TEST_STR("€", string_toupper ("€"));
WEE_TEST_STR("[⛄]", string_toupper ("[⛄]"));
}
diff --git a/tests/unit/core/test-core-utf8.cpp b/tests/unit/core/test-core-utf8.cpp
index 7051e1478..7da5482b1 100644
--- a/tests/unit/core/test-core-utf8.cpp
+++ b/tests/unit/core/test-core-utf8.cpp
@@ -469,15 +469,6 @@ TEST(CoreUtf8, Convert)
STRCMP_EQUAL(UNICODE_CJK_YELLOW, result);
LONGS_EQUAL(4, utf8_int_string (0x24b62, result));
STRCMP_EQUAL(UNICODE_HAN_CHAR, result);
-
- /* get wide char */
- LONGS_EQUAL(WEOF, utf8_wide_char (NULL));
- LONGS_EQUAL(WEOF, utf8_wide_char (""));
- LONGS_EQUAL(65, utf8_wide_char ("A"));
- LONGS_EQUAL(0xc3ab, utf8_wide_char ("ë"));
- LONGS_EQUAL(0xe282ac, utf8_wide_char ("€"));
- LONGS_EQUAL(0xe2bba9, utf8_wide_char (UNICODE_CJK_YELLOW));
- LONGS_EQUAL(0xf0a4ada2, utf8_wide_char (UNICODE_HAN_CHAR));
}
/*