summaryrefslogtreecommitdiff
path: root/src/ninep/ctl.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/ctl.zig')
-rw-r--r--src/ninep/ctl.zig30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 973f87e2..ae68ed91 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -1995,6 +1995,36 @@ test "a Get file that fails changes nothing: no such file, a directory, or unsav
try testing.expectEqualStrings("here\nmore\n", pane.file.?.content);
}
+test "Zerox twins dump their text once and come back on one buffer from a Restore" {
+ const p = try withFile(testing.allocator, "one\ntwo\n");
+ defer p.deinit();
+ const first = serialOf(p);
+ _ = wr(p, Node.of(first, .name), "/tmp/pardes-zerox-dump.txt\n");
+ _ = wr(p, Node.of(first, .body), "unsaved " ** 64 ++ "\n");
+ try testing.expect(p.executeBuiltinLine(0, "Zerox"));
+ try testing.expect(p.executeBuiltinLine(0, "Zerox"));
+ try pardes.dump.dumpState(p);
+ const text = p.dump_out.?;
+ // The text is kept once though three panes show it.
+ const encoded = try pardes.dump.encodeBytes(p.scratch.allocator(), p.panes[0].?.file.?.content);
+ try testing.expectEqual(@as(usize, 1), std.mem.count(u8, text, encoded));
+ const restored = try pardes.dump.restore(p, text, "/tmp/pardes.dump.zon");
+ defer restored.deinit();
+ var files: [3]*pardes.panes.File.State = undefined;
+ var n: usize = 0;
+ for (restored.panes) |slot| if (slot) |pane| if (pane.file) |*f| if (std.mem.eql(u8, f.path, "/tmp/pardes-zerox-dump.txt")) {
+ files[n] = f;
+ n += 1;
+ };
+ try testing.expectEqual(@as(usize, 3), n);
+ for (files[1..]) |f| {
+ try testing.expectEqual(files[0].content.ptr, f.content.ptr);
+ try testing.expectEqual(files[0].history, f.history);
+ try testing.expect(f.twin != 0 and f.twin == files[0].twin);
+ }
+ try testing.expect(std.mem.startsWith(u8, files[0].content, "one\ntwo\nunsaved "));
+}
+
test "a body write to a terminal is typed input, not a paste, even to a program that asked for bracketed paste" {
const p = try Pardes.init(testing.allocator, .{ .cols = 90, .rows = 30 });
defer p.deinit();