summaryrefslogtreecommitdiff
path: root/core/jj.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/jj.zig')
-rw-r--r--core/jj.zig30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/jj.zig b/core/jj.zig
index e35da662..74870c00 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -2552,6 +2552,36 @@ test "the lanes ride with the text: a line typed in a nested block is nobody's,
try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
}
+test "a client's own line opened over pinned changes, rolled back by the session's key first: the lanes it spliced under its copy are the copy's again, freed once; the client ends equal" {
+ var repo = try Stack.repo(null) orelse return error.SkipZigTest;
+ defer repo.deinit(testing.allocator);
+ const R = pardes.replica;
+ const a = try R.Authority.init(testing.allocator, .{ .cols = 80, .rows = 24 }, .{});
+ defer a.deinit();
+ const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0));
+ defer r.deinit();
+ var line: [4200]u8 = undefined;
+ r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) }));
+ r.confirm(try a.local(.{ .command = "Changes ::@" }));
+ r.confirm(try a.local(.{ .command = "Look a.zig:4" }));
+ r.settle();
+ const serial = a.core.panes[a.core.view().active].?.serial;
+ // The client opens a line below: an edit of the file, whose step splices
+ // the pinned lines' values (jj.edited) under the copy it takes.
+ const typed = try testing.allocator.dupe(u8, try r.input(.{ .key = .{ .cp = 'o', .text = "o" } }));
+ defer testing.allocator.free(typed);
+ try testing.expectEqual(@as(usize, 1), r.applied);
+ // The session's own key comes first: the copy put back, the `o` applied
+ // again over it, then confirmed.
+ r.confirm(try a.local(.{ .key = .{ .cp = 'k', .text = "k" } }));
+ r.settle();
+ r.confirm(try a.take(typed));
+ r.settle();
+ try testing.expect(r.diverged == null);
+ try testing.expectEqualSlices(Line, answered(a.core, serial).?.lines, answered(r.core(), serial).?.lines);
+ try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
+}
+
/// Two functions four changes wrote: `fn` both, `f2` and `f3` rewrote
/// f's line, `g2` g's: f three changes, g two.
const Churned = struct {