Update tests to return errors

master
LeRoyce Pearson 4 years ago
parent 514a893918
commit 44192a1398

@ -53,11 +53,11 @@ test "actor" {
std.debug.assert(!actor.has(f32));
actor.addTyped(f32, 67.45);
if (actor.tryGet(f32)) |val| {
std.testing.expectEqual(val.*, 67.45);
try std.testing.expectEqual(val.*, 67.45);
}
actor.addTyped(u64, 8888);
std.testing.expectEqual(actor.get(u64).*, 8888);
try std.testing.expectEqual(actor.get(u64).*, 8888);
std.debug.assert(actor.has(u64));
actor.remove(u64);
@ -83,6 +83,6 @@ test "actor structs" {
pos.*.x += vel.x;
pos.*.y += vel.y;
std.testing.expectEqual(actor.get(Position).*.x, 5);
std.testing.expectEqual(actor.get(Position).*.y, 10);
try std.testing.expectEqual(actor.get(Position).*.x, 5);
try std.testing.expectEqual(actor.get(Position).*.y, 10);
}

@ -294,15 +294,15 @@ test "add/try-get/remove/clear" {
defer store.deinit();
store.add(3, 66.45);
std.testing.expectEqual(store.tryGetConst(3).?, 66.45);
try std.testing.expectEqual(store.tryGetConst(3).?, 66.45);
if (store.tryGet(3)) |found| {
std.testing.expectEqual(@as(f32, 66.45), found.*);
try std.testing.expectEqual(@as(f32, 66.45), found.*);
}
store.remove(3);
var val_null = store.tryGet(3);
std.testing.expectEqual(val_null, null);
try std.testing.expectEqual(val_null, null);
store.clear();
}
@ -312,11 +312,11 @@ test "add/get/remove" {
defer store.deinit();
store.add(3, 66.45);
if (store.tryGet(3)) |found| std.testing.expectEqual(@as(f32, 66.45), found.*);
std.testing.expectEqual(store.tryGetConst(3).?, 66.45);
if (store.tryGet(3)) |found| try std.testing.expectEqual(@as(f32, 66.45), found.*);
try std.testing.expectEqual(store.tryGetConst(3).?, 66.45);
store.remove(3);
std.testing.expectEqual(store.tryGet(3), null);
try std.testing.expectEqual(store.tryGet(3), null);
}
test "iterate" {
@ -329,13 +329,13 @@ test "iterate" {
for (store.data()) |entity, i| {
if (i == 0) {
std.testing.expectEqual(entity, 3);
try std.testing.expectEqual(entity, 3);
}
if (i == 1) {
std.testing.expectEqual(entity, 5);
try std.testing.expectEqual(entity, 5);
}
if (i == 2) {
std.testing.expectEqual(entity, 7);
try std.testing.expectEqual(entity, 7);
}
}
}
@ -394,14 +394,14 @@ test "sort empty component" {
comptime const asc_u32 = std.sort.asc(u32);
store.sort(u32, {}, asc_u32);
for (store.data()) |e, i| {
std.testing.expectEqual(@intCast(u32, i), e);
try std.testing.expectEqual(@intCast(u32, i), e);
}
comptime const desc_u32 = std.sort.desc(u32);
store.sort(u32, {}, desc_u32);
var counter: u32 = 2;
for (store.data()) |e, i| {
std.testing.expectEqual(counter, e);
try std.testing.expectEqual(counter, e);
if (counter > 0) counter -= 1;
}
}
@ -428,7 +428,7 @@ test "sort by entity" {
var compare: f32 = 5;
for (store.raw()) |val, i| {
std.testing.expect(compare > val);
try std.testing.expect(compare > val);
compare = val;
}
}
@ -446,7 +446,7 @@ test "sort by component" {
var compare: f32 = 5;
for (store.raw()) |val, i| {
std.testing.expect(compare > val);
try std.testing.expect(compare > val);
compare = val;
}
}

@ -41,7 +41,7 @@ test "entity traits" {
const m = EntityTraitsType(.medium).init();
const l = EntityTraitsType(.large).init();
std.testing.expectEqual(sm.entity_mask, std.math.maxInt(sm.index_type));
std.testing.expectEqual(m.entity_mask, std.math.maxInt(m.index_type));
std.testing.expectEqual(l.entity_mask, std.math.maxInt(l.index_type));
try std.testing.expectEqual(sm.entity_mask, std.math.maxInt(sm.index_type));
try std.testing.expectEqual(m.entity_mask, std.math.maxInt(m.index_type));
try std.testing.expectEqual(l.entity_mask, std.math.maxInt(l.index_type));
}

@ -277,7 +277,7 @@ test "BasicGroup creation/iteration" {
defer reg.deinit();
var group = reg.group(.{}, .{ i32, u32 }, .{});
std.testing.expectEqual(group.len(), 0);
try std.testing.expectEqual(group.len(), 0);
var e0 = reg.create();
reg.add(e0, @as(i32, 44));
@ -290,13 +290,13 @@ test "BasicGroup creation/iteration" {
while (iter.next()) |entity| {
iterated_entities += 1;
}
std.testing.expectEqual(iterated_entities, 1);
try std.testing.expectEqual(iterated_entities, 1);
iterated_entities = 0;
for (group.data()) |entity| {
iterated_entities += 1;
}
std.testing.expectEqual(iterated_entities, 1);
try std.testing.expectEqual(iterated_entities, 1);
reg.remove(i32, e0);
std.debug.assert(group.len() == 0);
@ -307,7 +307,7 @@ test "BasicGroup excludes" {
defer reg.deinit();
var group = reg.group(.{}, .{i32}, .{u32});
std.testing.expectEqual(group.len(), 0);
try std.testing.expectEqual(group.len(), 0);
var e0 = reg.create();
reg.add(e0, @as(i32, 44));
@ -319,7 +319,7 @@ test "BasicGroup excludes" {
while (iter.next()) |entity| {
iterated_entities += 1;
}
std.testing.expectEqual(iterated_entities, 1);
try std.testing.expectEqual(iterated_entities, 1);
reg.add(e0, @as(u32, 55));
std.debug.assert(group.len() == 0);
@ -334,7 +334,7 @@ test "BasicGroup create late" {
reg.add(e0, @as(u32, 55));
var group = reg.group(.{}, .{ i32, u32 }, .{});
std.testing.expectEqual(group.len(), 1);
try std.testing.expectEqual(group.len(), 1);
}
test "OwningGroup" {
@ -346,19 +346,19 @@ test "OwningGroup" {
var e0 = reg.create();
reg.add(e0, @as(i32, 44));
reg.add(e0, @as(u32, 55));
std.testing.expectEqual(group.len(), 1);
std.testing.expect(group.contains(e0));
try std.testing.expectEqual(group.len(), 1);
try std.testing.expect(group.contains(e0));
std.testing.expectEqual(group.get(i32, e0).*, 44);
std.testing.expectEqual(group.getConst(u32, e0), 55);
try std.testing.expectEqual(group.get(i32, e0).*, 44);
try std.testing.expectEqual(group.getConst(u32, e0), 55);
var vals = group.getOwned(e0, struct { int: *i32, uint: *u32 });
std.testing.expectEqual(vals.int.*, 44);
std.testing.expectEqual(vals.uint.*, 55);
try std.testing.expectEqual(vals.int.*, 44);
try std.testing.expectEqual(vals.uint.*, 55);
vals.int.* = 666;
var vals2 = group.getOwned(e0, struct { int: *i32, uint: *u32 });
std.testing.expectEqual(vals2.int.*, 666);
try std.testing.expectEqual(vals2.int.*, 666);
}
test "OwningGroup add/remove" {
@ -370,10 +370,10 @@ test "OwningGroup add/remove" {
var e0 = reg.create();
reg.add(e0, @as(i32, 44));
reg.add(e0, @as(u32, 55));
std.testing.expectEqual(group.len(), 1);
try std.testing.expectEqual(group.len(), 1);
reg.remove(u32, e0);
std.testing.expectEqual(group.len(), 0);
try std.testing.expectEqual(group.len(), 0);
}
test "OwningGroup iterate" {
@ -394,13 +394,13 @@ test "OwningGroup iterate" {
var iter = group.iterator(struct { int: *i32, uint: *u32 });
while (iter.next()) |item| {
if (iter.entity() == e0) {
std.testing.expectEqual(item.int.*, 44);
std.testing.expectEqual(item.uint.*, 55);
std.testing.expectEqual(iter.get(u8).*, 11);
try std.testing.expectEqual(item.int.*, 44);
try std.testing.expectEqual(item.uint.*, 55);
try std.testing.expectEqual(iter.get(u8).*, 11);
} else {
std.testing.expectEqual(item.int.*, 666);
std.testing.expectEqual(item.uint.*, 999);
std.testing.expectEqual(iter.get(f32).*, 55.5);
try std.testing.expectEqual(item.int.*, 666);
try std.testing.expectEqual(item.uint.*, 999);
try std.testing.expectEqual(iter.get(f32).*, 55.5);
}
}
}
@ -409,8 +409,8 @@ fn each(components: struct {
int: *i32,
uint: *u32,
}) void {
std.testing.expectEqual(components.int.*, 44);
std.testing.expectEqual(components.uint.*, 55);
std.testing.expectEqual(components.int.*, 44) catch unreachable;
std.testing.expectEqual(components.uint.*, 55) catch unreachable;
}
test "OwningGroup each" {
@ -426,8 +426,8 @@ test "OwningGroup each" {
int: *i32,
uint: *u32,
}) void {
std.testing.expectEqual(components.int.*, 44);
std.testing.expectEqual(components.uint.*, 55);
std.testing.expectEqual(components.int.*, 44) catch unreachable;
std.testing.expectEqual(components.uint.*, 55) catch unreachable;
}
};
var thing = Thing{};
@ -456,11 +456,11 @@ test "multiple OwningGroups" {
// ensure groups are ordered correctly internally
var last_size: u8 = 0;
for (reg.groups.items) |grp| {
std.testing.expect(last_size <= grp.size);
try std.testing.expect(last_size <= grp.size);
last_size = grp.size;
}
std.testing.expect(!reg.sortable(Sprite));
try std.testing.expect(!reg.sortable(Sprite));
// this will break the group
// var group6 = reg.group(.{Sprite, Rotation}, .{}, .{});

@ -136,7 +136,7 @@ test "handles" {
hm.remove(e1) catch unreachable;
std.debug.assert(!hm.alive(e1));
std.testing.expectError(error.RemovedInvalidHandle, hm.remove(e1));
try std.testing.expectError(error.RemovedInvalidHandle, hm.remove(e1));
var e_tmp = hm.create();
std.debug.assert(hm.alive(e_tmp));

@ -228,15 +228,15 @@ test "add/remove/clear" {
set.add(4);
set.add(3);
std.testing.expectEqual(set.len(), 2);
std.testing.expectEqual(set.index(4), 0);
std.testing.expectEqual(set.index(3), 1);
try std.testing.expectEqual(set.len(), 2);
try std.testing.expectEqual(set.index(4), 0);
try std.testing.expectEqual(set.index(3), 1);
set.remove(4);
std.testing.expectEqual(set.len(), 1);
try std.testing.expectEqual(set.len(), 1);
set.clear();
std.testing.expectEqual(set.len(), 0);
try std.testing.expectEqual(set.len(), 0);
}
test "grow" {
@ -248,7 +248,7 @@ test "grow" {
set.add(@intCast(u32, i));
}
std.testing.expectEqual(set.len(), std.math.maxInt(u8));
try std.testing.expectEqual(set.len(), std.math.maxInt(u8));
}
test "swap" {
@ -257,12 +257,12 @@ test "swap" {
set.add(4);
set.add(3);
std.testing.expectEqual(set.index(4), 0);
std.testing.expectEqual(set.index(3), 1);
try std.testing.expectEqual(set.index(4), 0);
try std.testing.expectEqual(set.index(3), 1);
set.swap(4, 3);
std.testing.expectEqual(set.index(3), 0);
std.testing.expectEqual(set.index(4), 1);
try std.testing.expectEqual(set.index(3), 0);
try std.testing.expectEqual(set.index(4), 1);
}
test "data() synced" {
@ -275,12 +275,12 @@ test "data() synced" {
set.add(3);
var data = set.data();
std.testing.expectEqual(data[1], 1);
std.testing.expectEqual(set.len(), data.len);
try std.testing.expectEqual(data[1], 1);
try std.testing.expectEqual(set.len(), data.len);
set.remove(0);
set.remove(1);
std.testing.expectEqual(set.len(), set.data().len);
try std.testing.expectEqual(set.len(), set.data().len);
}
test "iterate" {
@ -295,7 +295,7 @@ test "iterate" {
var i: u32 = @intCast(u32, set.len()) - 1;
var iter = set.reverseIterator();
while (iter.next()) |entity| {
std.testing.expectEqual(i, entity);
try std.testing.expectEqual(i, entity);
if (i > 0) i -= 1;
}
}
@ -319,8 +319,8 @@ test "respect 1" {
set1.respect(set2);
std.testing.expectEqual(set1.dense.items[0], set2.dense.items[1]);
std.testing.expectEqual(set1.dense.items[1], set2.dense.items[2]);
try std.testing.expectEqual(set1.dense.items[0], set2.dense.items[1]);
try std.testing.expectEqual(set1.dense.items[1], set2.dense.items[2]);
}
const desc_u32 = std.sort.desc(u32);

@ -67,23 +67,23 @@ test "TypeStore" {
var orig = Vector{ .x = 5, .y = 6, .z = 8 };
store.add(orig);
std.testing.expect(store.has(Vector));
std.testing.expectEqual(store.get(Vector).*, orig);
try std.testing.expect(store.has(Vector));
try std.testing.expectEqual(store.get(Vector).*, orig);
var v = store.get(Vector);
std.testing.expectEqual(v.*, Vector{ .x = 5, .y = 6, .z = 8 });
try std.testing.expectEqual(v.*, Vector{ .x = 5, .y = 6, .z = 8 });
v.*.x = 666;
var v2 = store.get(Vector);
std.testing.expectEqual(v2.*, Vector{ .x = 666, .y = 6, .z = 8 });
try std.testing.expectEqual(v2.*, Vector{ .x = 666, .y = 6, .z = 8 });
store.remove(Vector);
std.testing.expect(!store.has(Vector));
try std.testing.expect(!store.has(Vector));
var v3 = store.getOrAdd(u32);
std.testing.expectEqual(v3.*, 0);
try std.testing.expectEqual(v3.*, 0);
v3.* = 777;
var v4 = store.get(u32);
std.testing.expectEqual(v3.*, 777);
try std.testing.expectEqual(v3.*, 777);
}

@ -133,7 +133,7 @@ test "ReverseSliceIterator" {
var iter = ReverseSliceIterator(usize).init(slice);
var i: usize = 9;
while (iter.next()) |val| {
std.testing.expectEqual(i, val);
try std.testing.expectEqual(i, val);
if (i > 0) i -= 1;
}
}

@ -159,16 +159,16 @@ test "single basic view" {
store.add(7, 70);
var view = BasicView(f32).init(&store);
std.testing.expectEqual(view.len(), 3);
try std.testing.expectEqual(view.len(), 3);
store.remove(7);
std.testing.expectEqual(view.len(), 2);
try std.testing.expectEqual(view.len(), 2);
var i: usize = 0;
var iter = view.iterator();
while (iter.next()) |comp| {
if (i == 0) std.testing.expectEqual(comp, 50);
if (i == 1) std.testing.expectEqual(comp, 30);
if (i == 0) try std.testing.expectEqual(comp, 50);
if (i == 1) try std.testing.expectEqual(comp, 30);
i += 1;
}
@ -176,12 +176,12 @@ test "single basic view" {
var entIter = view.entityIterator();
while (entIter.next()) |ent| {
if (i == 0) {
std.testing.expectEqual(ent, 5);
std.testing.expectEqual(view.getConst(ent), 50);
try std.testing.expectEqual(ent, 5);
try std.testing.expectEqual(view.getConst(ent), 50);
}
if (i == 1) {
std.testing.expectEqual(ent, 3);
std.testing.expectEqual(view.getConst(ent), 30);
try std.testing.expectEqual(ent, 3);
try std.testing.expectEqual(view.getConst(ent), 30);
}
i += 1;
}
@ -197,27 +197,27 @@ test "single basic view data" {
var view = BasicView(f32).init(&store);
std.testing.expectEqual(view.get(3).*, 30);
try std.testing.expectEqual(view.get(3).*, 30);
for (view.data()) |entity, i| {
if (i == 0)
std.testing.expectEqual(entity, 3);
try std.testing.expectEqual(entity, 3);
if (i == 1)
std.testing.expectEqual(entity, 5);
try std.testing.expectEqual(entity, 5);
if (i == 2)
std.testing.expectEqual(entity, 7);
try std.testing.expectEqual(entity, 7);
}
for (view.raw()) |data, i| {
if (i == 0)
std.testing.expectEqual(data, 30);
try std.testing.expectEqual(data, 30);
if (i == 1)
std.testing.expectEqual(data, 50);
try std.testing.expectEqual(data, 50);
if (i == 2)
std.testing.expectEqual(data, 70);
try std.testing.expectEqual(data, 70);
}
std.testing.expectEqual(view.len(), 3);
try std.testing.expectEqual(view.len(), 3);
}
test "basic multi view" {
@ -244,7 +244,7 @@ test "basic multi view" {
iterated_entities += 1;
}
std.testing.expectEqual(iterated_entities, 2);
try std.testing.expectEqual(iterated_entities, 2);
iterated_entities = 0;
reg.remove(u32, e0);
@ -254,7 +254,7 @@ test "basic multi view" {
iterated_entities += 1;
}
std.testing.expectEqual(iterated_entities, 1);
try std.testing.expectEqual(iterated_entities, 1);
}
test "basic multi view with excludes" {
@ -282,7 +282,7 @@ test "basic multi view with excludes" {
iterated_entities += 1;
}
std.testing.expectEqual(iterated_entities, 1);
try std.testing.expectEqual(iterated_entities, 1);
iterated_entities = 0;
reg.remove(u8, e2);
@ -292,5 +292,5 @@ test "basic multi view with excludes" {
iterated_entities += 1;
}
std.testing.expectEqual(iterated_entities, 2);
try std.testing.expectEqual(iterated_entities, 2);
}

@ -231,5 +231,5 @@ test "scheduler.attach.next" {
_ = scheduler.attach(Tester, &counter).next(Tester, &counter);
scheduler.update();
scheduler.update();
std.testing.expectEqual(counter, 2);
try std.testing.expectEqual(counter, 2);
}

@ -17,7 +17,7 @@ pub const Assets = struct {
var iter = self.caches.iterator();
while (iter.next()) |ptr| {
// HACK: we dont know the Type here but we need to call deinit
@intToPtr(*Cache(u1), ptr.value).deinit();
@intToPtr(*Cache(u1), ptr.value_ptr.*).deinit();
}
self.caches.deinit();
@ -77,17 +77,17 @@ test "assets" {
defer assets.deinit();
var thing = assets.get(Thing).load(6, ThingLoadArgs{});
std.testing.expectEqual(assets.get(Thing).size(), 1);
try std.testing.expectEqual(assets.get(Thing).size(), 1);
var thing2 = assets.load(4, ThingLoadArgs{});
std.testing.expectEqual(assets.get(Thing).size(), 2);
try std.testing.expectEqual(assets.get(Thing).size(), 2);
var other_thing = assets.get(OtherThing).load(6, OtherThingLoadArgs{});
std.testing.expectEqual(assets.get(OtherThing).size(), 1);
try std.testing.expectEqual(assets.get(OtherThing).size(), 1);
var other_thing2 = assets.load(8, OtherThingLoadArgs{});
std.testing.expectEqual(assets.get(OtherThing).size(), 2);
try std.testing.expectEqual(assets.get(OtherThing).size(), 2);
assets.get(OtherThing).clear();
std.testing.expectEqual(assets.get(OtherThing).size(), 0);
try std.testing.expectEqual(assets.get(OtherThing).size(), 0);
}

@ -57,7 +57,7 @@ pub fn Cache(comptime T: type) type {
}
pub fn remove(self: *@This(), id: u32) void {
if (self.resources.remove(id)) |kv| {
if (self.resources.fetchRemove(id)) |kv| {
if (@hasDecl(T, "deinit")) {
@call(.{ .modifier = .always_inline }, @field(kv.value, "deinit"), .{});
}
@ -69,7 +69,7 @@ pub fn Cache(comptime T: type) type {
if (@hasDecl(T, "deinit")) {
var iter = self.resources.iterator();
while (iter.next()) |kv| {
@call(.{ .modifier = .always_inline }, @field(kv.value, "deinit"), .{});
@call(.{ .modifier = .always_inline }, @field(kv.value_ptr.*, "deinit"), .{});
}
}
self.resources.clearAndFree();
@ -102,11 +102,11 @@ test "cache" {
var thing = cache.load(utils.hashString("my/id"), ThingLoadArgs{});
var thing2 = cache.load(utils.hashString("another/id"), ThingLoadArgs{});
std.testing.expectEqual(cache.size(), 2);
try std.testing.expectEqual(cache.size(), 2);
cache.remove(utils.hashString("my/id"));
std.testing.expectEqual(cache.size(), 1);
try std.testing.expectEqual(cache.size(), 1);
cache.clear();
std.testing.expectEqual(cache.size(), 0);
try std.testing.expectEqual(cache.size(), 0);
}

@ -63,14 +63,14 @@ pub fn Delegate(comptime Event: type) type {
}
fn tester(param: u32) void {
std.testing.expectEqual(@as(u32, 666), param);
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
}
const Thing = struct {
field: f32 = 0,
pub fn tester(self: *Thing, param: u32) void {
std.testing.expectEqual(@as(u32, 777), param);
std.testing.expectEqual(@as(u32, 777), param) catch unreachable;
}
};

@ -18,7 +18,7 @@ pub const Dispatcher = struct {
var iter = self.signals.iterator();
while (iter.next()) |ptr| {
// HACK: we dont know the Type here but we need to call deinit
var signal = @intToPtr(*Signal(void), ptr.value);
var signal = @intToPtr(*Signal(void), ptr.value_ptr.*);
signal.deinit();
}

@ -58,14 +58,14 @@ pub fn Signal(comptime Event: type) type {
}
fn tester(param: u32) void {
std.testing.expectEqual(@as(u32, 666), param);
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
}
const Thing = struct {
field: f32 = 0,
pub fn tester(self: *Thing, param: u32) void {
std.testing.expectEqual(@as(u32, 666), param);
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
}
};
@ -75,7 +75,7 @@ test "Signal/Sink" {
var sink = signal.sink();
sink.connect(tester);
std.testing.expectEqual(@as(usize, 1), signal.size());
try std.testing.expectEqual(@as(usize, 1), signal.size());
// bound listener
var thing = Thing{};
@ -85,10 +85,10 @@ test "Signal/Sink" {
sink.disconnect(tester);
signal.publish(666);
std.testing.expectEqual(@as(usize, 1), signal.size());
try std.testing.expectEqual(@as(usize, 1), signal.size());
sink.disconnectBound(&thing);
std.testing.expectEqual(@as(usize, 0), signal.size());
try std.testing.expectEqual(@as(usize, 0), signal.size());
}
test "Sink Before null" {
@ -97,9 +97,9 @@ test "Sink Before null" {
var sink = signal.sink();
sink.connect(tester);
std.testing.expectEqual(@as(usize, 1), signal.size());
try std.testing.expectEqual(@as(usize, 1), signal.size());
var thing = Thing{};
sink.before(null).connectBound(&thing, "tester");
std.testing.expectEqual(@as(usize, 2), signal.size());
try std.testing.expectEqual(@as(usize, 2), signal.size());
}

@ -79,14 +79,14 @@ pub fn Sink(comptime Event: type) type {
}
fn tester(param: u32) void {
std.testing.expectEqual(@as(u32, 666), param);
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
}
const Thing = struct {
field: f32 = 0,
pub fn tester(self: *Thing, param: u32) void {
std.testing.expectEqual(@as(u32, 666), param);
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
}
};
@ -95,11 +95,11 @@ test "Sink Before free" {
defer signal.deinit();
signal.sink().connect(tester);
std.testing.expectEqual(signal.sink().indexOf(tester).?, 0);
try std.testing.expectEqual(signal.sink().indexOf(tester).?, 0);
var thing = Thing{};
signal.sink().before(tester).connectBound(&thing, "tester");
std.testing.expectEqual(signal.sink().indexOfBound(&thing).?, 0);
try std.testing.expectEqual(signal.sink().indexOfBound(&thing).?, 0);
}
test "Sink Before bound" {
@ -108,8 +108,8 @@ test "Sink Before bound" {
var thing = Thing{};
signal.sink().connectBound(&thing, "tester");
std.testing.expectEqual(signal.sink().indexOfBound(&thing).?, 0);
try std.testing.expectEqual(signal.sink().indexOfBound(&thing).?, 0);
signal.sink().beforeBound(&thing).connect(tester);
std.testing.expectEqual(signal.sink().indexOf(tester).?, 0);
try std.testing.expectEqual(signal.sink().indexOf(tester).?, 0);
}

@ -2,22 +2,22 @@ const std = @import("std");
const Dispatcher = @import("ecs").Dispatcher;
fn tester(param: u32) void {
std.testing.expectEqual(@as(u32, 666), param);
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
}
fn tester2(param: i32) void {
std.testing.expectEqual(@as(i32, -543), param);
std.testing.expectEqual(@as(i32, -543), param) catch unreachable;
}
const Thing = struct {
field: f32 = 0,
pub fn testU32(self: *Thing, param: u32) void {
std.testing.expectEqual(@as(u32, 666), param);
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
}
pub fn testI32(self: *Thing, param: i32) void {
std.testing.expectEqual(@as(i32, -543), param);
std.testing.expectEqual(@as(i32, -543), param) catch unreachable;
}
};

@ -51,7 +51,7 @@ test "sort BasicGroup by Entity" {
var val: f32 = 0;
var iter = group.iterator();
while (iter.next()) |entity| {
std.testing.expectEqual(val, group.getConst(Sprite, entity).x);
try std.testing.expectEqual(val, group.getConst(Sprite, entity).x);
val += 1;
}
}
@ -79,7 +79,7 @@ test "sort BasicGroup by Component" {
var val: f32 = 0;
var iter = group.iterator();
while (iter.next()) |entity| {
std.testing.expectEqual(val, group.getConst(Sprite, entity).x);
try std.testing.expectEqual(val, group.getConst(Sprite, entity).x);
val += 1;
}
}
@ -112,7 +112,7 @@ test "sort OwningGroup by Entity" {
var val: f32 = 0;
var iter = group.iterator(struct { s: *Sprite, r: *Renderable });
while (iter.next()) |entity| {
std.testing.expectEqual(val, entity.s.*.x);
try std.testing.expectEqual(val, entity.s.*.x);
val += 1;
}
}
@ -140,7 +140,7 @@ test "sort OwningGroup by Component" {
var val: f32 = 0;
var iter = group.iterator(struct { s: *Sprite, r: *Renderable });
while (iter.next()) |entity| {
std.testing.expectEqual(val, entity.s.*.x);
try std.testing.expectEqual(val, entity.s.*.x);
val += 1;
}
}
@ -161,13 +161,13 @@ test "sort OwningGroup by Component ensure unsorted non-matches" {
reg.add(e2, Sprite{ .x = @intToFloat(f32, i + 1 * 50) });
}
std.testing.expectEqual(group.len(), 5);
std.testing.expectEqual(reg.len(Sprite), 10);
try std.testing.expectEqual(group.len(), 5);
try std.testing.expectEqual(reg.len(Sprite), 10);
const SortContext = struct {
fn sort(this: void, a: Sprite, b: Sprite) bool {
// sprites with x > 50 shouldnt match in the group
std.testing.expect(a.x < 50 and b.x < 50);
std.testing.expect(a.x < 50 and b.x < 50) catch unreachable;
return a.x > b.x;
}
};
@ -182,7 +182,7 @@ test "sort OwningGroup by Component ensure unsorted non-matches" {
// all sprite.x > 50 should be at the end and we iterate backwards
if (count < 6) {
std.testing.expect(sprite.x >= 50);
try std.testing.expect(sprite.x >= 50);
}
}
}
@ -195,23 +195,23 @@ test "nested OwningGroups add/remove components" {
var group2 = reg.group(.{ Sprite, Transform }, .{Renderable}, .{});
var group3 = reg.group(.{ Sprite, Transform }, .{ Renderable, Rotation }, .{});
std.testing.expect(!reg.sortable(Sprite));
std.testing.expect(!reg.sortable(Transform));
std.testing.expect(reg.sortable(Renderable));
try std.testing.expect(!reg.sortable(Sprite));
try std.testing.expect(!reg.sortable(Transform));
try std.testing.expect(reg.sortable(Renderable));
var e1 = reg.create();
reg.addTypes(e1, .{ Sprite, Renderable, Rotation });
std.testing.expectEqual(group1.len(), 1);
std.testing.expectEqual(group2.len(), 0);
std.testing.expectEqual(group3.len(), 0);
try std.testing.expectEqual(group1.len(), 1);
try std.testing.expectEqual(group2.len(), 0);
try std.testing.expectEqual(group3.len(), 0);
reg.add(e1, Transform{});
std.testing.expectEqual(group3.len(), 1);
try std.testing.expectEqual(group3.len(), 1);
reg.remove(Sprite, e1);
std.testing.expectEqual(group1.len(), 0);
std.testing.expectEqual(group2.len(), 0);
std.testing.expectEqual(group3.len(), 0);
try std.testing.expectEqual(group1.len(), 0);
try std.testing.expectEqual(group2.len(), 0);
try std.testing.expectEqual(group3.len(), 0);
}
test "nested OwningGroups entity order" {
@ -228,8 +228,8 @@ test "nested OwningGroups entity order" {
reg.add(e, Renderable{ .x = @intToFloat(f32, i) });
}
std.testing.expectEqual(group1.len(), 5);
std.testing.expectEqual(group2.len(), 0);
try std.testing.expectEqual(group1.len(), 5);
try std.testing.expectEqual(group2.len(), 0);
var sprite_store = reg.assure(Sprite);
var transform_store = reg.assure(Transform);

@ -20,15 +20,15 @@ test "Registry" {
reg.addTypes(e1, .{ Empty, Position });
reg.add(e1, BigOne{ .pos = Position{ .x = 5, .y = 5 }, .vel = Velocity{ .x = 5, .y = 5 }, .accel = Velocity{ .x = 5, .y = 5 } });
std.testing.expect(reg.has(Empty, e1));
std.testing.expect(reg.has(Position, e1));
std.testing.expect(reg.has(BigOne, e1));
try std.testing.expect(reg.has(Empty, e1));
try std.testing.expect(reg.has(Position, e1));
try std.testing.expect(reg.has(BigOne, e1));
var iter = reg.entities();
while (iter.next()) |e| std.testing.expectEqual(e1, e);
while (iter.next()) |e| try std.testing.expectEqual(e1, e);
reg.remove(Empty, e1);
std.testing.expect(!reg.has(Empty, e1));
try std.testing.expect(!reg.has(Empty, e1));
}
test "context get/set/unset" {
@ -36,16 +36,16 @@ test "context get/set/unset" {
defer reg.deinit();
var ctx = reg.getContext(Position);
std.testing.expectEqual(ctx, null);
try std.testing.expectEqual(ctx, null);
var pos = Position{ .x = 5, .y = 5 };
reg.setContext(&pos);
ctx = reg.getContext(Position);
std.testing.expectEqual(ctx.?, &pos);
try std.testing.expectEqual(ctx.?, &pos);
reg.unsetContext(Position);
ctx = reg.getContext(Position);
std.testing.expectEqual(ctx, null);
try std.testing.expectEqual(ctx, null);
}
// this test should fail
@ -64,16 +64,16 @@ test "context get/set/unset" {
defer reg.deinit();
var ctx = reg.getContext(SomeType);
std.testing.expectEqual(ctx, null);
try std.testing.expectEqual(ctx, null);
var pos = SomeType{ .dummy = 0 };
reg.setContext(&pos);
ctx = reg.getContext(SomeType);
std.testing.expectEqual(ctx.?, &pos);
try std.testing.expectEqual(ctx.?, &pos);
reg.unsetContext(SomeType);
ctx = reg.getContext(SomeType);
std.testing.expectEqual(ctx, null);
try std.testing.expectEqual(ctx, null);
}
test "singletons" {
@ -82,11 +82,11 @@ test "singletons" {
var pos = Position{ .x = 5, .y = 5 };
reg.singletons.add(pos);
std.testing.expect(reg.singletons.has(Position));
std.testing.expectEqual(reg.singletons.get(Position).*, pos);
try std.testing.expect(reg.singletons.has(Position));
try std.testing.expectEqual(reg.singletons.get(Position).*, pos);
reg.singletons.remove(Position);
std.testing.expect(!reg.singletons.has(Position));
try std.testing.expect(!reg.singletons.has(Position));
}
test "destroy" {
@ -105,7 +105,7 @@ test "destroy" {
i = 0;
while (i < 6) : (i += 1) {
if (i != 3 and i != 4)
std.testing.expectEqual(Position{ .x = @intToFloat(f32, i), .y = @intToFloat(f32, i) }, reg.getConst(Position, i));
try std.testing.expectEqual(Position{ .x = @intToFloat(f32, i), .y = @intToFloat(f32, i) }, reg.getConst(Position, i));
}
}
@ -117,11 +117,11 @@ test "remove all" {
reg.add(e, Position{ .x = 1, .y = 1 });
reg.addTyped(u32, e, 666);
std.testing.expect(reg.has(Position, e));
std.testing.expect(reg.has(u32, e));
try std.testing.expect(reg.has(Position, e));
try std.testing.expect(reg.has(u32, e));
reg.removeAll(e);
std.testing.expect(!reg.has(Position, e));
std.testing.expect(!reg.has(u32, e));
try std.testing.expect(!reg.has(Position, e));
try std.testing.expect(!reg.has(u32, e));
}

Loading…
Cancel
Save