From 899cf8c10e7665f6e18fc966c05cd40a08f73026 Mon Sep 17 00:00:00 2001 From: copygirl Date: Wed, 13 Sep 2023 19:28:39 +0200 Subject: [PATCH] Add a couple more entity tests --- test/entity.zig | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/entity.zig b/test/entity.zig index c5d3e66..7133e9c 100644 --- a/test/entity.zig +++ b/test/entity.zig @@ -554,3 +554,70 @@ test "Entity_find_id_path_mismatch_w_scope" { const r = world.entity(.{ .id = e, .path = unnamed_path }, .{}); try expect.err(FlecsError.Unknown, r); } + +test "Entity_find_id_add_1_comp" { + const TagA = struct {}; + + flecs.init(alloc); + var world = try World.initMinimal(); + defer world.deinit(); + + _ = try world.tag(TagA); + + const e = try world.entity(.{ .name = "foo" }, .{}); + try expect.equal("foo", e.getName()); + + const r = try world.entity(.{ .name = "foo" }, .{TagA}); + try expect.equal(e, r); + try expect.true(e.has(TagA)); +} + +test "Entity_find_id_add_2_comp" { + const TagA = struct {}; + const TagB = struct {}; + + flecs.init(alloc); + var world = try World.initMinimal(); + defer world.deinit(); + + _ = try world.tag(TagA); + _ = try world.tag(TagB); + + const e = try world.entity(.{ .name = "foo" }, .{}); + try expect.equal("foo", e.getName()); + + const r = try world.entity(.{ .name = "foo" }, .{ TagA, TagB }); + try expect.equal(e, r); + try expect.true(e.has(TagA)); + try expect.true(e.has(TagB)); +} + +test "Entity_init_w_scope_name" { + flecs.init(alloc); + var world = try World.initMinimal(); + defer world.deinit(); + + _ = try world.entity(.{ .name = "parent" }, .{}); + + const foo_parts = Path.buildParts(.{ "parent", "foo" }); + const foo_path = Path.fromParts(false, &foo_parts); + const foo = try world.entity(.{ .path = foo_path }, .{}); + + _ = world.setScope(foo); + + const child = try world.entity(.{ .name = "foo" }, .{}); + try expect.equal("foo", child.getName()); + + const path = try child.getPath(flecs.allocator); + defer path.deinit(); + try expect.fmt("parent.foo.foo", "{}", .{path}); +} + +test "Entity_init_w_core_name" { + flecs.init(alloc); + var world = try World.initMinimal(); + defer world.deinit(); + + const e = try world.entity(.{ .name = "Prefab" }, .{}); + try expect.false(c.EcsPrefab == e.raw); +}