mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:17:35 +00:00
Tests: Add a few tests to verify vectors are using inline storage
This commit is contained in:
parent
c0b7ff3c4c
commit
654950eaf7
1 changed files with 45 additions and 0 deletions
|
@ -572,3 +572,48 @@ TEST_CASE(reverse_range_for_loop)
|
||||||
for (auto item : v.in_reverse())
|
for (auto item : v.in_reverse())
|
||||||
EXPECT_EQ(item, index--);
|
EXPECT_EQ(item, index--);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_inline_element(auto& el, auto& vector)
|
||||||
|
{
|
||||||
|
uintptr_t vector_ptr = (uintptr_t)&vector;
|
||||||
|
uintptr_t element_ptr = (uintptr_t)⪙
|
||||||
|
return (element_ptr >= vector_ptr && element_ptr < (vector_ptr + sizeof(vector)));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(uses_inline_capacity_when_appended_to)
|
||||||
|
{
|
||||||
|
Vector<int, 10> v;
|
||||||
|
v.unchecked_append(1);
|
||||||
|
v.unchecked_append(123);
|
||||||
|
v.unchecked_append(50);
|
||||||
|
v.unchecked_append(43);
|
||||||
|
|
||||||
|
for (auto& el : v)
|
||||||
|
EXPECT(is_inline_element(el, v));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(uses_inline_capacity_when_constructed_from_initializer_list)
|
||||||
|
{
|
||||||
|
Vector<int, 10> v { 10, 9, 3, 1, 3 };
|
||||||
|
|
||||||
|
for (auto& el : v)
|
||||||
|
EXPECT(is_inline_element(el, v));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(uses_inline_capacity_when_constructed_from_other_vector)
|
||||||
|
{
|
||||||
|
Vector other { 4, 3, 2, 1 };
|
||||||
|
Vector<int, 10> v(other);
|
||||||
|
|
||||||
|
for (auto& el : v)
|
||||||
|
EXPECT(is_inline_element(el, v));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(uses_inline_capacity_when_constructed_from_span)
|
||||||
|
{
|
||||||
|
Array array { "f00", "bar", "baz" };
|
||||||
|
Vector<char const*, 10> v(array.span());
|
||||||
|
|
||||||
|
for (auto& el : v)
|
||||||
|
EXPECT(is_inline_element(el, v));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue