diff options
Diffstat (limited to 'src/replica.zig')
| -rw-r--r-- | src/replica.zig | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/replica.zig b/src/replica.zig index b1b0514c..d10cdf83 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -4473,6 +4473,43 @@ test "a kind's place moved in a step of another view's: a replica's key that rea try agrees(a, r); } +/// A kind whose every key asks a job, for the job tokens' test. +const Jobber = struct { + const pa = pardes.Kind.c; + fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { + return pardes.Kind.api.alloc.?(4); + } + fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {} + fn press(_: ?*anyopaque, _: [*c]const pa.pa_key) callconv(.c) c_int { + _ = pardes.Kind.api.job.?(null, 0); + return 1; + } + const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Jobber", .opens = 1, .doc = "a key a job" })}; + const ops = std.mem.zeroInit(pardes.Kind.Ops, .{ + .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "jobber".* ++ @as([10]u8, @splat(0)), .version = 1, .exts = "", .words = &words, .nwords = 1 }), + .open = open, + .paint = paint, + .key = press, + }); +}; + +test "a client joined from a dump numbers a kind's next job as the session does" { + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + defer a.deinit(); + var words: [64]pardes.Kind.LoadedWord = undefined; + const jobber = pardes.Kind.loadedOf(&Jobber.ops, "/x/jobber.so", @splat(7), &words); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &jobber } }); + _ = try a.local(.{ .command = "Jobber" }); + for (0..3) |_| _ = try a.local(.{ .key = .{ .cp = 'x', .text = "x" } }); + const id = a.core.view().active; + try std.testing.expectEqual(@as(u32, 3), a.core.panes[id].?.addon.?.tokens); + const joiner = try joinedNow(a, 2, 1); + defer joiner.deinit(); + try std.testing.expectEqual(@as(u32, 3), joiner.core().panes[id].?.addon.?.tokens); + try std.testing.expectEqual(digestOf(a), joiner.digest()); +} + test "a replica's word that opens a kind's pane with no file waits for the authority's open: never mispredicted" { const gpa = std.testing.allocator; const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); |
