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;
|
_ = gfx;
|
||||||
_ = math;
|
_ = math;
|
||||||
_ = testing;
|
_ = testing;
|
||||||
|
std.testing.refAllDeclsRecursive(@import("module.zig"));
|
||||||
std.testing.refAllDeclsRecursive(ecs);
|
std.testing.refAllDeclsRecursive(ecs);
|
||||||
std.testing.refAllDeclsRecursive(gamemode);
|
std.testing.refAllDeclsRecursive(gamemode);
|
||||||
std.testing.refAllDeclsRecursive(math);
|
std.testing.refAllDeclsRecursive(math);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ const testing = std.testing;
|
||||||
// TODO: eliminate dependency on ECS here.
|
// TODO: eliminate dependency on ECS here.
|
||||||
const EntityID = @import("ecs/entities.zig").EntityID;
|
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 {
|
pub fn Module(comptime T: type) type {
|
||||||
if (@typeInfo(T) != .Struct) @compileError("Module must be a struct type. Found:" ++ @typeName(T));
|
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;`");
|
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;
|
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 {
|
fn NamespacedComponents(comptime modules: anytype) type {
|
||||||
var fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{};
|
var fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{};
|
||||||
inline for (modules) |M| {
|
inline for (modules) |M| {
|
||||||
|
|
@ -80,18 +92,7 @@ fn NamespacedState(comptime modules: anytype) type {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Modules(comptime mods: anytype) type {
|
test Module {
|
||||||
inline for (mods) |M| _ = Module(M);
|
|
||||||
return struct {
|
|
||||||
pub const modules = mods;
|
|
||||||
|
|
||||||
pub const components = NamespacedComponents(mods){};
|
|
||||||
|
|
||||||
pub const State = NamespacedState(mods);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
test "module" {
|
|
||||||
_ = Module(struct {
|
_ = Module(struct {
|
||||||
// Physics module state
|
// Physics module state
|
||||||
pointer: usize,
|
pointer: usize,
|
||||||
|
|
@ -111,7 +112,7 @@ test "module" {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "modules" {
|
test Modules {
|
||||||
const Physics = Module(struct {
|
const Physics = Module(struct {
|
||||||
// Physics module state
|
// Physics module state
|
||||||
pointer: usize,
|
pointer: usize,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue