| ... | ... | @@ -865,3 +865,42 @@ test { |
| 865 | 865 | \\ |
| 866 | 866 | ); |
| 867 | 867 | } |
| 868 | |
| 869 | // each |
| 870 | test { |
| 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 | } |