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.zig1483
1 files changed, 22 insertions, 1461 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index bd460098..89549933 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -1465,386 +1465,41 @@ test "commands lists every builtin with its argument and the ctl that takes it"
try testing.expect(std.mem.indexOf(u8, listed.bytes, row) != null);
}
-test "Undo and Redo on a pane's ctl step its body through its edits" {
- const p = try withFile(testing.allocator, "one\n");
- defer p.deinit();
- const serial = serialOf(p);
- const body = Node.of(serial, .body);
- try testing.expectEqual(Status.ok, wr(p, body, "two\n").reply.status);
- try testing.expectEqualStrings("one\ntwo\n", rd(p, body, 0, 64).bytes);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Undo").reply.status);
- try testing.expectEqualStrings("one\n", rd(p, body, 0, 64).bytes);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Redo").reply.status);
- try testing.expectEqualStrings("one\ntwo\n", rd(p, body, 0, 64).bytes);
- // Nothing left: said, and the write still succeeds, as acme's is silent.
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Redo").reply.status);
- try testing.expect(th.logHas(p, "Redo: nothing to redo"));
- _ = wr(p, Node.of(serial, .ctl), "Undo");
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Undo").reply.status);
- try testing.expect(th.logHas(p, "Undo: nothing to undo"));
- // Said again word for word, it is that line counted, as err's are.
- for (0..3) |_| _ = wr(p, Node.of(serial, .ctl), "Undo");
- try testing.expect(th.logHas(p, "Undo: nothing to undo (x4)\n"));
-}
-
-test "Edit through a pane's ctl renames every foo in one undo step, and a failed one changes nothing" {
- const p = try withFile(testing.allocator, "foo x foo y foo\n");
- defer p.deinit();
- const serial = serialOf(p);
- const ctl_node = Node.of(serial, .ctl);
- const body = Node.of(serial, .body);
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "Edit ,x/foo/c/foobar/\n").reply.status);
- try testing.expectEqualStrings("foobar x foobar y foobar\n", rd(p, body, 0, 64).bytes);
- const failed = wr(p, ctl_node, "Edit ,s/nothing/x/\n");
- try testing.expectEqual(E.IO, failed.errno());
- try testing.expectStringStartsWith(failed.reply.ename, "Edit: no substitution");
- try testing.expectEqualStrings("foobar x foobar y foobar\n", rd(p, body, 0, 64).bytes);
- // The whole rename is one undo step.
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "Undo").reply.status);
- try testing.expectEqualStrings("foo x foo y foo\n", rd(p, body, 0, 64).bytes);
-}
-
-test "dirty goes back to 0 when the text is the saved text again" {
- const p = try withFile(testing.allocator, "one\n");
- defer p.deinit();
- const serial = serialOf(p);
- const dirty = Node.of(serial, .dirty);
- try testing.expectEqualStrings("0\n", rd(p, dirty, 0, 8).bytes);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "two\n").reply.status);
- try testing.expectEqualStrings("1\n", rd(p, dirty, 0, 8).bytes);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Undo").reply.status);
- try testing.expectEqualStrings("0\n", rd(p, dirty, 0, 8).bytes);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Redo").reply.status);
- try testing.expectEqualStrings("1\n", rd(p, dirty, 0, 8).bytes);
-}
-
-test "a look's miss repeats the path whole up to 256 bytes, then gives up its middle to an ellipsis" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "x\n");
- defer p.deinit();
- const root = @backingInt(tree.TopFile.look);
- const long = "some/deeply/nested/directory/that/goes/on/and/on/with/a_rather_long_file_name.txt";
- var line: [512]u8 = undefined;
- _ = wr(p, root, try std.fmt.bufPrint(&line, "{s}\n", .{long}));
- try testing.expect(th.logHas(p, try std.fmt.bufPrint(&line, "look: no match for \"{s}\"\n", .{long})));
- const huge = std.mem.asBytes(&@as([150][2]u8, @splat("é".*))); // 300 bytes: its middle cut to fit 256, between characters
- _ = wr(p, root, huge ++ "\n");
- try testing.expect(th.logHas(p, "look: no match for \"" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "…" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "\"\n"));
-}
-
-test "status reads the editor, and look and exec validate whole batches" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "Msg root\n");
+test "status in a window says whether the pointer is over it" {
+ // The rest of status is test/behaviour/look_and_exec.zig's: a session
+ // there is a terminal's view.
+ const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- // A terminal's view first (a window's build starts windowed).
- p.windowed = false;
- const status = rd(p, root_status, 0, 4096);
- try testing.expectEqual(Status.ok, status.reply.status);
- var lines = std.mem.tokenizeScalar(u8, status.bytes, '\n');
- try testing.expect(std.mem.startsWith(u8, lines.next().?, "pid "));
- var expected: [64]u8 = undefined;
- try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "version {s}", .{pardes.version}), lines.next().?);
- var live: usize = 0;
- for (p.panes) |slot| live += @intFromBool(slot != null);
- try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "panes {d}", .{live}), lines.next().?);
- try testing.expect(lines.next() == null);
- // A window says whether the pointer is over it.
p.windowed = true;
- var again = std.mem.tokenizeScalar(u8, rd(p, root_status, 0, 4096).bytes, '\n');
- for (0..3) |_| _ = again.next();
- try testing.expectEqualStrings("pointer out", again.next().?);
+ var lines = std.mem.tokenizeScalar(u8, rd(p, root_status, 0, 4096).bytes, '\n');
+ for (0..3) |_| _ = lines.next();
+ try testing.expectEqualStrings("pointer out", lines.next().?);
p.windowed = false;
- const stat = call(p, .{ .tag = 1, .op = .getattr, .node = root_status });
- try testing.expectEqual(@as(u64, status.bytes.len), stat.reply.attr.size);
- try testing.expectEqual(@as(u16, 0o444), stat.reply.attr.mode);
- try testing.expectEqual(E.PERM, wr(p, root_status, "anything\n").errno());
- try testing.expectEqualStrings("", rd(p, root_exec, 0, 4096).bytes);
-
- const serial = p.next_serial;
- for ([_][]const u8{ "Msg a\x00b", "Msg x\nMsg \x01y\n" }) |invalid| {
- try testing.expectEqual(E.INVAL, wr(p, root_exec, invalid).errno());
- try testing.expectEqual(serial, p.next_serial);
- }
- // An empty write is a no-op, not a command.
- try testing.expectEqual(Status.ok, wr(p, root_exec, "\n \n").reply.status);
- try testing.expectEqualStrings("", rd(p, root_exec, 0, 4096).bytes);
- try testing.expectEqualStrings(status.bytes, rd(p, root_status, 0, 4096).bytes);
-
- const pane = p.panes[0].?;
- try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg hello there\n").reply.status);
- try testing.expectEqualStrings("hello there", pane.msg[0..pane.msg_len]);
- try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{pane.serial}), rd(p, root_exec, 0, 4096).bytes);
-
- try testing.expectEqual(Status.ok, wr(p, root_look, "/virtual/index\n").reply.status);
- const opened = p.panes[p.active].?;
- try testing.expectEqualStrings("/virtual/index", opened.file.?.path);
- try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes);
-
- try testing.expectEqual(Status.ok, wr(p, root_exec, "New\n").reply.status);
- const made = p.panes[p.active].?;
- try testing.expect(made.serial != opened.serial);
- try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{made.serial}), rd(p, root_exec, 0, 4096).bytes);
-}
-
-test "look opens spaced paths and locations without editing the source pane" {
- if (!fs.platform_has_fs) return error.SkipZigTest;
- const gpa = testing.allocator;
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "two words.zig", .data = "first\nsecond\nthird\n" });
- var path_buf: [4096]u8 = undefined;
- const path = path_buf[0..try tmp.dir.realPathFile(testing.io, "two words.zig", &path_buf)];
- const p = try withFile(gpa, "source stays intact\n");
- defer p.deinit();
- const source = p.panes[0].?;
- const look_node = Node.of(source.serial, .look);
- const revision = source.file.?.revision;
- const undo_len = source.file.?.history.undo_len;
- source.body.cur_col = 3;
- var clicked: [4200]u8 = undefined;
- try testing.expectEqual(Status.ok, wr(p, look_node, try std.fmt.bufPrint(&clicked, "{s}:2:3\n", .{path})).reply.status);
- const opened = p.panes[p.active].?;
- try testing.expect(opened != source);
- try testing.expectEqualStrings(path, opened.file.?.path);
- try testing.expectEqualStrings("first\nsecond\nthird\n", opened.file.?.content);
- try testing.expectEqual(@as(i32, 1), opened.body.cur_row);
- try testing.expectEqual(@as(i32, 2), opened.body.cur_col);
- try testing.expectEqualStrings("source stays intact\n", source.file.?.content);
- try testing.expectEqual(revision, source.file.?.revision);
- try testing.expectEqual(undo_len, source.file.?.history.undo_len);
- try testing.expectEqual(@as(i32, 3), source.body.cur_col);
- var expected: [16]u8 = undefined;
- try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes);
-
- p.active = 0;
- try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&clicked, "{s}:3:2\n", .{path})).reply.status);
- try testing.expect(p.panes[p.active].? == opened);
- try testing.expectEqual(@as(i32, 2), opened.body.cur_row);
- try testing.expectEqual(@as(i32, 1), opened.body.cur_col);
- try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes);
-}
-
-test "look validates the whole batch before opening virtual files" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "source\n");
- defer p.deinit();
- const source = p.panes[0].?;
- const look_node = Node.of(source.serial, .look);
- const serial = p.next_serial;
- for ([_][]const u8{
- "/virtual/index\x00ignored", "/virtual/index\n/virtual/\x01index\n",
- }) |invalid| {
- try testing.expectEqual(E.INVAL, wr(p, look_node, invalid).errno());
- try testing.expectEqual(serial, p.next_serial);
- try testing.expectEqual(@as(usize, 0), p.active);
- try testing.expectEqualStrings("source\n", source.file.?.content);
- }
- try testing.expectEqual(Status.ok, wr(p, look_node, "/n/self/index\n").reply.status);
- const opened = p.panes[p.active].?;
- try testing.expectEqualStrings("/virtual/index", opened.file.?.path);
- try testing.expect(std.mem.indexOf(u8, opened.file.?.content, "/test.txt") != null);
- try testing.expectEqualStrings("source\n", source.file.?.content);
-}
-
-test "get reloads the pane from disk and reports a missing file without losing dirty contents" {
- const gpa = testing.allocator;
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "note.txt", .data = "from disk\n" });
- var directory_buf: [4096]u8 = undefined;
- const directory = directory_buf[0..try tmp.dir.realPath(testing.io, &directory_buf)];
- var path_buf: [4096]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buf, "{s}/note.txt", .{directory});
-
- const p = try withFile(gpa, "in memory\n");
- defer p.deinit();
- const serial = serialOf(p);
- const ctl_node = Node.of(serial, .ctl);
- const pane = p.panes[0].?;
-
- var name: [std.fs.max_path_bytes + 8]u8 = undefined;
- _ = wr(p, Node.of(serial, .name), try std.fmt.bufPrint(&name, "{s}\n", .{path}));
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "get\n").reply.status);
- try testing.expectEqualStrings("from disk\n", pane.file.?.content);
- try testing.expect(!pane_files.dirtyOf(pane));
- try testing.expect(pane.file.?.history.undo_len > 0);
- // Renamed but never edited, it was clean: nothing thrown away, nothing
- // logged as reloaded over edits.
- var reloaded: [32]u8 = undefined;
- try testing.expect(!th.logHas(p, try std.fmt.bufPrint(&reloaded, "changed {d} reloaded\n", .{serial})));
-
- _ = wr(p, Node.of(serial, .name), try std.fmt.bufPrint(&name, "{s}/missing.txt\n", .{directory}));
- _ = wr(p, Node.of(serial, .body), "unsaved\n");
- // Unsaved text is asked about once, as acme's get asks winclean.
- const asked = wr(p, ctl_node, "get\n");
- try testing.expectEqual(E.IO, asked.errno());
- try testing.expect(std.mem.endsWith(u8, asked.reply.ename, ": Modified (get again to discard)"));
- var unsaved: [4200]u8 = undefined;
- try testing.expect(th.logHas(p, try std.fmt.bufPrint(&unsaved, "unsaved {d} {s}/missing.txt\n", .{ serial, directory })));
- try testing.expectEqual(E.NOENT, wr(p, ctl_node, "get\n").errno());
- try testing.expect(p.paneBySerial(serial) != null);
- try testing.expectEqualStrings("from disk\nunsaved\n", pane.file.?.content);
- try testing.expect(pane_files.dirtyOf(pane));
-}
-
-test "Get reads the pane's file again, refusing unsaved edits once, and Get file loads that file into the pane" {
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "note.txt", .data = "from disk\n" });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "other.txt", .data = "the other\n" });
- var directory_buf: [4096]u8 = undefined;
- const directory = directory_buf[0..try tmp.dir.realPath(testing.io, &directory_buf)];
- const p = try withFile(testing.allocator, "in memory\n");
- defer p.deinit();
- const serial = serialOf(p);
- const pane = p.panes[0].?;
- var name: [std.fs.max_path_bytes + 8]u8 = undefined;
- _ = wr(p, Node.of(serial, .name), try std.fmt.bufPrint(&name, "{s}/note.txt\n", .{directory}));
- try testing.expect(p.executeBuiltinLine(0, "Get"));
- try testing.expectEqualStrings("from disk\n", pane.file.?.content);
- try testing.expect(!pane_files.dirtyOf(pane));
- // Edited: asked once, then read again.
- _ = wr(p, Node.of(serial, .body), "unsaved\n");
- const failures = p.fs.failures;
- try testing.expect(p.executeBuiltinLine(0, "Get"));
- try testing.expect(p.fs.failures != failures);
- try testing.expectEqualStrings("from disk\nunsaved\n", pane.file.?.content);
- try testing.expect(p.executeBuiltinLine(0, "Get"));
- try testing.expectEqualStrings("from disk\n", pane.file.?.content);
- // Get file: that file, by a name from the pane's directory.
- try testing.expect(p.executeBuiltinLine(0, "Get other.txt"));
- try testing.expectEqualStrings("the other\n", pane.file.?.content);
- try testing.expect(std.mem.endsWith(u8, pane.file.?.path, "/other.txt"));
- try testing.expect(!pane_files.dirtyOf(pane));
}
-test "Zerox makes a second pane on one buffer: one text, undo and dirty state, its own cursor; Save cleans both, Del of one asks nothing" {
+test "Zerox twins: a Save from one, performed, cleans both" {
+ // The rest of Zerox is test/behaviour/panes.zig's; this needs the save done.
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
var dir_buf: [4096]u8 = undefined;
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
- const p = try withFile(testing.allocator, "one\ntwo\nthree\n");
+ const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
- const first = serialOf(p);
var name: [std.fs.max_path_bytes + 8]u8 = undefined;
- _ = wr(p, Node.of(first, .name), try std.fmt.bufPrint(&name, "{s}/z.txt\n", .{dir}));
+ _ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&name, "{s}/z.txt\n", .{dir}));
try testing.expect(p.executeBuiltinLine(0, "Zerox"));
const twin_id = for (p.panes, 0..) |slot, id| {
if (id != 0) if (slot) |pane| if (pane.file != null) break id;
} else return error.NoTwin;
const a = p.panes[0].?;
const b = p.panes[twin_id].?;
- // Both in the index, each its serial, one name.
- const index = rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes;
- try testing.expectEqual(@as(usize, 2), std.mem.count(u8, index, "/z.txt"));
- // b's cursor on `three`; a line written above it in a moves it down.
- b.body.cur_row = 2;
- b.body.cur_col = 1;
- _ = wr(p, Node.of(first, .addr), "0");
- try testing.expectEqual(Status.ok, wr(p, Node.of(first, .data), "zero\n").reply.status);
- try testing.expectEqualStrings("zero\none\ntwo\nthree\n", b.file.?.content);
- try testing.expectEqual(a.file.?.content.ptr, b.file.?.content.ptr);
- try testing.expectEqual(@as(i32, 3), b.body.cur_row);
- try testing.expectEqual(@as(i32, 1), b.body.cur_col);
- try testing.expect(pane_files.dirtyOf(a) and pane_files.dirtyOf(b));
- // A write through b is a's too; Undo in a takes it back from both.
- try testing.expectEqual(Status.ok, wr(p, Node.of(b.serial, .body), "four\n").reply.status);
- try testing.expectEqualStrings("zero\none\ntwo\nthree\nfour\n", a.file.?.content);
- try testing.expect(p.executeBuiltinLine(0, "Undo"));
- try testing.expectEqualStrings("zero\none\ntwo\nthree\n", b.file.?.content);
- // Saved from b: both come clean.
+ try testing.expectEqual(Status.ok, wr(p, Node.of(b.serial, .body), "two\n").reply.status);
try testing.expect(p.executeBuiltinLine(twin_id, "Save"));
while (p.nextEffect()) |e| p.perform(e);
try testing.expect(!pane_files.dirtyOf(a) and !pane_files.dirtyOf(b));
- try testing.expectEqualStrings("zero\none\ntwo\nthree\n", p.fallback.get(b.file.?.path).?);
- // Edited again, Del of a asks nothing: b holds the text.
- try testing.expectEqual(Status.ok, wr(p, Node.of(b.serial, .body), "five\n").reply.status);
- const failures = p.fs.failures;
- try testing.expect(p.executeBuiltinLine(0, "Del"));
- p.sync();
- try testing.expectEqual(failures, p.fs.failures);
- try testing.expect(p.paneBySerial(first) == null);
- try testing.expect(pane_files.dirtyOf(b));
- try testing.expectEqualStrings("zero\none\ntwo\nthree\nfive\n", b.file.?.content);
- // Alone now, it is no twin; Del asks about it as about any pane.
- try testing.expectEqual(@as(u32, 0), b.file.?.twin);
- try testing.expect(p.executeBuiltinLine(p.paneBySerial(b.serial).?, "Del"));
- try testing.expect(p.fs.failures != failures);
-}
-
-test "Undo after a load under another name (Get file, Edit e) puts the old name back with the old text and its clean state; Putall then writes nothing over the loaded file" {
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "other.txt", .data = "other\n" });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "keep.txt", .data = "keep\n" });
- var dir_buf: [4096]u8 = undefined;
- const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
- var other_buf: [4200]u8 = undefined;
- const other = try std.fmt.bufPrint(&other_buf, "{s}/other.txt", .{dir});
- var keep_buf: [4200]u8 = undefined;
- const keep = try std.fmt.bufPrint(&keep_buf, "{s}/keep.txt", .{dir});
- for ([_][]const u8{ "Get keep.txt", "Edit e keep.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}\n", .{other}));
- try testing.expect(p.executeBuiltinLine(0, "Get"));
- try testing.expectEqualStrings("other\n", pane.file.?.content);
- try testing.expect(!pane_files.dirtyOf(pane));
- // Loaded: keep.txt's text under its name.
- try testing.expect(p.executeBuiltinLine(0, load));
- try testing.expectEqualStrings("keep\n", pane.file.?.content);
- try testing.expectEqualStrings(keep, pane.file.?.path);
- if (std.mem.startsWith(u8, load, "Get")) try testing.expect(!pane_files.dirtyOf(pane));
- // Undo: other.txt's text, other.txt's name, clean as it was.
- try testing.expect(p.executeBuiltinLine(0, "Undo"));
- try testing.expectEqualStrings("other\n", pane.file.?.content);
- try testing.expectEqualStrings(other, pane.file.?.path);
- try testing.expect(!pane_files.dirtyOf(pane));
- // Putall saves nothing, and nothing lands on keep.txt.
- while (p.nextEffect()) |_| {}
- try testing.expect(p.executeBuiltinLine(0, "Putall"));
- while (p.nextEffect()) |e| try testing.expect(e != .save_file);
- // Redo: keep.txt again.
- try testing.expect(p.executeBuiltinLine(0, "Redo"));
- try testing.expectEqualStrings(keep, pane.file.?.path);
- try testing.expectEqualStrings("keep\n", pane.file.?.content);
- }
-}
-
-test "a Get file that fails changes nothing: no such file, a directory, or unsaved edits asked about once" {
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "here.txt", .data = "here\n" });
- try tmp.dir.createDirPath(testing.io, "sub");
- var dir_buf: [4096]u8 = undefined;
- const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
- 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;
- const here = try std.fmt.bufPrint(&name, "{s}/here.txt\n", .{dir});
- _ = wr(p, Node.of(serial, .name), here);
- try testing.expect(p.executeBuiltinLine(0, "Get"));
- const undo_len = pane.file.?.history.undo_len;
- for ([_][]const u8{ "Get nosuch.txt", "Get sub" }) |line| {
- const failures = p.fs.failures;
- try testing.expect(p.executeBuiltinLine(0, line));
- try testing.expect(p.fs.failures != failures);
- try testing.expectEqualStrings(here[0 .. here.len - 1], pane.file.?.path);
- try testing.expectEqualStrings("here\n", pane.file.?.content);
- try testing.expectEqual(undo_len, pane.file.?.history.undo_len);
- }
- // Edited, the first Get asks and renames nothing.
- _ = wr(p, Node.of(serial, .body), "more\n");
- try testing.expect(p.executeBuiltinLine(0, "Get other.txt"));
- try testing.expectEqualStrings(here[0 .. here.len - 1], pane.file.?.path);
- try testing.expectEqualStrings("here\nmore\n", pane.file.?.content);
+ try testing.expectEqualStrings("one\ntwo\n", p.fallback.get(b.file.?.path).?);
}
test "Zerox twins dump their text once and come back on one buffer from a Restore" {
@@ -1876,36 +1531,6 @@ test "Zerox twins dump their text once and come back on one buffer from a Restor
try testing.expect(std.mem.startsWith(u8, files[0].content, "one\ntwo\nunsaved "));
}
-test "a bad Tab width and a bad Incl directory are refused invalid, changing nothing; a twin's rename is each twin's" {
- defer config.tab_now = config.tab_width;
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const root_ctl = @backingInt(tree.TopFile.ctl);
- for ([_][]const u8{ "Tab 0\n", "Tab 17\n", "Tab x\n" }) |line| {
- try testing.expectEqual(E.INVAL, wr(p, root_ctl, line).errno());
- // Run from a pane, as a tag click runs it: said invalid too.
- const r = wr(p, Node.of(serialOf(p), .exec), line);
- try testing.expectEqual(E.INVAL, r.errno());
- try testing.expect(std.mem.indexOf(u8, r.reply.ename, "invalid tab width") != null);
- }
- try testing.expectEqual(config.tab_width, config.tab_now);
- const before = p.incl.items.len;
- try testing.expectEqual(E.INVAL, wr(p, root_ctl, "Incl rel/dir\n").errno());
- try testing.expectEqual(E.INVAL, wr(p, root_ctl, "Incl - /usr/include\n").errno());
- if (comptime pardes.hosted) try testing.expectEqual(E.NOENT, wr(p, root_ctl, "Incl /tmp/pardes-surely-no-such-dir\n").errno());
- try testing.expectEqual(before, p.incl.items.len);
- // A twin renamed: a rename record for each.
- const first = serialOf(p);
- try testing.expect(p.executeBuiltinLine(0, "Zerox"));
- const twin = for (p.panes) |slot| {
- if (slot) |pane| if (pane.serial != first and pane.file != null) break pane.serial;
- } else return error.NoTwin;
- _ = wr(p, Node.of(first, .name), "/tmp/pardes-twin-renamed.txt\n");
- var rec: [64]u8 = undefined;
- try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /tmp/pardes-twin-renamed.txt\n", .{first})));
- 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();
@@ -1939,73 +1564,10 @@ test "Undo to unsaved text under its old name says nothing changed on disk when
}
}
-test "round 39's small refusals: one name an open, small scratches unasked, twins saved once, bare Tab on ctl, and errnos in words a mount reads" {
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "f\n" });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "noread.txt", .data = "secret\n" });
- try tmp.dir.createDirPath(testing.io, "sub");
- var dir_buf: [4096]u8 = undefined;
- const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
- const pane = p.panes[0].?;
- var line: [4300]u8 = undefined;
- // One name an open: a second line, in the write or after, is refused.
- try testing.expectEqual(E.INVAL, wr(p, Node.of(serial, .name), "/tmp/pardes-a\nb").errno());
- const before = try testing.allocator.dupe(u8, pane.file.?.path);
- defer testing.allocator.free(before);
- const h = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .name), .omode = 1 }).reply.handle;
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = Node.of(serial, .name), .handle = h, .data = "/tmp/pardes-one.txt\n" }).reply.status);
- try testing.expectEqual(E.INVAL, call(p, .{ .tag = 3, .op = .write, .node = Node.of(serial, .name), .handle = h, .data = "b" }).errno());
- _ = call(p, .{ .tag = 4, .op = .release, .node = Node.of(serial, .name), .handle = h, .opened = true });
- tree.runClosedLines(p);
- try testing.expectEqualStrings("/tmp/pardes-one.txt", pane.file.?.path);
- // Bare Tab on the root ctl says the width, as from a pane.
- try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Tab\n").reply.status);
- // Errnos a mount reads from the words.
- _ = wr(p, Node.of(serial, .name), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir}));
- try testing.expect(p.executeBuiltinLine(0, "Get"));
- try testing.expectEqual(E.ISDIR, wr(p, Node.of(serial, .exec), "Get sub\n").errno());
- if (comptime pardes.hosted) {
- var noread_buf: [4300]u8 = undefined;
- _ = std.c.chmod(try std.fmt.bufPrintSentinel(&noread_buf, "{s}/noread.txt", .{dir}, 0), 0);
- try testing.expectEqual(@as(u16, 13), wr(p, Node.of(serial, .exec), "Get noread.txt\n").errno());
- try testing.expectEqual(E.NOTDIR, wr(p, Node.of(serial, .exec), try std.fmt.bufPrint(&line, "Incl {s}/f.txt\n", .{dir})).errno());
- const zero = wr(p, Node.of(serial, .look), "/dev/zero\n");
- _ = zero;
- try testing.expect(th.logHas(p, "not a regular file"));
- }
- // Twins saved once by Putall.
- _ = wr(p, Node.of(serial, .body), "edited\n");
- try testing.expect(p.executeBuiltinLine(0, "Zerox"));
- while (p.nextEffect()) |_| {}
- try testing.expect(p.executeBuiltinLine(0, "Putall"));
- var saves: usize = 0;
- while (p.nextEffect()) |e| if (e == .save_file) {
- saves += 1;
- };
- try testing.expectEqual(@as(usize, 1), saves);
- // A scratch of 2 bytes is loaded over unasked.
- try testing.expect(p.executeBuiltinLine(0, "New"));
- const scratch = p.panes[p.active].?;
- _ = pane_files.spliceBody(p, scratch, 0, 0, "hi") orelse return error.NoScratch;
- const failures = p.fs.failures;
- try testing.expect(p.executeBuiltinLine(p.active, try std.fmt.bufPrint(&line, "Get {s}/f.txt", .{dir})));
- try testing.expectEqual(failures, p.fs.failures);
- try testing.expectEqualStrings("f\n", scratch.file.?.content);
-}
-
-test "Get of a file not there says so without asking about unsaved edits; the init file saved says a bad line as startup does" {
+test "the init file saved says a bad line as startup does" {
+ // Get of a file not there is test/behaviour/panes.zig's.
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .startup_config = "Theme dusk\n", .startup_config_path = "/tmp/pardes-init-test/init" });
defer p.deinit();
- const pane = try p.setTestFile("x\n");
- _ = wr(p, Node.of(pane.serial, .body), "unsaved\n");
- try testing.expect(p.executeBuiltinLine(0, "Get /tmp/pardes-surely-no-such-file.txt"));
- try testing.expect(th.logHas(p, "no such file"));
- try testing.expect(!th.logHas(p, "again to discard"));
- try testing.expect(pane.discard_warned == null);
pardes.exec.reapplyInitFile(p, "/tmp/pardes-init-test/init", "Theme acme\nnosuchword 1\nNewcol\n");
try testing.expect(th.logHas(p, "err - init file line 2: unknown word \"nosuchword 1\""));
try testing.expect(!th.logHas(p, "init file line 3"));
@@ -2131,66 +1693,6 @@ test "a refusal's +Unsaved goes in the session's directory when the active pane'
try testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(unsaved).?);
}
-test "a look at a file it may not read fails the write naming the file" {
- if (comptime !pardes.hosted) return;
- 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 = "locked.txt", .data = "secret\n", .flags = .{ .permissions = .fromMode(0o000) } });
- 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 path = try std.fmt.bufPrint(&line, "{s}/locked.txt", .{dir});
- var want: [4200]u8 = undefined;
- const expected = try std.fmt.bufPrint(&want, "look: {s}: permission denied", .{path});
- var with_newline: [4300]u8 = undefined;
- const refused = wr(p, root_look, try std.fmt.bufPrint(&with_newline, "{s}\n", .{path}));
- if (refused.reply.status == .ok) return error.SkipZigTest; // root reads anything
- try testing.expectEqualStrings(expected, refused.reply.ename);
-}
-
-test "a bad setting value is quoted, so two different bad values log as two records, never one counted twice" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const root_ctl = @backingInt(tree.TopFile.ctl);
- _ = wr(p, root_ctl, "Verbose maybe\n");
- _ = wr(p, root_ctl, "Verbose nope\n");
- try testing.expect(th.logHas(p, "takes on, off \"maybe\"\n"));
- try testing.expect(th.logHas(p, "takes on, off \"nope\"\n"));
- 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 builtin's Verbose announcement is logged only when it succeeds, its failure said now or by the host later" {
const gpa = testing.allocator;
@@ -2366,32 +1868,10 @@ test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path,
try testing.expectEqual(Status.ok, wr(p, root_ctl, "ThemeFile " ++ path ++ "\n").reply.status);
}
-test "Joincol with no column to the right and Theme with no such theme say so" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "x\n");
- defer p.deinit();
- const root_ctl = @backingInt(tree.TopFile.ctl);
- const joined = wr(p, root_ctl, "Joincol\n");
- try testing.expectEqual(tree.Status.err, joined.reply.status);
- try testing.expectStringStartsWith(joined.reply.ename, "Joincol: no column to the right");
- const themed = wr(p, root_ctl, "Theme drak\n");
- try testing.expectEqual(E.INVAL, themed.errno());
- try testing.expectStringStartsWith(themed.reply.ename, "bad value in control message; like it: ");
- try testing.expect(std.mem.indexOf(u8, themed.reply.ename, ": dr") != null);
- try testing.expect(std.mem.endsWith(u8, themed.reply.ename, "\"drak\""));
- // A click on the word says it on the message row.
- _ = wr(p, Node.of(serialOf(p), .exec), "Theme drak\n");
- const pane = p.panes[p.active].?;
- try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "no theme \"drak\"") != null);
- // Within the 128 bytes an Rerror carries, the quoted line kept.
- try testing.expect(themed.reply.ename.len <= 128);
- // A name in any case is the theme.
- try testing.expectEqual(Status.ok, wr(p, root_ctl, "Theme DRACULA\n").reply.status);
- try testing.expectEqualStrings("dracula", pardes.themes[p.settings.theme].name);
- // A misspelling far from any first letter's list still finds its like.
+test "themesNear finds a misspelling's like far from any first letter, and every theme sharing the first letter when they fit" {
+ // Joincol and Theme's refusals are test/behaviour/root_ctl.zig's.
var near: [170]u8 = undefined;
try testing.expect(std.mem.indexOf(u8, pardes.colors.themesNear(&near, "9dracula"), "dracula") != null);
- // Every theme sharing the first letter, when they fit.
var tested = false;
for ("abcdefghijklmnopqrstuvwxyz") |letter| {
var count: usize = 0;
@@ -2408,19 +1888,6 @@ test "Joincol with no column to the right and Theme with no such theme say so" {
}
-test "a look at file:addr whose file is not there is one miss, quoting what was written, in a terminal too" {
- const p = try th.withTerm(testing.allocator);
- defer p.deinit();
- const looked = Node.of(serialOf(p), .look);
- for ([_][]const u8{ "zzq:#3", "zzq:2", "zzq:/re/" }) |written| {
- var line: [64]u8 = undefined;
- _ = wr(p, looked, try std.fmt.bufPrint(&line, "{s}\n", .{written}));
- var want: [64]u8 = undefined;
- try testing.expectEqual(@as(usize, 1), th.logCount(p, try std.fmt.bufPrint(&want, "look: no match for \"{s}\"\n", .{written})));
- }
- try testing.expectEqual(@as(usize, 3), th.logCount(p, "\nerr "));
-}
-
test "a look whose pane is refused a place fails with that alone, not a missing line too" {
const gpa = testing.allocator;
// A screen with rows for one pane only.
@@ -2441,26 +1908,6 @@ test "a look whose pane is refused a place fails with that alone, not a missing
try testing.expectEqual(@as(usize, 1), th.logCount(p, "\nerr "));
}
-test "a look under pardes's placement, from a pane pane/new made after Delcol, opens its file" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "x\n");
- defer p.deinit();
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "file\n" });
- var dir: [4096]u8 = undefined;
- const at = dir[0..try tmp.dir.realPath(testing.io, &dir)];
- var line: [4200]u8 = undefined;
- const first = serialOf(p);
- try testing.expectEqual(tree.Status.ok, wr(p, Node.of(first, .exec), "Placement\n").reply.status);
- try testing.expectEqual(tree.Status.ok, wr(p, Node.of(first, .exec), "Delcol\n").reply.status);
- const made = try th.newPane(p);
- try testing.expectEqual(tree.Status.ok, wr(p, Node.of(made, .look), try std.fmt.bufPrint(&line, "{s}/f.txt:#4\n", .{at})).reply.status);
- // The pane pane/new made is placed, and so is the one its look opened.
- for (p.panes, 0..) |slot, i| if (slot != null) try testing.expect(layout.findPane(p, i) != null);
- try testing.expect(p.panes[p.active].?.serial != made);
-}
-
test "a Restore of a file that is no dump fails the write before any warning, and a failed Dump fails its write" {
if (comptime !pardes.hosted) return error.SkipZigTest;
const p = try withFile(testing.allocator, "x\n");
@@ -2493,58 +1940,6 @@ test "a Restore of a file that is no dump fails the write before any warning, an
try testing.expectEqualStrings("Dump /dev/null/pardes.dump.zon: /dev/null is not a directory", p.fs.late_failure[0..p.fs.late_failure_len]);
}
-test "a setting this frontend cannot show says GUI-only, and DumpDir reads back the directory in effect" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const root_ctl = @backingInt(tree.TopFile.ctl);
- if (!builtins.viewCapabilities(p).lift) {
- try testing.expectEqualStrings("Lift is GUI-only, invalid here \"Lift\"", wr(p, root_ctl, "Lift on\n").reply.ename);
- try testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", wr(p, root_ctl, "GripWidth 120\n").reply.ename);
- // A builtin the GUI alone has, written to a ctl or an exec, never
- // runs as a shell command.
- if (comptime !pardes.font_picker) {
- try testing.expectEqualStrings("Fonts is GUI-only, invalid here \"Fonts\"", wr(p, root_ctl, "Fonts\n").reply.ename);
- const ran = wr(p, root_exec, "Fonts\n");
- try testing.expectEqual(E.INVAL, ran.errno());
- try testing.expectEqualStrings("Fonts is GUI-only, invalid here", ran.reply.ename);
- }
- }
- try testing.expectEqualStrings("unknown control message \"Liftt\"", wr(p, root_ctl, "Liftt on\n").reply.ename);
- var buf: [900]u8 = undefined;
- if (pardes.dump.directory(&buf, "")) |dir| {
- var want: [920]u8 = undefined;
- const line = try std.fmt.bufPrint(&want, "\nDumpDir {s}\n", .{dir});
- try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, line) != null);
- }
-}
-
-test "an exec line over the command limit fails the write and says the limit; a builtin's may be longer" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const long = "echo " ++ &@as([pardes.exec.command_max]u8, @splat('y')) ++ "\n";
- const refused = wr(p, root_exec, long);
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expectEqualStrings(e_too_long, refused.reply.ename);
- var rec: [96]u8 = undefined;
- try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: a command line is at most 1024 bytes", .{serialOf(p)})));
- try testing.expectEqualStrings(e_control, wr(p, root_exec, "echo a\x01b\n").reply.ename);
- try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: it holds", .{serialOf(p)})));
- try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg " ++ &@as([1100]u8, @splat('z')) ++ "\n").reply.status);
-}
-
-test "Edit's p and = never fail for want of room for +Errors: the text is logged instead" {
- const p = try withFile(testing.allocator, "one\ntwo\n");
- defer p.deinit();
- p.update(.{ .resize = .{ .cols = 80, .rows = 6 } });
- const ctl_node = Node.of(serialOf(p), .ctl);
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "Edit ,p\n").reply.status);
- try testing.expect(th.logHas(p, " one\n") and th.logHas(p, " two\n"));
- p.sync();
- var count: usize = 0;
- for (p.panes) |slot| count += @intFromBool(slot != null);
- try testing.expectEqual(@as(usize, 1), count); // the +Errors that had no room is gone
-}
-
test "Mount dials its peer and fails, mounting nothing, when none answers; a look through a peer gone says dial failed" {
const p = try withFile(testing.allocator, "x\n");
@@ -2603,16 +1998,6 @@ test "Tty in a directory that is not there fails and makes no pane; a shell that
try testing.expectEqualStrings("error shell gone\n", call(p, .{ .tag = 3, .op = .read, .node = run_node, .handle = h, .size = 64 }).bytes);
}
-test "a builtin that needs its argument, written bare to an exec, is EINVAL as through ctl" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- for ([_]u64{ root_exec, Node.of(serialOf(p), .exec), @backingInt(tree.TopFile.tagexec) }) |node| {
- const refused = wr(p, node, "Mount\n");
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expectEqualStrings("wrong #args in control message \"Mount\"", refused.reply.ename);
- }
-}
-
test "a script's Grep and Find fill the pane's one query pane, a row a line under its file; a miss says not found and opens nothing" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -2677,14 +2062,6 @@ test "a script's Grep and Find fill the pane's one query pane, a row a line unde
try testing.expect(panes.Query.ofOwner(p, serialOf(p)) == null);
}
-test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const refused = wr(p, @backingInt(tree.TopFile.ctl), "Unmount nothere\n");
- try testing.expectEqual(E.NOENT, refused.errno());
- try testing.expectStringStartsWith(refused.reply.ename, "Unmount: no such mount nothere");
-}
-
test "a terminal told the directory it already goes by logs no rename" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -2938,31 +2315,6 @@ test "Grep, Symbols and Diagnostics share their directory's one +Search" {
try testing.expectEqual(@as(usize, 1), searches);
}
-test "+Unsaved drops a pane once it has closed" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const a = try th.newPane(p);
- _ = wr(p, Node.of(a, .name), "/tmp/pardes-unsaved-a.txt\n");
- _ = wr(p, Node.of(a, .body), "edited\n");
- const b = try th.newPane(p);
- _ = wr(p, Node.of(b, .name), "/tmp/pardes-unsaved-b.txt\n");
- _ = wr(p, Node.of(b, .body), "edited\n");
- const root_ctl = @backingInt(tree.TopFile.ctl);
- try testing.expectEqual(Status.err, wr(p, root_ctl, "Exit\n").reply.status);
- var listed: ?*pardes.Pane = null;
- for (p.panes) |slot| if (slot) |q| if (q.file) |f| if (f.output) |o| if (o.from == .unsaved) {
- listed = q;
- };
- const list = listed.?;
- try testing.expect(std.mem.indexOf(u8, list.file.?.content, "/tmp/pardes-unsaved-a.txt: Modified") != null);
- // a closes (discarded): its row goes; b's stays.
- _ = wr(p, Node.of(a, .ctl), "Del\n");
- _ = wr(p, Node.of(a, .ctl), "Del\n");
- p.sync();
- try testing.expect(p.paneBySerial(a) == null);
- try testing.expect(std.mem.indexOf(u8, list.file.?.content, "/tmp/pardes-unsaved-a.txt: Modified") == null);
-}
-
test "a buffer whose file was deleted on disk is dirty, and Del asks first" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -2987,31 +2339,6 @@ test "a failure said while a 9P write waits on it posts no msg, only the write's
try testing.expect(p.fs.late_failure_len > 0);
}
-test "Mini with no argument is wrong #args, EINVAL, as every word that needs one" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const r = wr(p, Node.of(serialOf(p), .ctl), "Mini\n");
- try testing.expectEqual(E.INVAL, r.errno());
- try testing.expectEqualStrings("wrong #args in control message \"Mini\"", r.reply.ename);
-}
-
-test "a look that misses file:/re/ names the file, and is logged as its pane'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 = "f.txt", .data = "alpha\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}/f.txt\n", .{dir}));
- p.sync();
- const f_serial = p.panes[p.active].?.serial;
- _ = wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "{s}/f.txt:/zzqq/\n", .{dir}));
- var want: [4300]u8 = undefined;
- try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "err {d} look: {s}/f.txt: no match for regexp", .{ f_serial, dir })));
-}
-
test "with no pane at all, the root look opens its file and the root exec runs in the session's directory" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -3049,26 +2376,6 @@ test "with no pane at all, the root look opens its file and the root exec runs i
try testing.expectEqualStrings(session, made.cwdSlice());
}
-test "a look at file:3:0 is refused as addr 3:0 is, a column counting from 1" {
- const p = try withFile(testing.allocator, "one\ntwo\nthree\n");
- defer p.deinit();
- const serial = serialOf(p);
- const by_addr = wr(p, Node.of(serial, .addr), "3:0");
- const by_look = wr(p, Node.of(serial, .look), "/test.txt:3:0\n");
- try testing.expectEqual(E.INVAL, by_addr.errno());
- try testing.expectEqual(E.INVAL, by_look.errno());
- try testing.expectEqualStrings(by_addr.reply.ename, by_look.reply.ename);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), "/test.txt:3:1\n").reply.status);
-}
-
-test "Kill with a name and nothing running says so and does not fail, as bare Kill does" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const r = wr(p, @backingInt(tree.TopFile.ctl), "Kill zzz\n");
- try testing.expectEqual(Status.ok, r.reply.status);
- try testing.expect(th.logHas(p, "Kill: nothing running"));
-}
-
test "a restored pane whose file is gone from disk comes back dirty, and Del asks first" {
if (comptime !pardes.hosted) return error.SkipZigTest;
const p = try withFile(testing.allocator, "kept text\n");
@@ -3136,98 +2443,6 @@ test "a Restore of a name in the DumpDir asks for, and logs, the whole path it r
}
-test "a builtin that takes no argument, written with one to an exec, is refused wrong #args, as at a ctl" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
- for ([_]u64{ @backingInt(tree.TopFile.exec), Node.of(serial, .exec) }) |node| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| {
- const r = wr(p, node, line);
- try testing.expectEqual(E.INVAL, r.errno());
- try testing.expectStringStartsWith(r.reply.ename, "wrong #args in control message");
- };
-}
-
-test "acme's words run as pardes's (Put is Save, Delete a Del that does not ask) or are refused, never run as commands" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
- for ([_][]const u8{ "Snarf\n", "Indent\n", "Local\n", "Abort\n" }) |line| {
- for ([_]u64{ Node.of(serial, .ctl), Node.of(serial, .exec) }) |node| {
- const r = wr(p, node, line);
- try testing.expectEqual(E.INVAL, r.errno());
- try testing.expect(std.mem.indexOf(u8, r.reply.ename, "is not a pardes builtin") != null);
- }
- }
- // Load is Restore: whatever it says, never acme's word refused.
- const load = wr(p, Node.of(serial, .exec), "Load /tmp/pardes-surely-no-dump.zon\n");
- try testing.expect(std.mem.indexOf(u8, load.reply.ename, "is not a pardes builtin") == null);
- // Put saves, as Save does.
- _ = wr(p, Node.of(serial, .name), "/tmp/pardes-put.txt\n");
- const put = wr(p, Node.of(serial, .exec), "Put\n");
- try testing.expectEqual(Status.ok, put.reply.status);
- try testing.expect(put.saved);
- // Delete closes an edited pane without asking.
- const made = try th.newPane(p);
- _ = wr(p, Node.of(made, .name), "/tmp/pardes-delete.txt\n");
- _ = wr(p, Node.of(made, .body), "edited\n");
- try testing.expectEqual(Status.ok, wr(p, Node.of(made, .ctl), "Delete\n").reply.status);
- p.sync();
- try testing.expect(p.paneBySerial(made) == null);
-}
-
-test "a pane's ctl takes acme's words: done by the files that replace them, or refused with why" {
- const p = try withFile(testing.allocator, "one two\n");
- defer p.deinit();
- const serial = serialOf(p);
- const ctl_node = Node.of(serial, .ctl);
- const pane = p.panes[p.paneBySerial(serial).?].?;
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "name /tmp/pardes-acme-ctl.txt\n").reply.status);
- try testing.expectEqualStrings("/tmp/pardes-acme-ctl.txt", pane.file.?.path);
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "dirty\n").reply.status);
- try testing.expectEqualStrings("1", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n"));
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "clean\n").reply.status);
- try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n"));
- _ = wr(p, Node.of(serial, .addr), "/two/");
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "dot=addr\nshow\nnomark\nmark\nlimit=addr\n").reply.status);
- try testing.expectEqual(@as(u32, 4), pane_files.dotOf(pane).q0);
- try testing.expect(pane.fs.limit != null);
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "cleartag\n").reply.status);
- for ([_][]const u8{ "menu", "nomenu", "dump echo hi", "dumpdir /tmp", "font Go Mono" }) |line| {
- const r = wr(p, ctl_node, line);
- try testing.expectEqual(E.INVAL, r.errno());
- try testing.expect(std.mem.startsWith(u8, r.reply.ename, "invalid: acme's "));
- }
- // Checked whole: a refused word anywhere and nothing ran.
- try testing.expectEqual(E.INVAL, wr(p, ctl_node, "dirty\nmenu\n").errno());
- try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n"));
-}
-
-test "ctl reads acme's fields in acme's order, undo and redo flags included, then pardes's own" {
- const p = try withFile(testing.allocator, "one\n");
- defer p.deinit();
- const serial = serialOf(p);
- const ctl_node = Node.of(serial, .ctl);
- const fields = struct {
- fn of(text: []const u8, buf: *[16][]const u8) [][]const u8 {
- var it = std.mem.tokenizeScalar(u8, text, ' ');
- var n: usize = 0;
- while (it.next()) |t| : (n += 1) buf[n] = t;
- return buf[0..n];
- }
- };
- var buf: [16][]const u8 = undefined;
- var f = fields.of(rd(p, ctl_node, 0, 4096).bytes, &buf);
- try testing.expectEqualStrings("0", f[8]); // nothing to undo
- try testing.expectEqualStrings("0", f[9]); // nothing to redo
- try testing.expect(std.mem.eql(u8, f[10], "current") or std.mem.eql(u8, f[10], "notcurrent"));
- _ = wr(p, Node.of(serial, .body), "two\n");
- f = fields.of(rd(p, ctl_node, 0, 4096).bytes, &buf);
- try testing.expectEqualStrings("1", f[8]);
- _ = wr(p, ctl_node, "Undo\n");
- f = fields.of(rd(p, ctl_node, 0, 4096).bytes, &buf);
- try testing.expectEqualStrings("1", f[9]);
-}
-
test "a write to addr, limit or mark asks for no frame; one to body does" {
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
@@ -3242,28 +2457,6 @@ test "a write to addr, limit or mark asks for no frame; one to body does" {
try testing.expect(p.needs_frame);
}
-test "every EINVAL a write gets says why, in its err record too; DEL is a control character in a line" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
- const log = @backingInt(tree.TopFile.log);
- const h = call(p, .{ .tag = 1, .op = .open, .node = log, .omode = 2 }).reply.handle;
- const Case = struct { node: u64, data: []const u8, words: []const u8, handle: u32 = 0 };
- for ([_]Case{
- .{ .node = root_exec, .data = "echo a\x7fb\n", .words = "control character" },
- .{ .node = root_look, .data = "a\x7fb\n", .words = "control character" },
- .{ .node = Node.of(serial, .name), .data = "\n", .words = "an empty name" },
- .{ .node = log, .data = "bogus\n", .words = "takes `follow`", .handle = h },
- }) |c| {
- const refused = call(p, .{ .tag = 2, .op = .write, .node = c.node, .handle = c.handle, .data = c.data });
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expect(std.mem.indexOf(u8, refused.reply.ename, c.words) != null);
- }
- _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
- try testing.expect(!th.logHas(p, "Invalid argument"));
- try testing.expect(th.logHas(p, "an empty name"));
-}
-
test "/index shows a name as the log does: a newline in it is \\n, a control byte, C1 or byte not UTF-8 \\xNN" {
const p = try th.withTerm(testing.allocator);
defer p.deinit();
@@ -3278,92 +2471,7 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt
// Its tag never carries the raw newline either.
const tag = rd(p, Node.of(serialOf(p), .tag), 0, 4096).bytes;
try testing.expect(std.mem.indexOf(u8, tag, "/tmp/two\\nlines") != null);
- // A backslash of the name's own is doubled: `\n` written in a name
- // reads back unlike a newline.
- p.setCwd(term, "/tmp/back\\nslash");
- try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null);
-}
-
-test "a look at a ./ or ../ name that is not there is a miss naming the file; a plain one is looked for as text" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.createDirPath(testing.io, "many");
- 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, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/many/a.txt\n", .{dir}));
- for ([_][]const u8{ "./zz.txt", "../zz.txt" }) |name| {
- const r = wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "{s}\n", .{name}));
- try testing.expectEqual(Status.ok, r.reply.status);
- var want: [64]u8 = undefined;
- try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "look: {s}: no such file", .{name})));
- }
- try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .look), "zz.txt\n").reply.status);
- try testing.expect(th.logHas(p, "look: no match for \"zz.txt\""));
-}
-
-test "a served-tree pane spoils no Grep, and Look . from a gone directory is ENOENT, not /virtual/" {
- 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 = "hit.txt", .data = "needle here\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, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/other.txt\n", .{dir}));
- // A pane of the served tree.
- const virtual = try th.newPane(p);
- _ = wr(p, Node.of(virtual, .name), "/virtual/index\n");
- // One named the served tree's root, whose directory is `/`.
- const top = try th.newPane(p);
- _ = wr(p, Node.of(top, .name), "/virtual\n");
- try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Grep needle\n").reply.status);
- // `.` from a pane whose directory is gone.
- const gone = try th.newPane(p);
- _ = wr(p, Node.of(gone, .name), "/tmp/pardes-no-such-dir-zz/f.txt\n");
- const looked = wr(p, Node.of(gone, .look), ".\n");
- try testing.expectEqual(E.NOENT, looked.errno());
- try testing.expectStringStartsWith(looked.reply.ename, "look: /tmp/pardes-no-such-dir-zz: no such directory");
-}
-
-test "a malformed address is bad address syntax; on a pane with no text any address is refused as nothing to address" {
- const p = try th.withTerm(testing.allocator);
- defer p.deinit();
- const t = try withFile(testing.allocator, "one\n");
- defer t.deinit();
- for ([_][]const u8{ "1x", "/(/", ",,x" }) |expr| {
- const refused = wr(t, Node.of(serialOf(t), .addr), expr);
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expect(refused.reply.ename.len > 0);
- }
- try testing.expectEqualStrings("bad address syntax", wr(t, Node.of(serialOf(t), .addr), "1x").reply.ename);
- // A terminal (as an image or a PDF): addr, dot and limit alike.
- for ([_]tree.PaneFile{ .addr, .dot, .limit }) |file| for ([_][]const u8{ "1", "1x" }) |expr| {
- const refused = wr(p, Node.of(serialOf(p), file), expr);
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expectEqualStrings("invalid address: this pane has no text to address", refused.reply.ename);
- };
-}
-
-test "a bad event record says what is wrong with it" {
- const p = try withFile(testing.allocator, "one\n");
- defer p.deinit();
- const event = Node.of(serialOf(p), .event);
- const h = call(p, .{ .tag = 1, .op = .open, .node = event, .omode = 2 }).reply.handle;
- for ([_][2][]const u8{
- .{ "MI0 1 0 1 x\n", "only a look or exec" },
- .{ "MX3 1 0 0 \n", "ends before it starts" },
- .{ "MX9 9 0 0 \n", "range past end" },
- .{ "garbage\n", "a record is" },
- }) |c| {
- const refused = call(p, .{ .tag = 2, .op = .write, .node = event, .handle = h, .data = c[0] });
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expect(std.mem.indexOf(u8, refused.reply.ename, c[1]) != null);
- }
- _ = call(p, .{ .tag = 3, .op = .release, .node = event, .handle = h });
+ // A name's own backslash doubled is test/behaviour/other_files.zig's.
}
test "a column takes panes until their documented minimums fill it, not until none can be halved" {
@@ -3384,261 +2492,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();
@@ -3669,82 +2522,11 @@ test "a new file saved shows in /recent, open, while it is" {
test "/recent shows a name as /index does, a newline in it escaped" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- p.recent.opened(p.recentGpa(), "/tmp/a\nb\\c");
+ // A backslash doubled is test/behaviour/other_files.zig's; a 9P name
+ // write cannot hold a newline.
+ p.recent.opened(p.recentGpa(), "/tmp/a\nb");
const text = rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes;
- 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);
+ try testing.expect(std.mem.indexOf(u8, text, "closed /tmp/a\\nb\n") != null);
}
test "size is monotonic: growing is never refused, and a size once taken is taken again" {
@@ -3790,24 +2572,6 @@ test "size is monotonic: growing is never refused, and a size once taken is take
try testing.expectStringStartsWith(bad.reply.ename, "invalid size");
}
-test "Repl with no such language is invalid, EINVAL, and names a few whole and how many more" {
- const p = try th.withTerm(testing.allocator);
- defer p.deinit();
- const refused = wr(p, Node.of(serialOf(p), .ctl), "Repl zzlang\n");
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "Repl: invalid language \"zzlang\"; - or one like zig ada bash c c_sharp clojure (") != null);
- try testing.expect(std.mem.endsWith(u8, refused.reply.ename, " more)"));
-}
-
-test "answer quotes the choice it refuses, and a bare name says it names nothing" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const node = Node.of(serialOf(p), .ctl);
- const empty = wr(p, node, "name \n");
- try testing.expectEqual(E.INVAL, empty.errno());
- try testing.expectEqualStrings("invalid file name: name takes the name, and there is none", empty.reply.ename);
-}
-
test "a 10k-line Edit text block is taken in linear time and memory" {
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
@@ -3853,39 +2617,6 @@ test "a file changed on disk under unsaved edits is not reloaded: it says so, ge
try testing.expect(wr(p, Node.of(serial, .ctl), "Save\n").saved);
}
-test "a looked word is found in its own pane, next place after the dot, wrapping, and opens no pane" {
- const p = try withFile(testing.allocator, "foo x foo y\n");
- defer p.deinit();
- const serial = serialOf(p);
- const look_node = Node.of(serial, .look);
- const dot = Node.of(serial, .dot);
- var count: usize = 0;
- for (p.panes) |slot| count += @intFromBool(slot != null);
- for ([_][]const u8{ " 0 3 ", " 6 9 ", " 0 3 " }) |want| {
- try testing.expectEqual(Status.ok, wr(p, look_node, "foo\n").reply.status);
- try testing.expectEqualStrings(want, rd(p, dot, 0, 64).bytes);
- }
- var after: usize = 0;
- for (p.panes) |slot| after += @intFromBool(slot != null);
- try testing.expectEqual(count, after);
- // LookWord list: the +Search listing, as before.
- try testing.expect(p.executeBuiltinLine(0, "LookWord list"));
- try testing.expectEqual(Status.ok, wr(p, look_node, "foo\n").reply.status);
- after = 0;
- for (p.panes) |slot| after += @intFromBool(slot != null);
- try testing.expect(after > count);
- // ...and look reads back that +Search pane, where the places are.
- var listed = false;
- var rows = std.mem.tokenizeScalar(u8, rd(p, look_node, 0, 256).bytes, '\n');
- while (rows.next()) |row| {
- const made = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, row, 10)).?].?;
- if (made.file) |f| if (f.output) |o| if (o.from == .search) {
- listed = true;
- };
- }
- try testing.expect(listed);
-}
-
test "every word's /commands description is its own doc comment's first sentence, no citation" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -3996,37 +2727,6 @@ test "get names the path it could not read, logs the edits it threw away, and a
_ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
}
-test "a builtin that fails through exec, tagexec or a column's exec fails the write with one err and no msg" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- p.update(.tick); // the pane's `new` is logged first
- while (p.nextEffect()) |_| {}
- const serial = serialOf(p);
- for ([_]u64{ root_exec, Node.of(serial, .exec), @backingInt(tree.TopFile.tagexec), Node.ofCol(pardes.layout.columnSerial(p, 0), .exec) }) |node| {
- const failed = wr(p, node, "Unmount zzz\n");
- try testing.expectEqual(Status.err, failed.reply.status);
- try testing.expect(std.mem.indexOf(u8, failed.reply.ename, "Unmount: no such mount zzz") != null);
- }
- const log = @backingInt(tree.TopFile.log);
- const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
- const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
- try testing.expect(std.mem.indexOf(u8, text, "msg ") == null);
- // The root's exec ran at the pane, so its err and the pane's exec's are
- // the same record, counted.
- try testing.expectEqual(@as(usize, 3), std.mem.count(u8, text, "Unmount: no such mount zzz"));
- try testing.expect(std.mem.indexOf(u8, text, "mount zzz (x2)") != null);
- _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
- // A control character is refused with its reason.
- try testing.expectEqualStrings(e_control, wr(p, root_exec, "Msg a\x01b\n").reply.ename);
- // A look miss: one err, no msg.
- _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n");
- try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\""));
- try testing.expect(!th.logHas(p, "msg 1 Look: no match"));
- // The same miss again is that record counted, as any repeated err is.
- _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n");
- try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\" (x2)\n"));
-}
-
test "a word written to a raw terminal's look is listed as in normal mode" {
const p = try th.withTerm(testing.allocator);
defer p.deinit();
@@ -4040,64 +2740,6 @@ test "a word written to a raw terminal's look is listed as in normal mode" {
try testing.expect(made.file.?.output.?.from == .search);
}
-test "@p<serial>:<address> takes any sam address; a miss and an unknown serial are errs" {
- const p = try withFile(testing.allocator, "foo x foo y\nbar\n");
- defer p.deinit();
- const serial = serialOf(p);
- const root = @backingInt(tree.TopFile.look);
- const dot = Node.of(serial, .dot);
- const Case = struct { addr: []const u8, want: []const u8 };
- for ([_]Case{
- .{ .addr = "0/foo/", .want = " 0 3 " },
- .{ .addr = "/foo/", .want = " 6 9 " },
- .{ .addr = "#12,#15", .want = " 12 15 " },
- .{ .addr = "$", .want = " 16 16 " },
- .{ .addr = "1,2", .want = " 0 16 " },
- // Backward, as in addr: from the dot's start, wrapping to the last.
- .{ .addr = "?foo?", .want = " 6 9 " },
- .{ .addr = "$-?y?", .want = " 10 11 " },
- }) |c| {
- var line: [64]u8 = undefined;
- try testing.expectEqual(Status.ok, wr(p, root, try std.fmt.bufPrint(&line, "@p{d}:{s}\n", .{ serial, c.addr })).reply.status);
- try testing.expectEqualStrings(c.want, rd(p, dot, 0, 64).bytes);
- }
- var line: [64]u8 = undefined;
- _ = wr(p, root, try std.fmt.bufPrint(&line, "@p{d}:/zzqq/\n", .{serial}));
- try testing.expect(th.logHas(p, ": no match for regexp"));
- try testing.expectEqualStrings("", rd(p, root, 0, 64).bytes);
- _ = wr(p, root, "@p999:/foo/\n");
- try testing.expect(th.logHas(p, "look: no pane @p999"));
- try testing.expectEqualStrings("", rd(p, root, 0, 64).bytes);
- // A line address to no pane is a miss too, not the active pane.
- _ = wr(p, root, "@p77:1\n");
- try testing.expect(th.logHas(p, "look: no pane @p77"));
- try testing.expectEqualStrings("", rd(p, root, 0, 64).bytes);
-}
-
-test "a look that goes to another pane leaves the looking pane's dot alone" {
- const p = try withFile(testing.allocator, "alpha bravo\ncharlie\n");
- defer p.deinit();
- const source = serialOf(p);
- const other = try th.newPane(p);
- _ = wr(p, Node.of(other, .body), "one\ntwo\nthree\n");
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "f one\nf 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;
- for ([_][]const u8{ "@p{d}:2", "@p{d}:/three/", "{s}/f.txt:2" }) |form| {
- @import("pane.zig").setDot(p.panes[p.paneBySerial(source).?].?, .{ .q0 = 6, .q1 = 11 });
- const text = if (form[0] == '@')
- (if (std.mem.eql(u8, form, "@p{d}:2")) try std.fmt.bufPrint(&line, "@p{d}:2\n", .{other}) else try std.fmt.bufPrint(&line, "@p{d}:/three/\n", .{other}))
- else
- try std.fmt.bufPrint(&line, "{s}/f.txt:2\n", .{dir});
- try testing.expectEqual(Status.ok, wr(p, Node.of(source, .look), text).reply.status);
- try testing.expect(p.active != p.paneBySerial(source).?);
- try testing.expectEqualStrings(" 6 11 ", rd(p, Node.of(source, .dot), 0, 64).bytes);
- }
-}
-
test "@p<terminal>:<address> takes any address over the terminal's lines, selecting the match" {
const p = try th.withTerm(testing.allocator);
defer p.deinit();
@@ -4265,45 +2907,6 @@ test "Edit on an image pane is refused as a data write there is, EINVAL, before
try testing.expectEqual(E.INVAL, wr(p, Node.of(doc.serial, .name), "/tmp/other.ppm\n").errno());
}
-test "`@pN:` looks at pane N as `a.txt:` looks at a.txt, and a line past the end is said one way, `:N` or `file:N`" {
- const p = try withFile(testing.allocator, "one\ntwo\n");
- defer p.deinit();
- const s = serialOf(p);
- var buf: [64]u8 = undefined;
- p.look_missed = false;
- pardes.look.lookAt(p, 0, try std.fmt.bufPrint(&buf, "@p{d}:", .{s}));
- try testing.expect(!p.look_missed);
- const f = pane_files.fileOf(p.panes[0].?).?;
- for ([_][]const u8{ ":99999", try std.fmt.bufPrint(&buf, "{s}:99999", .{f.path}) }) |looked| {
- pardes.look.lookAt(p, 0, looked);
- const said = p.panes[0].?.msg[0..p.panes[0].?.msg_len];
- try testing.expect(std.mem.endsWith(u8, said, "/test.txt:99999 has no line 99999"));
- }
-}
-
-test "a second LookWord list look in a directory refills its +Search rather than stacking another" {
- if (comptime !pardes.hosted) return;
- const gpa = testing.allocator;
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "words.txt", .data = "alpha beta\nalpha beta\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}/words.txt", .{dir});
- const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 });
- defer p.deinit();
- _ = wr(p, @backingInt(tree.TopFile.ctl), "LookWord list\n");
- pardes.look.lookAt(p, 0, "alpha");
- pardes.look.lookAt(p, 0, "beta");
- var searches: usize = 0;
- for (p.panes) |slot| if (slot) |pn| if (pn.file) |f| if (std.mem.endsWith(u8, f.path, "+Search")) {
- searches += 1;
- try testing.expectEqualStrings("beta", f.output.?.arg());
- };
- try testing.expectEqual(@as(usize, 1), searches);
-}
-
test "Petscii, Palette and Ascii take the state their tag word names, set rather than flipped" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -4380,40 +2983,6 @@ test "Lspinfo's answer is the +Lsp pane it fills, as a Rename preview's is its +
}
-test "a look of ./x that is not there is a miss, as x and /abs/x are: answered, the err logged" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- for ([_][]const u8{ "./zzq-nosuch.txt\n", "zzq-nosuch.txt\n", "/zzq-nosuch.txt\n" }) |line| {
- const r = wr(p, Node.of(serialOf(p), .look), line);
- try testing.expectEqual(Status.ok, r.reply.status);
- }
- try testing.expect(th.logHas(p, "look: ./zzq-nosuch.txt: no such file"));
-}
-
-test "a ctl line over 1 MiB is refused once, EINVAL, and its tail is not run as a line of its own" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const node = Node.of(serialOf(p), .ctl);
- const h = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle;
- const chunk: [4096]u8 = @splat('z');
- var refused: usize = 0;
- var off: u64 = 0;
- for (0..270) |_| {
- const r = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .off = off, .data = &chunk });
- if (r.reply.status == .err) {
- refused += 1;
- try testing.expectEqual(E.INVAL, r.errno());
- }
- off += chunk.len;
- }
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 3, .op = .write, .node = node, .handle = h, .off = off, .data = "zzz\nEdit ,d\n" }).reply.status);
- try testing.expectEqual(@as(usize, 1), refused);
- try testing.expect(!th.logHas(p, "unknown control message"));
- // What came after the long line's newline ran.
- try testing.expectEqualStrings("", pane_files.fileOf(p.panes[0].?).?.content);
- _ = call(p, .{ .tag = 4, .op = .release, .node = node, .handle = h });
-}
-
test "DumpDir refuses a relative directory and one that may not be written, up front; a Dump there says permission denied" {
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
@@ -4429,14 +2998,6 @@ test "DumpDir refuses a relative directory and one that may not be written, up f
try testing.expect(std.mem.endsWith(u8, p.fs.late_failure[0..p.fs.late_failure_len], ": permission denied"));
}
-test "a Mount dial with a network it does not know is a bad dial address, EINVAL" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const r = wr(p, @backingInt(tree.TopFile.ctl), "Mount peer nowhere!x\n");
- try testing.expectEqual(E.INVAL, r.errno());
- try testing.expectStringStartsWith(r.reply.ename, "Mount: bad dial address: nowhere!x");
-}
-
test "a command or a terminal refused for room is refused before anything is logged of it, and its serial is never handed out again" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();