srctree

Gregory Mullen parent eb15d046 c5cc40e4
fix an off by one bug in precomputed pages

:D
src/template.zig added: 7, removed: 11, total 0
@@ -349,10 +349,7 @@ test "directive nothing new" {
const pg = Page(t, @TypeOf(ctx)).init(.{});
const p = try allocPrint(a, "{}", .{pg});
defer a.free(p);
// TODO this is closer to the correct behavior, but it should still return
// an error. It doesn't because reader rules, but we can, and should move it
// to comptime.
try std.testing.expectEqualStrings("", p);
try std.testing.expectEqualStrings("<Nothing>", p);
}
 
test "directive ORELSE" {
@@ -520,7 +517,6 @@ test "directive For & For" {
}
 
test "directive for then for" {
if (true) return error.SkipZigTest;
var a = std.testing.allocator;
 
const blob =
 
src/template/page.zig added: 7, removed: 11, total 0
@@ -93,15 +93,15 @@ pub fn Page(comptime template: Template, comptime PageDataType: type) type {
}
 
pub fn format(self: Self, comptime _: []const u8, _: std.fmt.FormatOptions, out: anytype) !void {
//std.debug.print("data offsets {any}\n", .{Self.DataOffsets});
const blob = Self.PageTemplate.blob;
if (Self.DataOffsets.len == 0)
return try out.writeAll(blob);
 
var last_end: usize = 0;
for (Self.DataOffsets) |offs| {
const start = offs[0];
const end = offs[0];
try out.writeAll(blob[0..start]);
const end = offs[1];
try out.writeAll(blob[last_end..start]);
//blob = blob[start..];
 
if (Directive.init(blob[start..])) |drct| {
@@ -119,9 +119,9 @@ pub fn Page(comptime template: Template, comptime PageDataType: type) type {
std.debug.print("init failed ?\n", .{});
try out.writeAll(blob[end..]);
}
last_end = end;
continue;
} else {
const last_end = Self.DataOffsets[Self.DataOffsets.len - 1][1];
return try out.writeAll(blob[last_end..]);
}
}