module: improve testing
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
56fc29743f
commit
5e353e60bb
2 changed files with 16 additions and 14 deletions
|
|
@ -38,6 +38,7 @@ test {
|
|||
_ = gfx;
|
||||
_ = math;
|
||||
_ = testing;
|
||||
std.testing.refAllDeclsRecursive(@import("module.zig"));
|
||||
std.testing.refAllDeclsRecursive(ecs);
|
||||
std.testing.refAllDeclsRecursive(gamemode);
|
||||
std.testing.refAllDeclsRecursive(math);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const testing = std.testing;
|
|||
// TODO: eliminate dependency on ECS here.
|
||||
const EntityID = @import("ecs/entities.zig").EntityID;
|
||||
|
||||
/// Verifies that T matches the basic layout of a mach.Module
|
||||
/// Verifies that T matches the basic layout of a Mach module
|
||||
pub fn Module(comptime T: type) type {
|
||||
if (@typeInfo(T) != .Struct) @compileError("Module must be a struct type. Found:" ++ @typeName(T));
|
||||
if (!@hasDecl(T, "name")) @compileError("Module must have `pub const name = .foobar;`");
|
||||
|
|
@ -15,6 +15,18 @@ pub fn Module(comptime T: type) type {
|
|||
return T;
|
||||
}
|
||||
|
||||
/// Verifies that the given list of module structs `.{Foo, Bar}` satisfy `Module(M)`.
|
||||
pub fn Modules(comptime mods: anytype) type {
|
||||
inline for (mods) |M| _ = Module(M);
|
||||
return struct {
|
||||
pub const modules = mods;
|
||||
|
||||
pub const components = NamespacedComponents(mods){};
|
||||
|
||||
pub const State = NamespacedState(mods);
|
||||
};
|
||||
}
|
||||
|
||||
fn NamespacedComponents(comptime modules: anytype) type {
|
||||
var fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{};
|
||||
inline for (modules) |M| {
|
||||
|
|
@ -80,18 +92,7 @@ fn NamespacedState(comptime modules: anytype) type {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn Modules(comptime mods: anytype) type {
|
||||
inline for (mods) |M| _ = Module(M);
|
||||
return struct {
|
||||
pub const modules = mods;
|
||||
|
||||
pub const components = NamespacedComponents(mods){};
|
||||
|
||||
pub const State = NamespacedState(mods);
|
||||
};
|
||||
}
|
||||
|
||||
test "module" {
|
||||
test Module {
|
||||
_ = Module(struct {
|
||||
// Physics module state
|
||||
pointer: usize,
|
||||
|
|
@ -111,7 +112,7 @@ test "module" {
|
|||
});
|
||||
}
|
||||
|
||||
test "modules" {
|
||||
test Modules {
|
||||
const Physics = Module(struct {
|
||||
// Physics module state
|
||||
pointer: usize,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue