summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-08 16:33:30 -0500
committerAndrew Kaster <andrewdkaster@gmail.com>2023-01-09 19:23:46 -0700
commit6fcc1c742647f05fc65264290622f67b9a6ec745 (patch)
treed354c518445daf878dcf28dc3653180ed8d7e48e /Tests
parent12f6793223e87d4358392e44dbc6cdb8620705b8 (diff)
downloadserenity-6fcc1c742647f05fc65264290622f67b9a6ec745.zip
AK+LibUnicode: Provide Unicode-aware String case transformations
Since AK can't refer to LibUnicode directly, the strategy here is that if you need case transformations, you can link LibUnicode and receive them. If you try to use either of these methods without linking it, then you'll of course get a linker error (note we don't do any fallbacks to e.g. ASCII case transformations). If you don't need these methods, you don't have to link LibUnicode.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/AK/CMakeLists.txt2
-rw-r--r--Tests/AK/TestString.cpp38
2 files changed, 40 insertions, 0 deletions
diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt
index e7e0c0855f..957304cb77 100644
--- a/Tests/AK/CMakeLists.txt
+++ b/Tests/AK/CMakeLists.txt
@@ -86,3 +86,5 @@ set(AK_TEST_SOURCES
foreach(source IN LISTS AK_TEST_SOURCES)
serenity_test("${source}" AK)
endforeach()
+
+target_link_libraries(TestString PRIVATE LibUnicode)
diff --git a/Tests/AK/TestString.cpp b/Tests/AK/TestString.cpp
index 3cc88317a9..3faaa3b654 100644
--- a/Tests/AK/TestString.cpp
+++ b/Tests/AK/TestString.cpp
@@ -107,3 +107,41 @@ TEST_CASE(replace)
EXPECT_EQ(result, "anon@courage:~"sv);
}
}
+
+TEST_CASE(to_lowercase)
+{
+ {
+ auto string = MUST(String::from_utf8("Aa"sv));
+ auto result = MUST(string.to_lowercase());
+ EXPECT_EQ(result, "aa"sv);
+ }
+ {
+ auto string = MUST(String::from_utf8("Ωω"sv));
+ auto result = MUST(string.to_lowercase());
+ EXPECT_EQ(result, "ωω"sv);
+ }
+ {
+ auto string = MUST(String::from_utf8("İi̇"sv));
+ auto result = MUST(string.to_lowercase());
+ EXPECT_EQ(result, "i̇i̇"sv);
+ }
+}
+
+TEST_CASE(to_uppercase)
+{
+ {
+ auto string = MUST(String::from_utf8("Aa"sv));
+ auto result = MUST(string.to_uppercase());
+ EXPECT_EQ(result, "AA"sv);
+ }
+ {
+ auto string = MUST(String::from_utf8("Ωω"sv));
+ auto result = MUST(string.to_uppercase());
+ EXPECT_EQ(result, "ΩΩ"sv);
+ }
+ {
+ auto string = MUST(String::from_utf8("ʼn"sv));
+ auto result = MUST(string.to_uppercase());
+ EXPECT_EQ(result, "ʼN"sv);
+ }
+}