Add a couple more entity tests

main
copygirl 1 year ago
parent efd821aa87
commit 899cf8c10e
  1. 67
      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);
}

Loading…
Cancel
Save