Add Entity tests for adding and checking tags

main
copygirl 1 year ago
parent f259c9b821
commit 9faed20c54
  1. 32
      test/entity.zig

@ -23,7 +23,6 @@ test "Entity_init_id" {
defer world.deinit(); defer world.deinit();
const e = try world.entity(.{}, .{}); 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); try expect(c.ecs_get_type(world.raw, e.raw) == null);
} }
@ -33,7 +32,6 @@ test "Entity_init_id_name" {
defer world.deinit(); defer world.deinit();
const e = try world.entity(.{ .name = "foo" }, .{}); 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().?); try expectEqualStrings("foo", e.getName().?);
const path2 = try e.getPath(flecs.allocator); 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); const p = try Path.fromString("parent.child", null, flecs.allocator);
defer p.deinit(); defer p.deinit();
const e = try world.entity(.{ .path = p }, .{}); 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().?); try expectEqualStrings("child", e.getName().?);
const path = try e.getPath(flecs.allocator); const path = try e.getPath(flecs.allocator);
defer path.deinit(); defer path.deinit();
try expectFmt("parent.child", "{}", .{path}); 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));
}

Loading…
Cancel
Save