authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-06-21 18:52:13 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-06-21 18:52:13 -07:00
log645a7dede162499ce58e9278d2070f69b7045d84
tree83a0af7b00d2e9b8ad027c86dbdbf042638634fe
parent46d5986b679e5cbe544aa01fed92aabc2a95024f

add a test for an {#each block


1 files changed, 39 insertions(+), 0 deletions(-)

test.zig+39
......@@ -865,3 +865,42 @@ test {
865865 \\
866866 );
867867}
868
869// each
870test {
871 const alloc = std.testing.allocator;
872 var builder = std.ArrayList(u8).init(alloc);
873 defer builder.deinit();
874 const S = struct {
875 abbr: []const u8,
876 name: []const u8,
877 index: u8,
878 };
879 const states = [_]S{
880 .{ .abbr = "MA", .name = "Massachusetts", .index = 0 },
881 .{ .abbr = "OR", .name = "Oregon", .index = 0 },
882 .{ .abbr = "CA", .name = "California", .index = 0 },
883 };
884 const doc = comptime pek.parse(
885 \\body(
886 \\ {#each states}
887 \\ p("The US state '"{this.name}"' can be shortened to '"{this.abbr}"'.")
888 \\ /each/
889 \\)
890 );
891 try pek.compileInner(
892 alloc,
893 builder.writer(),
894 doc,
895 .{ .Ctx = @This(), .indent = 0, .flag1 = false },
896 .{ .states = &states },
897 );
898 try expect(builder.items).toEqualString(
899 \\<body>
900 \\ <p>The US state 'Massachusetts' can be shortened to 'MA'.</p>
901 \\ <p>The US state 'Oregon' can be shortened to 'OR'.</p>
902 \\ <p>The US state 'California' can be shortened to 'CA'.</p>
903 \\</body>
904 \\
905 );
906}