diff options
Diffstat (limited to 'core/dump.zig')
| -rw-r--r-- | core/dump.zig | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/core/dump.zig b/core/dump.zig index 9dcc076e..b4561ae2 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -143,14 +143,6 @@ pub fn dumpExit(p: *Pardes) !void { /// view showed in a dump made before the layer's lines were the buffer's /// (wire 31 and older: a view's bit, no lines), its lines in it (jj.loaded). fn afterLoad(p: *Pardes) void { - // Each view laid out again over its columns and its screen, as a resize - // lays it out: its geometry is derived, never read (View.replica). - const live = p.live; - for (p.views, 0..) |slot, k| if (slot != null) { - p.live = @intCast(k); - layout.compute(p); - }; - p.live = live; for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| { const text = pardes.panes.File.fileText(f, p.scratch.allocator()) catch continue; f.context.reload(p.tree_sitter_gpa, f.path, text, f.revision); @@ -1036,24 +1028,45 @@ test "a dump keeps the session's settings, and a restore applies them" { try std.testing.expect(!restored.settings.wrap); } -test "a view's geometry is laid out again at a load, never read: a pane's rect past its screen in a dump is the layout's after it" { - // The fuzz's restore road, seed 589: an image whose pane 0 said 534 - // rows on a 24-row screen, drawn: surface.zig's `at` asserted. +test "a view's geometry is read back as the session holds it, never laid out again; a rect or a column off its screen is refused, the field named" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); - const want = p.view().rects[0]; - p.view().rects[0].h = 534; - p.view().col_w[0] = 900; - const dumped = try dumpBytes(p); - defer gpa.free(dumped); - p.view().rects[0] = want; - const q = try load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, dumped, null); - defer q.deinit(); - try std.testing.expectEqual(want, q.view().rects[0]); - try std.testing.expectEqual(@as(u16, 80), q.view().col_w[0]); - _ = q.frame_arena.reset(.retain_capacity); - _ = try q.render(q.frame_arena.allocator()); + // Not what the layout pass would make of its columns (a view opened + // and not laid out yet has no rects at all): as the session has it. + p.view().rects[0].h -= 1; + const held = p.view().rects[0]; + inline for (.{ byteDump, dumpBytes }) |dumpOf| { + const bytes = try dumpOf(p); + defer gpa.free(bytes); + const q = try load(gpa, p.opts, bytes, null); + defer q.deinit(); + try std.testing.expectEqual(held, q.view().rects[0]); + } + // The fuzz's restore road, seed 589: an image whose pane 0 said 534 + // rows on a 24-row screen, drawn: surface.zig's `at` asserted. + const Off = struct { at: *u16, to: u16, why: []const u8 }; + for ([_]Off{ + .{ .at = &p.view().rects[0].h, .to = 534, .why = "View.rects[0] is not within" }, + .{ .at = &p.view().col_w[0], .to = 900, .why = "View.col_w[0] is not within" }, + // A column's edge is held with its width. + .{ .at = &p.view().col_x[0], .to = 900, .why = "View.col_w[0] is not within" }, + }) |off| { + const was = off.at.*; + off.at.* = off.to; + defer off.at.* = was; + inline for (.{ byteDump, dumpBytes }) |dumpOf| { + const bytes = try dumpOf(p); + defer gpa.free(bytes); + var notes: std.ArrayList(u8) = .empty; + defer notes.deinit(gpa); + try std.testing.expectError(error.BadDump, load(gpa, p.opts, bytes, ¬es)); + std.testing.expect(std.mem.indexOf(u8, notes.items, off.why) != null) catch |err| { + std.debug.print("refused, but not by {s}: {s}\n", .{ off.why, notes.items }); + return err; + }; + } + } } test "a dump whose index names no view or pane there is refused, the field named; a top past its text is its last line; a key's replay is not dumped" { |
