Add Entity tests involving World.setScope

main
copygirl 1 year ago
parent 680852f4f8
commit 50c5a83c90
  1. 105
      test/entity.zig

@ -82,3 +82,108 @@ test "Entity_init_id_add_2_comp" {
try expect(e.has(TagA));
try expect(e.has(TagB));
}
test "Entity_init_id_w_scope" {
flecs.init(std.testing.allocator);
var world = try World.initMinimal();
defer world.deinit();
const scope = try world.entity(.{}, .{});
_ = world.setScope(scope);
try expectEqual(scope, world.getScope().?);
const e = try world.entity(.{}, .{});
try expect(e.has(.{ c.EcsChildOf, scope }));
}
test "Entity_init_id_name_w_scope" {
flecs.init(std.testing.allocator);
var world = try World.initMinimal();
defer world.deinit();
const scope = try world.entity(.{ .name = "parent" }, .{});
try expectEqualStrings("parent", scope.getName().?);
_ = world.setScope(scope);
try expectEqual(scope, world.getScope().?);
const e = try world.entity(.{ .name = "child" }, .{});
try expect(e.has(.{ c.EcsChildOf, scope }));
try expectEqualStrings("child", e.getName().?);
const path = try e.getPath(flecs.allocator);
defer path.deinit();
try expectFmt("parent.child", "{}", .{path});
}
test "Entity_init_id_path_w_scope" {
flecs.init(std.testing.allocator);
var world = try World.initMinimal();
defer world.deinit();
const scope = try world.entity(.{ .name = "parent" }, .{});
try expectEqualStrings("parent", scope.getName().?);
_ = world.setScope(scope);
try expectEqual(scope, world.getScope().?);
const p = try Path.fromString("child.grandchild", null, flecs.allocator);
defer p.deinit();
const e = try world.entity(.{ .path = p }, .{});
try expectEqualStrings("grandchild", e.getName().?);
const path = try e.getPath(flecs.allocator);
defer path.deinit();
try expectFmt("parent.child.grandchild", "{}", .{path});
}
test "Entity_init_id_fullpath_w_scope" {
flecs.init(std.testing.allocator);
var world = try World.initMinimal();
defer world.deinit();
const scope = try world.entity(.{ .name = "parent" }, .{});
try expectEqualStrings("parent", scope.getName().?);
_ = world.setScope(scope);
try expectEqual(scope, world.getScope().?);
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecs.allocator);
defer p.deinit();
const e = try world.entity(.{ .path = p }, .{});
try expectEqualStrings("grandchild", e.getName().?);
const path = try e.getPath(flecs.allocator);
defer path.deinit();
try expectFmt("parent.child.grandchild", "{}", .{path});
}
test "Entity_init_id_fullpath_w_scope_existing" {
flecs.init(std.testing.allocator);
var world = try World.initMinimal();
defer world.deinit();
const scope = try world.entity(.{ .name = "parent" }, .{});
try expectEqualStrings("parent", scope.getName().?);
_ = world.setScope(scope);
try expectEqual(scope, world.getScope().?);
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecs.allocator);
defer p.deinit();
const e = try world.entity(.{ .path = p }, .{});
const r = try world.entity(.{ .path = p }, .{});
try expectEqual(e, r);
try expectEqualStrings("grandchild", e.getName().?);
const path = try e.getPath(flecs.allocator);
defer path.deinit();
try expectFmt("parent.child.grandchild", "{}", .{path});
}

Loading…
Cancel
Save