✓
Passing This code compiles and runs correctly.
Code
// Test: Registry Scope - Basic
//
// Verifies that ~std.runtime:register generates a dispatcher function
~import "$std/runtime"
~import "$std/io"
const std = @import("std");
// Define some application events
~pub event greet { name: []const u8 }
| greeted { message: []const u8 }
~proc greet {
const msg = std.fmt.allocPrint(std.heap.page_allocator, "Hello, {s}!", .{name}) catch "Hello!";
return .{ .greeted = .{ .message = msg } };
}
~pub event farewell { name: []const u8 }
| done {}
~proc farewell {
std.debug.print("Goodbye, {s}!\n", .{name});
return .{ .done = .{} };
}
// Register a scope with these events
~std.runtime:register(scope: "api") {
greet
farewell
}
// Test: Verify the registry was generated
pub fn main() void {
std.debug.print("\n", .{});
std.debug.print("╔══════════════════════════════════════════════════════════════╗\n", .{});
std.debug.print("║ REGISTRY SCOPE BASIC TEST ║\n", .{});
std.debug.print("╚══════════════════════════════════════════════════════════════╝\n\n", .{});
// Test 1: dispatch_api should exist and be callable
std.debug.print("Test 1: Calling dispatch_api with 'greet'...\n", .{});
const segments = [_][]const u8{"greet"};
const path = Path{
.module_qualifier = null,
.segments = &segments,
};
var args_array = [_]Arg{
.{ .name = "name", .value = "World" },
};
const inv = Invocation{
.path = path,
.args = &args_array,
};
var result: DispatchResult = undefined;
dispatch_api(&inv, &result) catch |err| {
std.debug.print(" ✗ FAILED: Dispatch error: {}\n", .{err});
return;
};
std.debug.print(" ✓ Dispatched successfully, branch: {s}\n", .{result.branch});
std.debug.print("\n╔══════════════════════════════════════════════════════════════╗\n", .{});
std.debug.print("║ REGISTRY TESTS COMPLETE ║\n", .{});
std.debug.print("╚══════════════════════════════════════════════════════════════╝\n", .{});
}