summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig62
1 files changed, 62 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 0ae302e8..936eb3e4 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -4012,6 +4012,68 @@ test "the count of writes outside the copy is digested: a session's emulator wri
try std.testing.expectEqualStrings("outside ", try partsApart(b.a, b.r, arena.allocator()));
}
+test "bytes: a terminal's rows read before an idle client's copy are the copy's: a rollback puts them back, neither dropped nor freed twice" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const b = try BytesPair.init();
+ defer b.deinit();
+ try b.output("a line of the program's\r\nand another\r\n");
+ // Its rows read between steps (a draw's), then the copy taken while it
+ // idles (`ready`): the rows are what the core holds at the copy.
+ const pane = b.r.core().panes[b.shell.index()].?;
+ _ = try pardes.edit.shellRows(b.r.core(), pane);
+ const cached = b.r.core().shell_rows.text_alloc.ptr;
+ b.r.ready();
+ try std.testing.expect(b.r.copy.held);
+ // A key of the client's on top, the session's own key first: the copy
+ // put back, the rows with it (not left orphaned in the epoch).
+ try b.rollback();
+ try std.testing.expectEqual(cached, b.r.core().shell_rows.text_alloc.ptr);
+ try agrees(b.a, b.r);
+ try b.output("after\r\n");
+ _ = try pardes.edit.shellRows(b.r.core(), pane);
+ try agrees(b.a, b.r);
+}
+
+test "bytes: a client's key that reads a terminal's rows, the session's output before it in the session's order: the output rolls it back, its read is made again over the fed rows, and the input is kept on the fast path with the session's reading" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const gpa = std.testing.allocator;
+ const b = try BytesPair.init();
+ defer b.deinit();
+ try b.output("l1\r\nl2\r\nl3\r\n");
+ // The shell's pane focused and out of its tty mode (^B): a cursor over
+ // its rows.
+ const id = b.shell.index();
+ const rect = b.a.core.view().rects[id];
+ for ([_]pardes.Event{
+ .{ .mouse = .{ .button = .left, .kind = .press, .col = rect.x + 2, .row = rect.y + 1 } },
+ .{ .mouse = .{ .button = .left, .kind = .release, .col = rect.x + 2, .row = rect.y + 1 } },
+ .{ .key = .{ .cp = 'b', .ctrl = true } },
+ }) |ev| {
+ b.r.confirm(try b.a.own(ev));
+ b.r.settle();
+ }
+ try agrees(b.a, b.r);
+ // G: to the last of its rows, which it reads (edit.shellRows).
+ const last = try gpa.dupe(u8, try b.r.input(.{ .key = .{ .cp = 'G', .text = "G" } }));
+ defer gpa.free(last);
+ try std.testing.expectEqual(@as(usize, 1), b.r.applied);
+ const read_before = b.r.core().panes[id].?.body.cur_row;
+ // The program prints two lines before the session takes the G: the
+ // emulator fed (its count moved, so never a neutral unit), the G
+ // undone and read again over the rows as fed.
+ b.a.output(.{ .output = .{ .pane = b.shell, .bytes = "l4\r\nl5\r\n" } });
+ b.r.confirm((try b.a.pending()).?);
+ b.r.settle();
+ try std.testing.expectEqual(@as(usize, 1), b.r.applied);
+ try std.testing.expect(b.r.core().panes[id].?.body.cur_row > read_before);
+ const fast = b.r.stats.fast;
+ b.r.confirm(try b.a.take(last));
+ b.r.settle();
+ try std.testing.expectEqual(fast + 1, b.r.stats.fast);
+ try agrees(b.a, b.r);
+ try std.testing.expectEqual(b.a.core.panes[id].?.body.cur_row, b.r.core().panes[id].?.body.cur_row);
+}
+
test "bytes: what a terminal's emulator gains while a copy is held is its own: a rollback frees none of it" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const b = try BytesPair.init();