diff options
Diffstat (limited to 'core/replica.zig')
| -rw-r--r-- | core/replica.zig | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig index 24d1ad21..e05cf79e 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -5560,6 +5560,70 @@ test "a client joined from a dump makes a `/` query's rows as the session does, } } +// A query row's colours come from what this process has (its frames' +// paint of the owner, File.highlights; a worker's paint kept in the +// locations cache): out of the rows' digest. Whether a step asks a +// worker to paint the rows' file (Stream.paintRows, an effect on the +// tape) must not come from them: a session whose host paints on workers +// (search), that has drawn its owner, and a client that has not. +test "a client joined from a dump asks a worker for a `/` query's colours as the session does, though only the session has drawn its owner" { + const Paints = struct { + fn search(_: ?*anyopaque, _: u32) void {} + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .search = search }; + }; + const gpa = std.testing.allocator; + // A view as tall as the text: the frame paints every line of it. + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 500, .file = "build.zig" }, .{ .vtable = &Paints.vtable }, false); + defer a.deinit(); + { + const was = Stepping.begin(&a.t, null); + defer was.end(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + _ = try a.core.render(arena.allocator()); + } + _ = try a.openView(2); + const joiner = try joinedNow(a, 3, 1); + defer joiner.deinit(); + var buf: [256]u8 = undefined; + for ("/co", 1..) |c, seq| { + const u = try gpa.dupe(u8, try a.take(try inputOf(&buf, 1, @intCast(seq), .{ .key = .{ .cp = c, .text = &.{c} } }))); + defer gpa.free(u); + joiner.confirm(u); + try agrees(a, joiner); + } +} + +// The same for the colours a worker painted earlier, kept in the session's +// locations cache (a Grep since has asked again of every file): a dump +// carries no cache, so a client joined since has none. +test "a client joined from a dump asks a worker for a `/` query's colours as the session does, though only the session has them from an earlier paint" { + const Paints = struct { + fn search(_: ?*anyopaque, _: u32) void {} + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .search = search }; + }; + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, .{ .vtable = &Paints.vtable }, false); + defer a.deinit(); + { + const p = a.core; + const f = &p.panes[0].?.file.?; + const colors = try pardes.syntax.highlightFileRange(gpa, f.path, f.content, 0, f.content.len); + defer gpa.free(colors); + try p.locations_cache.put(p.tree_sitter_gpa, f.path, f.content, colors); + } + _ = try a.openView(2); + const joiner = try joinedNow(a, 3, 1); + defer joiner.deinit(); + var buf: [256]u8 = undefined; + for ("/co", 1..) |c, seq| { + const u = try gpa.dupe(u8, try a.take(try inputOf(&buf, 1, @intCast(seq), .{ .key = .{ .cp = c, .text = &.{c} } }))); + defer gpa.free(u); + joiner.confirm(u); + try agrees(a, joiner); + } +} + test "a step that reads a terminal's rows as the core keeps them sends a new client the ones it holds as holes" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; |
