Test to check reusing components

main
copygirl 7 months ago
parent fa89eca82d
commit 0797eff416
  1. 25
      src/world.zig

@ -339,3 +339,28 @@ test "World REST API" {
world.quit(); world.quit();
} }
test "World delete and reuse component" {
flecszigble.init(std.testing.allocator);
var world = try World(void).initMinimal();
defer world.deinit();
const Position = struct { x: f32, y: f32 };
const position_1 = try world.component(Position);
// Remove default component cleanup policy to allow deletion of the component.
position_1.remove(.{ flecs.core.OnDelete, flecs.core.Panic });
const entity = try world.entity(.{}, .{Position});
entity.set(Position, .{ .x = 1.0, .y = 2.0 });
try expect.equal(.{ .x = 1.0, .y = 2.0 }, entity.get(Position));
// Deleting the component automatically removes it from any entity.
position_1.delete();
const position_2 = try world.component(Position);
try expect.equal(position_2, world.lookupType(Position));
entity.set(Position, .{ .x = 2.0, .y = 4.0 });
try expect.equal(.{ .x = 2.0, .y = 4.0 }, entity.get(Position));
}

Loading…
Cancel
Save