mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +00:00
AK: Add a unit test for Vector::prepend(Vector&&) with complex T.
It's good to verify that complex objects can be moved nicely by Vector.
This commit is contained in:
parent
4179283562
commit
aeae1cb5e2
1 changed files with 36 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <AK/TestSuite.h>
|
#include <AK/TestSuite.h>
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
|
#include <AK/OwnPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
TEST_CASE(construct)
|
TEST_CASE(construct)
|
||||||
|
@ -98,4 +99,39 @@ TEST_CASE(prepend_vector)
|
||||||
EXPECT_EQ(ints.size(), 0);
|
EXPECT_EQ(ints.size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(prepend_vector_object)
|
||||||
|
{
|
||||||
|
struct SubObject {
|
||||||
|
SubObject(int v) : value(v) {}
|
||||||
|
int value { 0 };
|
||||||
|
};
|
||||||
|
struct Object {
|
||||||
|
OwnPtr<SubObject> object;
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector<Object> objects;
|
||||||
|
objects.append({ make<SubObject>(1) });
|
||||||
|
objects.append({ make<SubObject>(2) });
|
||||||
|
objects.append({ make<SubObject>(3) });
|
||||||
|
|
||||||
|
EXPECT_EQ(objects.size(), 3);
|
||||||
|
|
||||||
|
Vector<Object> more_objects;
|
||||||
|
objects.append({ make<SubObject>(4) });
|
||||||
|
objects.append({ make<SubObject>(5) });
|
||||||
|
objects.append({ make<SubObject>(6) });
|
||||||
|
EXPECT_EQ(more_objects.size(), 3);
|
||||||
|
|
||||||
|
objects.prepend(move(more_objects));
|
||||||
|
EXPECT_EQ(more_objects.size(), 0);
|
||||||
|
EXPECT_EQ(objects.size(), 6);
|
||||||
|
|
||||||
|
EXPECT_EQ(objects[0].object->value, 4);
|
||||||
|
EXPECT_EQ(objects[1].object->value, 5);
|
||||||
|
EXPECT_EQ(objects[2].object->value, 6);
|
||||||
|
EXPECT_EQ(objects[3].object->value, 1);
|
||||||
|
EXPECT_EQ(objects[4].object->value, 2);
|
||||||
|
EXPECT_EQ(objects[5].object->value, 3);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_MAIN(Vector)
|
TEST_MAIN(Vector)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue