From 9faed20c54bca6b81ca9c0a618110943d7c352db Mon Sep 17 00:00:00 2001 From: copygirl Date: Thu, 7 Sep 2023 12:44:03 +0200 Subject: [PATCH] Add Entity tests for adding and checking tags --- test/entity.zig | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/test/entity.zig b/test/entity.zig index c1f384b..2731b1f 100644 --- a/test/entity.zig +++ b/test/entity.zig @@ -23,7 +23,6 @@ test "Entity_init_id" { defer world.deinit(); const e = try world.entity(.{}, .{}); - // try expect(e.raw != 0); -- Not necessary, world.entity() returns error if result would be 0. try expect(c.ecs_get_type(world.raw, e.raw) == null); } @@ -33,7 +32,6 @@ test "Entity_init_id_name" { defer world.deinit(); const e = try world.entity(.{ .name = "foo" }, .{}); - // try expect(e.raw != 0); -- Not necessary, world.entity() returns error if result would be 0. try expectEqualStrings("foo", e.getName().?); const path2 = try e.getPath(flecs.allocator); @@ -49,10 +47,38 @@ test "Entity_init_id_path" { const p = try Path.fromString("parent.child", null, flecs.allocator); defer p.deinit(); const e = try world.entity(.{ .path = p }, .{}); - // try expect(e.raw != 0); -- Not necessary, world.entity() returns error if result would be 0. try expectEqualStrings("child", e.getName().?); const path = try e.getPath(flecs.allocator); defer path.deinit(); try expectFmt("parent.child", "{}", .{path}); } + +test "Entity_init_id_add_1_comp" { + const TagA = struct {}; + + flecs.init(std.testing.allocator); + var world = try World.initMinimal(); + defer world.deinit(); + + _ = try world.tag(TagA); + + const e = try world.entity(.{}, .{TagA}); + try expect(e.has(TagA)); +} + +test "Entity_init_id_add_2_comp" { + const TagA = struct {}; + const TagB = struct {}; + + flecs.init(std.testing.allocator); + var world = try World.initMinimal(); + defer world.deinit(); + + _ = try world.tag(TagA); + _ = try world.tag(TagB); + + const e = try world.entity(.{}, .{ TagA, TagB }); + try expect(e.has(TagA)); + try expect(e.has(TagB)); +}