Use Path.buildParts and .fromParts in tests

main
copygirl 1 year ago
parent f0a956318e
commit f04bc1b093
  1. 90
      test/entity.zig

@ -36,9 +36,9 @@ test "Entity_init_id_name" {
const e = try world.entity(.{ .name = "foo" }, .{}); const e = try world.entity(.{ .name = "foo" }, .{});
try expectEqualStrings("foo", e.getName().?); try expectEqualStrings("foo", e.getName().?);
const path2 = try e.getPath(flecs.allocator); const path = try e.getPath(flecs.allocator);
defer path2.deinit(); defer path.deinit();
try expectFmt("foo", "{}", .{path2}); try expectFmt("foo", "{}", .{path});
} }
test "Entity_init_id_path" { test "Entity_init_id_path" {
@ -46,9 +46,9 @@ test "Entity_init_id_path" {
var world = try World.initMinimal(); var world = try World.initMinimal();
defer world.deinit(); defer world.deinit();
const p = try Path.fromString("parent.child", null, flecs.allocator); const e_parts = Path.buildParts(.{ "parent", "child" });
defer p.deinit(); const e_path = Path.fromParts(false, &e_parts);
const e = try world.entity(.{ .path = p }, .{}); const e = try world.entity(.{ .path = e_path }, .{});
try expectEqualStrings("child", e.getName().?); try expectEqualStrings("child", e.getName().?);
const path = try e.getPath(flecs.allocator); const path = try e.getPath(flecs.allocator);
@ -132,9 +132,9 @@ test "Entity_init_id_path_w_scope" {
_ = world.setScope(scope); _ = world.setScope(scope);
try expectEqual(scope, world.getScope().?); try expectEqual(scope, world.getScope().?);
const p = try Path.fromString("child.grandchild", null, flecs.allocator); const e_parts = Path.buildParts(.{ "child", "grandchild" });
defer p.deinit(); const e_path = Path.fromParts(false, &e_parts);
const e = try world.entity(.{ .path = p }, .{}); const e = try world.entity(.{ .path = e_path }, .{});
try expectEqualStrings("grandchild", e.getName().?); try expectEqualStrings("grandchild", e.getName().?);
@ -356,16 +356,16 @@ test "Entity_find_id_path" {
var world = try World.initMinimal(); var world = try World.initMinimal();
defer world.deinit(); defer world.deinit();
const p = try Path.fromString("parent.child", null, flecs.allocator); const e_parts = Path.buildParts(.{ "parent", "child" });
defer p.deinit(); const e_path = Path.fromParts(false, &e_parts);
const e = try world.entity(.{ .path = p }, .{}); const e = try world.entity(.{ .path = e_path }, .{});
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});
const r = try world.entity(.{ .path = p }, .{}); const r = try world.entity(.{ .path = e_path }, .{});
try expectEqual(e, r); try expectEqual(e, r);
} }
@ -380,16 +380,16 @@ test "Entity_find_id_path_w_scope" {
_ = world.setScope(scope); _ = world.setScope(scope);
try expectEqual(scope, world.getScope().?); try expectEqual(scope, world.getScope().?);
const p = try Path.fromString("child.grandchild", null, flecs.allocator); const e_parts = Path.buildParts(.{ "child", "grandchild" });
defer p.deinit(); const e_path = Path.fromParts(false, &e_parts);
const e = try world.entity(.{ .path = p }, .{}); const e = try world.entity(.{ .path = e_path }, .{});
try expectEqualStrings("grandchild", e.getName().?); try expectEqualStrings("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 expectFmt("parent.child.grandchild", "{}", .{path});
const r = try world.entity(.{ .path = p }, .{}); const r = try world.entity(.{ .path = e_path }, .{});
try expectEqual(e, r); try expectEqual(e, r);
} }
@ -428,9 +428,9 @@ test "Entity_find_id_name_match_w_scope" {
_ = world.setScope(null); _ = world.setScope(null);
const p2 = try Path.fromString("parent.child", null, flecs.allocator); const r2_parts = Path.buildParts(.{ "parent", "child" });
defer p2.deinit(); const r2_path = Path.fromParts(false, &r2_parts);
const r2 = try world.entity(.{ .id = e, .path = p2 }, .{}); const r2 = try world.entity(.{ .id = e, .path = r2_path }, .{});
try expectEqual(e, r2); try expectEqual(e, r2);
} }
@ -439,12 +439,12 @@ test "Entity_find_id_path_match" {
var world = try World.initMinimal(); var world = try World.initMinimal();
defer world.deinit(); defer world.deinit();
const p = try Path.fromString("parent.child", null, flecs.allocator); const e_parts = Path.buildParts(.{ "parent", "child" });
defer p.deinit(); const e_path = Path.fromParts(false, &e_parts);
const e = try world.entity(.{ .path = p }, .{}); const e = try world.entity(.{ .path = e_path }, .{});
try expectEqualStrings("child", e.getName().?); try expectEqualStrings("child", e.getName().?);
const r = try world.entity(.{ .id = e, .path = p }, .{}); const r = try world.entity(.{ .id = e, .path = e_path }, .{});
try expectEqual(e, r); try expectEqual(e, r);
} }
@ -459,19 +459,19 @@ test "Entity_find_id_path_match_w_scope" {
_ = world.setScope(scope); _ = world.setScope(scope);
try expectEqual(scope, world.getScope().?); try expectEqual(scope, world.getScope().?);
const p = try Path.fromString("child.grandchild", null, flecs.allocator); const e_parts = Path.buildParts(.{ "child", "grandchild" });
defer p.deinit(); const e_path = Path.fromParts(false, &e_parts);
const e = try world.entity(.{ .path = p }, .{}); const e = try world.entity(.{ .path = e_path }, .{});
try expectEqualStrings("grandchild", e.getName().?); try expectEqualStrings("grandchild", e.getName().?);
const r1 = try world.entity(.{ .id = e, .path = p }, .{}); const r1 = try world.entity(.{ .id = e, .path = e_path }, .{});
try expectEqual(e, r1); try expectEqual(e, r1);
_ = world.setScope(null); _ = world.setScope(null);
const p2 = try Path.fromString("parent.child.grandchild", null, flecs.allocator); const r2_parts = Path.buildParts(.{ "parent", "child", "grandchild" });
defer p2.deinit(); const r2_path = Path.fromParts(false, &r2_parts);
const r2 = try world.entity(.{ .id = e, .path = p2 }, .{}); const r2 = try world.entity(.{ .id = e, .path = r2_path }, .{});
try expectEqual(e, r2); try expectEqual(e, r2);
} }
@ -514,15 +514,15 @@ test "Entity_find_id_path_mismatch" {
var world = try World.initMinimal(); var world = try World.initMinimal();
defer world.deinit(); defer world.deinit();
const p = try Path.fromString("parent.child", null, flecs.allocator); const e_parts = Path.buildParts(.{ "parent", "child" });
defer p.deinit(); const e_path = Path.fromParts(false, &e_parts);
const e = try world.entity(.{ .path = p }, .{}); const e = try world.entity(.{ .path = e_path }, .{});
try expectEqualStrings("child", e.getName().?); try expectEqualStrings("child", e.getName().?);
_ = c.ecs_log_set_level(-4); _ = c.ecs_log_set_level(-4);
const p2 = try Path.fromString("parent.foo", null, flecs.allocator); const r_parts = Path.buildParts(.{ "parent", "foo" });
defer p2.deinit(); const r_path = Path.fromParts(false, &r_parts);
const r = world.entity(.{ .id = e, .path = p2 }, .{}); const r = world.entity(.{ .id = e, .path = r_path }, .{});
try expectError(FlecsError.Unknown, r); try expectError(FlecsError.Unknown, r);
} }
@ -537,18 +537,16 @@ test "Entity_find_id_path_mismatch_w_scope" {
_ = world.setScope(scope); _ = world.setScope(scope);
try expectEqual(scope, world.getScope().?); try expectEqual(scope, world.getScope().?);
const p = try Path.fromString("child.grandchild", null, flecs.allocator); const e_parts = Path.buildParts(.{ "child", "grandchild" });
defer p.deinit(); const e_path = Path.fromParts(false, &e_parts);
const e = try world.entity(.{ .path = p }, .{}); const e = try world.entity(.{ .path = e_path }, .{});
try expectEqualStrings("grandchild", e.getName().?); try expectEqualStrings("grandchild", e.getName().?);
const p2 = try Path.fromString("child.foo", null, flecs.allocator); const unnamed_parts = Path.buildParts(.{ "child", "foo" });
defer p2.deinit(); const unnamed_path = Path.fromParts(false, &unnamed_parts);
_ = try world.entity(.{ .path = p2 }, .{}); _ = try world.entity(.{ .path = unnamed_path }, .{});
_ = c.ecs_log_set_level(-4); _ = c.ecs_log_set_level(-4);
const p3 = try Path.fromString("child.foo", null, flecs.allocator); const r = world.entity(.{ .id = e, .path = unnamed_path }, .{});
defer p3.deinit();
const r = world.entity(.{ .id = e, .path = p3 }, .{});
try expectError(FlecsError.Unknown, r); try expectError(FlecsError.Unknown, r);
} }

Loading…
Cancel
Save