Initial commit: Pugz - Pug-like HTML template engine in Zig
Features: - Lexer with indentation tracking and raw text block support - Parser producing AST from token stream - Runtime with variable interpolation, conditionals, loops - Mixin support (params, defaults, rest args, block content, attributes) - Template inheritance (extends/block/append/prepend) - Plain text (piped, dot blocks, literal HTML) - Tag interpolation (#[tag text]) - Block expansion with colon - Self-closing tags (void elements + explicit /) - Case/when statements - Comments (rendered and silent) All 113 tests passing.
This commit is contained in:
24
src/tests/helper.zig
Normal file
24
src/tests/helper.zig
Normal file
@@ -0,0 +1,24 @@
|
||||
//! Test helper for Pugz engine
|
||||
//! Provides common utilities for template testing
|
||||
|
||||
const std = @import("std");
|
||||
const pugz = @import("pugz");
|
||||
|
||||
/// Expects the template to produce the expected output when rendered with the given data.
|
||||
/// Uses arena allocator for automatic cleanup.
|
||||
pub fn expectOutput(template: []const u8, data: anytype, expected: []const u8) !void {
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const allocator = arena.allocator();
|
||||
|
||||
var lexer = pugz.Lexer.init(allocator, template);
|
||||
const tokens = try lexer.tokenize();
|
||||
|
||||
var parser = pugz.Parser.init(allocator, tokens);
|
||||
const doc = try parser.parse();
|
||||
|
||||
const raw_result = try pugz.render(allocator, doc, data);
|
||||
const result = std.mem.trimRight(u8, raw_result, "\n");
|
||||
|
||||
try std.testing.expectEqualStrings(expected, result);
|
||||
}
|
||||
Reference in New Issue
Block a user