summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorValtteri Koskivuori <vkoskiv@gmail.com>2021-05-03 21:46:18 +0300
committerLinus Groh <mail@linusgroh.de>2021-05-07 11:46:53 +0100
commit1069979ddff984737c10eb74b70f00850de565ca (patch)
treeda478e25320eaca073c528009a1d00d1ff2e803c /Tests
parentaacbee8ed84ef1e58b9845774c89436cf3d479db (diff)
downloadserenity-1069979ddff984737c10eb74b70f00850de565ca.zip
AK: Implement Span::starts_with()
Useful for checking for contents at the start of a span.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/AK/TestSpan.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Tests/AK/TestSpan.cpp b/Tests/AK/TestSpan.cpp
index 2668133c4e..8affd79584 100644
--- a/Tests/AK/TestSpan.cpp
+++ b/Tests/AK/TestSpan.cpp
@@ -123,3 +123,19 @@ TEST_CASE(span_from_c_string)
const char* str = "Serenity";
[[maybe_unused]] ReadonlyBytes bytes { str, strlen(str) };
}
+
+TEST_CASE(starts_with)
+{
+ const char* str = "HeyFriends!";
+ ReadonlyBytes bytes { str, strlen(str) };
+ const char* str_hey = "Hey";
+ ReadonlyBytes hey_bytes { str_hey, strlen(str_hey) };
+ EXPECT(bytes.starts_with(hey_bytes));
+ const char* str_nah = "Nah";
+ ReadonlyBytes nah_bytes { str_nah, strlen(str_nah) };
+ EXPECT(!bytes.starts_with(nah_bytes));
+
+ const u8 hey_array[3] = { 'H', 'e', 'y' };
+ ReadonlyBytes hey_bytes_u8 { hey_array, 3 };
+ EXPECT(bytes.starts_with(hey_bytes_u8));
+}