|
|
@ -2,15 +2,11 @@ |
|
|
|
// https://github.com/SanderMertens/flecs/blob/master/test/api/src/Entity.c |
|
|
|
// https://github.com/SanderMertens/flecs/blob/master/test/api/src/Entity.c |
|
|
|
|
|
|
|
|
|
|
|
const std = @import("std"); |
|
|
|
const std = @import("std"); |
|
|
|
const expect = std.testing.expect; |
|
|
|
const alloc = std.testing.allocator; |
|
|
|
const expectFmt = std.testing.expectFmt; |
|
|
|
const expect = @import("../src/expect.zig"); |
|
|
|
const expectEqual = std.testing.expectEqual; |
|
|
|
|
|
|
|
const expectEqualStrings = std.testing.expectEqualStrings; |
|
|
|
|
|
|
|
const expectError = std.testing.expectError; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const util = @import("./util.zig"); |
|
|
|
const util = @import("./util.zig"); |
|
|
|
const FlecsError = @import("../src/error.zig").FlecsError; |
|
|
|
const FlecsError = @import("../src/error.zig").FlecsError; |
|
|
|
|
|
|
|
|
|
|
|
const flecs = @import("../src/main.zig"); |
|
|
|
const flecs = @import("../src/main.zig"); |
|
|
|
const c = flecs.c; |
|
|
|
const c = flecs.c; |
|
|
|
|
|
|
|
|
|
|
@ -20,60 +16,60 @@ const Path = context.Path; |
|
|
|
const World = context.World; |
|
|
|
const World = context.World; |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id" { |
|
|
|
test "Entity_init_id" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{}, .{}); |
|
|
|
const e = try world.entity(.{}, .{}); |
|
|
|
try expect(c.ecs_get_type(world.raw, e.raw) == null); |
|
|
|
try expect.null(c.ecs_get_type(world.raw, e.raw)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_name" { |
|
|
|
test "Entity_init_id_name" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
try expectEqualStrings("foo", e.getName().?); |
|
|
|
try expect.equal("foo", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const path = try e.getPath(flecs.allocator); |
|
|
|
const path = try e.getPath(flecs.allocator); |
|
|
|
defer path.deinit(); |
|
|
|
defer path.deinit(); |
|
|
|
try expectFmt("foo", "{}", .{path}); |
|
|
|
try expect.fmt("foo", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_path" { |
|
|
|
test "Entity_init_id_path" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const e_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("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 expect.fmt("parent.child", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_add_1_comp" { |
|
|
|
test "Entity_init_id_add_1_comp" { |
|
|
|
const TagA = struct {}; |
|
|
|
const TagA = struct {}; |
|
|
|
|
|
|
|
|
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
_ = try world.tag(TagA); |
|
|
|
_ = try world.tag(TagA); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{}, .{TagA}); |
|
|
|
const e = try world.entity(.{}, .{TagA}); |
|
|
|
try expect(e.has(TagA)); |
|
|
|
try expect.true(e.has(TagA)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_add_2_comp" { |
|
|
|
test "Entity_init_id_add_2_comp" { |
|
|
|
const TagA = struct {}; |
|
|
|
const TagA = struct {}; |
|
|
|
const TagB = struct {}; |
|
|
|
const TagB = struct {}; |
|
|
|
|
|
|
|
|
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
@ -81,138 +77,138 @@ test "Entity_init_id_add_2_comp" { |
|
|
|
_ = try world.tag(TagB); |
|
|
|
_ = try world.tag(TagB); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{}, .{ TagA, TagB }); |
|
|
|
const e = try world.entity(.{}, .{ TagA, TagB }); |
|
|
|
try expect(e.has(TagA)); |
|
|
|
try expect.true(e.has(TagA)); |
|
|
|
try expect(e.has(TagB)); |
|
|
|
try expect.true(e.has(TagB)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_w_scope" { |
|
|
|
test "Entity_init_id_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{}, .{}); |
|
|
|
const scope = try world.entity(.{}, .{}); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{}, .{}); |
|
|
|
const e = try world.entity(.{}, .{}); |
|
|
|
|
|
|
|
|
|
|
|
try expect(e.has(.{ c.EcsChildOf, scope })); |
|
|
|
try expect.true(e.has(.{ c.EcsChildOf, scope })); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_name_w_scope" { |
|
|
|
test "Entity_init_id_name_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
const e = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
|
|
|
|
|
|
|
|
try expect(e.has(.{ c.EcsChildOf, scope })); |
|
|
|
try expect.true(e.has(.{ c.EcsChildOf, scope })); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("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 expect.fmt("parent.child", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_path_w_scope" { |
|
|
|
test "Entity_init_id_path_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e_parts = Path.buildParts(.{ "child", "grandchild" }); |
|
|
|
const e_parts = Path.buildParts(.{ "child", "grandchild" }); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
|
|
|
|
|
|
|
|
try expectEqualStrings("grandchild", e.getName().?); |
|
|
|
try expect.equal("grandchild", 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.grandchild", "{}", .{path}); |
|
|
|
try expect.fmt("parent.child.grandchild", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_fullpath_w_scope" { |
|
|
|
test "Entity_init_id_fullpath_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecs.allocator); |
|
|
|
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecs.allocator); |
|
|
|
defer p.deinit(); |
|
|
|
defer p.deinit(); |
|
|
|
const e = try world.entity(.{ .path = p }, .{}); |
|
|
|
const e = try world.entity(.{ .path = p }, .{}); |
|
|
|
|
|
|
|
|
|
|
|
try expectEqualStrings("grandchild", e.getName().?); |
|
|
|
try expect.equal("grandchild", 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.grandchild", "{}", .{path}); |
|
|
|
try expect.fmt("parent.child.grandchild", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_fullpath_w_scope_existing" { |
|
|
|
test "Entity_init_id_fullpath_w_scope_existing" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecs.allocator); |
|
|
|
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecs.allocator); |
|
|
|
defer p.deinit(); |
|
|
|
defer p.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .path = p }, .{}); |
|
|
|
const e = try world.entity(.{ .path = p }, .{}); |
|
|
|
const r = try world.entity(.{ .path = p }, .{}); |
|
|
|
const r = try world.entity(.{ .path = p }, .{}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
|
|
|
|
|
|
|
|
try expectEqualStrings("grandchild", e.getName().?); |
|
|
|
try expect.equal("grandchild", 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.grandchild", "{}", .{path}); |
|
|
|
try expect.fmt("parent.child.grandchild", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_name_1_comp" { |
|
|
|
test "Entity_init_id_name_1_comp" { |
|
|
|
const TagA = struct {}; |
|
|
|
const TagA = struct {}; |
|
|
|
|
|
|
|
|
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
_ = try world.tag(TagA); |
|
|
|
_ = try world.tag(TagA); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{TagA}); |
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{TagA}); |
|
|
|
try expect(e.has(TagA)); |
|
|
|
try expect.true(e.has(TagA)); |
|
|
|
try expectEqualStrings("foo", e.getName().?); |
|
|
|
try expect.equal("foo", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const path = try e.getPath(flecs.allocator); |
|
|
|
const path = try e.getPath(flecs.allocator); |
|
|
|
defer path.deinit(); |
|
|
|
defer path.deinit(); |
|
|
|
try expectFmt("foo", "{}", .{path}); |
|
|
|
try expect.fmt("foo", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_name_2_comp" { |
|
|
|
test "Entity_init_id_name_2_comp" { |
|
|
|
const TagA = struct {}; |
|
|
|
const TagA = struct {}; |
|
|
|
const TagB = struct {}; |
|
|
|
const TagB = struct {}; |
|
|
|
|
|
|
|
|
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
@ -220,19 +216,19 @@ test "Entity_init_id_name_2_comp" { |
|
|
|
_ = try world.tag(TagB); |
|
|
|
_ = try world.tag(TagB); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{ TagA, TagB }); |
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{ TagA, TagB }); |
|
|
|
try expect(e.has(TagA)); |
|
|
|
try expect.true(e.has(TagA)); |
|
|
|
try expectEqualStrings("foo", e.getName().?); |
|
|
|
try expect.equal("foo", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const path = try e.getPath(flecs.allocator); |
|
|
|
const path = try e.getPath(flecs.allocator); |
|
|
|
defer path.deinit(); |
|
|
|
defer path.deinit(); |
|
|
|
try expectFmt("foo", "{}", .{path}); |
|
|
|
try expect.fmt("foo", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_name_2_comp_w_scope" { |
|
|
|
test "Entity_init_id_name_2_comp_w_scope" { |
|
|
|
const TagA = struct {}; |
|
|
|
const TagA = struct {}; |
|
|
|
const TagB = struct {}; |
|
|
|
const TagB = struct {}; |
|
|
|
|
|
|
|
|
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
@ -240,24 +236,24 @@ test "Entity_init_id_name_2_comp_w_scope" { |
|
|
|
_ = try world.tag(TagB); |
|
|
|
_ = try world.tag(TagB); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "child" }, .{ TagA, TagB }); |
|
|
|
const e = try world.entity(.{ .name = "child" }, .{ TagA, TagB }); |
|
|
|
try expect(e.has(TagA)); |
|
|
|
try expect.true(e.has(TagA)); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("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 expect.fmt("parent.child", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_id_add_1_comp" { |
|
|
|
test "Entity_id_add_1_comp" { |
|
|
|
const TagA = struct {}; |
|
|
|
const TagA = struct {}; |
|
|
|
|
|
|
|
|
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
@ -265,15 +261,15 @@ test "Entity_id_add_1_comp" { |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{}, .{}); |
|
|
|
const e = try world.entity(.{}, .{}); |
|
|
|
const r = try world.entity(.{ .id = e }, .{TagA}); |
|
|
|
const r = try world.entity(.{ .id = e }, .{TagA}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
try expect(e.has(TagA)); |
|
|
|
try expect.true(e.has(TagA)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_id_add_2_comp" { |
|
|
|
test "Entity_id_add_2_comp" { |
|
|
|
const TagA = struct {}; |
|
|
|
const TagA = struct {}; |
|
|
|
const TagB = struct {}; |
|
|
|
const TagB = struct {}; |
|
|
|
|
|
|
|
|
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
@ -282,265 +278,265 @@ test "Entity_id_add_2_comp" { |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{}, .{}); |
|
|
|
const e = try world.entity(.{}, .{}); |
|
|
|
const r = try world.entity(.{ .id = e }, .{ TagA, TagB }); |
|
|
|
const r = try world.entity(.{ .id = e }, .{ TagA, TagB }); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
try expect(e.has(TagA)); |
|
|
|
try expect.true(e.has(TagA)); |
|
|
|
try expect(e.has(TagB)); |
|
|
|
try expect.true(e.has(TagB)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_init_id_path_w_sep" { |
|
|
|
test "Entity_init_id_path_w_sep" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const p = try Path.fromString("parent::child", .{ .root_sep = null, .sep = "::" }, flecs.allocator); |
|
|
|
const p = try Path.fromString("parent::child", .{ .root_sep = null, .sep = "::" }, flecs.allocator); |
|
|
|
defer p.deinit(); |
|
|
|
defer p.deinit(); |
|
|
|
const e = try world.entity(.{ .path = p }, .{}); |
|
|
|
const e = try world.entity(.{ .path = p }, .{}); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("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 expect.fmt("parent.child", "{}", .{path}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_name" { |
|
|
|
test "Entity_find_id_name" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
try expectEqualStrings("foo", e.getName().?); |
|
|
|
try expect.equal("foo", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const r = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
const r = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_w_existing_id_name" { |
|
|
|
test "Entity_find_w_existing_id_name" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const id = try world.entity(.{}, .{}); |
|
|
|
const id = try world.entity(.{}, .{}); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .id = id, .name = "foo" }, .{}); |
|
|
|
const e = try world.entity(.{ .id = id, .name = "foo" }, .{}); |
|
|
|
try expectEqual(e, id); |
|
|
|
try expect.equal(e, id); |
|
|
|
try expectEqualStrings("foo", e.getName().?); |
|
|
|
try expect.equal("foo", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const r = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
const r = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_name_w_scope" { |
|
|
|
test "Entity_find_id_name_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
const e = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("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 expect.fmt("parent.child", "{}", .{path}); |
|
|
|
|
|
|
|
|
|
|
|
const r = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
const r = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_path" { |
|
|
|
test "Entity_find_id_path" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const e_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("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 expect.fmt("parent.child", "{}", .{path}); |
|
|
|
|
|
|
|
|
|
|
|
const r = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const r = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_path_w_scope" { |
|
|
|
test "Entity_find_id_path_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e_parts = Path.buildParts(.{ "child", "grandchild" }); |
|
|
|
const e_parts = Path.buildParts(.{ "child", "grandchild" }); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqualStrings("grandchild", e.getName().?); |
|
|
|
try expect.equal("grandchild", 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.grandchild", "{}", .{path}); |
|
|
|
try expect.fmt("parent.child.grandchild", "{}", .{path}); |
|
|
|
|
|
|
|
|
|
|
|
const r = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const r = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_name_match" { |
|
|
|
test "Entity_find_id_name_match" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
try expectEqualStrings("foo", e.getName().?); |
|
|
|
try expect.equal("foo", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const r = try world.entity(.{ .id = e, .name = "foo" }, .{}); |
|
|
|
const r = try world.entity(.{ .id = e, .name = "foo" }, .{}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_name_match_w_scope" { |
|
|
|
test "Entity_find_id_name_match_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
const e = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("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 expect.fmt("parent.child", "{}", .{path}); |
|
|
|
|
|
|
|
|
|
|
|
const r1 = try world.entity(.{ .id = e, .name = "child" }, .{}); |
|
|
|
const r1 = try world.entity(.{ .id = e, .name = "child" }, .{}); |
|
|
|
try expectEqual(e, r1); |
|
|
|
try expect.equal(e, r1); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(null); |
|
|
|
_ = world.setScope(null); |
|
|
|
|
|
|
|
|
|
|
|
const r2_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const r2_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const r2_path = Path.fromParts(false, &r2_parts); |
|
|
|
const r2_path = Path.fromParts(false, &r2_parts); |
|
|
|
const r2 = try world.entity(.{ .id = e, .path = r2_path }, .{}); |
|
|
|
const r2 = try world.entity(.{ .id = e, .path = r2_path }, .{}); |
|
|
|
try expectEqual(e, r2); |
|
|
|
try expect.equal(e, r2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_path_match" { |
|
|
|
test "Entity_find_id_path_match" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const e_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("child", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const r = try world.entity(.{ .id = e, .path = e_path }, .{}); |
|
|
|
const r = try world.entity(.{ .id = e, .path = e_path }, .{}); |
|
|
|
try expectEqual(e, r); |
|
|
|
try expect.equal(e, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_path_match_w_scope" { |
|
|
|
test "Entity_find_id_path_match_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e_parts = Path.buildParts(.{ "child", "grandchild" }); |
|
|
|
const e_parts = Path.buildParts(.{ "child", "grandchild" }); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqualStrings("grandchild", e.getName().?); |
|
|
|
try expect.equal("grandchild", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const r1 = try world.entity(.{ .id = e, .path = e_path }, .{}); |
|
|
|
const r1 = try world.entity(.{ .id = e, .path = e_path }, .{}); |
|
|
|
try expectEqual(e, r1); |
|
|
|
try expect.equal(e, r1); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(null); |
|
|
|
_ = world.setScope(null); |
|
|
|
|
|
|
|
|
|
|
|
const r2_parts = Path.buildParts(.{ "parent", "child", "grandchild" }); |
|
|
|
const r2_parts = Path.buildParts(.{ "parent", "child", "grandchild" }); |
|
|
|
const r2_path = Path.fromParts(false, &r2_parts); |
|
|
|
const r2_path = Path.fromParts(false, &r2_parts); |
|
|
|
const r2 = try world.entity(.{ .id = e, .path = r2_path }, .{}); |
|
|
|
const r2 = try world.entity(.{ .id = e, .path = r2_path }, .{}); |
|
|
|
try expectEqual(e, r2); |
|
|
|
try expect.equal(e, r2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_name_mismatch" { |
|
|
|
test "Entity_find_id_name_mismatch" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
const e = try world.entity(.{ .name = "foo" }, .{}); |
|
|
|
try expectEqualStrings("foo", e.getName().?); |
|
|
|
try expect.equal("foo", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = try world.entity(.{ .name = "bar" }, .{}); |
|
|
|
_ = try world.entity(.{ .name = "bar" }, .{}); |
|
|
|
|
|
|
|
|
|
|
|
_ = c.ecs_log_set_level(-4); |
|
|
|
_ = c.ecs_log_set_level(-4); |
|
|
|
const r = world.entity(.{ .id = e, .name = "bar" }, .{}); |
|
|
|
const r = world.entity(.{ .id = e, .name = "bar" }, .{}); |
|
|
|
try expectError(FlecsError.Unknown, r); |
|
|
|
try expect.err(FlecsError.Unknown, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_name_mismatch_w_scope" { |
|
|
|
test "Entity_find_id_name_mismatch_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
const e = try world.entity(.{ .name = "child" }, .{}); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("child", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = c.ecs_log_set_level(-4); |
|
|
|
_ = c.ecs_log_set_level(-4); |
|
|
|
const r = world.entity(.{ .id = e, .name = "parent" }, .{}); |
|
|
|
const r = world.entity(.{ .id = e, .name = "parent" }, .{}); |
|
|
|
try expectError(FlecsError.Unknown, r); |
|
|
|
try expect.err(FlecsError.Unknown, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_path_mismatch" { |
|
|
|
test "Entity_find_id_path_mismatch" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const e_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const e_parts = Path.buildParts(.{ "parent", "child" }); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqualStrings("child", e.getName().?); |
|
|
|
try expect.equal("child", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = c.ecs_log_set_level(-4); |
|
|
|
_ = c.ecs_log_set_level(-4); |
|
|
|
const r_parts = Path.buildParts(.{ "parent", "foo" }); |
|
|
|
const r_parts = Path.buildParts(.{ "parent", "foo" }); |
|
|
|
const r_path = Path.fromParts(false, &r_parts); |
|
|
|
const r_path = Path.fromParts(false, &r_parts); |
|
|
|
const r = world.entity(.{ .id = e, .path = r_path }, .{}); |
|
|
|
const r = world.entity(.{ .id = e, .path = r_path }, .{}); |
|
|
|
try expectError(FlecsError.Unknown, r); |
|
|
|
try expect.err(FlecsError.Unknown, r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
test "Entity_find_id_path_mismatch_w_scope" { |
|
|
|
test "Entity_find_id_path_mismatch_w_scope" { |
|
|
|
flecs.init(std.testing.allocator); |
|
|
|
flecs.init(alloc); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
var world = try World.initMinimal(); |
|
|
|
defer world.deinit(); |
|
|
|
defer world.deinit(); |
|
|
|
|
|
|
|
|
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
const scope = try world.entity(.{ .name = "parent" }, .{}); |
|
|
|
try expectEqualStrings("parent", scope.getName().?); |
|
|
|
try expect.equal("parent", scope.getName()); |
|
|
|
|
|
|
|
|
|
|
|
_ = world.setScope(scope); |
|
|
|
_ = world.setScope(scope); |
|
|
|
try expectEqual(scope, world.getScope().?); |
|
|
|
try expect.equal(scope, world.getScope()); |
|
|
|
|
|
|
|
|
|
|
|
const e_parts = Path.buildParts(.{ "child", "grandchild" }); |
|
|
|
const e_parts = Path.buildParts(.{ "child", "grandchild" }); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e_path = Path.fromParts(false, &e_parts); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
const e = try world.entity(.{ .path = e_path }, .{}); |
|
|
|
try expectEqualStrings("grandchild", e.getName().?); |
|
|
|
try expect.equal("grandchild", e.getName()); |
|
|
|
|
|
|
|
|
|
|
|
const unnamed_parts = Path.buildParts(.{ "child", "foo" }); |
|
|
|
const unnamed_parts = Path.buildParts(.{ "child", "foo" }); |
|
|
|
const unnamed_path = Path.fromParts(false, &unnamed_parts); |
|
|
|
const unnamed_path = Path.fromParts(false, &unnamed_parts); |
|
|
@ -548,5 +544,5 @@ test "Entity_find_id_path_mismatch_w_scope" { |
|
|
|
|
|
|
|
|
|
|
|
_ = c.ecs_log_set_level(-4); |
|
|
|
_ = c.ecs_log_set_level(-4); |
|
|
|
const r = world.entity(.{ .id = e, .path = unnamed_path }, .{}); |
|
|
|
const r = world.entity(.{ .id = e, .path = unnamed_path }, .{}); |
|
|
|
try expectError(FlecsError.Unknown, r); |
|
|
|
try expect.err(FlecsError.Unknown, r); |
|
|
|
} |
|
|
|
} |
|
|
|