diff options
author | Linus Groh <mail@linusgroh.de> | 2021-02-20 22:39:22 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-21 19:47:47 +0100 |
commit | 4fafe14691512b787f15de292029c145566786f4 (patch) | |
tree | 06f220c171104c012a34c251f37b09622c76e528 /AK/Tests | |
parent | 43948aee51f6e535eb98a73666d4c76deabe7b44 (diff) | |
download | serenity-4fafe14691512b787f15de292029c145566786f4.zip |
AK: Add String{,Utils}::to_snakecase()
This is an improved version of WrapperGenerator's snake_name(), which
seems like the kind of thing that could be useful elsewhere but would
end up getting duplicated - so let's add this to AK::String instead,
like to_{lowercase,uppercase}().
Diffstat (limited to 'AK/Tests')
-rw-r--r-- | AK/Tests/TestStringUtils.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/AK/Tests/TestStringUtils.cpp b/AK/Tests/TestStringUtils.cpp index d1edda37ed..f5760f4b0f 100644 --- a/AK/Tests/TestStringUtils.cpp +++ b/AK/Tests/TestStringUtils.cpp @@ -310,4 +310,18 @@ TEST_CASE(find) EXPECT_EQ(AK::StringUtils::find(test_string, "78").has_value(), false); } +TEST_CASE(to_snakecase) +{ + EXPECT_EQ(AK::StringUtils::to_snakecase("foobar"), "foobar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("Foobar"), "foobar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("FOOBAR"), "foobar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("fooBar"), "foo_bar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("FooBar"), "foo_bar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("fooBAR"), "foo_bar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("FOOBar"), "foo_bar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("foo_bar"), "foo_bar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("FBar"), "f_bar"); + EXPECT_EQ(AK::StringUtils::to_snakecase("FooB"), "foo_b"); +} + TEST_MAIN(StringUtils) |