diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-07-01 15:01:29 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-02 21:54:21 +0200 |
commit | 3bdaed501e13a8b2dcdbbe2b5f4f68ffa22db59e (patch) | |
tree | 223fcf2b828bcf3bc93f636c1e5a1611c5961bd9 /Tests | |
parent | 56253bf3895e258729130a7ec22acff74e5b4212 (diff) | |
download | serenity-3bdaed501e13a8b2dcdbbe2b5f4f68ffa22db59e.zip |
AK+Everywhere: Remove StringView::find_{first,last}_of(char) methods
This removes StringView::find_first_of(char) and find_last_of(char) and
replaces all its usages with find and find_last respectively. This is
because those two methods are functionally equivalent.
find_{first,last}_of should only be used if searching for multiple
different characters, which is never the case with the char argument.
This also adds the [[nodiscard]] to the remaining find_{first,last}_of
methods.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/AK/TestStringView.cpp | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/Tests/AK/TestStringView.cpp b/Tests/AK/TestStringView.cpp index 8f7785dce3..fa079c9ebb 100644 --- a/Tests/AK/TestStringView.cpp +++ b/Tests/AK/TestStringView.cpp @@ -104,52 +104,45 @@ TEST_CASE(lines) EXPECT_EQ(test_string_vector.at(2).is_empty(), true); } -TEST_CASE(find_first_of) +TEST_CASE(find) { - String test_string = "aabbcc_xy_ccbbaa"; - StringView test_string_view = test_string.view(); - - EXPECT_EQ(test_string_view.find_first_of('b').has_value(), true); - EXPECT_EQ(test_string_view.find_first_of('b').value(), 2U); - - EXPECT_EQ(test_string_view.find_first_of('_').has_value(), true); - EXPECT_EQ(test_string_view.find_first_of('_').value(), 6U); + auto test_string_view = "aabbcc_xy_ccbbaa"sv; + EXPECT_EQ(test_string_view.find('b'), 2U); + EXPECT_EQ(test_string_view.find('_'), 6U); + EXPECT_EQ(test_string_view.find('n').has_value(), false); +} - EXPECT_EQ(test_string_view.find_first_of("bc").has_value(), true); - EXPECT_EQ(test_string_view.find_first_of("bc").value(), 2U); +TEST_CASE(find_last) +{ + auto test_string_view = "aabbcc_xy_ccbbaa"sv; + EXPECT_EQ(test_string_view.find_last('b'), 13U); + EXPECT_EQ(test_string_view.find_last('_'), 9U); + EXPECT_EQ(test_string_view.find_last('3').has_value(), false); - EXPECT_EQ(test_string_view.find_first_of("yx").has_value(), true); - EXPECT_EQ(test_string_view.find_first_of("yx").value(), 7U); + test_string_view = "/"sv; + EXPECT_EQ(test_string_view.find_last('/'), 0U); +} - EXPECT_EQ(test_string_view.find_first_of('n').has_value(), false); +TEST_CASE(find_first_of) +{ + auto test_string_view = "aabbcc_xy_ccbbaa"sv; + EXPECT_EQ(test_string_view.find_first_of("bc"), 2U); + EXPECT_EQ(test_string_view.find_first_of("yx"), 7U); EXPECT_EQ(test_string_view.find_first_of("defg").has_value(), false); + + test_string_view = "/"sv; + EXPECT_EQ(test_string_view.find_first_of("/"), 0U); } TEST_CASE(find_last_of) { - String test_string = "aabbcc_xy_ccbbaa"; - StringView test_string_view = test_string.view(); - - EXPECT_EQ(test_string_view.find_last_of('b').has_value(), true); - EXPECT_EQ(test_string_view.find_last_of('b').value(), 13U); - - EXPECT_EQ(test_string_view.find_last_of('_').has_value(), true); - EXPECT_EQ(test_string_view.find_last_of('_').value(), 9U); - - EXPECT_EQ(test_string_view.find_last_of("bc").has_value(), true); - EXPECT_EQ(test_string_view.find_last_of("bc").value(), 13U); - - EXPECT_EQ(test_string_view.find_last_of("yx").has_value(), true); - EXPECT_EQ(test_string_view.find_last_of("yx").value(), 8U); - - EXPECT_EQ(test_string_view.find_last_of('3').has_value(), false); + auto test_string_view = "aabbcc_xy_ccbbaa"sv; + EXPECT_EQ(test_string_view.find_last_of("bc"), 13U); + EXPECT_EQ(test_string_view.find_last_of("yx"), 8U); EXPECT_EQ(test_string_view.find_last_of("fghi").has_value(), false); - test_string_view = "/"; - EXPECT_EQ(test_string_view.find_last_of('/').has_value(), true); - EXPECT_EQ(test_string_view.find_last_of('/').value(), 0U); - EXPECT_EQ(test_string_view.find_last_of("/").has_value(), true); - EXPECT_EQ(test_string_view.find_last_of("/").value(), 0U); + test_string_view = "/"sv; + EXPECT_EQ(test_string_view.find_last_of("/"), 0U); } TEST_CASE(split_view) |