summaryrefslogtreecommitdiff
path: root/Tests/AK
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-05-24 11:50:46 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-24 11:59:18 +0200
commitde395a3df236eb653db78b5b88a0178036f99ba0 (patch)
tree2a6bd2f6126aa62650fc92092eaa4d88ebebc19e /Tests/AK
parent875a2cbb7150b036af343364a8bf2d07a97dd03d (diff)
downloadserenity-de395a3df236eb653db78b5b88a0178036f99ba0.zip
AK+Everywhere: Consolidate String::index_of() and String::find()
We had two functions for doing mostly the same thing. Combine both of them into String::find() and use that everywhere. Also add some tests to cover basic behavior.
Diffstat (limited to 'Tests/AK')
-rw-r--r--Tests/AK/TestString.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Tests/AK/TestString.cpp b/Tests/AK/TestString.cpp
index 40953ec418..01c6368c58 100644
--- a/Tests/AK/TestString.cpp
+++ b/Tests/AK/TestString.cpp
@@ -255,3 +255,19 @@ TEST_CASE(sprintf)
EXPECT_EQ(String(buf1), String("+12"));
EXPECT_EQ(String(buf2), String("-12"));
}
+
+TEST_CASE(find)
+{
+ String a = "foobarbar";
+ EXPECT_EQ(a.find("bar"sv), Optional<size_t> { 3 });
+ EXPECT_EQ(a.find("baz"sv), Optional<size_t> {});
+ EXPECT_EQ(a.find("bar"sv, 4), Optional<size_t> { 6 });
+ EXPECT_EQ(a.find("bar"sv, 9), Optional<size_t> {});
+
+ EXPECT_EQ(a.find('f'), Optional<size_t> { 0 });
+ EXPECT_EQ(a.find('x'), Optional<size_t> {});
+ EXPECT_EQ(a.find('f', 1), Optional<size_t> {});
+ EXPECT_EQ(a.find('b'), Optional<size_t> { 3 });
+ EXPECT_EQ(a.find('b', 4), Optional<size_t> { 6 });
+ EXPECT_EQ(a.find('b', 9), Optional<size_t> {});
+}