From 645a7dede162499ce58e9278d2070f69b7045d84 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 21 Jun 2025 18:52:13 -0700 Subject: [PATCH] add a test for an {#each block --- test.zig | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test.zig b/test.zig index 1c9926d9dc7dc03ec52cc69ce68928db845b84fd..f9cadcef2d4b6ec8fc506723d2c4b72e1eb5fcec 100644 --- a/test.zig +++ b/test.zig @@ -865,3 +865,42 @@ test { \\ ); } + +// each +test { + const alloc = std.testing.allocator; + var builder = std.ArrayList(u8).init(alloc); + defer builder.deinit(); + const S = struct { + abbr: []const u8, + name: []const u8, + index: u8, + }; + const states = [_]S{ + .{ .abbr = "MA", .name = "Massachusetts", .index = 0 }, + .{ .abbr = "OR", .name = "Oregon", .index = 0 }, + .{ .abbr = "CA", .name = "California", .index = 0 }, + }; + const doc = comptime pek.parse( + \\body( + \\ {#each states} + \\ p("The US state '"{this.name}"' can be shortened to '"{this.abbr}"'.") + \\ /each/ + \\) + ); + try pek.compileInner( + alloc, + builder.writer(), + doc, + .{ .Ctx = @This(), .indent = 0, .flag1 = false }, + .{ .states = &states }, + ); + try expect(builder.items).toEqualString( + \\ + \\

The US state 'Massachusetts' can be shortened to 'MA'.

+ \\

The US state 'Oregon' can be shortened to 'OR'.

+ \\

The US state 'California' can be shortened to 'CA'.

+ \\ + \\ + ); +} -- 2.54.0