summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/panes.zig43
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" {