mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
AK: Add a somewhat naive implementation of String::reverse
This will reverse the String's code points (i.e. not just its bytes), but is not aware of grapheme clusters.
This commit is contained in:
parent
f5d253dcfa
commit
9db9b2f9be
3 changed files with 38 additions and 0 deletions
|
@ -108,6 +108,23 @@ TEST_CASE(replace)
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE(reverse)
|
||||
{
|
||||
auto test_reverse = [](auto test, auto expected) {
|
||||
auto string = MUST(String::from_utf8(test));
|
||||
auto result = MUST(string.reverse());
|
||||
|
||||
EXPECT_EQ(result, expected);
|
||||
};
|
||||
|
||||
test_reverse(""sv, ""sv);
|
||||
test_reverse("a"sv, "a"sv);
|
||||
test_reverse("ab"sv, "ba"sv);
|
||||
test_reverse("ab cd ef"sv, "fe dc ba"sv);
|
||||
test_reverse("😀"sv, "😀"sv);
|
||||
test_reverse("ab😀cd"sv, "dc😀ba"sv);
|
||||
}
|
||||
|
||||
TEST_CASE(to_lowercase)
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue