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.zig328
1 files changed, 0 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();