summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 11:01:39 -0300
committerGabriel Schneider <[email protected]>2026-11-04 11:02:14 -0300
commit3c5cddb963c67df5df0ed0ec023d68e43ba26bd5 (patch)
tree2e0bc9d5a65497d341220c3c3be1a5d9425bf859
parent350e7cc22b85130cbe95a114c668945b1dc12fd7 (diff)
downloadpardes-3c5cddb963c67df5df0ed0ec023d68e43ba26bd5.tar.gz
pardes-3c5cddb963c67df5df0ed0ec023d68e43ba26bd5.zip
test: the Recent, Jumplist and Back/Forward group of src/ninep/ctl.zig, nine tests, through the 9P tree alone: in test/behaviour/other_files.zig Jumplist refilling its one +Jumps, a Jumplist entry (closed) only while no pane has its file, Recent's row of an open file at its dot now, a closed file found again (/recent and Recent list it closed, a look at its row reopens it at its dot, a Back under JumpScope all too), Back and Forward over a closed file's two entries reopening it once, Recent keeping only files on disk, Back over a closed file deleted since skipping it and saying so, and a remembered place clamped to the file as it is now; in settings.zig Back and Forward written to exec keeping to the focused file, and JumpScope all taking every place in order; each checked to fail against a break (refillOrOpen never refilling, a look's reopen not relinking a closed entry, Recent's open row at its closing place, Recent's (closed) word, a jump's reopen relinking no other entry, JumpScope's file test inverted, recentKeeps keeping any local name, Back's deleted words, the clamp's words)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/ninep/ctl.zig328
-rw-r--r--test/behaviour/other_files.zig229
-rw-r--r--test/behaviour/settings.zig42
3 files changed, 271 insertions, 328 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index f23f2579..ec7cb3bc 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2495,261 +2495,6 @@ test "a column takes panes until their documented minimums fill it, not until no
}
}
-test "Jumplist fills its one +Jumps again, as Recent does, never a second" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
- var count: [2]usize = undefined;
- for (&count) |*n| {
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "Jumplist\n").reply.status);
- p.sync();
- n.* = 0;
- for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output) |o| {
- n.* += @intFromBool(std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Jumplist }));
- };
- }
- try testing.expectEqual(@as(usize, 1), count[0]);
- try testing.expectEqual(@as(usize, 1), count[1]);
-}
-
-test "a Jumplist entry is (closed) only while no pane has 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\n" });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "two\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;
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt\n", .{dir}));
- p.sync();
- const a = p.panes[p.active].?.serial;
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/b.txt\n", .{dir}));
- p.sync();
- _ = wr(p, Node.of(a, .ctl), "Del\n");
- p.sync();
- var closed: usize = 0;
- for (p.jumps[0..p.njumps]) |j| closed += @intFromBool(j.serial == 0);
- try testing.expect(closed > 0);
- // Open again, by a look: no entry is closed any more.
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt\n", .{dir}));
- p.sync();
- for (p.jumps[0..p.njumps]) |j| try testing.expect(j.serial != 0);
-}
-
-test "Recent's row for a file still open is where its dot is now, not where it last closed" {
- 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;
- try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:3\n", .{dir})).reply.status);
- p.sync();
- const pane = p.panes[p.active].?;
- pane.body.vsel.active = false; // the look's selection of line 3 let go
- pane.body.cur_row = 1;
- pane.body.cur_col = 2;
- try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status);
- const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?;
- // A query pane under the file (line 1 `Recent `), its rows said from
- // its directory.
- try testing.expect(std.mem.startsWith(u8, rows.file.?.content, "Recent \n"));
- try testing.expect(std.mem.indexOf(u8, rows.file.?.content, "\na.txt:2:3 open\n") != null);
-}
-
-test "a closed file is found again: Recent and /recent list it closed, a look at its row reopens it at its dot, and a jump back does too" {
- 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" });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "bee\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 a_path = try std.fmt.bufPrint(&line, "{s}/a.txt", .{dir});
- var a_buf: [4200]u8 = undefined;
- const a = a_buf[0..a_path.len];
- @memcpy(a, a_path);
- // Opened, its dot on line 3, then closed.
- try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}:3\n", .{a})).reply.status);
- p.sync();
- const opened = p.active;
- try testing.expectEqualStrings(a, p.panes[opened].?.file.?.path);
- var want: [4300]u8 = undefined;
- try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{a})) != null);
- // Another file, so the jumplist has somewhere to come back from.
- try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/b.txt\n", .{dir})).reply.status);
- p.sync();
- try testing.expectEqual(Status.ok, wr(p, Node.of(p.panes[opened].?.serial, .ctl), "Del\n").reply.status);
- p.sync();
- try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "closed {s}\n", .{a})) != null);
- // Recent lists it, closed, at its dot; a look at the row opens it there.
- try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status);
- const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?;
- // Its query pane's rows are said from its directory, a.txt's.
- const at = std.mem.indexOf(u8, rows.file.?.content, "\na.txt:3:").? + 1;
- const row = rows.file.?.content[at..std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?];
- try testing.expect(std.mem.endsWith(u8, row, " (closed)"));
- try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), try std.fmt.bufPrint(&line, "{s}\n", .{row[0 .. row.len - " (closed)".len]})).reply.status);
- p.sync();
- const back = p.panes[p.active].?;
- try testing.expectEqualStrings(a, back.file.?.path);
- try testing.expectEqual(@as(i32, 2), back.body.cur_row);
- // Closed again; the jumplist keeps its entry, closed, and a jump back
- // to it opens it again.
- _ = wr(p, Node.of(back.serial, .ctl), "Del\n");
- p.sync();
- var closed_entry = false;
- for (p.jumps[0..p.njumps]) |j| closed_entry = closed_entry or j.serial == 0;
- try testing.expect(closed_entry);
- // Every entry in order (JumpScope all): which file has the focus after
- // a Del is the layout's to choose, and Back keeps to it first.
- p.settings.jump_scope = .all;
- var tries: usize = 0;
- while (tries < p.njumps) : (tries += 1) {
- p.jumpBy(-1);
- p.sync();
- if (p.panes[p.active].?.file) |f| if (std.mem.eql(u8, f.path, a)) break;
- }
- try testing.expectEqualStrings(a, p.panes[p.active].?.file.?.path);
-}
-
-test "Back and Forward over a closed file's entries: one reopen is that file's pane in every entry, so the next step moves" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- var long: [400]u8 = undefined;
- var n: usize = 0;
- for (0..100) |_| {
- @memcpy(long[n..][0..4], "row\n");
- n += 4;
- }
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = long[0..n] });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "bee\n" });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.txt", .data = "sea\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;
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/b.txt\n", .{dir}));
- p.sync();
- const b_serial = p.panes[p.active].?.serial;
- // Two entries for a.txt, far apart in it.
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:1\n", .{dir}));
- p.sync();
- const a = p.active;
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:90\n", .{dir}));
- p.sync();
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/c.txt\n", .{dir}));
- p.sync();
- const c_serial = p.panes[p.active].?.serial;
- _ = wr(p, Node.of(p.panes[a].?.serial, .ctl), "Del\n");
- p.sync();
- var closed: usize = 0;
- for (p.jumps[0..p.njumps]) |j| closed += @intFromBool(j.serial == 0);
- try testing.expectEqual(@as(usize, 2), closed);
- // Back reopens it at line 90: both its entries are that pane now.
- p.jumpBy(-1);
- p.sync();
- const re = p.panes[p.active].?;
- try testing.expect(std.mem.endsWith(u8, re.file.?.path, "/a.txt"));
- try testing.expectEqual(@as(i32, 89), re.body.cur_row);
- for (p.jumps[0..p.njumps]) |j| try testing.expect(j.serial != 0);
- // Back again goes to its line 1, in the same pane, then to b.
- p.jumpBy(-1);
- p.sync();
- try testing.expectEqual(re.serial, p.panes[p.active].?.serial);
- try testing.expectEqual(@as(i32, 0), re.body.cur_row);
- p.jumpBy(-1);
- p.sync();
- try testing.expectEqual(b_serial, p.panes[p.active].?.serial);
- // And Forward walks it all again, to c.
- p.jumpBy(1);
- p.sync();
- p.jumpBy(1);
- p.sync();
- try testing.expectEqual(@as(i32, 89), re.body.cur_row);
- p.jumpBy(1);
- p.sync();
- try testing.expectEqual(c_serial, p.panes[p.active].?.serial);
-}
-
-test "Back and Forward written to exec keep to the focused file, and JumpScope all, written to ctl, takes every place in order" {
- 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 = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\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;
- // Each a look, as a user's jumps are: b1 a1 b40 a40 b80 a80.
- for ([_][]const u8{ "b.txt:1", "a.txt:1", "b.txt:40", "a.txt:40", "b.txt:80", "a.txt:80" }) |place| {
- try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/{s}\n", .{ dir, place })).reply.status);
- p.sync();
- }
- const Step = struct { word: []const u8, file: []const u8, line: i32 };
- const walk = struct {
- fn run(q: *Pardes, steps: []const Step) !void {
- for (steps) |s| {
- var cmd: [16]u8 = undefined;
- try testing.expectEqual(Status.ok, wr(q, root_exec, try std.fmt.bufPrint(&cmd, "{s}\n", .{s.word})).reply.status);
- q.sync();
- const pane = q.panes[q.active].?;
- try testing.expect(std.mem.endsWith(u8, pane.file.?.path, s.file));
- try testing.expectEqual(s.line, pane.body.cur_row + 1);
- }
- }
- }.run;
- // a's places first, b only once a has none older; Forward mirrors it
- // from b and ends at a80, where it began.
- try walk(p, &.{
- .{ .word = "Back", .file = "/a.txt", .line = 40 },
- .{ .word = "Back", .file = "/a.txt", .line = 1 },
- .{ .word = "Back", .file = "/b.txt", .line = 1 },
- .{ .word = "Forward", .file = "/b.txt", .line = 40 },
- .{ .word = "Forward", .file = "/b.txt", .line = 80 },
- .{ .word = "Forward", .file = "/a.txt", .line = 80 },
- });
- try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "JumpScope all\n").reply.status);
- try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.ctl), 0, 8192).bytes, "JumpScope all\n") != null);
- try walk(p, &.{
- .{ .word = "Back", .file = "/b.txt", .line = 80 },
- .{ .word = "Back", .file = "/a.txt", .line = 40 },
- .{ .word = "Forward", .file = "/b.txt", .line = 80 },
- });
-}
-
-test "Recent keeps only files on disk: not a name never saved, nor the served tree's" {
- 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 = "real.txt", .data = "real\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 names = [_][]const u8{ try std.fmt.allocPrint(testing.allocator, "{s}/c", .{dir}), try testing.allocator.dupe(u8, "/virtual/zz"), try std.fmt.allocPrint(testing.allocator, "{s}/real.txt", .{dir}) };
- defer for (names) |n| testing.allocator.free(n);
- for (names) |name| {
- const made = try th.newPane(p);
- _ = wr(p, Node.of(made, .name), try std.fmt.bufPrint(&line, "{s}\n", .{name}));
- p.sync();
- _ = wr(p, Node.of(made, .ctl), "Del\n");
- _ = wr(p, Node.of(made, .ctl), "Del\n");
- p.sync();
- }
- try testing.expect(p.recent.get(names[0]) == null);
- try testing.expect(p.recent.get(names[1]) == null);
- try testing.expect(p.recent.get(names[2]) != null);
-}
-
test "a new file saved shows in /recent, open, while it is" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -2785,79 +2530,6 @@ test "/recent shows a name as /index does, a newline in it escaped" {
try testing.expect(std.mem.indexOf(u8, text, "closed /tmp/a\\nb\\\\c\n") != null);
}
-test "Back over a closed file deleted since skips it, says so, and goes on to the place before" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- for ([_][]const u8{ "a.txt", "gone.txt", "c.txt" }) |name| try tmp.dir.writeFile(testing.io, .{ .sub_path = name, .data = "text\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;
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt\n", .{dir}));
- p.sync();
- const a_serial = p.panes[p.active].?.serial;
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/gone.txt\n", .{dir}));
- p.sync();
- const gone = p.active;
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/c.txt\n", .{dir}));
- p.sync();
- const c_id = p.active;
- _ = wr(p, Node.of(p.panes[gone].?.serial, .ctl), "Del\n");
- p.sync();
- try tmp.dir.deleteFile(testing.io, "gone.txt");
- p.active = c_id;
- p.jumpBy(-1);
- p.sync();
- try testing.expectEqual(a_serial, p.panes[p.active].?.serial);
- try testing.expect(std.mem.indexOf(u8, p.panes[c_id].?.msg[0..p.panes[c_id].?.msg_len], "gone.txt: deleted, skipped") != null);
-}
-
-test "a remembered place is clamped to the file as it is now, its selection's two ends kept where they fit" {
- 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 = "c.txt", .data = "one\ntwo\nthree\nfour\nfive\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;
- _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/c.txt:2\n", .{dir}));
- p.sync();
- const c = p.panes[p.active].?;
- // A selection over lines 2 to 4, then closed.
- @import("pane.zig").setDot(c, .{ .q0 = 4, .q1 = 19 });
- try testing.expect(c.body.vsel.active);
- _ = wr(p, Node.of(c.serial, .ctl), "Del\n");
- p.sync();
- // The file shrinks to two lines while it is closed.
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.txt", .data = "one\ntwo\n" });
- _ = wr(p, root_exec, "Recent\n");
- const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?;
- const at = std.mem.indexOf(u8, rows.file.?.content, "c.txt:").?;
- const row = rows.file.?.content[at..std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?];
- // Both ends are in the row, a range.
- try testing.expect(std.mem.indexOfScalar(u8, row, '-') != null);
- var full: [4400]u8 = undefined;
- const loc = try std.fmt.bufPrint(&full, "{s}/{s}\n", .{ dir, row[0..std.mem.indexOfScalar(u8, row, ' ').?] });
- // A look at it opens the file, never a miss, clamped to its last line.
- try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), loc).reply.status);
- p.sync();
- const back = p.panes[p.active].?;
- try testing.expect(std.mem.endsWith(u8, back.file.?.path, "/c.txt"));
- try testing.expect(back.body.cur_row <= 1);
- try testing.expect(back.body.vsel.active);
- // Its ends clamped to the last character, `two`'s `o`, not its newline.
- try testing.expect(back.body.cur_col <= 2 and back.body.vsel.col <= 2);
- try testing.expect(std.mem.indexOf(u8, back.msg[0..back.msg_len], "c.txt has 2 lines now: at its last") != null);
- // The same row with the file open: the same place, said the same way.
- _ = wr(p, Node.of(rows.serial, .look), loc);
- p.sync();
- try testing.expectEqual(back.serial, p.panes[p.active].?.serial);
- try testing.expect(back.body.cur_row <= 1);
- try testing.expect(std.mem.indexOf(u8, back.msg[0..back.msg_len], "at its last") != null);
-}
-
test "size is monotonic: growing is never refused, and a size once taken is taken again" {
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 60 });
defer p.deinit();
diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig
index ef1fab7e..2d5cb112 100644
--- a/test/behaviour/other_files.zig
+++ b/test/behaviour/other_files.zig
@@ -80,3 +80,232 @@ test "other-files: /recent keeps a PDF as it keeps a file: open, then closed" {
try s.write(s.at("/pane/{d}/ctl", .{n}), "Del\n");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("closed {s}\n", .{name})) != null);
}
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+/// A fresh directory's absolute path, kept until deinit.
+fn tmpPath(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 {
+ var buf: [4096]u8 = undefined;
+ return s.at("{s}", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]});
+}
+
+/// The serials /index lists with a name ending `suffix`.
+fn named(s: *Session, suffix: []const u8) ![]u32 {
+ var out: std.ArrayList(u32) = .empty;
+ var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n');
+ while (rows.next()) |line| {
+ const name = line[0 .. std.mem.lastIndexOfScalar(u8, line, ' ') orelse continue];
+ if (std.mem.endsWith(u8, name, suffix)) try out.append(s.arena.allocator(), try std.fmt.parseInt(u32, line[0..std.mem.indexOfScalar(u8, line, ' ').?], 10));
+ }
+ return out.items;
+}
+
+/// The body of the pane a root exec of `word` answers (Recent, Jumplist).
+fn listing(s: *Session, word: []const u8) ![]const u8 {
+ try s.write("/exec", s.at("{s}\n", .{word}));
+ return s.read(s.at("/pane/{s}/body", .{std.mem.trimEnd(u8, try s.read("/exec"), "\n")}));
+}
+
+test "other-files: Jumplist fills its one +Jumps again, as Recent does, never a second" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ for (0..2) |_| {
+ try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Jumplist\n");
+ try std.testing.expectEqual(@as(usize, 1), (try named(&s, "/+Jumps")).len);
+ }
+}
+
+test "other-files: a Jumplist entry is (closed) only while no pane has its file open" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "two\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ try s.write("/look", s.at("{s}/a.txt\n", .{dir}));
+ const a = try s.focused();
+ try s.write("/look", s.at("{s}/b.txt\n", .{dir}));
+ try s.write(s.at("/pane/{d}/ctl", .{a}), "Del\n");
+ try std.testing.expect(has(try listing(&s, "Jumplist"), "(closed)"));
+ // Open again, by a look: no entry is closed any more.
+ try s.write("/look", s.at("{s}/a.txt\n", .{dir}));
+ try std.testing.expect(!has(try listing(&s, "Jumplist"), "(closed)"));
+}
+
+test "other-files: Recent's row for a file still open is where its dot is now, not where it last closed" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try s.write("/look", s.at("{s}/a.txt:3\n", .{try tmpPath(&s, &tmp)}));
+ try s.write(s.at("/pane/{d}/dot", .{try s.focused()}), "6 6"); // line 2, column 3
+ // A query pane under the file (line 1 `Recent `), its rows said from
+ // its directory.
+ const rows = try listing(&s, "Recent");
+ try std.testing.expect(std.mem.startsWith(u8, rows, "Recent \n"));
+ try std.testing.expect(has(rows, "\na.txt:2:3 open\n"));
+}
+
+test "other-files: a closed file is found again: Recent and /recent list it closed, a look at its row reopens it at its dot, and a jump back does too" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "bee\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const a = s.at("{s}/a.txt", .{dir});
+ // Opened, its dot on line 3, then closed.
+ try s.write("/look", s.at("{s}:3\n", .{a}));
+ const opened = try s.focused();
+ try std.testing.expect(has(try s.read("/recent"), s.at("open {s}\n", .{a})));
+ // Another file, so the jumplist has somewhere to come back from.
+ try s.write("/look", s.at("{s}/b.txt\n", .{dir}));
+ try s.write(s.at("/pane/{d}/ctl", .{opened}), "Del\n");
+ try std.testing.expect(has(try s.read("/recent"), s.at("closed {s}\n", .{a})));
+ // Recent lists it, closed, at its dot; a look at the row opens it there.
+ const rows = try listing(&s, "Recent");
+ const recent = std.mem.trimEnd(u8, try s.read("/exec"), "\n");
+ const at = std.mem.indexOf(u8, rows, "\na.txt:3:").? + 1;
+ const row = rows[at..std.mem.indexOfScalarPos(u8, rows, at, '\n').?];
+ try std.testing.expect(std.mem.endsWith(u8, row, " (closed)"));
+ try s.write(s.at("/pane/{s}/look", .{recent}), s.at("{s}\n", .{row[0 .. row.len - " (closed)".len]}));
+ const back = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{back}), s.at("{s}\n", .{a}));
+ try std.testing.expectEqual(@as(u32, 8), (try s.range(s.at("/pane/{d}/dot", .{back})))[0]);
+ // Closed again; the jumplist keeps its entry, closed, and a jump back
+ // to it opens it again.
+ try s.write(s.at("/pane/{d}/ctl", .{back}), "Del\n");
+ try std.testing.expect(has(try listing(&s, "Jumplist"), "(closed)"));
+ // Every entry in order (JumpScope all): which file has the focus after
+ // a Del is the layout's to choose, and Back keeps to it first.
+ try s.write("/ctl", "JumpScope all\n");
+ for (0..8) |_| {
+ if ((try named(&s, "/a.txt")).len > 0) break;
+ try s.write("/exec", "Back\n");
+ }
+ try s.expect(s.at("/pane/{d}/name", .{try s.focused()}), s.at("{s}\n", .{a}));
+}
+
+test "other-files: Back and Forward over a closed file's entries: one reopen is that file's pane in every entry, so the next step moves" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "bee\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.txt", .data = "sea\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ try s.write("/look", s.at("{s}/b.txt\n", .{dir}));
+ const b = try s.focused();
+ // Two entries for a.txt, far apart in it.
+ try s.write("/look", s.at("{s}/a.txt:1\n", .{dir}));
+ const a = try s.focused();
+ try s.write("/look", s.at("{s}/a.txt:90\n", .{dir}));
+ try s.write("/look", s.at("{s}/c.txt\n", .{dir}));
+ const c = try s.focused();
+ try s.write(s.at("/pane/{d}/ctl", .{a}), "Del\n");
+ try s.write("/focus", s.at("{d}\n", .{c}));
+ try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, try listing(&s, "Jumplist"), "(closed)"));
+ try s.write("/focus", s.at("{d}\n", .{c}));
+ // Back reopens it at line 90: both its entries are that pane now.
+ try s.write("/exec", "Back\n");
+ const re = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{re}), s.at("{s}/a.txt\n", .{dir}));
+ try std.testing.expectEqual(@as(u32, 89), (try s.range(s.at("/pane/{d}/dot", .{re})))[0] / 4);
+ try std.testing.expect(!has(try listing(&s, "Jumplist"), "(closed)"));
+ try s.write("/focus", s.at("{d}\n", .{re}));
+ // Back again goes to its line 1, in the same pane, then to b.
+ try s.write("/exec", "Back\n");
+ try std.testing.expectEqual(re, try s.focused());
+ try std.testing.expectEqual(@as(u32, 0), (try s.range(s.at("/pane/{d}/dot", .{re})))[0] / 4);
+ try s.write("/exec", "Back\n");
+ try std.testing.expectEqual(b, try s.focused());
+ // And Forward walks it all again, to c.
+ try s.write("/exec", "Forward\n");
+ try s.write("/exec", "Forward\n");
+ try std.testing.expectEqual(@as(u32, 89), (try s.range(s.at("/pane/{d}/dot", .{re})))[0] / 4);
+ try s.write("/exec", "Forward\n");
+ try std.testing.expectEqual(c, try s.focused());
+}
+
+test "other-files: Recent keeps only files on disk: not a name never saved, nor the served tree's" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "real.txt", .data = "real\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const names = [_][]const u8{ s.at("{s}/c", .{dir}), "/virtual/zz", s.at("{s}/real.txt", .{dir}) };
+ for (names) |name| {
+ const made = try s.newPane();
+ try s.write(s.at("/pane/{d}/name", .{made}), s.at("{s}\n", .{name}));
+ // Asked once if it is a file with text to lose; gone either way.
+ _ = try s.refused(s.at("/pane/{d}/ctl", .{made}), "Del\n");
+ _ = s.refused(s.at("/pane/{d}/ctl", .{made}), "Del\n") catch 0;
+ }
+ const recent = try s.read("/recent");
+ try std.testing.expect(!has(recent, s.at(" {s}\n", .{names[0]})));
+ try std.testing.expect(!has(recent, " /virtual/zz\n"));
+ try std.testing.expect(has(recent, s.at(" {s}\n", .{names[2]})));
+}
+
+test "other-files: Back over a closed file deleted since skips it, says so, and goes on to the place before" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ for ([_][]const u8{ "a.txt", "gone.txt", "c.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "text\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ try s.write("/look", s.at("{s}/a.txt\n", .{dir}));
+ const a = try s.focused();
+ try s.write("/look", s.at("{s}/gone.txt\n", .{dir}));
+ const gone = try s.focused();
+ try s.write("/look", s.at("{s}/c.txt\n", .{dir}));
+ const c = try s.focused();
+ try s.write(s.at("/pane/{d}/ctl", .{gone}), "Del\n");
+ try tmp.dir.deleteFile(std.testing.io, "gone.txt");
+ try s.write("/focus", s.at("{d}\n", .{c}));
+ try s.write("/exec", "Back\n");
+ try std.testing.expectEqual(a, try s.focused());
+ try std.testing.expect(has(try s.read("/log"), "gone.txt: deleted, skipped"));
+}
+
+test "other-files: a remembered place is clamped to the file as it is now, its selection's two ends kept where they fit" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.txt", .data = "one\ntwo\nthree\nfour\nfive\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ try s.write("/look", s.at("{s}/c.txt:2\n", .{dir}));
+ const c = try s.focused();
+ // A selection over lines 2 to 4, then closed.
+ try s.write(s.at("/pane/{d}/dot", .{c}), "4 19");
+ try s.write(s.at("/pane/{d}/ctl", .{c}), "Del\n");
+ // The file shrinks to two lines while it is closed.
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.txt", .data = "one\ntwo\n" });
+ const rows = try listing(&s, "Recent");
+ const recent = std.mem.trimEnd(u8, try s.read("/exec"), "\n");
+ const at = std.mem.indexOf(u8, rows, "c.txt:").?;
+ const row = rows[at..std.mem.indexOfScalarPos(u8, rows, at, '\n').?];
+ // Both ends are in the row, a range.
+ try std.testing.expect(std.mem.indexOfScalar(u8, row, '-') != null);
+ const loc = s.at("{s}/{s}\n", .{ dir, row[0..std.mem.indexOfScalar(u8, row, ' ').?] });
+ // A look at it opens the file, never a miss, clamped to its last line.
+ try s.write(s.at("/pane/{s}/look", .{recent}), loc);
+ const back = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{back}), s.at("{s}/c.txt\n", .{dir}));
+ // Its ends clamped to the last character, `two`'s `o`, not its newline.
+ const dot = try s.range(s.at("/pane/{d}/dot", .{back}));
+ try std.testing.expect(dot[0] < dot[1] and dot[1] <= 7);
+ try std.testing.expect(has(try s.read("/log"), "c.txt has 2 lines now: at its last"));
+ // The same row with the file open: the same place, said the same way.
+ try s.write(s.at("/pane/{s}/look", .{recent}), loc);
+ try std.testing.expectEqual(back, try s.focused());
+ try std.testing.expectEqual(dot, try s.range(s.at("/pane/{d}/dot", .{back})));
+}
diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig
index f3ed57de..df70dbe6 100644
--- a/test/behaviour/settings.zig
+++ b/test/behaviour/settings.zig
@@ -132,3 +132,45 @@ test "settings: a setting this frontend cannot show says GUI-only, never run as
try std.testing.expectEqualStrings("unknown control message \"Liftt\"", s.said);
try std.testing.expect(has(try s.read("/ctl"), "\nDumpDir /"));
}
+
+test "settings: Back and Forward written to exec keep to the focused file, and JumpScope all, written to ctl, takes every place in order" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ // Each a look, as a user's jumps are: b1 a1 b40 a40 b80 a80.
+ for ([_][]const u8{ "b.txt:1", "a.txt:1", "b.txt:40", "a.txt:40", "b.txt:80", "a.txt:80" }) |place| try s.write("/look", s.at("{s}/{s}\n", .{ dir, place }));
+ const Step = struct { []const u8, []const u8, u32 };
+ const walk = struct {
+ fn run(q: *Session, steps: []const Step) !void {
+ for (steps) |st| {
+ try q.write("/exec", q.at("{s}\n", .{st[0]}));
+ const n = try q.focused();
+ try std.testing.expect(std.mem.endsWith(u8, try q.read(q.at("/pane/{d}/name", .{n})), q.at("{s}\n", .{st[1]})));
+ // Each line is `row\n`: the line the dot is on.
+ try std.testing.expectEqual(st[2] - 1, (try q.range(q.at("/pane/{d}/dot", .{n})))[0] / 4);
+ }
+ }
+ }.run;
+ // a's places first, b only once a has none older; Forward mirrors it
+ // from b and ends at a80, where it began.
+ try walk(&s, &.{
+ .{ "Back", "/a.txt", 40 },
+ .{ "Back", "/a.txt", 1 },
+ .{ "Back", "/b.txt", 1 },
+ .{ "Forward", "/b.txt", 40 },
+ .{ "Forward", "/b.txt", 80 },
+ .{ "Forward", "/a.txt", 80 },
+ });
+ try s.write("/ctl", "JumpScope all\n");
+ try std.testing.expect(has(try s.read("/ctl"), "JumpScope all\n"));
+ try walk(&s, &.{
+ .{ "Back", "/b.txt", 80 },
+ .{ "Back", "/a.txt", 40 },
+ .{ "Forward", "/b.txt", 80 },
+ });
+}