diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 11:26:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 13:14:28 -0300 |
| commit | d815a5cc854b3cd14a89f401565db212c3dc9d88 (patch) | |
| tree | 1335995520095445488d26dc030dd777db010fd9 /test/panes.zig | |
| parent | 8640107e29a940d50a5eef0dc7d12689a515d856 (diff) | |
| download | pardes-d815a5cc854b3cd14a89f401565db212c3dc9d88.tar.gz pardes-d815a5cc854b3cd14a89f401565db212c3dc9d88.zip | |
text journal, the ring and undo over it: a file's undo is the journal of its edits (Text.Journal: entries of an offset, the bytes taken out and the count put in, grouped in steps between marks, each step with the place it began at and the place it was undone from), bounded at 256 steps or 64 MiB, the newest kept; pushUndo marks a step (none when the last changed nothing, as a snapshot equal to the text was none) and every edit goes into the last step, joined to its last entry when they touch (typing on, backspace over it, a write going on where the last ended); undo and redo turn a step's entries round, one in place, several in a copy whose gap moves from one to the next (File.Gap), one edit and one revision as the snapshot's was; the snapshots go (File.Snapshot, the undo and redo arrays and their copies of the whole text at every step); the replica's copy pins an entry's bytes (Entry.removed, a blob) as it pinned a snapshot's; tests: 'undo keeps its steps within a byte bound, the newest always' reads the journal, 'file history owns bounded snapshot storage without per-edit bookkeeping allocations' becomes 'file history keeps its last undo_max steps, and an undo or redo with no memory changes nothing', the far join's blob test makes its two blobs beside the text with a delete and a yank (its history held whole texts before), and the counts of steps read history.journal.done
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/panes.zig')
| -rw-r--r-- | test/panes.zig | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/test/panes.zig b/test/panes.zig index aa54d483..958c35a2 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -1376,8 +1376,7 @@ test "file history construction failures preserve existing panes" { if (result) |pane| { if (case == .output) incoming = null; try std.testing.expect(pane.file.?.history != old_history); - try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len); - try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.redo_len); + try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.journal.steps.items.len); succeeded = true; break; } else |err| { @@ -1394,7 +1393,7 @@ test "file history construction failures preserve existing panes" { } } -test "file history owns bounded snapshot storage without per-edit bookkeeping allocations" { +test "file history keeps its last undo_max steps, and an undo or redo with no memory changes nothing" { var failing = std.testing.FailingAllocator.init(std.testing.allocator, .{}); const p = try Pardes.init(failing.allocator(), .{ .tty_only = true, .cols = 40, .rows = 12 }); defer p.deinit(); @@ -1403,39 +1402,35 @@ test "file history owns bounded snapshot storage without per-edit bookkeeping al const history = file.history; for (0..pardes.memory.limits.undo_max + 2) |index| { const next = try std.fmt.allocPrint(p.gpa, "{d}", .{index}); - const before = failing.alloc_index; panes.File.pushUndo(p, pane); - try std.testing.expectEqual(before + 1, failing.alloc_index); panes.File.setContent(p, file, next); try std.testing.expectEqual(history, file.history); } - try std.testing.expectEqual(pardes.memory.limits.undo_max, history.undo_len); - try std.testing.expectEqualStrings("1", history.undo[0].content); - const current = file.content; + const j = &history.journal; + try std.testing.expectEqual(pardes.memory.limits.undo_max, j.done); + // The two oldest steps went: the oldest kept took "1" out for "2". + try std.testing.expectEqualStrings("1", j.entries.items[j.steps.items[0].first].removed); + // No memory for the bytes an undo keeps: nothing changes. failing.fail_index = failing.alloc_index; - panes.File.pushUndo(p, pane); panes.File.undoStep(p, pane, true); - try std.testing.expectEqual(current.ptr, file.content.ptr); - try std.testing.expectEqual(pardes.memory.limits.undo_max, history.undo_len); - try std.testing.expectEqual(@as(usize, 0), history.redo_len); + try std.testing.expectEqualStrings("257", file.content); + try std.testing.expectEqual(pardes.memory.limits.undo_max, j.done); failing.fail_index = std.math.maxInt(usize); - const before = failing.alloc_index; panes.File.undoStep(p, pane, true); - try std.testing.expectEqual(before + 2, failing.alloc_index); - try std.testing.expectEqual(@as(usize, 1), file.line_starts.len); - try std.testing.expectEqual(@as(usize, 1), history.redo_len); - const undone = file.content; + try std.testing.expectEqualStrings("256", file.content); + try std.testing.expectEqual(@as(usize, 1), j.steps.items.len - j.done); failing.fail_index = failing.alloc_index; panes.File.undoStep(p, pane, false); - try std.testing.expectEqual(undone.ptr, file.content.ptr); - try std.testing.expectEqual(@as(usize, 1), history.redo_len); + try std.testing.expectEqualStrings("256", file.content); + try std.testing.expectEqual(@as(usize, 1), j.steps.items.len - j.done); failing.fail_index = std.math.maxInt(usize); - const before_redo = failing.alloc_index; panes.File.undoStep(p, pane, false); - // The snapshot's copy alone: the line index moves in place. - try std.testing.expectEqual(before_redo + 1, failing.alloc_index); - try std.testing.expectEqual(pardes.memory.limits.undo_max, history.undo_len); - try std.testing.expectEqual(@as(usize, 0), history.redo_len); + try std.testing.expectEqualStrings("257", file.content); + try std.testing.expectEqual(pardes.memory.limits.undo_max, j.done); + // Back through every step kept, and no further. + for (0..pardes.memory.limits.undo_max + 1) |_| panes.File.undoStep(p, pane, true); + try std.testing.expectEqualStrings("1", file.content); + try std.testing.expectEqual(@as(usize, 0), j.done); } test "file history allocation precedes reading the served tree" { |
