1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

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}().
This commit is contained in:
Linus Groh 2021-02-20 22:39:22 +01:00 committed by Andreas Kling
parent 43948aee51
commit 4fafe14691
5 changed files with 50 additions and 0 deletions

View file

@ -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)