summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ninep/ctl.zig558
1 files changed, 9 insertions, 549 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index fc09c730..f23f2579 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -1466,118 +1466,16 @@ test "commands lists every builtin with its argument and the ctl that takes it"
}
-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);
}
@@ -1795,55 +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 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;
@@ -2019,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;
@@ -2081,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");
@@ -2133,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");
@@ -2560,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();
@@ -2609,23 +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 "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();
@@ -2730,61 +2443,6 @@ test "a Restore of a name in the DumpDir asks for, and logs, the whole path it r
}
-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 "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();
@@ -2799,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();
@@ -2841,31 +2477,6 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt
try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null);
}
-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 column takes panes until their documented minimums fill it, not until none can be halved" {
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 });
defer p.deinit();
@@ -3335,39 +2946,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();
@@ -3478,37 +3056,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();
@@ -3522,30 +3069,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 "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();
@@ -3713,45 +3236,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();
@@ -3828,30 +3312,6 @@ test "Lspinfo's answer is the +Lsp pane it fills, as a Rename preview's is its +
}
-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");