|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|