fix(array): use copy constructor and call destructors appropriately

This commit is contained in:
fallenoak 2023-02-05 21:36:49 -06:00
parent 3492f8b8f2
commit 955a0bbba7
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
2 changed files with 31 additions and 7 deletions

View file

@ -2,6 +2,10 @@
#include "storm/String.hpp"
#include "test/Test.hpp"
struct TestArrayObject {
uint32_t index = 0;
};
TEST_CASE("TSBaseArray", "[array]") {
SECTION("constructs correctly") {
TSBaseArray<uint32_t> array;
@ -59,3 +63,27 @@ TEST_CASE("TSGrowableArray", "[array]") {
REQUIRE(array.Count() == 0);
}
}
TEST_CASE("TSGrowableArray::Reserve", "[array]") {
SECTION("reserves slot when array is empty") {
TSGrowableArray<uint32_t> array;
array.Reserve(1, 1);
REQUIRE(array.Count() == 0);
}
SECTION("reserves slot when array has elements") {
TSGrowableArray<TestArrayObject> array;
auto elementA = array.New();
elementA->index = 10;
array.Reserve(1, 1);
auto elementB = array.New();
elementB->index = 20;
REQUIRE(array.Count() == 2);
REQUIRE(array[0].index == 10);
REQUIRE(array[1].index == 20);
}
}