update: csrf_token and lorem

This commit is contained in:
Lucas F. 2026-01-03 21:00:11 -03:00
parent bbab647430
commit b09da93f0d
3 changed files with 175 additions and 3 deletions

View file

@ -643,3 +643,69 @@ test "parse load com múltiplas" {
try testing.expectEqualStrings("admin_urls", l.libraries[0]);
try testing.expectEqualStrings("static", l.libraries[1]);
}
test "parse csrf_token simples" {
const allocator = testing.allocator;
const template = "<form>{% csrf_token %}</form>";
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("<form>", nodes[0].text.?.content);
try testing.expect(nodes[1].type == .csrf_token);
try testing.expect(nodes[2].type == .text);
try testing.expectEqualStrings("</form>", nodes[2].text.?.content);
}
test "parse csrf_token sozinho" {
const allocator = testing.allocator;
const template = "{% csrf_token %}";
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 == .csrf_token);
}
test "parse lorem padrão" {
const allocator = testing.allocator;
const template = "{% lorem %}";
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 == .lorem);
const l = nodes[0].lorem.?;
try testing.expect(l.count == null);
try testing.expect(l.method == null);
try testing.expect(l.format == null);
}
test "parse lorem com argumentos" {
const allocator = testing.allocator;
const template = "{% lorem 5 p html %}";
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 == .lorem);
const l = nodes[0].lorem.?;
try testing.expectEqualStrings("5", l.count.?);
try testing.expectEqualStrings("p", l.method.?);
try testing.expectEqualStrings("html", l.format.?);
}