From c992fa2f2f539490f13fe1e8987f1d123704d206 Mon Sep 17 00:00:00 2001 From: copygirl Date: Fri, 5 Apr 2024 16:53:56 +0200 Subject: [PATCH] Test to check multiple contexts work --- src/context.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/context.zig b/src/context.zig index 4677a6a..7c1e8c8 100644 --- a/src/context.zig +++ b/src/context.zig @@ -157,3 +157,33 @@ pub fn Context(comptime ctx: anytype) type { } }; } + +test "Context multiple contexts" { + const flecszigble = @import("./main.zig"); + const expect = @import("./test/expect.zig"); + + flecszigble.init(std.testing.allocator); + var world1 = try Context(1).World.initMinimal(); + var world2 = try Context(2).World.initMinimal(); + defer world1.deinit(); + defer world2.deinit(); + + const Foo = struct {}; + const Bar = struct {}; + + const foo1 = try world1.tag(Foo); + const bar1 = try world1.tag(Bar); + // Register tags in opposite order in `world2`. + const bar2 = try world2.tag(Bar); + const foo2 = try world2.tag(Foo); + + try expect.equal(foo1, try world1.lookupType(Foo)); + try expect.equal(bar1, try world1.lookupType(Bar)); + try expect.equal(foo2, try world2.lookupType(Foo)); + try expect.equal(bar2, try world2.lookupType(Bar)); + + // Due to registration order, and IDs being unique to each World, + // `Foo` from `world1` should have the same ID as `Bar` from `world2`. + try expect.equal(foo1.raw, bar2.raw); + try expect.equal(bar1.raw, foo2.raw); +}