update: add debug, partialdef and partial

This commit is contained in:
Lucas F. 2026-01-03 21:06:54 -03:00
parent b09da93f0d
commit 1e0329a597
3 changed files with 207 additions and 7 deletions

View file

@ -709,3 +709,66 @@ test "parse lorem com argumentos" {
try testing.expectEqualStrings("p", l.method.?);
try testing.expectEqualStrings("html", l.format.?);
}
test "parse debug simples" {
const allocator = testing.allocator;
const template = "Antes {% debug %} Depois";
const nodes = try parser.parse(allocator, template);
defer {
for (nodes) |node| node.deinit(allocator);
allocator.free(nodes);
}
try testing.expectEqual(@as(usize, 3), nodes.len);
try testing.expect(nodes[0].type == .text);
try testing.expectEqualStrings("Antes ", nodes[0].text.?.content);
try testing.expect(nodes[1].type == .debug);
try testing.expect(nodes[2].type == .text);
try testing.expectEqualStrings(" Depois", nodes[2].text.?.content);
}
test "parse debug sozinho" {
const allocator = testing.allocator;
const template = "{% debug %}";
const nodes = try parser.parse(allocator, template);
defer {
for (nodes) |node| node.deinit(allocator);
allocator.free(nodes);
}
try testing.expectEqual(@as(usize, 1), nodes.len);
try testing.expect(nodes[0].type == .debug);
}
test "parse partialdef simples" {
const allocator = testing.allocator;
const template = "{% partialdef cabecalho %}Cabeçalho{% endpartialdef %}";
const nodes = try parser.parse(allocator, template);
defer {
for (nodes) |node| node.deinit(allocator);
allocator.free(nodes);
}
try testing.expectEqual(@as(usize, 1), nodes.len);
try testing.expect(nodes[0].type == .partialdef);
const pd = nodes[0].partialdef.?;
try testing.expectEqualStrings("cabecalho", pd.name);
try testing.expectEqual(@as(usize, 1), pd.body.len);
try testing.expectEqualStrings("Cabeçalho", pd.body[0].text.?.content);
}
test "parse partial uso" {
const allocator = testing.allocator;
const template = "Início {% partial \"cabecalho\" %} Fim";
const nodes = try parser.parse(allocator, template);
defer {
for (nodes) |node| node.deinit(allocator);
allocator.free(nodes);
}
try testing.expectEqual(@as(usize, 3), nodes.len);
try testing.expect(nodes[1].type == .partial);
try testing.expectEqualStrings("cabecalho", nodes[1].partial.?.name);
}