From f04bc1b093fb222f2cdedaa4190be92eb36d3c07 Mon Sep 17 00:00:00 2001 From: copygirl Date: Fri, 8 Sep 2023 22:33:36 +0200 Subject: [PATCH] Use Path.buildParts and .fromParts in tests --- test/entity.zig | 90 ++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/test/entity.zig b/test/entity.zig index ecef955..de2d078 100644 --- a/test/entity.zig +++ b/test/entity.zig @@ -36,9 +36,9 @@ test "Entity_init_id_name" { const e = try world.entity(.{ .name = "foo" }, .{}); try expectEqualStrings("foo", e.getName().?); - const path2 = try e.getPath(flecs.allocator); - defer path2.deinit(); - try expectFmt("foo", "{}", .{path2}); + const path = try e.getPath(flecs.allocator); + defer path.deinit(); + try expectFmt("foo", "{}", .{path}); } test "Entity_init_id_path" { @@ -46,9 +46,9 @@ test "Entity_init_id_path" { var world = try World.initMinimal(); defer world.deinit(); - const p = try Path.fromString("parent.child", null, flecs.allocator); - defer p.deinit(); - const e = try world.entity(.{ .path = p }, .{}); + const e_parts = Path.buildParts(.{ "parent", "child" }); + const e_path = Path.fromParts(false, &e_parts); + const e = try world.entity(.{ .path = e_path }, .{}); try expectEqualStrings("child", e.getName().?); const path = try e.getPath(flecs.allocator); @@ -132,9 +132,9 @@ test "Entity_init_id_path_w_scope" { _ = 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 }, .{}); + const e_parts = Path.buildParts(.{ "child", "grandchild" }); + const e_path = Path.fromParts(false, &e_parts); + const e = try world.entity(.{ .path = e_path }, .{}); try expectEqualStrings("grandchild", e.getName().?); @@ -356,16 +356,16 @@ test "Entity_find_id_path" { var world = try World.initMinimal(); defer world.deinit(); - const p = try Path.fromString("parent.child", null, flecs.allocator); - defer p.deinit(); - const e = try world.entity(.{ .path = p }, .{}); + const e_parts = Path.buildParts(.{ "parent", "child" }); + const e_path = Path.fromParts(false, &e_parts); + const e = try world.entity(.{ .path = e_path }, .{}); try expectEqualStrings("child", e.getName().?); const path = try e.getPath(flecs.allocator); defer path.deinit(); try expectFmt("parent.child", "{}", .{path}); - const r = try world.entity(.{ .path = p }, .{}); + const r = try world.entity(.{ .path = e_path }, .{}); try expectEqual(e, r); } @@ -380,16 +380,16 @@ test "Entity_find_id_path_w_scope" { _ = 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 }, .{}); + const e_parts = Path.buildParts(.{ "child", "grandchild" }); + const e_path = Path.fromParts(false, &e_parts); + const e = try world.entity(.{ .path = e_path }, .{}); try expectEqualStrings("grandchild", e.getName().?); const path = try e.getPath(flecs.allocator); defer path.deinit(); 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); } @@ -428,9 +428,9 @@ test "Entity_find_id_name_match_w_scope" { _ = world.setScope(null); - const p2 = try Path.fromString("parent.child", null, flecs.allocator); - defer p2.deinit(); - const r2 = try world.entity(.{ .id = e, .path = p2 }, .{}); + const r2_parts = Path.buildParts(.{ "parent", "child" }); + const r2_path = Path.fromParts(false, &r2_parts); + const r2 = try world.entity(.{ .id = e, .path = r2_path }, .{}); try expectEqual(e, r2); } @@ -439,12 +439,12 @@ test "Entity_find_id_path_match" { var world = try World.initMinimal(); defer world.deinit(); - const p = try Path.fromString("parent.child", null, flecs.allocator); - defer p.deinit(); - const e = try world.entity(.{ .path = p }, .{}); + const e_parts = Path.buildParts(.{ "parent", "child" }); + const e_path = Path.fromParts(false, &e_parts); + const e = try world.entity(.{ .path = e_path }, .{}); 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); } @@ -459,19 +459,19 @@ test "Entity_find_id_path_match_w_scope" { _ = 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 }, .{}); + const e_parts = Path.buildParts(.{ "child", "grandchild" }); + const e_path = Path.fromParts(false, &e_parts); + const e = try world.entity(.{ .path = e_path }, .{}); 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); _ = world.setScope(null); - const p2 = try Path.fromString("parent.child.grandchild", null, flecs.allocator); - defer p2.deinit(); - const r2 = try world.entity(.{ .id = e, .path = p2 }, .{}); + const r2_parts = Path.buildParts(.{ "parent", "child", "grandchild" }); + const r2_path = Path.fromParts(false, &r2_parts); + const r2 = try world.entity(.{ .id = e, .path = r2_path }, .{}); try expectEqual(e, r2); } @@ -514,15 +514,15 @@ test "Entity_find_id_path_mismatch" { var world = try World.initMinimal(); defer world.deinit(); - const p = try Path.fromString("parent.child", null, flecs.allocator); - defer p.deinit(); - const e = try world.entity(.{ .path = p }, .{}); + const e_parts = Path.buildParts(.{ "parent", "child" }); + const e_path = Path.fromParts(false, &e_parts); + const e = try world.entity(.{ .path = e_path }, .{}); try expectEqualStrings("child", e.getName().?); _ = c.ecs_log_set_level(-4); - const p2 = try Path.fromString("parent.foo", null, flecs.allocator); - defer p2.deinit(); - const r = world.entity(.{ .id = e, .path = p2 }, .{}); + const r_parts = Path.buildParts(.{ "parent", "foo" }); + const r_path = Path.fromParts(false, &r_parts); + const r = world.entity(.{ .id = e, .path = r_path }, .{}); try expectError(FlecsError.Unknown, r); } @@ -537,18 +537,16 @@ test "Entity_find_id_path_mismatch_w_scope" { _ = 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 }, .{}); + const e_parts = Path.buildParts(.{ "child", "grandchild" }); + const e_path = Path.fromParts(false, &e_parts); + const e = try world.entity(.{ .path = e_path }, .{}); try expectEqualStrings("grandchild", e.getName().?); - const p2 = try Path.fromString("child.foo", null, flecs.allocator); - defer p2.deinit(); - _ = try world.entity(.{ .path = p2 }, .{}); + const unnamed_parts = Path.buildParts(.{ "child", "foo" }); + const unnamed_path = Path.fromParts(false, &unnamed_parts); + _ = try world.entity(.{ .path = unnamed_path }, .{}); _ = c.ecs_log_set_level(-4); - const p3 = try Path.fromString("child.foo", null, flecs.allocator); - defer p3.deinit(); - const r = world.entity(.{ .id = e, .path = p3 }, .{}); + const r = world.entity(.{ .id = e, .path = unnamed_path }, .{}); try expectError(FlecsError.Unknown, r); }