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.zig33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 917c9c39..c6b76d51 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2073,6 +2073,39 @@ test "a bad Tab width and a bad Incl directory are refused invalid, changing not
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /tmp/pardes-twin-renamed.txt\n", .{twin})));
}
+test "Undo to unsaved text under its old name says nothing changed on disk when nothing did, and Save then writes" {
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "e.txt", .data = "e\n" });
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "b\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
+ for ([_][]const u8{ "Get b.txt", "Edit e b.txt" }) |load| {
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ const serial = serialOf(p);
+ const pane = p.panes[0].?;
+ var name: [4300]u8 = undefined;
+ _ = wr(p, Node.of(serial, .name), try std.fmt.bufPrint(&name, "{s}/e.txt\n", .{dir}));
+ try testing.expect(p.executeBuiltinLine(0, "Get"));
+ _ = wr(p, Node.of(serial, .body), "appended\n");
+ // Asked once, then loaded.
+ try testing.expect(p.executeBuiltinLine(0, load));
+ try testing.expect(p.executeBuiltinLine(0, load));
+ try testing.expectEqualStrings("b\n", pane.file.?.content);
+ try testing.expect(p.executeBuiltinLine(0, "Undo"));
+ try testing.expectEqualStrings("e\nappended\n", pane.file.?.content);
+ try testing.expect(pane_files.dirtyOf(pane));
+ // The watch looks again at e.txt, as it was all along.
+ pardes.panes.File.changed(p, 0, "e\n");
+ try testing.expectEqual(@as(?u64, null), pane.file.?.disk_newer);
+ try testing.expect(!th.logHas(p, "changed on disk"));
+ // A change there is still news.
+ pardes.panes.File.changed(p, 0, "someone else\n");
+ try testing.expect(pane.file.?.disk_newer != null);
+ }
+}
+
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();