diff options
Diffstat (limited to 'src/ninep/ctl.zig')
| -rw-r--r-- | src/ninep/ctl.zig | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index f4aff960..1a2dbdbc 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -4213,3 +4213,43 @@ test "Petscii, Palette and Ascii take the state their tag word names, set rather _ = wr(p, ctl_node, "Petscii maybe\n"); try testing.expect(th.logHas(p, "Petscii takes on or off")); } + +test "a Restore reads a clean file from disk; an unsaved one whose file changed since is said so, and its first Save asks" { + if (comptime !pardes.hosted) return; + const gpa = testing.allocator; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "one\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/a.txt", .{dir}); + const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + // Clean: the dump keeps no text, and the newer disk is what comes back. + try pardes.dump.dumpState(p); + try testing.expect(std.mem.indexOf(u8, p.dump_out.?, "b25lCg==") == null); // "one\n" in base64 + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "two\n" }); + { + const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon"); + defer restored.deinit(); + const f = pane_files.fileOf(restored.panes[0].?).?; + try testing.expectEqualStrings("two\n", f.content); + try testing.expectEqual(f.saved_revision, f.revision); + } + // Unsaved: its text comes back, the disk changed under it is said, and + // Save asks once before overwriting it. + const f = pane_files.fileOf(p.panes[0].?).?; + const edited = try gpa.dupe(u8, "edited\n"); + pardes.panes.File.setContent(p, f, edited); + try testing.expect(f.revision != f.saved_revision); + try pardes.dump.dumpState(p); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "three\n" }); + const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon"); + defer restored.deinit(); + const rf = pane_files.fileOf(restored.panes[0].?).?; + try testing.expectEqualStrings("edited\n", rf.content); + try testing.expect(rf.disk_newer != null); + pardes.exec.saveFile(restored, 0); + try testing.expect(th.logHas(restored, "modified on disk since read (Save again to overwrite)")); +} |
