summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/panes.zig61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/panes.zig b/test/panes.zig
index 249ce7eb..3e147c95 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -3902,6 +3902,67 @@ const PdfAddon = struct {
try std.testing.expect(r.diverged == null);
}
+ test "a pane of each kind, dumped and loaded on another core, has every Slot field a step reads as the session's" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const R = pardes.replica;
+ const gpa = std.testing.allocator;
+ const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }, false);
+ defer a.deinit();
+ const Land = struct {
+ a: *R.Authority,
+ fn step(l: @This(), ev: pardes.Event) !void {
+ _ = try l.a.local(ev);
+ }
+ };
+ const land: Land = .{ .a = a };
+ const pdf = try opened(a, land);
+ try land.step(.{ .command = "PdfFit width" });
+ a.core.panes[pdf].?.addon.?.cancelled[0] = 7;
+ // A picture beside it (the image addon's).
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ var why: pardes.Kind.Buf(160) = .{};
+ const lib = pardes.Addon.readLoaded(@import("test_addons").image, &words, &why);
+ try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } });
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "dot.ppm", .data = "P6\n1 1\n255\n\x01\x02\x03" });
+ var buf: [4096]u8 = undefined;
+ var line: [4200]u8 = undefined;
+ try land.step(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/dot.ppm", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]}) });
+ try jobs(a.core, land);
+ const was = pardes.tape.on;
+ pardes.tape.on = &a.t;
+ const bytes = try pardes.dump.byteDump(a.core);
+ pardes.tape.resync(&a.t);
+ pardes.tape.on = was;
+ defer a.core.gpa.free(bytes);
+ const r = try R.Replica.initDump(gpa, 2, 0, bytes, .{ .cols = 80, .rows = 24 });
+ defer r.deinit();
+ try std.testing.expect(r.loaded(pardes.tape.digestOf(a.core)));
+ // Every field but those the Slot says are the kind's or a frame's
+ // (`replica.local`): a field added and not dumped fails here.
+ var kinds: usize = 0;
+ for (a.core.panes, r.core().panes) |mine, theirs| if (mine) |pane| if (pane.addon) |s| {
+ const t = theirs.?.addon.?;
+ kinds += 1;
+ inline for (@typeInfo(pardes.Kind.Slot).@"struct".field_names) |name| {
+ const local = comptime for (pardes.Kind.Slot.replica.local) |n| {
+ if (std.mem.eql(u8, n, name)) break true;
+ } else false;
+ const F = @FieldType(pardes.Kind.Slot, name);
+ if (comptime local) {} else if (comptime @typeInfo(F) == .@"struct" and @hasDecl(F, "slice"))
+ try std.testing.expectEqualStrings(@field(s, name).slice(), @field(t, name).slice())
+ else
+ try std.testing.expectEqualDeep(@field(s, name), @field(t, name));
+ }
+ // Its place: what its kind says, and the Shadow's copy of it.
+ var here: [32]u8 = undefined;
+ var there: [32]u8 = undefined;
+ try std.testing.expectEqualStrings(pardes.Kind.where(s, &here), pardes.Kind.where(t, &there));
+ };
+ try std.testing.expectEqual(2, kinds);
+ }
+
test "a client's input that moves a PDF's view is guessed right, never waited for, and the session's tick of it is a unit of its own the client replays" {
if (!addons.has_pdf) return error.SkipZigTest;
const R = pardes.replica;