diff options
Diffstat (limited to 'core/dump.zig')
| -rw-r--r-- | core/dump.zig | 132 |
1 files changed, 117 insertions, 15 deletions
diff --git a/core/dump.zig b/core/dump.zig index deb18dba..b4561ae2 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -555,21 +555,25 @@ fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void { pane.terminal = try pardes.Term.open(&p.outside, pardes.panes.emulatorGpa(p.gpa), @max(1, pane.cols), @max(1, pane.rows)); } -/// The panes a column lists that are not there (another build's dump left -/// them out) taken out of it, and the keyboard on one that is. -fn dropMissing(p: *Pardes) void { - const v = p.view(); - for (0..p.view().ncol) |c| { - var n: usize = 0; - for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (id < MAX_PANES and p.panes[id] != null) { - v.cols[c].panes[n] = id; - n += 1; - }; - v.cols[c].n = n; - } - if (v.active >= MAX_PANES or p.panes[v.active] == null) v.active = for (p.panes, 0..) |slot, i| { - if (slot != null) break i; - } else 0; +/// The panes each view's columns list that are not there (another build's +/// dump left them out) taken out of them, and its keyboard on one that is: +/// at the load's end, and where the core's fields end (walk.zig +/// `left_out`), before what names a pane is held to one there. Every view: +/// the live one may not be one yet then. (Their lengths are held already.) +pub fn dropMissing(p: *Pardes) void { + for (&p.views) |*slot| if (slot.*) |*v| { + for (v.cols[0..v.ncol]) |*col| { + var n: usize = 0; + for (col.panes[0..col.n]) |id| if (id < MAX_PANES and p.panes[id] != null) { + col.panes[n] = id; + n += 1; + }; + col.n = n; + } + if (v.active >= MAX_PANES or p.panes[v.active] == null) v.active = for (p.panes, 0..) |s, i| { + if (s != null) break i; + } else 0; + }; } /// The replacement core for a Restore of the dump at `from`, whose log says @@ -1024,6 +1028,104 @@ 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 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(); + // 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" { + // The fuzz's join road (core/fuzz.zig): `live` read past the views + // (views.zig `bit`), a file's top past its text (File.zig fillBody's + // `wrap_line`), and `multi_count` sizing a yank's register at 17 GB. + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true }); + defer p.deinit(); + const pane = try p.setTestFile("one\ntwo\n"); + const id = p.view().active; + const Refused = struct { + fn by(q: *Pardes, why: []const u8) !void { + inline for (.{ byteDump, dumpBytes }) |dumpOf| { + const bytes = try dumpOf(q); + defer q.gpa.free(bytes); + var notes: std.ArrayList(u8) = .empty; + defer notes.deinit(q.gpa); + try std.testing.expectError(error.BadDump, load(q.gpa, q.opts, bytes, ¬es)); + std.testing.expect(std.mem.indexOf(u8, notes.items, why) != null) catch |err| { + std.debug.print("refused, but not by {s}: {s}\n", .{ why, notes.items }); + return err; + }; + } + } + }; + // No view open to write the shares of (the live one's are its panes'). + p.live = 9; + p.views_open = 0; + try Refused.by(p, "live says 9"); + p.live = 0; + p.views_open = 1; + p.view().active = 9; + try Refused.by(p, ".active says 9"); + p.view().active = id; + const col = &p.view().cols[0].panes[0]; + col.* = 9; + try Refused.by(p, "Column.panes says 9"); + col.* = id; + pane.sized_by = 7; + try Refused.by(p, "Pane.sized_by says 7"); + pane.sized_by = 0; + // Where a thing is, past its end: its last place, the session there. + pane.file.?.scroll = 1 << 40; + p.multi_count = 1 << 30; + 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(@as(usize, 2), q.panes[id].?.file.?.scroll); + try std.testing.expectEqual(@as(usize, 1), q.multi_count); + _ = q.frame_arena.reset(.retain_capacity); + _ = try q.render(q.frame_arena.allocator()); + } + pane.file.?.scroll = 0; + p.multi_count = 1; +} + test "a session with every column it may hold dumps and restores them all" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 1200, .rows = 24 }); |
