✓
Passing This code compiles and runs correctly.
Code
// Pins the explain-command spine: a library ships a [explainer] event returning
// an ExplainReport; the `explain` command discovers it, calls it, and renders the
// collected report to text / json / html. This inline explainer stands in for a
// real library explainer (std/store's lands separately) — it exercises the full
// path: annotation discovery -> struct-return gather -> the typed property catalog.
~import std/explain
~[comptime|explainer]pub tor explain-demo {
program: *const Program,
allocator: __koru_std.mem.Allocator,
} -> ExplainReport
~proc explain-demo|zig {
_ = program;
_ = allocator;
return .{
.title = "demo/store",
.sections = &.{
.{
.heading = "Layout",
.entries = &.{
.{ .note = "struct-of-arrays elected for hot fields" },
.{ .property = .{ .key = "stores", .value = .{ .integer = 3 } } },
.{ .property = .{ .key = "users.layout", .value = .{ .string = "SoA" } } },
.{ .property = .{ .key = "users.listeners", .value = .{ .integer = 7 } } },
},
},
},
};
}
Test Configuration
Post-validation Script:
#!/bin/bash
# The `explain` command discovers a library's ~[explainer], calls it, and renders
# the returned ExplainReport. Assert text prose + property rows, and TYPED json
# (integers stay integers, strings are quoted) — the tagged-union value payoff.
set -e
echo "=== koruc input.kz explain (text) ==="
TEXT=$(koruc input.kz explain 2>&1)
echo "$TEXT"
echo "$TEXT" | grep -q "demo/store" || { echo "FAIL: report title missing"; exit 1; }
echo "$TEXT" | grep -q "stores = 3" || { echo "FAIL: counter property missing"; exit 1; }
echo "$TEXT" | grep -q "users.layout = SoA" || { echo "FAIL: string property missing"; exit 1; }
echo "=== koruc input.kz explain json (typed) ==="
JSON=$(koruc input.kz explain json 2>&1)
echo "$JSON" | grep -q '"stores":3' || { echo "FAIL: integer not emitted as typed JSON number"; exit 1; }
echo "$JSON" | grep -q '"users.layout":"SoA"' || { echo "FAIL: string not emitted as quoted JSON"; exit 1; }
echo "=== PASS: explain renders text + typed json ==="