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 6326b1c0..9092a307 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -1852,6 +1852,36 @@ test "a bad setting value is quoted, so two different bad values log as two reco
try testing.expect(!th.logHas(p, "(x2)"));
}
+test "a look line's trailing colon is dropped, and a look whose address fails never leaves its file open" {
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
+ var line: [4200]u8 = undefined;
+ const count = struct {
+ fn of(pp: *Pardes) usize {
+ var n: usize = 0;
+ for (pp.panes) |slot| n += @intFromBool(slot != null);
+ return n;
+ }
+ }.of;
+ const before = count(p);
+ // Failing addresses: nothing opened, the write still answered.
+ inline for ([_][]const u8{ "{s}/a.txt:/nomatch/\n", "{s}/a.txt:9:\n" }) |fmt| {
+ _ = wr(p, root_look, try std.fmt.bufPrint(&line, fmt, .{dir}));
+ try testing.expectEqual(before, count(p));
+ }
+ // `a.txt:2:3:` is `a.txt:2:3`: it opens there.
+ try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:2:3:\n", .{dir})).reply.status);
+ try testing.expectEqual(before + 1, count(p));
+ const opened = p.panes[p.active].?;
+ try testing.expect(std.mem.endsWith(u8, opened.file.?.path, "/a.txt"));
+ try testing.expectEqual(@as(i32, 1), opened.body.cur_row);
+}
+
test "a bare :N or :N:M look addresses the pane itself, from its look, the root's and event write-back" {
const p = try withFile(testing.allocator, "alpha\nbeta\ngamma\n");
defer p.deinit();