✓
Passing This code compiles and runs correctly.
Code
// Test: Does ~log.error match the glob pattern log.* ?
//
// This test verifies that invocations can match glob pattern events:
// - ~log.error(...) should match the glob event log.*
// - The transform should run and replace the invocation
//
// The transform replaces the invocation with a simple inline print.
// Glob pattern transform event - matches any log.* invocation
~[comptime|transform]pub event log.* {
expr: Expression,
item: *const Item,
program: *const Program,
}
| transformed { program: *const Program }
// Transform proc - replaces invocation with inline comment
~proc log.* {
const ast = @import("ast");
const ast_functional = @import("ast_functional");
const allocator = @import("std").heap.page_allocator;
// Get the flow from the item
const flow = if (item.* == .flow) &item.flow else return .{ .transformed = .{ .program = program } };
// Create inline code to replace the flow (simple comment, no keywords)
const inline_code_item = ast.Item{
.inline_code = .{
.code = "// glob transform ran",
.location = flow.location,
.module = allocator.dupe(u8, flow.module) catch return .{ .transformed = .{ .program = program } },
},
};
const maybe_new_program = ast_functional.replaceFlowRecursive(allocator, program, flow, inline_code_item) catch return .{ .transformed = .{ .program = program } };
if (maybe_new_program) |new_program| {
const result = allocator.create(ast.Program) catch return .{ .transformed = .{ .program = program } };
result.* = new_program;
return .{ .transformed = .{ .program = result } };
}
return .{ .transformed = .{ .program = program } };
}
// This invocation should match log.* glob pattern
~log.error("Something went wrong")