summaryrefslogtreecommitdiff
path: root/Tests/AK
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2023-02-10 19:12:10 +0000
committerLinus Groh <mail@linusgroh.de>2023-02-10 22:18:19 +0000
commitd9d556fbabd58cac630cd2e28c77f499460fb724 (patch)
treeb402d5911ec3ce8c8ed58e494b8c86ea4cafba1c /Tests/AK
parent237df9df5c471edb8db44b96bb8a9f51418824c2 (diff)
downloadserenity-d9d556fbabd58cac630cd2e28c77f499460fb724.zip
AK: Allow Vector<ByteBuffer>::contains_slow to accept (Readonly)Bytes
This is done by providing Traits<ByteBuffer>::equals functions for (Readonly)Bytes, as the base GenericTraits<T>::equals is unable to convert the ByteBuffer to (Readonly)Bytes to then use Span::operator== This allows us to check if a Vector<ByteBuffer> contains a (Readonly)Bytes without having to making a copy of it into a ByteBuffer first. The initial use of this is in LibWeb with CORS-preflight, where we check the split contents of the Access-Control headers with Fetch::Infrastructure::Request::method() and static StringViews such as "*"sv.bytes().
Diffstat (limited to 'Tests/AK')
-rw-r--r--Tests/AK/TestByteBuffer.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/Tests/AK/TestByteBuffer.cpp b/Tests/AK/TestByteBuffer.cpp
index 29ed85d32f..7122b3264a 100644
--- a/Tests/AK/TestByteBuffer.cpp
+++ b/Tests/AK/TestByteBuffer.cpp
@@ -7,6 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/ByteBuffer.h>
+#include <AK/Vector.h>
TEST_CASE(equality_operator)
{
@@ -33,6 +34,18 @@ TEST_CASE(equality_operator)
EXPECT_EQ(d == d, true);
}
+TEST_CASE(byte_buffer_vector_contains_slow_bytes)
+{
+ Vector<ByteBuffer> vector;
+ ByteBuffer a = ByteBuffer::copy("Hello, friend", 13).release_value();
+ vector.append(a);
+
+ ReadonlyBytes b = "Hello, friend"sv.bytes();
+ Bytes c = a.bytes();
+ EXPECT_EQ(vector.contains_slow(b), true);
+ EXPECT_EQ(vector.contains_slow(c), true);
+}
+
BENCHMARK_CASE(append)
{
ByteBuffer bb;