Browse Source

table: more tests

Michele Caini 1 năm trước cách đây
mục cha
commit
7ca3f84891
1 tập tin đã thay đổi với 46 bổ sung0 xóa
  1. 46 0
      test/entt/entity/table.cpp

+ 46 - 0
test/entt/entity/table.cpp

@@ -16,3 +16,49 @@ TEST(Table, Constructors) {
 
 
     ASSERT_NO_THROW([[maybe_unused]] auto alloc = table.get_allocator());
     ASSERT_NO_THROW([[maybe_unused]] auto alloc = table.get_allocator());
 }
 }
+
+TEST(Table, Move) {
+    entt::table<int, char> table;
+
+    table.emplace(3, 'c');
+
+    static_assert(std::is_move_constructible_v<decltype(table)>, "Move constructible type required");
+    static_assert(std::is_move_assignable_v<decltype(table)>, "Move assignable type required");
+
+    entt::table<int, char> other{std::move(table)};
+
+    test::is_initialized(table);
+
+    ASSERT_TRUE(table.empty());
+    ASSERT_FALSE(other.empty());
+
+    ASSERT_EQ(other[0u], std::make_tuple(3, 'c'));
+
+    entt::table<int, char> extended{std::move(other), std::allocator<void>{}};
+
+    test::is_initialized(other);
+
+    ASSERT_TRUE(other.empty());
+    ASSERT_FALSE(extended.empty());
+
+    ASSERT_EQ(extended[0u], std::make_tuple(3, 'c'));
+
+    table = std::move(extended);
+    test::is_initialized(extended);
+
+    ASSERT_FALSE(table.empty());
+    ASSERT_TRUE(other.empty());
+    ASSERT_TRUE(extended.empty());
+
+    ASSERT_EQ(table[0u], std::make_tuple(3, 'c'));
+
+    other = entt::table<int, char>{};
+    other.emplace(1, 'a');
+    other = std::move(table);
+    test::is_initialized(table);
+
+    ASSERT_TRUE(table.empty());
+    ASSERT_FALSE(other.empty());
+
+    ASSERT_EQ(other[0u], std::make_tuple(3, 'c'));
+}