Tests: Add test for String::find with empty needle

This adds a test case for String::find and String::find_all with empty
needles. The expected behavior is in line with what the C++ standard
library (and other languages standard libraries) expect.
This commit is contained in:
Max Wipfli 2021-07-01 20:00:07 +02:00 committed by Andreas Kling
parent 9cc35d1ba3
commit 4b87dd5c5c
Notes: sideshowbarker 2024-07-18 11:05:57 +09:00

View file

@ -271,3 +271,14 @@ TEST_CASE(find)
EXPECT_EQ(a.find('b', 4), Optional<size_t> { 6 });
EXPECT_EQ(a.find('b', 9), Optional<size_t> {});
}
TEST_CASE(find_with_empty_needle)
{
String string = "";
EXPECT_EQ(string.find(""sv), 0u);
EXPECT_EQ(string.find_all(""sv), (Vector<size_t> { 0u }));
string = "abc";
EXPECT_EQ(string.find(""sv), 0u);
EXPECT_EQ(string.find_all(""sv), (Vector<size_t> { 0u, 1u, 2u, 3u }));
}