summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/next-tests.md14
-rw-r--r--src/ninep/ctl.zig1483
-rw-r--r--src/ninep/pane.zig522
-rw-r--r--src/pardes.zig493
-rw-r--r--test/behaviour.zig3
-rw-r--r--test/behaviour/addresses.zig111
-rw-r--r--test/behaviour/builtins.zig36
-rw-r--r--test/behaviour/columns_and_tags.zig61
-rw-r--r--test/behaviour/edit.zig28
-rw-r--r--test/behaviour/event.zig16
-rw-r--r--test/behaviour/flags.zig102
-rw-r--r--test/behaviour/from_acme.zig28
-rw-r--r--test/behaviour/keys.zig152
-rw-r--r--test/behaviour/limits.zig22
-rw-r--r--test/behaviour/look_and_exec.zig390
-rw-r--r--test/behaviour/modes.zig382
-rw-r--r--test/behaviour/mounts.zig7
-rw-r--r--test/behaviour/mouse.zig65
-rw-r--r--test/behaviour/other_files.zig246
-rw-r--r--test/behaviour/panes.zig541
-rw-r--r--test/behaviour/placement.zig110
-rw-r--r--test/behaviour/repls.zig11
-rw-r--r--test/behaviour/root_ctl.zig56
-rw-r--r--test/behaviour/rules.zig22
-rw-r--r--test/behaviour/settings.zig168
-rw-r--r--test/behaviour/tags.zig84
-rw-r--r--test/output.zig70
-rw-r--r--test/panes.zig177
-rw-r--r--test/pdf.zig28
-rw-r--r--test/session.zig29
30 files changed, 2747 insertions, 2710 deletions
diff --git a/docs/next-tests.md b/docs/next-tests.md
index 1ee47612..b7b5d3ef 100644
--- a/docs/next-tests.md
+++ b/docs/next-tests.md
@@ -123,15 +123,15 @@ What the M tests reach into, and the public surface for it:
## Progress
-After the first fan-out (2026-11-03: four migrators, each followed by a
-reviewer that ran its own breaks; 108 tests in test/behaviour/):
+Two fan-outs (2026-11-03 and 2026-11-04; a migrator per area, then a
+reviewer running breaks of its own): 211 tests moved, 216 in
+test/behaviour/, plus the first process test.
-| area | moved | M left | X kept |
+| area | moved | M left (most excluded: effects, T2, images, LSP) | X kept |
|---|---|---|---|
-| src/ninep/ctl.zig, pane.zig | 38 (9 by hand) | about 72 | 6 |
-| test/panes.zig | 30 | 15 | 16 |
-| src/pardes.zig | 28 | 17 | 36 |
-| test/pdf.zig, test/output.zig | 14 | 28 | 13 |
+| src/ninep/ctl.zig | 9 + 29 + 62 | 37 | 14 |
+| src/ninep/pane.zig, test/panes.zig | 30 + 27 | 16 | 19 |
+| src/pardes.zig, test/output.zig, test/pdf.zig | 28 + 14 + 21 | 13 | 51 |
What the M left need, most first:
- **Effects performed:** Session counts a save and drops it; a save
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();
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index bf9dc381..28f1882d 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -312,56 +312,6 @@ pub fn spliceBody(p: *Pardes, pane: *Pane, q0: usize, q1: usize, bytes: []const
return take;
}
-test "a shell's > into an empty pane's body is one undo step, as into any other" {
- const p = try withFile(testing.allocator, "");
- defer p.deinit();
- const pane = p.panes[0].?;
- const f = &pane.file.?;
- const body = Node.of(pane.serial, .body);
- const steps = f.history.undo_len;
- const h = call(p, .{ .tag = 1, .op = .open, .node = body, .omode = 1 }).reply.handle;
- _ = call(p, .{ .tag = 2, .op = .setattr, .node = body, .truncate = true });
- try testing.expectEqual(tree.Status.ok, call(p, .{ .tag = 3, .op = .write, .node = body, .handle = h, .data = "fresh\n" }).reply.status);
- _ = call(p, .{ .tag = 4, .op = .release, .node = body, .handle = h, .opened = true });
- try testing.expectEqualStrings("fresh\n", f.content);
- try testing.expectEqual(steps + 1, f.history.undo_len);
-}
-
-test "a write that changes nothing, an empty range deleted or a range replaced by itself, makes no undo step" {
- const p = try withFile(testing.allocator, "abc\ndef\n");
- defer p.deinit();
- const pane = p.panes[0].?;
- const serial = pane.serial;
- const f = &pane.file.?;
- const steps = f.history.undo_len;
- const revision = f.revision;
- const data = Node.of(serial, .data);
- // Each as a shell does it, on an open of its own: `: > data` after
- // an empty address, then `echo abc > data` over the line it holds.
- _ = wr(p, Node.of(serial, .addr), "#2,#2");
- const h = call(p, .{ .tag = 1, .op = .open, .node = data, .omode = 1 }).reply.handle;
- try testing.expectEqual(tree.Status.ok, call(p, .{ .tag = 2, .op = .setattr, .node = data, .truncate = true }).reply.status);
- _ = call(p, .{ .tag = 3, .op = .release, .node = data, .handle = h, .opened = true });
- for ([_][]const u8{ "abc\n", "abd\n" }) |text| {
- _ = wr(p, Node.of(serial, .addr), "1");
- const w = call(p, .{ .tag = 4, .op = .open, .node = data, .omode = 1 }).reply.handle;
- try testing.expectEqual(tree.Status.ok, call(p, .{ .tag = 5, .op = .write, .node = data, .handle = w, .data = text }).reply.status);
- _ = call(p, .{ .tag = 6, .op = .release, .node = data, .handle = w, .opened = true });
- if (text[2] == 'c') {
- try testing.expectEqualStrings("abc\ndef\n", f.content);
- try testing.expectEqual(steps, f.history.undo_len);
- try testing.expectEqual(revision, f.revision);
- }
- }
- // Edit's `s/d/d/` is the same nothing.
- const undone = f.history.undo_len;
- try testing.expectEqual(tree.Status.ok, wr(p, Node.of(serial, .ctl), "Edit ,s/d/d/\n").reply.status);
- try testing.expectEqual(undone, f.history.undo_len);
- // A real change is still one.
- try testing.expectEqualStrings("abd\ndef\n", f.content);
- try testing.expectEqual(steps + 1, f.history.undo_len);
-}
-
test "rows through the line index are the ones counting newlines gives, at every offset" {
const p = try withFile(testing.allocator, "héllo\nwo\u{301}rld\n\n last line é\ntail");
defer p.deinit();
@@ -1114,38 +1064,6 @@ test "a body write to a terminal pane types at its shell" {
try testing.expectEqual(Status.ok, r.reply.status);
}
-test "tag reads the whole tag and writes append to the editable tail" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "x\n");
- defer p.deinit();
- const pane = p.panes[0].?;
- const node = Node.of(pane.serial, .tag);
-
- const whole = rd(p, node, 0, 4096);
- try testing.expect(std.mem.startsWith(u8, whole.bytes, "/test.txt"));
- try testing.expect(std.mem.indexOf(u8, whole.bytes, "Del") != null);
- try testing.expectEqual(@as(u64, whole.bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = node }).reply.attr.size);
-
- const before = rd(p, node, 0, 4096).bytes.len;
- const w = wr(p, node, " Mine");
- try testing.expectEqual(@as(u32, 5), w.reply.written);
- try testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Mine"));
- const after = rd(p, node, 0, 4096);
- try testing.expectEqual(before + 5, after.bytes.len);
- try testing.expect(std.mem.endsWith(u8, after.bytes, " Mine"));
-
- // A tag is a text like the body: a newline written to it stays one, and
- // the tag reads back taller by it.
- try testing.expectEqual(@as(u32, 10), wr(p, node, "\nNext Line").reply.written);
- try testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Mine\nNext Line"));
- try testing.expect(std.mem.endsWith(u8, rd(p, node, 0, 4096).bytes, " Mine\nNext Line"));
-
- if (pane.tag.own) |own| p.gpa.free(own);
- pane.tag.own = try p.gpa.alloc(u8, limits.max_tag_tail);
- @memset(pane.tag.own.?, 'x');
- try testing.expectEqual(E.NOSPC, wr(p, node, "x").errno());
-}
-
test "data never splits a rune, in either direction" {
const gpa = testing.allocator;
const p = try withFile(gpa, "\u{00e9}x\n");
@@ -1179,32 +1097,6 @@ test "the writes of one open are one undo step, as bash's line-buffered printf m
}
}
-test "an open's writes in a row are held and go in as one edit, seen by the next request" {
- const p = try withFile(testing.allocator, "one\n");
- defer p.deinit();
- const serial = serialOf(p);
- const body = Node.of(serial, .body);
- const h = call(p, .{ .tag = 1, .op = .open, .node = body, .omode = 1 }).reply.handle;
- const revision = p.panes[0].?.file.?.revision;
- for (0..100) |_| _ = call(p, .{ .tag = 2, .op = .write, .node = body, .handle = h, .data = "0123456789\n" });
- // Held: nothing edited yet.
- try testing.expectEqual(revision, p.panes[0].?.file.?.revision);
- // Any other request puts them in, once.
- try testing.expectEqual(@as(usize, 4 + 1100), rd(p, body, 0, 4096).bytes.len);
- try testing.expectEqual(revision + 1, p.panes[0].?.file.?.revision);
- _ = call(p, .{ .tag = 3, .op = .release, .node = body, .handle = h, .opened = true });
- 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);
- // data inserts at its address go on the same way.
- const data = Node.of(serial, .data);
- _ = wr(p, Node.of(serial, .addr), "#0");
- const d = call(p, .{ .tag = 4, .op = .open, .node = data, .omode = 1 }).reply.handle;
- _ = call(p, .{ .tag = 5, .op = .write, .node = data, .handle = d, .data = "a" });
- _ = call(p, .{ .tag = 5, .op = .write, .node = data, .handle = d, .data = "b" });
- _ = call(p, .{ .tag = 6, .op = .release, .node = data, .handle = d, .opened = true });
- try testing.expectEqualStrings("abone\n", rd(p, body, 0, 64).bytes);
-}
-
test "writes held before the shell's clock is first seen go in at its first step" {
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
@@ -1266,97 +1158,12 @@ test "after a failed address, one that goes from it says there is none" {
try testing.expectEqual(Status.ok, wr(p, addr, ".").reply.status);
}
-test "a 9P write moves dot only as acme's textinsert does, and scrolls only the view" {
- const Case = struct { at: u32, want: State.Range };
- // dot is `cd` of `abcdef\n` (2..4); two bytes go in at `at`.
- for ([_]Case{
- .{ .at = 0, .want = .{ .q0 = 4, .q1 = 6 } }, // before: shifted
- .{ .at = 2, .want = .{ .q0 = 2, .q1 = 6 } }, // at its start: grown
- .{ .at = 3, .want = .{ .q0 = 2, .q1 = 6 } }, // inside: grown
- .{ .at = 4, .want = .{ .q0 = 2, .q1 = 4 } }, // at its end: left
- .{ .at = 6, .want = .{ .q0 = 2, .q1 = 4 } }, // after: left
- }) |c| {
- const p = try withFile(testing.allocator, "abcdef\n");
- defer p.deinit();
- const serial = serialOf(p);
- const pane = p.panes[p.paneBySerial(serial).?].?;
- setDot(pane, .{ .q0 = 2, .q1 = 4 });
- var addr: [16]u8 = undefined;
- _ = wr(p, Node.of(serial, .addr), try std.fmt.bufPrint(&addr, "#{d}", .{c.at}));
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .data), "XX").reply.status);
- try testing.expectEqual(c.want, dotOf(pane));
- }
- // A body append leaves dot, and a sel write after it replaces dot, not
- // the text appended.
- const p = try withFile(testing.allocator, "abcdef\n");
- defer p.deinit();
- const serial = serialOf(p);
- const pane = p.panes[p.paneBySerial(serial).?].?;
- setDot(pane, .{ .q0 = 2, .q1 = 4 });
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "more\n").reply.status);
- try testing.expectEqual(State.Range{ .q0 = 2, .q1 = 4 }, dotOf(pane));
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .sel), "YY").reply.status);
- try testing.expectEqualStrings("abYYef\nmore\n", fileOf(pane).?.content);
-}
-
-test "an addr pair out of order or out of range is refused as the address form is, not clamped" {
- const p = try withFile(testing.allocator, "abcdef\n");
- defer p.deinit();
- const serial = serialOf(p);
- const addr = Node.of(serial, .addr);
- try testing.expectEqualStrings(addressing.e_order, wr(p, addr, "5 2").reply.ename);
- try testing.expectEqualStrings(addressing.e_order, wr(p, addr, "#5,#2").reply.ename);
- try testing.expectEqualStrings(addressing.e_range, wr(p, addr, "2 99").reply.ename);
- try testing.expectEqualStrings(addressing.e_range, wr(p, addr, "#2,#99").reply.ename);
- try testing.expectEqual(Status.ok, wr(p, addr, "2 4").reply.status);
- try testing.expectEqual(State.Range{ .q0 = 2, .q1 = 4 }, p.panes[p.paneBySerial(serial).?].?.fs.addr);
-}
-
-test "name refuses a directory, EISDIR, and leaves the name as it was" {
+// The rest moved to test/behaviour/panes.zig; a Save's failure and the
+// watches a rename asks for are effects a host performs.
+test "a long path's failed Save keeps its reason" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const serial = serialOf(p);
- const node = Node.of(serial, .name);
- for ([_][]const u8{ "/\n", "/tmp/\n", "sub/\n", "/tmp\n" }) |dir| {
- if (comptime !pardes.hosted) if (std.mem.eql(u8, dir, "/tmp\n")) continue;
- const r = wr(p, node, dir);
- try testing.expectEqual(E.ISDIR, r.errno());
- try testing.expect(std.mem.indexOf(u8, r.reply.ename, "is a directory") != null);
- }
- try testing.expectEqualStrings("/test.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?));
-}
-
-test "a write of two lines to name is refused EINVAL, on a held open or not" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
- const node = Node.of(serial, .name);
- try testing.expectEqual(E.INVAL, wr(p, node, "/tmp/a\n/tmp/b\n").errno());
- const h = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle;
- try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "/tmp/a\n/tmp/b\n" }).errno());
- _ = call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true });
- try testing.expectEqualStrings("/test.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?));
- // Line by line, as bash writes it: the second line is refused.
- const h2 = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle;
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h2, .data = "/tmp/pardes-a\n" }).reply.status);
- try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h2, .data = "/tmp/pardes-b\n" }).errno());
- _ = call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h2, .opened = true });
- try testing.expectEqualStrings("/tmp/pardes-a", nameOf(p, p.panes[p.paneBySerial(serial).?].?));
-}
-
-test "a name with a component over 255 bytes is refused, and a long path's failed Save keeps its reason" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
- const refused = wr(p, Node.of(serial, .name), "/tmp/" ++ &@as([256]u8, @splat('c')) ++ "/f.txt\n");
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expectEqualStrings("invalid file name: a component over 255 bytes", refused.reply.ename);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/" ++ &@as([255]u8, @splat('c')) ++ "\n").reply.status);
- // Held with no newline, it is refused by that write, not at the close.
- const held = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .name), .omode = 1 }).reply.handle;
- try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = Node.of(serial, .name), .handle = held, .data = "/tmp/" ++ &@as([256]u8, @splat('e')) }).errno());
- _ = call(p, .{ .tag = 3, .op = .release, .node = Node.of(serial, .name), .handle = held, .opened = true });
- try testing.expectEqual(@as(usize, 0), p.fs.closed_lines.items.len);
// A Save of a 3000-byte path the host refuses: the waiting write's
// reason is at the end, the path giving up its middle.
// (Under /tmp: under / a user's Save is refused permission, not
@@ -1372,28 +1179,25 @@ test "a name with a component over 255 bytes is refused, and a long path's faile
try testing.expect(std.mem.endsWith(u8, late, "/f.txt: no such directory"));
}
-test "a name cut across writes is one name, applied once at its newline or its close" {
- const p = try withFile(testing.allocator, "x\n");
+test "a scratch renamed to a file watches it only after its Save, and a virtual name never" {
+ const p = try withFile(testing.allocator, "opener\n");
defer p.deinit();
- const serial = serialOf(p);
- const node = Node.of(serial, .name);
- const h = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle;
- try testing.expect(h != 0);
- // A piece that fills its Twrite goes on in the next.
- p.fs.write_room = "/tmp/pardes-na".len;
- _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "/tmp/pardes-na" });
- p.fs.write_room = 0;
- try testing.expectEqualStrings("/test.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?));
- _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "me.txt\n" });
- try testing.expectEqualStrings("/tmp/pardes-name.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?));
- _ = call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true });
- // No newline: held, whatever the write's size, and applied at the close.
- const h3 = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle;
- _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h3, .data = "/tmp/pardes-closed.txt" });
- try testing.expectEqualStrings("/tmp/pardes-name.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?));
- _ = call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h3, .opened = true });
- tree.runClosedLines(p);
- try testing.expectEqualStrings("/tmp/pardes-closed.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?));
+ const serial = try th.newPane(p);
+ const pane = p.panes[p.paneBySerial(serial).?].?;
+ const name = Node.of(serial, .name);
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var directory_buf: [4096]u8 = undefined;
+ const directory = directory_buf[0..try tmp.dir.realPath(testing.io, &directory_buf)];
+ var line: [4120]u8 = undefined;
+ const renamed = wr(p, name, try std.fmt.bufPrint(&line, "{s}/renamed.zig\n", .{directory}));
+ try testing.expectEqual(false, renamed.watch.?);
+ try testing.expect(pane.file.?.watch_after_save);
+ const virtual = try th.newPane(p);
+ _ = wr(p, Node.of(virtual, .name), try std.fmt.bufPrint(&line, "/virtual/pane/{d}/body\n", .{serial}));
+ const unchanged = wr(p, Node.of(virtual, .name), "./body\n");
+ try testing.expect(unchanged.watch == null);
+ try testing.expect(!p.panes[p.paneBySerial(virtual).?].?.file.?.watch_after_save);
}
test "a replace through data, truncate then write, is one undo step" {
@@ -1424,189 +1228,6 @@ test "writes under mark 0 are one undo step, even with no history before them" {
try testing.expectEqualStrings("one\ntwo\nthree\n", rd(p, body, 0, 64).bytes);
}
-test "truncating the tag clears its editable tail" {
- const p = try withFile(testing.allocator, "x\n");
- defer p.deinit();
- const pane = p.panes[0].?;
- const tag = Node.of(pane.serial, .tag);
- _ = wr(p, tag, " Mine");
- try testing.expect(tagline.curTail(pane).len > 0);
- const cleared = call(p, .{ .tag = 1, .op = .setattr, .node = tag, .truncate = true });
- try testing.expectEqual(Status.ok, cleared.reply.status);
- // Done at the first read or write after it (or the close).
- _ = rd(p, tag, 0, 4096);
- try testing.expectEqualStrings("", pane.tag.own.?);
- try testing.expect(std.mem.indexOf(u8, rd(p, tag, 0, 4096).bytes, " Mine") == null);
- // The tag keeps its undo: undoing in it brings back what was cleared.
- pardes.edit.doUndo(p, &pane.tag);
- try testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Mine"));
- _ = call(p, .{ .tag = 2, .op = .setattr, .node = tag, .truncate = true });
- _ = rd(p, tag, 0, 4096);
- try testing.expectEqualStrings("", pane.tag.own.?);
-
- // Written back without a leading space, the text still stands apart
- // from the path: the computed prefix brings the separator, so Look and
- // Exec find `Get`, not `test.txtGet`.
- _ = wr(p, tag, "Get");
- try testing.expectEqualStrings("Get", pane.tag.own.?);
- const whole = rd(p, tag, 0, 4096).bytes;
- try testing.expectEqualStrings("/test.txt Get", whole);
- const word = config.wordBounds(whole, whole.len - "Get".len);
- try testing.expectEqualStrings("Get", whole[word.lo..word.hi]);
- // and a click on the G puts the tag's cursor on it
- const at = tagline.tagOffsetAt(p, pane, 0, "/test.txt ".len).?;
- try testing.expectEqualStrings("Get", whole[at.col..]);
-
- // `echo Make > tag`: the newline ending the truncating write's text is
- // dropped, one only; a newline between its writes stays.
- _ = call(p, .{ .tag = 3, .op = .release, .node = tag });
- _ = call(p, .{ .tag = 4, .op = .setattr, .node = tag, .truncate = true });
- _ = wr(p, tag, "Make\n");
- try testing.expectEqualStrings("Make", pane.tag.own.?);
- _ = wr(p, tag, "More\n\n");
- try testing.expectEqualStrings("Make\nMore\n", pane.tag.own.?);
- _ = call(p, .{ .tag = 5, .op = .release, .node = tag });
- // `>>` keeps what it is given.
- _ = wr(p, tag, " Tail\n");
- try testing.expectEqualStrings("Make\nMore\n Tail\n", pane.tag.own.?);
-}
-
-test "name reads the file name and writing it promotes a scratch without touching its body" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "opener\n");
- defer p.deinit();
- const serial = try th.newPane(p);
- const pane = p.panes[p.paneBySerial(serial).?].?;
- const name = Node.of(serial, .name);
- const body = Node.of(serial, .body);
- var scratch_name: [4200]u8 = undefined;
- const scratch_line = try std.fmt.bufPrint(&scratch_name, "{s}\n", .{nameOf(p, pane)});
- try testing.expectEqualStrings(scratch_line, rd(p, name, 0, 4096).bytes);
- try testing.expectEqual(@as(u64, scratch_line.len), call(p, .{ .tag = 1, .op = .getattr, .node = name }).reply.attr.size);
- _ = wr(p, body, "scratch ");
- _ = wr(p, body, "work\n");
- const undo_len = pane.file.?.history.undo_len;
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "renamed.zig", .data = "existing target\n" });
- var directory_buf: [4096]u8 = undefined;
- const directory = directory_buf[0..try tmp.dir.realPath(testing.io, &directory_buf)];
- var path_buffer: [4096]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buffer, "{s}/renamed.zig", .{directory});
- var line: [4104]u8 = undefined;
- const renamed = wr(p, name, try std.fmt.bufPrint(&line, "{s}\n", .{path}));
- try testing.expectEqual(Status.ok, renamed.reply.status);
- try testing.expectEqual(false, renamed.watch.?);
- try testing.expectEqualStrings("scratch work\n", pane.file.?.content);
- try testing.expectEqual(undo_len, pane.file.?.history.undo_len);
- try testing.expect(pane.file.?.output == null and dirtyOf(pane));
- try testing.expect(pane.file.?.watch_after_save);
- try testing.expectEqualStrings(path, std.mem.trimEnd(u8, rd(p, name, 0, 4096).bytes, "\n"));
- const target = try fs.readFile(gpa, path);
- defer gpa.free(target);
- try testing.expectEqualStrings("existing target\n", target);
- for ([_][]const u8{ "", "\n" }) |bad|
- try testing.expectEqual(E.INVAL, wr(p, name, bad).errno());
- // One name, and what no file name holds: a second line, a NUL.
- for ([_][2][]const u8{
- .{ "two\nlines\n", "a newline" },
- .{ "nul\x00.zig\n", "a NUL" },
- }) |c| {
- const refused = wr(p, name, c[0]);
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expectStringStartsWith(refused.reply.ename, "bad character in file name: ");
- try testing.expect(std.mem.indexOf(u8, refused.reply.ename, c[1]) != null);
- }
- // Any other byte a file name holds is taken, and reads back as written:
- // blanks at its ends, a tab, a control byte, DEL, C1, bytes not UTF-8.
- for ([_][]const u8{ " lead.zig ", "tab\t.zig", "c\x01.zig", "del\x7f.zig", "c1\xc2\x85.zig", "bad\xff.zig" }) |odd| {
- try testing.expectEqual(Status.ok, wr(p, name, try std.fmt.bufPrint(&line, "{s}\n", .{odd})).reply.status);
- const read_back = std.mem.trimEnd(u8, rd(p, name, 0, 4096).bytes, "\n");
- try testing.expect(std.mem.endsWith(u8, read_back, odd));
- var again: [4200]u8 = undefined;
- @memcpy(again[0..read_back.len], read_back);
- try testing.expectEqual(Status.ok, wr(p, name, again[0..read_back.len]).reply.status);
- try testing.expectEqualStrings(again[0..read_back.len], pane.file.?.path);
- }
- // A name that is one line and UTF-8 is taken, é and all.
- try testing.expectEqual(Status.ok, wr(p, name, "caf\xc3\xa9.zig\n").reply.status);
- try testing.expect(std.mem.endsWith(u8, pane.file.?.path, "/caf\xc3\xa9.zig"));
- try testing.expectEqual(Status.ok, wr(p, name, try std.fmt.bufPrint(&line, "{s}\n", .{path})).reply.status);
- try testing.expectEqualStrings(path, pane.file.?.path);
- try testing.expectEqual(Status.ok, wr(p, name, "two words.zig\n").reply.status);
- const spaced = try std.fmt.bufPrint(&path_buffer, "{s}/two words.zig", .{directory});
- try testing.expectEqualStrings(spaced, pane.file.?.path);
-}
-
-test "name refreshes cached syntax for unchanged contents" {
- if (!pardes.syntax.enabled) return error.SkipZigTest;
- pardes.syntax.start(testing.allocator);
- defer pardes.syntax.stop();
- const p = try withFile(testing.allocator, "fn check() void {}\n");
- defer p.deinit();
- const pane = p.panes[0].?;
- panes.File.refreshHighlights(p);
- try testing.expectEqual(@as(usize, 0), pane.file.?.highlights.len);
- try testing.expectEqual(Status.ok, wr(p, Node.of(pane.serial, .name), "renamed.zig\n").reply.status);
- panes.File.refreshHighlights(p);
- try testing.expect(pane.file.?.highlights.len >= 2);
- try testing.expectEqual(@backingInt(pardes.syntax.Syn.keyword), pane.file.?.highlights[0]);
- try testing.expectEqual(@backingInt(pardes.syntax.Syn.keyword), pane.file.?.highlights[1]);
- try testing.expectEqualStrings("fn check() void {}\n", pane.file.?.content);
-}
-
-test "relative names use the file directory and can name a new target" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "retained body\n");
- defer p.deinit();
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "note.txt", .data = "from pane directory\n" });
- var directory_buf: [4096]u8 = undefined;
- const directory = directory_buf[0..try tmp.dir.realPath(testing.io, &directory_buf)];
- const pane = p.panes[0].?;
- const name = Node.of(pane.serial, .name);
- const ctl_node = Node.of(pane.serial, .ctl);
- var line: [4140]u8 = undefined;
- try testing.expectEqual(Status.ok, wr(p, name, try std.fmt.bufPrint(&line, "{s}/old.txt\n", .{directory})).reply.status);
- try testing.expectEqual(Status.ok, wr(p, name, "child/../note.txt\n").reply.status);
- try testing.expectEqual(Status.ok, wr(p, ctl_node, "get\n").reply.status);
- try testing.expectEqualStrings("from pane directory\n", pane.file.?.content);
- try testing.expectEqualStrings(directory, Pardes.paneDir(pane));
- try testing.expectEqual(Status.ok, wr(p, name, "./created.txt\n").reply.status);
- var expected_buf: [4096]u8 = undefined;
- const expected = try std.fmt.bufPrint(&expected_buf, "{s}/created.txt", .{directory});
- try testing.expectEqualStrings(expected, pane.file.?.path);
- try testing.expect(!dirtyOf(pane)); // a name alone is no edit
-}
-
-test "relative names follow a pane/new scratch's session directory and virtual directories" {
- const p = try withFile(testing.allocator, "source body\n");
- defer p.deinit();
- const source = p.panes[0].?;
- try testing.expectEqual(Status.ok, wr(p, Node.of(source.serial, .name), "/elsewhere/source.zig\n").reply.status);
- // pane/new's scratch is the session's, not the active pane's.
- const session = "/project/src";
- @memcpy(p.session_dir[0..session.len], session);
- p.session_dir_len = session.len;
- const serial = try th.newPane(p);
- const scratch = p.panes[p.paneBySerial(serial).?].?;
- const name = Node.of(serial, .name);
- try testing.expectEqualStrings("/project/src", Pardes.paneDir(scratch));
- try testing.expectEqual(Status.ok, wr(p, name, "../out/./notes.txt\n").reply.status);
- try testing.expectEqualStrings("/project/out/notes.txt", scratch.file.?.path);
- try testing.expectEqualStrings("/project/out", Pardes.paneDir(scratch));
- var line: [256]u8 = undefined;
- try testing.expectEqual(Status.ok, wr(p, name, try std.fmt.bufPrint(&line, "/virtual/pane/{d}/./body\n", .{source.serial})).reply.status);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "get\n").reply.status);
- try testing.expectEqualStrings(source.file.?.content, scratch.file.?.content);
- const unchanged = wr(p, name, "./body\n");
- try testing.expectEqual(Status.ok, unchanged.reply.status);
- try testing.expect(unchanged.watch == null);
- try testing.expect(!dirtyOf(scratch));
- try testing.expect(!scratch.file.?.watch_after_save);
-}
-
test "owned cwd name promotion releases the former directory" {
const p = try th.withTerm(testing.allocator);
defer p.deinit();
@@ -1622,96 +1243,6 @@ test "owned cwd name promotion releases the former directory" {
try testing.expectEqualStrings("/old/directory", Pardes.paneDir(pane));
}
-test "errors append to one +Errors buffer per directory" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
-
- const live = for (p.panes) |slot| {
- if (slot) |q| if (q.file) |f| if (f.output) |o| if (std.meta.activeTag(o.from) == .errors) break q;
- } else null;
- try testing.expect(live == null);
-
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .errors), "boom\n").reply.status);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .errors), "again\n").reply.status);
-
- var found: usize = 0;
- for (p.panes) |slot| {
- const q = slot orelse continue;
- const f = q.file orelse continue;
- const o = f.output orelse continue;
- if (std.meta.activeTag(o.from) != .errors) continue;
- found += 1;
- try testing.expectEqualStrings("boom\nagain\n", f.content);
- try testing.expectEqualStrings("/+Errors", f.path);
- }
- try testing.expectEqual(@as(usize, 1), found);
-}
-
-test "truncating data deletes only the addressed range, so > data replaces it" {
- const p = try withFile(testing.allocator, "hello world\nsecond line\n");
- defer p.deinit();
- const serial = serialOf(p);
- for ([_]PaneFile{ .data, .xdata }) |file| {
- _ = call(p, .{ .tag = 1, .op = .setattr, .node = Node.of(serial, .body), .truncate = true });
- _ = wr(p, Node.of(serial, .body), "hello world\nsecond line\n");
- _ = wr(p, Node.of(serial, .addr), "#0,#5");
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .setattr, .node = Node.of(serial, file), .truncate = true }).reply.status);
- try testing.expectEqualStrings(" world\nsecond line\n", p.panes[0].?.file.?.content);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, file), "HOWDY").reply.status);
- try testing.expectEqualStrings("HOWDY world\nsecond line\n", p.panes[0].?.file.?.content);
- }
-}
-
-test "setattr truncation empties the body and answers fresh attributes" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "one\ntwo\n");
- defer p.deinit();
- const serial = serialOf(p);
-
- const a = call(p, .{ .tag = 7, .op = .setattr, .node = Node.of(serial, .body), .truncate = true });
- try testing.expectEqual(Status.ok, a.reply.status);
- try testing.expectEqual(@as(u64, 0), a.reply.attr.size);
- try testing.expectEqualStrings("", p.panes[0].?.file.?.content);
-
- _ = wr(p, Node.of(serial, .body), "new text\n");
- try testing.expectEqualStrings("new text\n", p.panes[0].?.file.?.content);
-
- const noop = call(p, .{ .tag = 8, .op = .setattr, .node = Node.of(serial, .body) });
- try testing.expectEqual(@as(u64, 9), noop.reply.attr.size);
-}
-
-test "addresses are in runes: a combining mark and a lone \\r are places of their own" {
- const gpa = testing.allocator;
- // e, U+0301 (two bytes, 1-2), x, \r, \n
- const p = try withFile(gpa, "e\u{0301}x\r\n");
- defer p.deinit();
- const serial = serialOf(p);
- const addr_node = Node.of(serial, .addr);
- const dot = Node.of(serial, .dot);
- const Case = struct { expr: []const u8, q0: u32, q1: u32 };
- for ([_]Case{
- .{ .expr = "#1,#3", .q0 = 1, .q1 = 3 }, // the mark alone
- .{ .expr = "#2", .q0 = 1, .q1 = 1 }, // inside it: back to its start
- .{ .expr = "#4,#5", .q0 = 4, .q1 = 5 }, // the \r alone
- .{ .expr = "1:2", .q0 = 1, .q1 = 1 }, // line:col the same
- .{ .expr = "1:3", .q0 = 1, .q1 = 1 },
- .{ .expr = "0/\xCC/", .q0 = 1, .q1 = 3 }, // a match inside a rune covers it
- }) |c| {
- try testing.expectEqual(Status.ok, wr(p, addr_node, c.expr).reply.status);
- try testing.expectEqual(c.q0, p.panes[0].?.fs.addr.q0);
- try testing.expectEqual(c.q1, p.panes[0].?.fs.addr.q1);
- }
- // Copied to dot, it reads back the same.
- _ = wr(p, addr_node, "#1,#3");
- try testing.expectEqual(Status.ok, wr(p, dot, " 1 3 ").reply.status);
- p.sync();
- try testing.expectEqualStrings(" 1 3 ", rd(p, dot, 0, 100).bytes);
- _ = wr(p, addr_node, "#4,#5");
- try testing.expectEqualStrings("\r", rd(p, Node.of(serial, .xdata), 0, 100).bytes);
-}
-
test "a limit write that fails keeps the limit a truncation cleared before it" {
const gpa = testing.allocator;
const p = try withFile(gpa, "one two\n");
@@ -1727,17 +1258,6 @@ test "a limit write that fails keeps the limit a truncation cleared before it" {
try testing.expectEqualStrings("", rd(p, limit, 0, 100).bytes);
}
-test "a pane's tagexec runs a word as a click in its tag, and reads back what it touched" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "x\n");
- defer p.deinit();
- const serial = serialOf(p);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .tagexec), "Msg from the tag\n").reply.status);
- try testing.expect(th.logHas(p, "from the tag"));
- var want: [16]u8 = undefined;
- try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{serial}), rd(p, Node.of(serial, .tagexec), 0, 64).bytes);
-}
-
test "index names a command's pane cmd, a shell's term" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
diff --git a/src/pardes.zig b/src/pardes.zig
index b20fbb32..6c5a01af 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -1195,79 +1195,6 @@ test "first document keeps its originating shell and only opens a column when it
}
}
-test "acme placement: under a pane's text when it has many blank rows, else halving the biggest" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 });
- defer p.deinit();
- const top = p.active;
- _ = try p.setTestFile("one\ntwo\nthree\n");
- p.sync();
- p.setActiveColumn(0);
- // Most of the pane is blank: a document looked from it starts under its
- // three lines (makenewwindow, util.c:482-486).
- const second = p.freeSlot().?;
- _ = try p.openTutorView(second);
- exec.placeNew(p, top, top, second, .doc);
- p.sync();
- const text_end = p.bodyTop(p.panes[top].?, p.rects[top]) + 3;
- try std.testing.expectEqual(text_end, p.rects[second].y);
- // Fill both with text: no blank space is big, so the biggest pane is
- // halved.
- const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
- for ([_]usize{ top, second }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full));
- p.sync();
- const big = if (p.rects[second].h >= p.rects[top].h) second else top;
- const was = p.rects[big];
- const third = p.freeSlot().?;
- _ = try p.openTutorView(third);
- exec.placeNew(p, second, second, third, .doc);
- p.sync();
- try std.testing.expectEqual(big, p.col_panes[0][layout.findPane(p, third).?.idx - 1]);
- try std.testing.expectEqual(was.y + was.h / 2, p.rects[third].y);
- try std.testing.expectEqual(was.y + was.h, p.rects[third].y + p.rects[third].h);
-}
-
-test "acme placement: a pane made from the middle of a column moves only the one it splits, short ones round it kept short" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 });
- defer p.deinit();
- const top = p.active;
- _ = try p.setTestFile("one\n");
- p.sync();
- p.setActiveColumn(0);
- const middle = p.freeSlot().?;
- _ = try p.openTutorView(middle);
- exec.placeNew(p, top, top, middle, .doc);
- const bottom = p.freeSlot().?;
- _ = try p.openTutorView(bottom);
- exec.placeNew(p, middle, middle, bottom, .doc);
- p.sync();
- // A short pane above and below, dragged under a placement's minimum,
- // and the middle one full of text, so it is the one halved.
- const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
- for ([_]usize{ top, middle, bottom }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full));
- try std.testing.expectEqualSlices(usize, &.{ top, middle, bottom }, p.col_panes[0][0..3]);
- const total = p.rects[top].h + p.rects[middle].h + p.rects[bottom].h;
- p.panes[top].?.vweight = 2;
- p.panes[bottom].?.vweight = 2;
- p.panes[middle].?.vweight = @floatFromInt(total - 4);
- p.sync();
- const was_top = p.rects[top];
- const was_bottom = p.rects[bottom];
- try std.testing.expect(was_top.h < layout.minRows(p, top));
- const made = p.freeSlot().?;
- _ = try p.openTutorView(made);
- exec.placeNew(p, middle, middle, made, .doc);
- p.sync();
- try std.testing.expectEqual(layout.findPane(p, middle).?.idx + 1, layout.findPane(p, made).?.idx);
- try std.testing.expectEqual(was_top, p.rects[top]);
- try std.testing.expectEqual(was_bottom, p.rects[bottom]);
- // A new column narrows this one, and the short panes keep their rows.
- try std.testing.expect(p.executeBuiltinLine(made, "Newcol"));
- p.sync();
- try std.testing.expectEqual(@as(usize, 2), p.ncol);
- try std.testing.expectEqual(was_top.h, p.rects[top].h);
- try std.testing.expectEqual(was_bottom.h, p.rects[bottom].h);
-}
-
test "an empty column shows its theme's empty_col under its tag: acme's white, else the border" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 20 });
defer p.deinit();
@@ -2918,48 +2845,6 @@ test "every line of the board's boot buffer renders whole" {
// ---- the boundary types ----
-test "Unicode display cells map back to body and tag byte cursors" {
- const gpa = std.testing.allocator;
- const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("a界e\u{301}z\n");
- const f = &pane.file.?;
- p.gpa.free(f.path);
- f.path = try p.gpa.dupe(u8, "界e\u{301}.txt");
-
- var frame = std.heap.ArenaAllocator.init(gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const text_x = rect.x + config.GUTTER + config.PREFIX_W;
- const body_y = rect.y + BOX_H;
- // The second screen cell is the trailing half of the wide CJK grapheme.
- // Both halves map to its one byte boundary.
- p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = text_x + 2, .row = body_y } });
- p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = text_x + 2, .row = body_y } });
- try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
-
- // A click in the wide path glyph drafts a name with its caret at the
- // grapheme start; arrow motion then advances by the full UTF-8 cluster.
- tagline.draftName(p, pane, 1);
- try std.testing.expectEqual(@as(i32, 0), pane.input.cur_col);
- edit.insertKey(p, &pane.input, .{ .cp = Key.right });
- try std.testing.expectEqual(@as(i32, 3), pane.input.cur_col);
- edit.insertKey(p, &pane.input, .{ .cp = Key.right });
- try std.testing.expectEqual(@as(i32, 6), pane.input.cur_col);
- pane.closePrompt();
-
- const before = try gpa.dupe(u8, tagline.curTail(pane));
- defer gpa.free(before);
- tagline.enterTag(p, pane);
- const insertion = pane.tag.cur_col;
- edit.insertKey(p, &pane.tag, .{ .cp = 'λ', .text = "λ" });
- try std.testing.expectEqual(insertion + 2, pane.tag.cur_col);
- edit.insertKey(p, &pane.tag, .{ .cp = Key.backspace });
- try std.testing.expectEqual(insertion, pane.tag.cur_col);
- try std.testing.expectEqualStrings(before, tagline.curTail(pane));
-}
-
test "Tab N draws every pane's tab N cells wide and clicks count past it; bare Tab says the width; the ctl read and a Dump keep it" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 });
@@ -3110,65 +2995,6 @@ test "editable workspace and column tags are typed into and persist" {
try std.testing.expectEqualStrings("", tagline.columnTag(empty, 0));
}
-test "column tags render edit hover and scroll from the column edge" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true });
- defer p.deinit();
- _ = try p.setTestFile("untouched\n");
- p.newColumn(0);
- p.newScratchIn(0, p.activeColumn().?);
- p.sync();
- p.acknowledgePanelPresentation(&.{});
- var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer frame.deinit();
- for (0..p.ncol) |column| {
- const x = p.col_x[column] + TAG_TEXT_INSET;
- const width = p.col_w[column] - TAG_TEXT_INSET;
- const initial = try p.render(frame.allocator());
- for ("New", 0..) |byte, offset|
- try std.testing.expectEqual(byte, initial.at(x + @as(u16, @intCast(offset)), TOPBAR_H).text[0]);
- p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = x, .row = TOPBAR_H } });
- const hovered = try p.render(frame.allocator());
- try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, hovered.at(x, TOPBAR_H).style.bg);
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = TOPBAR_H } });
- try std.testing.expectEqual(column, p.header_column.?);
- try std.testing.expectEqual(@as(i32, 0), tagline.focusedHeader(p).?.cur_col);
- const at_start = try p.render(frame.allocator());
- try std.testing.expectEqual(x, at_start.cursor.?.x);
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = x + 3, .row = TOPBAR_H } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x + 3, .row = TOPBAR_H } });
- const selected = try p.render(frame.allocator());
- for (0..3) |offset|
- try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, selected.at(x + @as(u16, @intCast(offset)), TOPBAR_H).style.bg);
- p.update(.{ .key = .{ .cp = Key.home } });
- // A clicked header is in normal mode: `i` types there.
- p.update(.{ .key = .{ .cp = 'i', .text = "i" } });
- p.update(.{ .key = .{ .cp = 'H', .text = "Help " } });
- try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, column), "Help New Tty"));
- const edited = try p.render(frame.allocator());
- try std.testing.expectEqual(x + 5, edited.cursor.?.x);
- // Only the text viewport participates in caret reveal.
- const long: [80]u8 = @splat('a');
- if (p.col_tags[column].own) |own| p.gpa.free(own);
- p.col_tags[column].own = try p.gpa.dupe(u8, long[0 .. width - 1]);
- p.update(.{ .key = .{ .cp = Key.end } });
- const at_end = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 0), p.header_scroll);
- try std.testing.expectEqual(x + width - 1, at_end.cursor.?.x);
- p.update(.{ .key = .{ .cp = 'b', .text = "b" } });
- const revealed = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 1), p.header_scroll);
- try std.testing.expectEqual(x + width - 1, revealed.cursor.?.x);
- p.update(.{ .key = .{ .cp = Key.home } });
- const home = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 0), p.header_scroll);
- try std.testing.expectEqual(x, home.cursor.?.x);
- p.update(.{ .key = .{ .cp = Key.escape } });
- p.update(.pointer_leave);
- _ = frame.reset(.retain_capacity);
- }
- try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content);
-}
-
test "column tag first-cell execution keeps New local to the clicked column" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true });
defer p.deinit();
@@ -3238,45 +3064,6 @@ test "s in a header selects in the header's own text" {
try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
}
-test "window keys walk from a pane up through the column and workspace tags and back" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true });
- defer p.deinit();
- _ = try p.setTestFile("body\n");
- p.newColumn(0);
- p.newScratchIn(0, p.activeColumn().?);
- p.sync();
- p.active = p.col_panes[0][0];
- const window = struct {
- fn key(core: *Pardes, letter: u21) void {
- core.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- core.update(.{ .key = .{ .cp = letter } });
- }
- };
- // Up from the top pane: its column's tag, in normal mode; `:` there is
- // the way back to the body.
- window.key(p, 'k');
- try std.testing.expect(p.header_focus and p.header_column.? == 0);
- try std.testing.expectEqual(Text.Mode.normal, p.col_tags[0].mode);
- p.update(.{ .key = .{ .cp = 'w' } });
- try std.testing.expect(p.col_tags[0].cur_col > 0);
- const remembered = p.col_tags[0].cur_col;
- window.key(p, 'l');
- try std.testing.expect(p.header_focus and p.header_column.? == 1);
- window.key(p, 'h');
- try std.testing.expectEqual(remembered, p.col_tags[0].cur_col);
- window.key(p, 'k');
- try std.testing.expect(p.header_focus and p.header_column == null);
- window.key(p, 'j');
- try std.testing.expect(p.header_focus and p.header_column.? == 0);
- window.key(p, 'j');
- try std.testing.expect(!p.header_focus);
- try std.testing.expectEqual(p.col_panes[0][0], p.active);
- window.key(p, 'k');
- p.update(.{ .key = .{ .cp = ':' } });
- try std.testing.expect(!p.header_focus and p.panes[p.active].?.focus == .body);
- try std.testing.expectEqualStrings("body\n", p.panes[0].?.file.?.content);
-}
-
pub const Mouse = struct {
/// The host has inverted a compact body layer. Physical col/row still
/// route pane chrome; these coordinates address the pane's logical text.
@@ -8514,63 +8301,6 @@ test "with ProgramEsc raw tty Escape only leaves at a shell prompt" {
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
}
-test "window mode moves an outline and focuses it on Enter, Esc or a label" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 });
- defer p.deinit();
- _ = try p.setTestFile("left\n");
- _ = try p.newShell(1, "");
- try std.testing.expect(layout.splitColumn(p, 0, 1, false));
- p.newScratchBelow(1);
- p.sync();
- const lower = for (p.panes, 0..) |slot, id| {
- if (slot != null and id > 1) break id;
- } else return error.TestExpectedScratch;
- p.active = 0;
- // Ctrl-w enters it; h/j/k/l move only the outline.
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- try std.testing.expectEqual(@as(?usize, 0), p.window_pick);
- p.update(.{ .key = .{ .cp = 'l', .text = "l" } });
- try std.testing.expect(p.window_pick != null and p.window_pick.? != 0);
- p.update(.{ .key = .{ .cp = 'j', .text = "j" } });
- try std.testing.expectEqual(@as(?usize, lower), p.window_pick);
- try std.testing.expectEqual(@as(usize, 0), p.active);
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(lower, p.active);
- try std.testing.expect(p.window_pick == null);
- // SPC w enters it too, and Esc also leaves it on the outlined pane.
- p.update(.{ .key = .{ .cp = ' ', .text = " " } });
- p.update(.{ .key = .{ .cp = 'w', .text = "w" } });
- p.update(.{ .key = .{ .cp = 'h', .text = "h" } });
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
- try std.testing.expect(p.window_pick == null);
- // Other keys change nothing.
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- p.update(.{ .key = .{ .cp = '!', .text = "!" } });
- try std.testing.expectEqual(@as(?usize, 0), p.window_pick);
- p.update(.{ .key = .{ .cp = Key.escape } });
- // `:` focuses the outlined pane's tag.
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- p.update(.{ .key = .{ .cp = 'l', .text = "l" } });
- p.update(.{ .key = .{ .cp = ':', .text = ":" } });
- try std.testing.expect(p.active != 0 and p.panes[p.active].?.focus == .tag);
- p.update(.{ .key = .{ .cp = Key.escape } });
- // A label goes straight there: the left column's pane is "a".
- try std.testing.expectEqual(@as(?u8, 'a'), layout.windowLabel(p, 0));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Window"));
- p.update(.{ .key = .{ .cp = 'a', .text = "a" } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
- // Painted: the outlined tag's band in the selection colour, each pane's
- // letter in its tag's box.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Window"));
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
- defer arena.deinit();
- const shown = try p.render(arena.allocator());
- try std.testing.expectEqual(p.theme().sel_bg, shown.tag_layers[0].bg);
- const box = shown.at(p.rects[0].x, p.tagTop(p.panes[0].?, p.rects[0]));
- try std.testing.expectEqualStrings("a", box.text[0..box.len]);
-}
-
test "the Del question shows only once its delay is up: a quick SPC d j never sees it" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 });
@@ -8621,61 +8351,6 @@ test "the Del question shows only once its delay is up: a quick SPC d j never se
try std.testing.expect(p.panes[mid] == null);
}
-test "window mode d deletes the outlined pane and asks k or j, c collapses it, and the mode stays" {
- if (platform == .web) return;
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 });
- defer p.deinit();
- p.settings.placement = .pardes; // the neighbours below are what is under test
- const top = p.active;
- p.newScratchBelow(top);
- const mid = p.active;
- p.newScratchBelow(mid);
- const low = p.active;
- p.sync();
- const h = [_]u16{ p.rects[top].h, p.rects[mid].h, p.rects[low].h };
- // Neither key is a pane's label.
- try std.testing.expect(std.mem.indexOfAny(u8, layout.window_labels, "hjkldc") == null);
-
- // Ctrl-w from the bottom pane, the outline up to the middle one.
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- p.update(.{ .key = .{ .cp = 'k', .text = "k" } });
- try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
- // c folds the outlined pane to its tag and back, the mode staying.
- p.update(.{ .key = .{ .cp = 'c', .text = "c" } });
- try std.testing.expect(p.panes[mid].?.collapsed);
- try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
- p.update(.{ .key = .{ .cp = 'c', .text = "c" } });
- try std.testing.expect(!p.panes[mid].?.collapsed);
- p.sync();
- try std.testing.expectEqual(h[1], p.rects[mid].h);
-
- // d with panes above and below asks, as SPC d does; Esc takes it back
- // and the outline stays where it was.
- p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
- try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[mid].?.prompt);
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(p.panes[mid] != null and p.panes[mid].?.prompt == .none);
- try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
- // j: the pane below takes the rows, and the outline goes with them.
- p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
- p.update(.{ .key = .{ .cp = 'j', .text = "j" } });
- p.sync();
- try std.testing.expect(p.panes[mid] == null);
- try std.testing.expectEqual(h[0], p.rects[top].h);
- try std.testing.expectEqual(h[1] + h[2], p.rects[low].h);
- try std.testing.expectEqual(@as(?usize, low), p.window_pick);
- // With one neighbour there is nothing to ask: d closes it at once,
- // the outline on the pane that grew.
- p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
- p.sync();
- try std.testing.expect(p.panes[low] == null);
- try std.testing.expectEqual(@as(?usize, top), p.window_pick);
- // Enter leaves the mode on it.
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expect(p.window_pick == null);
- try std.testing.expectEqual(top, p.active);
-}
-
test "raw tty Ctrl-B switches to editor mode without sending child input" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" });
@@ -8773,56 +8448,6 @@ test "a Rename the language server finds nothing for says so, and changes nothin
try std.testing.expectEqualStrings("const value=1;\n", pane.file.?.content);
}
-test "hopping between two panes does not grow the jump stack" {
- if (platform == .web) return;
- const gpa = std.testing.allocator;
- const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" });
- p.settings.placement = .pardes; // two panes of room, not acme's fit to the doc's two lines
- defer p.deinit();
- p.update(.{ .resize = .{ .cols = 80, .rows = 24 } });
- p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc
- const doc = 0;
- const shell = p.active;
- try std.testing.expect(shell != doc);
- const depth = p.njumps;
-
- // Esc is Last — the everyday two-pane hop. Each press used to
- // append, so sixty-four of them left the stack remembering nothing else.
- for (0..8) |_| {
- const was = p.active;
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(p.active != was);
- }
- try std.testing.expectEqual(depth, p.njumps);
-
- // ...and so are the other two ways to switch panes.
- for (0..8) |_| {
- const want = if (p.active == doc) shell else doc;
- const dir: u21 = if (p.active == doc) 'j' else 'k';
- p.update(.{ .key = .{ .cp = ' ' } });
- p.update(.{ .key = .{ .cp = 'w' } });
- p.update(.{ .key = .{ .cp = dir } });
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(want, p.active);
- }
- try std.testing.expectEqual(depth, p.njumps);
-
- for (0..8) |_| {
- const other = if (p.active == doc) shell else doc;
- const r = p.rects[other];
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = r.x + config.GUTTER + 1, .row = r.y + BOX_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = r.x + config.GUTTER + 1, .row = r.y + BOX_H + 1 } });
- try std.testing.expectEqual(other, p.active);
- }
- try std.testing.expectEqual(depth, p.njumps);
-
- const before = p.active;
- exec.runBuiltin(p, .Back, p.active, "", null);
- p.sync();
- try std.testing.expect(p.active != before);
- try std.testing.expectEqual(depth, p.njumps);
-}
-
/// Every `.write` a keystroke produced, joined — what the pane's program would
/// actually have read off its pty.
fn drainWrites(p: *Pardes, buf: []u8) []const u8 {
@@ -9186,48 +8811,15 @@ test "board heap: every allocation failure during boot is a clean OutOfMemory" {
);
}
-test "a sweep pressed on the line numbers copies only the text" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("alpha beta\ngamma delta\n");
- const numbers: i32 = panes.File.gutterWidth(pane);
- const top: i32 = pane.tag_rows;
- pane.sel[0] = .{ .state = .done, .c0 = 1, .c1 = numbers + 4, .r0 = top, .r1 = top + 1 };
- // Live, while the drag is held, and captured, once it is released.
- try std.testing.expectEqualStrings("alpha beta\ngamma", try edit.selectionText(p, pane, pane.sel[0]));
- try edit.capturePointerSelection(p, pane, 0);
- try std.testing.expectEqualStrings("alpha beta\ngamma", try edit.selectionText(p, pane, pane.sel[0]));
-}
-
-test "jump history clears selections and lands at the recorded cursor" {
+test "jump history skips an entry whose pane slot or serial is gone, leaving the selection" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();
const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n");
p.njumps = 2;
p.jcur = 1;
- p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 3, .col = 8 };
p.jumps[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 };
- for ([_]u21{ 'o', 'i' }, 0..) |key, index| {
- pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true);
- pane.sel[0] = .{ .state = .done, .c0 = 2, .c1 = 5, .r0 = 1, .r1 = 1 };
- try edit.capturePointerSelection(p, pane, 0);
- pane.body.select = true;
- p.update(.{ .key = .{ .cp = key, .ctrl = true } });
- try std.testing.expectEqual(index, p.jcur);
- try std.testing.expectEqual(@as(usize, 2), p.njumps);
- try std.testing.expectEqual(@as(u32, 3), p.jumps[0].line);
- try std.testing.expect(!pane.body.vsel.active and !pane.body.msel.active and !pane.body.select);
- try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
- try std.testing.expectEqual(.none, pane.sel[0].state);
- try std.testing.expect(pane.pointer_selections[0] == null);
- try std.testing.expectEqual(@as(i32, if (index == 0) 2 else 0), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, if (index == 0) 7 else 0), pane.body.cur_col);
- }
pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true);
const selected = pane.body.primaryRange(pane.file.?.content, 0);
- p.jumpBy(1); // No forward entry: selection stays untouched.
- try std.testing.expectEqualDeep(selected, pane.body.primaryRange(pane.file.?.content, 0));
- try std.testing.expect(std.mem.indexOf(u8, p.panes[p.active].?.msg[0..p.panes[p.active].?.msg_len], "nothing further on") != null);
for ([_]Loc{
.{ .pane = 15, .serial = pane.serial, .line = 1, .col = 1 },
.{ .pane = 0, .serial = pane.serial + 1, .line = 1, .col = 1 },
@@ -9239,7 +8831,7 @@ test "jump history clears selections and lands at the recorded cursor" {
}
}
-/// A session for the JumpScope tests: four panes of 100 lines in one
+/// A session for the side-button jump test: four panes of 100 lines in one
/// column, A (pane 0) and B each on a file of its own, C on A's file, and O
/// an output buffer, no file behind it. `order` is the jumplist, a letter a
/// place, each letter's n-th place its line 10 + 40n: "ABABA" is A10 B10 A50
@@ -9249,7 +8841,7 @@ const JumpsTest = struct {
ids: [4]usize = .{ 0, 0, 0, 0 },
const letters = "ABCO";
- const Way = enum { call, key, builtin, mouse };
+ const Way = enum { call, mouse };
fn init(order: []const u8) !JumpsTest {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 80 });
@@ -9290,14 +8882,12 @@ const JumpsTest = struct {
return t;
}
- /// One step `delta` through `way`: the function, Ctrl-o or Ctrl-i, the
- /// mouse's side button pressed and let go, or the builtin's word.
+ /// One step `delta` through `way`: the function, or the mouse's side
+ /// button pressed and let go.
fn step(t: JumpsTest, way: Way, delta: i32) void {
const back = delta < 0;
switch (way) {
.call => t.p.jumpBy(delta),
- .key => t.p.update(.{ .key = .{ .cp = if (back) 'o' else 'i', .ctrl = true } }),
- .builtin => _ = t.p.executeBuiltinLine(t.p.active, if (back) "Back" else "Forward"),
.mouse => for ([_]Mouse.Kind{ .press, .release }) |kind|
t.p.update(.{ .mouse = .{ .button = if (back) .back else .forward, .kind = kind, .col = 0, .row = 0 } }),
}
@@ -9323,75 +8913,10 @@ const JumpsTest = struct {
}
};
-test "JumpScope file: Back keeps to the focused file, A50 then A10, and leaves it only once it runs out that way" {
- const t = try JumpsTest.init("BABABA");
- defer t.p.deinit();
- try std.testing.expectEqual(config.Runtime.JumpScope.file, t.p.settings.jump_scope);
- var buf: [128]u8 = undefined;
- // B90, B50 passed over, kept in their places: A has nothing older than
- // A10, so the step after it is the nearest place of any file, B10.
- try std.testing.expectEqualStrings("A50 A10 B10", try t.walk(.call, -1, &buf));
- try std.testing.expectEqual(@as(usize, 6), t.p.njumps);
- // Forward is the mirror, from B10 in B: B's own places first, then A90,
- // the newest, where the Backs started.
- try std.testing.expectEqualStrings("B50 B90 A90", try t.walk(.call, 1, &buf));
- try std.testing.expectEqual(@as(usize, 5), t.p.jcur);
-}
-
-test "JumpScope file: Forward retraces a run of Backs inside one file step for step, back to where it began" {
- const t = try JumpsTest.init("ABABA");
- defer t.p.deinit();
- var buf: [128]u8 = undefined;
- // A1 B1 A2 B2 A3 from A3: nothing older than A1 at all, so Back ends there.
- try std.testing.expectEqualStrings("A50 A10", try t.walk(.call, -1, &buf));
- try std.testing.expectEqual(@as(usize, 0), t.p.jcur);
- try std.testing.expectEqualStrings("A50 A90", try t.walk(.call, 1, &buf));
- try std.testing.expectEqual(@as(usize, 4), t.p.jcur);
- // One Back, one Forward: the same entry, whichever were passed over.
- t.step(.call, -1);
- try std.testing.expectEqual(@as(usize, 2), t.p.jcur);
- t.step(.call, 1);
- try std.testing.expectEqual(@as(usize, 4), t.p.jcur);
- try std.testing.expectEqual(@as(usize, 5), t.p.njumps);
-}
-
-test "JumpScope all: Back and Forward take every place in the order it was jumped to" {
- const t = try JumpsTest.init("ABABA");
- defer t.p.deinit();
- try std.testing.expect(t.p.executeBuiltinLine(t.p.active, "JumpScope all"));
- try std.testing.expectEqual(config.Runtime.JumpScope.all, t.p.settings.jump_scope);
- var buf: [128]u8 = undefined;
- try std.testing.expectEqualStrings("B50 A50 B10 A10", try t.walk(.call, -1, &buf));
- try std.testing.expectEqualStrings("B10 A50 B50 A90", try t.walk(.call, 1, &buf));
- // Bare, the word steps back to file.
- try std.testing.expect(t.p.executeBuiltinLine(t.p.active, "JumpScope"));
- try std.testing.expectEqual(config.Runtime.JumpScope.file, t.p.settings.jump_scope);
-}
-
-test "JumpScope file: from a pane with no file, Back and Forward are global" {
- const t = try JumpsTest.init("OAOBO");
- defer t.p.deinit();
- var buf: [128]u8 = undefined;
- // O90 keeps to nothing: B10, the next older of all. From B, nothing of
- // B is older, so O50; from O, A10; from A, O10.
- try std.testing.expectEqualStrings("B10 O50 A10 O10", try t.walk(.call, -1, &buf));
- try std.testing.expectEqualStrings("A10 O50 B10 O90", try t.walk(.call, 1, &buf));
-}
-
-test "JumpScope file: a file in two panes keeps to the pane first, then the file in the other pane" {
- // C is A's file in a second pane: C10 B10 A10 C50 A50.
- const t = try JumpsTest.init("CBACA");
- defer t.p.deinit();
- var buf: [128]u8 = undefined;
- // From A50: A10 in this pane, over the nearer C50; then none of A's
- // own is older, so the file's in C, C10, over B10.
- try std.testing.expectEqualStrings("A10 C10", try t.walk(.call, -1, &buf));
- // From C10 in C: C50, its own, then the file's newest, A50.
- try std.testing.expectEqualStrings("C50 A50", try t.walk(.call, 1, &buf));
-}
-
-test "Back and Forward take the same steps from Ctrl-o and Ctrl-i, the mouse's side buttons, the builtins and jumpBy" {
- for ([_]JumpsTest.Way{ .call, .key, .builtin, .mouse }) |way| {
+// The keys and builtins are test/behaviour/modes.zig's; a mouse's side
+// buttons have no /mousein bits.
+test "Back and Forward take the same steps from the mouse's side buttons and jumpBy" {
+ for ([_]JumpsTest.Way{ .call, .mouse }) |way| {
const t = try JumpsTest.init("BABABA");
defer t.p.deinit();
var buf: [128]u8 = undefined;
diff --git a/test/behaviour.zig b/test/behaviour.zig
index d9b15183..e19a847f 100644
--- a/test/behaviour.zig
+++ b/test/behaviour.zig
@@ -4,10 +4,12 @@
//! so a test sees the session as a 9P client does.
test {
_ = @import("behaviour/addresses.zig");
+ _ = @import("behaviour/builtins.zig");
_ = @import("behaviour/columns_and_tags.zig");
_ = @import("behaviour/edit.zig");
_ = @import("behaviour/event.zig");
_ = @import("behaviour/flags.zig");
+ _ = @import("behaviour/from_acme.zig");
_ = @import("behaviour/keys.zig");
_ = @import("behaviour/limits.zig");
_ = @import("behaviour/log.zig");
@@ -18,6 +20,7 @@ test {
_ = @import("behaviour/other_files.zig");
_ = @import("behaviour/panes.zig");
_ = @import("behaviour/placement.zig");
+ _ = @import("behaviour/repls.zig");
_ = @import("behaviour/root_ctl.zig");
_ = @import("behaviour/rules.zig");
_ = @import("behaviour/settings.zig");
diff --git a/test/behaviour/addresses.zig b/test/behaviour/addresses.zig
index a1474c3d..8e57ad9d 100644
--- a/test/behaviour/addresses.zig
+++ b/test/behaviour/addresses.zig
@@ -63,3 +63,114 @@ test "addresses: sel reads the selection, and a write to sel replaces it and is
try s.expect(body, "ab\ntwo\n");
try s.expect(sel, "ab");
}
+
+test "addresses: a malformed address is bad address syntax; on a pane with no text any address is refused as nothing to address" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const addr = s.at("/pane/{d}/addr", .{try s.focused()});
+ for ([_][]const u8{ "1x", "/(/", ",,x" }) |expr| {
+ try expectEqual(@as(u16, 22), try s.refused(addr, expr));
+ try std.testing.expect(s.said.len > 0);
+ }
+ _ = try s.refused(addr, "1x");
+ try std.testing.expectEqualStrings("bad address syntax", s.said);
+ // A terminal (as an image or a PDF): addr, dot and limit alike.
+ var t = try Session.initTerm(std.testing.allocator);
+ defer t.deinit();
+ const term = try t.focused();
+ for ([_][]const u8{ "addr", "dot", "limit" }) |file| for ([_][]const u8{ "1", "1x" }) |expr| {
+ try expectEqual(@as(u16, 22), try t.refused(t.at("/pane/{d}/{s}", .{ term, file }), expr));
+ try std.testing.expectEqualStrings("invalid address: this pane has no text to address", t.said);
+ };
+}
+
+test "addresses: a 9P write moves dot only as acme's textinsert does" {
+ // dot is `cd` of `abcdef\n` (2 4); two bytes go in at `at`.
+ for ([_][3]u32{
+ .{ 0, 4, 6 }, // before: shifted
+ .{ 2, 2, 6 }, // at its start: grown
+ .{ 3, 2, 6 }, // inside: grown
+ .{ 4, 2, 4 }, // at its end: left
+ .{ 6, 2, 4 }, // after: left
+ }) |c| {
+ var s = try Session.initFile(std.testing.allocator, "abcdef\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ try s.write(dot, "2 4");
+ try s.write(s.at("/pane/{d}/addr", .{n}), s.at("#{d}", .{c[0]}));
+ try s.write(s.at("/pane/{d}/data", .{n}), "XX");
+ try expectEqual(.{ c[1], c[2] }, try s.range(dot));
+ }
+ // A body append leaves dot, and a sel write after it replaces dot, not
+ // the text appended.
+ var s = try Session.initFile(std.testing.allocator, "abcdef\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ try s.write(dot, "2 4");
+ try s.write(s.at("/pane/{d}/body", .{n}), "more\n");
+ try expectEqual(.{ @as(u32, 2), @as(u32, 4) }, try s.range(dot));
+ try s.write(s.at("/pane/{d}/sel", .{n}), "YY");
+ try s.expect(s.at("/pane/{d}/body", .{n}), "abYYef\nmore\n");
+}
+
+test "addresses: a pair out of order or out of range is refused as the address form is, not clamped" {
+ var s = try Session.initFile(std.testing.allocator, "abcdef\n");
+ defer s.deinit();
+ const addr = s.at("/pane/{d}/addr", .{try s.focused()});
+ for ([_][2][]const u8{
+ .{ "5 2", "addresses out of order" },
+ .{ "#5,#2", "addresses out of order" },
+ .{ "2 99", "address out of range" },
+ .{ "#2,#99", "address out of range" },
+ }) |c| {
+ try expectEqual(@as(u16, 22), try s.refused(addr, c[0]));
+ try std.testing.expectEqualStrings(c[1], s.said);
+ }
+ try s.write(addr, "2 4");
+ try expectEqual(.{ @as(u32, 2), @as(u32, 4) }, try s.range(addr));
+}
+
+test "addresses: every address lands on a rune, and a combining mark and a lone \\r are places of their own" {
+ // e, U+0301 (two bytes, 1-2), x, \r, \n
+ var s = try Session.initFile(std.testing.allocator, "e\u{0301}x\r\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const addr = s.at("/pane/{d}/addr", .{n});
+ for ([_]struct { []const u8, u32, u32 }{
+ .{ "#1,#3", 1, 3 }, // the mark alone
+ .{ "#2", 1, 1 }, // inside it: back to its start
+ .{ "#4,#5", 4, 5 }, // the \r alone
+ .{ "1:2", 1, 1 }, // line:col the same
+ .{ "1:3", 1, 1 },
+ .{ "0/\xCC/", 1, 3 }, // a match inside a rune covers it
+ }) |c| {
+ try s.write(addr, c[0]);
+ try expectEqual(.{ c[1], c[2] }, try s.range(addr));
+ }
+ // Copied to dot, it reads back the same.
+ const dot = s.at("/pane/{d}/dot", .{n});
+ try s.write(addr, "#1,#3");
+ try s.write(dot, " 1 3 ");
+ try s.expect(dot, " 1 3 ");
+ try s.write(addr, "#4,#5");
+ try s.expect(s.at("/pane/{d}/xdata", .{n}), "\r");
+}
+
+test "addresses: truncating data or xdata deletes only the addressed range, so > data replaces it" {
+ var s = try Session.initFile(std.testing.allocator, "");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ for ([_][]const u8{ "data", "xdata" }) |file| {
+ try s.replace(body, "hello world\nsecond line\n");
+ try s.write(s.at("/pane/{d}/addr", .{n}), "#0,#5");
+ const h = try s.hold(s.at("/pane/{d}/{s}", .{ n, file }), 1);
+ try s.truncate(h);
+ try s.expect(body, " world\nsecond line\n");
+ try expectEqual(@as(u16, 0), try s.writeFid(h, "HOWDY"));
+ s.clunk(h);
+ try s.expect(body, "HOWDY world\nsecond line\n");
+ }
+}
diff --git a/test/behaviour/builtins.zig b/test/behaviour/builtins.zig
new file mode 100644
index 00000000..3c16a4a2
--- /dev/null
+++ b/test/behaviour/builtins.zig
@@ -0,0 +1,36 @@
+//! docs/typ/builtins.typ, the builtins' glossary.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "builtins: Mini maps a file of the pane's directory over pardes's own source of that name, in one pane, refreshed only when asked again" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "x\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try s.write("/look", s.at("{s}/a.txt\n", .{at}));
+ const a = try s.focused();
+ // The directory's one-line build.zig, one braille row, not pardes's.
+ try s.write(s.at("/pane/{d}/exec", .{a}), "Mini build.zig\n");
+ const mini = try s.focused();
+ try std.testing.expect(mini != a);
+ const body = s.at("/pane/{d}/body", .{mini});
+ try s.expect(body, "⠁\n");
+ const index = try s.read("/index");
+ try s.write(s.at("/pane/{d}/exec", .{mini}), "Mini build.zig\n");
+ try std.testing.expectEqual(mini, try s.focused());
+ try s.expect("/index", index);
+ // A snapshot: the file grown on disk shows only at the next Mini.
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "xx\n" });
+ try s.expect(body, "⠁\n");
+ try s.write(s.at("/pane/{d}/exec", .{mini}), "Mini build.zig\n");
+ try s.expect(body, "⠉\n");
+ try s.expect("/index", index);
+ // Save asks for a path; nothing is written for it.
+ try s.write(s.at("/pane/{d}/exec", .{mini}), "Save\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("ask {d} save path\n", .{mini})) != null);
+ try std.testing.expectEqual(@as(usize, 0), s.saved);
+}
diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig
index a1add750..b9e3b3f5 100644
--- a/test/behaviour/columns_and_tags.zig
+++ b/test/behaviour/columns_and_tags.zig
@@ -235,3 +235,64 @@ test "columns-and-tags: a refused Delcol changes nothing: no pane, no focus" {
try s.expect("/focus", focus);
try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "unsaved ") != null);
}
+
+/// Column `i`'s x and width, from /layout.
+fn columnBox(s: *Session, i: usize) !struct { usize, usize } {
+ var lines = std.mem.tokenizeScalar(u8, try s.read("/layout"), '\n');
+ for (0..i) |_| _ = lines.next();
+ var fields = std.mem.tokenizeScalar(u8, lines.next().?, ' ');
+ _ = fields.next(); // serial
+ _ = fields.next(); // index
+ return .{ try std.fmt.parseInt(usize, fields.next().?, 10), try std.fmt.parseInt(usize, fields.next().?, 10) };
+}
+
+test "columns-and-tags: a column tag lights the word under the mouse, is clicked and swept into, typed at its caret, and scrolls from its column's edge" {
+ var s = try Session.initFile(std.testing.allocator, "untouched\n");
+ defer s.deinit();
+ const file = try s.focused();
+ try s.write("/ctl", "Newcol\n");
+ try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n");
+ for (0..2) |i| {
+ const tag = s.at("/col/{d}/tag", .{try s.column(i)});
+ const left, const w = try columnBox(&s, i);
+ // Its text starts two cells into the column.
+ const x = left + 2;
+ const width = w - 2;
+ const plain = try s.bg(x, 1);
+ try s.write("/mousein", s.at("m {d} 1 0\n", .{x}));
+ const lit = try s.bg(x, 1);
+ try std.testing.expect(!std.mem.eql(u8, plain, lit));
+ try expectEqualStrings(plain, try s.bg(x + 4, 1)); // Tty, another word
+ // Pressed, the keyboard is on the tag, its caret where it was pressed.
+ try s.write("/mousein", s.at("m {d} 1 1\n", .{x}));
+ try s.expect("/focus", "");
+ try std.testing.expectEqual(.{ x, @as(usize, 1) }, (try s.cursor()).?);
+ // Swept over three cells: those and the caret's, normal mode's
+ // selection taking the cell under it, in the selection's colour.
+ try s.write("/mousein", s.at("m {d} 1 1\nm {d} 1 0\n", .{ x + 3, x + 3 }));
+ for (0..4) |k| try expectEqualStrings(lit, try s.bg(x + k, 1));
+ try std.testing.expect(!std.mem.eql(u8, lit, try s.bg(x + 4, 1)));
+ // A clicked tag is in normal mode: `i` types at its caret.
+ try s.keys("\u{F00D}iHelp ");
+ try std.testing.expect(std.mem.startsWith(u8, try s.read(tag), "Help New Tty"));
+ try std.testing.expectEqual(x + 5, (try s.cursor()).?[0]);
+ // A tag one short of its room: its caret at the end is drawn on the
+ // last cell, and one more letter scrolls the text, never the caret.
+ const as: [80]u8 = @splat('a');
+ const row = as[0 .. width - 1];
+ try s.replace(tag, row);
+ try s.keys("\u{F018}");
+ try std.testing.expectEqual(x + width - 1, (try s.cursor()).?[0]);
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), row) != null);
+ try s.keys("b");
+ try std.testing.expectEqual(x + width - 1, (try s.cursor()).?[0]);
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), s.at("{s}b", .{row[1..]})) != null);
+ try s.keys("\u{F00D}");
+ try std.testing.expectEqual(x, (try s.cursor()).?[0]);
+ // Scrolled back: the text drawn whole from its first cell again.
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), s.at("{s}b", .{row})) != null);
+ try s.keys("\x1b\x1b");
+ try s.write("/mousein", "m 0 23 0\n");
+ }
+ try s.expect(s.at("/pane/{d}/body", .{file}), "untouched\n");
+}
diff --git a/test/behaviour/edit.zig b/test/behaviour/edit.zig
index 3d1a731e..83b1b464 100644
--- a/test/behaviour/edit.zig
+++ b/test/behaviour/edit.zig
@@ -29,3 +29,31 @@ test "edit: a bad command inside an Edit block written whole is named, not the }
try std.testing.expect(std.mem.indexOf(u8, s.said, "z") != null);
try s.expect(s.at("/pane/{d}/body", .{n}), "abc\n");
}
+
+test "edit: Edit through a pane's ctl renames every foo in one undo step, and a failed one changes nothing" {
+ var s = try Session.initFile(std.testing.allocator, "foo x foo y foo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ const body = s.at("/pane/{d}/body", .{n});
+ try s.write(ctl, "Edit ,x/foo/c/foobar/\n");
+ try s.expect(body, "foobar x foobar y foobar\n");
+ try std.testing.expectEqual(@as(u16, 5), try s.refused(ctl, "Edit ,s/nothing/x/\n"));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "Edit: no substitution"));
+ try s.expect(body, "foobar x foobar y foobar\n");
+ // The whole rename is one undo step.
+ try s.write(ctl, "Undo");
+ try s.expect(body, "foo x foo y foo\n");
+}
+
+test "edit: Edit's p and = never fail for want of room for +Errors: the text is logged instead" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ s.detach();
+ try s.write("/ctl", "size 80 6\n");
+ const index = try s.read("/index");
+ try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Edit ,p\n");
+ const log = try s.read("/log");
+ try std.testing.expect(std.mem.indexOf(u8, log, " one\n") != null and std.mem.indexOf(u8, log, " two\n") != null);
+ try s.expect("/index", index); // the +Errors that had no room is gone
+}
diff --git a/test/behaviour/event.zig b/test/behaviour/event.zig
index 8aebe8f4..77a80e30 100644
--- a/test/behaviour/event.zig
+++ b/test/behaviour/event.zig
@@ -53,3 +53,19 @@ test "event: a refused Del written back through event fails that write, EIO, wit
try std.testing.expect(has(s.said, "Modified"));
_ = try s.read(s.at("/pane/{d}/ctl", .{n})); // still there
}
+
+test "event: a bad event record says what is wrong with it" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const event = try s.hold(s.at("/pane/{d}/event", .{try s.focused()}), 2);
+ defer s.clunk(event);
+ 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| {
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(event, c[0]));
+ try std.testing.expect(has(s.said, c[1]));
+ }
+}
diff --git a/test/behaviour/flags.zig b/test/behaviour/flags.zig
index 656d219f..ead267fe 100644
--- a/test/behaviour/flags.zig
+++ b/test/behaviour/flags.zig
@@ -40,3 +40,105 @@ test "flags: dirty, mark and scroll read and write the state acme kept behind ct
try t.expect(term_dirty, "0\n");
try std.testing.expectEqual(@as(u16, 22), try t.refused(term_dirty, "1"));
}
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+test "flags: Undo and Redo on a pane's ctl step its body through its edits, and say when there is none, counted" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ try s.write(body, "two\n");
+ try s.expect(body, "one\ntwo\n");
+ try s.write(ctl, "Undo");
+ try s.expect(body, "one\n");
+ try s.write(ctl, "Redo");
+ try s.expect(body, "one\ntwo\n");
+ // Nothing left: said, and the write still succeeds, as acme's is silent.
+ try s.write(ctl, "Redo");
+ try std.testing.expect(has(try s.read("/log"), "Redo: nothing to redo"));
+ try s.write(ctl, "Undo");
+ try s.write(ctl, "Undo");
+ try std.testing.expect(has(try s.read("/log"), "Undo: nothing to undo"));
+ // Said again word for word, it is that line counted, as err's are.
+ for (0..3) |_| try s.write(ctl, "Undo");
+ try std.testing.expect(has(try s.read("/log"), "Undo: nothing to undo (x4)\n"));
+}
+
+test "flags: dirty goes back to 0 when the text is the saved text again" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dirty = s.at("/pane/{d}/dirty", .{n});
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ try s.expect(dirty, "0\n");
+ try s.write(s.at("/pane/{d}/body", .{n}), "two\n");
+ try s.expect(dirty, "1\n");
+ try s.write(ctl, "Undo");
+ try s.expect(dirty, "0\n");
+ try s.write(ctl, "Redo");
+ try s.expect(dirty, "1\n");
+}
+
+test "flags: a > into an empty body is one undo step, as into any other" {
+ var s = try Session.initFile(std.testing.allocator, "");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ try s.replace(body, "fresh\n");
+ try s.expect(body, "fresh\n");
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n");
+ try s.expect(body, "");
+}
+
+test "flags: a write that changes nothing, an empty range deleted or a range replaced by itself, is no undo step and no new version" {
+ var s = try Session.initFile(std.testing.allocator, "abc\ndef\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ const addr = s.at("/pane/{d}/addr", .{n});
+ const data = s.at("/pane/{d}/data", .{n});
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ // One real change, so a step made after it would be the one undone.
+ try s.write(addr, "1");
+ try s.write(data, "abd\n");
+ const version = (try s.stat(body)).version;
+ // Each as a shell does it: `: > data` after an empty address, `echo
+ // abd > data` over the line it holds, and Edit's `s/d/d/`.
+ try s.write(addr, "#2,#2");
+ const h = try s.hold(data, 1);
+ try s.truncate(h);
+ s.clunk(h);
+ try s.write(addr, "1");
+ try s.write(data, "abd\n");
+ try s.write(ctl, "Edit ,s/d/d/\n");
+ try s.expect(body, "abd\ndef\n");
+ try std.testing.expectEqual(version, (try s.stat(body)).version);
+ try s.write(ctl, "Undo\n");
+ try s.expect(body, "abc\ndef\n");
+}
+
+test "flags: an open's writes in a row go in as one edit, seen by the next request" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ const version = (try s.stat(body)).version;
+ const h = try s.hold(body, 1);
+ for (0..100) |_| try std.testing.expectEqual(@as(u16, 0), try s.writeFid(h, "0123456789\n"));
+ try std.testing.expectEqual(@as(usize, 4 + 1100), (try s.read(body)).len);
+ try std.testing.expectEqual(version + 1, (try s.stat(body)).version);
+ s.clunk(h);
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n");
+ try s.expect(body, "one\n");
+ // data inserts at its address go on the same way.
+ try s.write(s.at("/pane/{d}/addr", .{n}), "#0");
+ const d = try s.hold(s.at("/pane/{d}/data", .{n}), 1);
+ _ = try s.writeFid(d, "a");
+ _ = try s.writeFid(d, "b");
+ s.clunk(d);
+ try s.expect(body, "abone\n");
+}
diff --git a/test/behaviour/from_acme.zig b/test/behaviour/from_acme.zig
new file mode 100644
index 00000000..62d4fc55
--- /dev/null
+++ b/test/behaviour/from_acme.zig
@@ -0,0 +1,28 @@
+//! docs/typ/reference.typ, Coming from acme <from-acme>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "from-acme: acme's words run as pardes's (Put is Save, Delete a Del that does not ask) or are refused, never run as commands" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ for ([_][]const u8{ "Snarf\n", "Indent\n", "Local\n", "Abort\n" }) |line| {
+ for ([_][]const u8{ s.at("/pane/{d}/ctl", .{n}), s.at("/pane/{d}/exec", .{n}) }) |path| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(path, line));
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "is not a pardes builtin") != null);
+ }
+ }
+ // Load is Restore: whatever it says, never acme's word refused.
+ _ = try s.refused(s.at("/pane/{d}/exec", .{n}), "Load /tmp/pardes-surely-no-dump.zon\n");
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "is not a pardes builtin") == null);
+ // Put saves, as Save does.
+ try s.write(s.at("/pane/{d}/name", .{n}), "/tmp/pardes-put.txt\n");
+ try s.write(s.at("/pane/{d}/exec", .{n}), "Put\n");
+ try std.testing.expectEqual(@as(usize, 1), s.saved);
+ // Delete closes an edited pane without asking.
+ const made = try s.newPane();
+ try s.write(s.at("/pane/{d}/name", .{made}), "/tmp/pardes-delete.txt\n");
+ try s.write(s.at("/pane/{d}/body", .{made}), "edited\n");
+ try s.write(s.at("/pane/{d}/ctl", .{made}), "Delete\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "/tmp/pardes-delete.txt") == null);
+}
diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig
index 3880b116..476504ce 100644
--- a/test/behaviour/keys.zig
+++ b/test/behaviour/keys.zig
@@ -226,3 +226,155 @@ test "keys: SPC j n and SPC j p walk Themes' rows, whole, never its section head
try s.keys("\t");
try std.testing.expectEqualStrings(names.items[brk - 1]["Theme ".len..], try setting(&s, "Theme"));
}
+
+test "keys: Save's prompt on a scratch starts from the scratch's directory, one slash after it" {
+ for ([_][2][]const u8{ .{ "/dír space/f.txt", " Save /dír space/zq" }, .{ "/f.txt", " Save /zq" } }) |c| {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}\n", .{c[0]}));
+ // New from the file's pane: a scratch in its directory.
+ try s.write(s.at("/pane/{d}/exec", .{n}), "New\n");
+ try std.testing.expect(try s.focused() != n);
+ try s.keys(":\tzq");
+ _ = try s.where(c[1]);
+ try s.keys("\x1b");
+ }
+}
+
+/// A B1 sweep from cell (x0, y0) to (x1, y1).
+fn sweep(s: *Session, x0: usize, y0: usize, x1: usize, y1: usize) !void {
+ try s.write("/mousein", s.at("m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 0\n", .{ x0, y0, x1, y1, x1, y1 }));
+}
+
+/// Whether any cell /screen draws is in `style`.
+fn drawsIn(s: *Session, style: []const u8) !bool {
+ for (try s.styles()) |cell| if (std.mem.eql(u8, cell, style)) return true;
+ return false;
+}
+
+test "keys: Ctrl-o and Ctrl-i jump back and forth, leaving no sweep drawn, a wrapped Unicode and tab one included" {
+ const ctl = "\u{F017}";
+ for ([_]struct { []const u8, []const u8, bool }{
+ .{ "alpha\nbravo\n", "alpha", false },
+ .{ "界\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n", "界", true },
+ }) |c| for ([_]bool{ false, true }) |reverse| {
+ const prefix, const first, const wrap = c;
+ var buf: [4096]u8 = undefined;
+ @memcpy(buf[0..prefix.len], prefix);
+ for (0..80) |i| @memcpy(buf[prefix.len + i * 27 ..][0..27], "unrelated destination text\n");
+ var s = try Session.initFile(std.testing.allocator, buf[0 .. prefix.len + 80 * 27]);
+ defer s.deinit();
+ const n = try s.focused();
+ s.detach();
+ try s.write("/ctl", "size 34 10\n");
+ try s.write("/ctl", if (wrap) "Wrap on\n" else "Wrap off\n");
+ const dot = s.at("/pane/{d}/dot", .{n});
+ const addr = s.at("/pane/{d}/addr", .{n});
+ // Two places in the jump list: line 60, then line 1.
+ try s.keys("60G1G");
+ const x, const y = try s.where(first);
+ const plain = (try s.styles())[0];
+ if (reverse) try sweep(&s, x + 3, y + 1, x + 1, y) else try sweep(&s, x + 1, y, x + 3, y + 1);
+ const screen = try s.screen();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0..std.mem.indexOfScalar(u8, screen, '\n').?]);
+ const swept = (try s.styles())[(y + 1) * cols + x];
+ try std.testing.expect(!std.mem.eql(u8, swept, plain));
+ try s.keys(ctl ++ "o");
+ try s.write(addr, "60");
+ const line60 = (try s.range(addr))[0];
+ try std.testing.expectEqual(.{ line60, line60 }, try s.range(dot));
+ try std.testing.expectError(error.NotOnScreen, s.where(first));
+ try std.testing.expect(!try drawsIn(&s, swept));
+ // A sweep made after Back is gone after Forward.
+ const x2, const y2 = try s.where("unrelated");
+ try sweep(&s, x2 + 1, y2, x2 + 3, y2 + 1);
+ try std.testing.expect(try drawsIn(&s, swept));
+ try s.keys(ctl ++ "i");
+ // Back where the sweep left the caret, nothing selected.
+ const q0, const q1 = try s.range(dot);
+ try std.testing.expect(q0 == q1 and q1 < line60);
+ _ = try s.where(first);
+ try std.testing.expect(!try drawsIn(&s, swept));
+ };
+}
+
+// Its rows whole and Tab running one are the Themes walk's test above.
+test "keys: SPC j n from the pane a Look gave the keyboard walks back into the command output" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ for ([_][]const u8{ "a.txt", "b.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try s.write("/look", s.at("{s}/a.txt\n", .{at}));
+ const a = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{a}), "Themes\n");
+ try s.keys(" jn");
+ const themes = try s.focused();
+ try std.testing.expect(themes != a);
+ const sel = s.at("/pane/{d}/sel", .{themes});
+ try s.expect(sel, "Theme orchard");
+ try s.write(s.at("/pane/{d}/exec", .{a}), "Look b.txt\n");
+ try std.testing.expect(try s.focused() != themes);
+ try s.keys(" jn");
+ try std.testing.expectEqual(themes, try s.focused());
+ try std.testing.expect(std.mem.startsWith(u8, try s.read(sel), "Theme "));
+}
+
+test "keys: SPC j n and SPC j p walk on from the place a Look's +Search listing chose, its keyboard left in the file" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "look-owner.txt", .data = "alpha target\nbeta target\ngamma target\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try s.write("/ctl", "LookWord list\n"); // the +Search listing is what is walked
+ try s.write("/look", s.at("{s}/look-owner.txt\n", .{at}));
+ const file = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{file}), "Look target\n");
+ try std.testing.expectEqual(file, try s.focused());
+ // The Look took the first; the walk goes on from it, and back.
+ try s.keys(" jn");
+ const results = try s.focused();
+ try std.testing.expect(results != file);
+ const sel = s.at("/pane/{d}/sel", .{results});
+ try s.expect(sel, "look-owner.txt:2:6-11");
+ try s.keys(" jp");
+ try std.testing.expectEqual(results, try s.focused());
+ try s.expect(sel, "look-owner.txt:1:7-12");
+}
+
+/// Screen row `row` as drawn.
+fn screenRow(s: *Session, row: usize) ![]const u8 {
+ var rows = std.mem.splitScalar(u8, try s.screen(), '\n');
+ for (0..row) |_| _ = rows.next();
+ return rows.next().?;
+}
+
+test "keys: a PDF in normal mode keeps : (its tag and back), SPC (a leader, cancelled by a key it has not) and / (a search prompt, Esc closing it)" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.lookFile("docs/design.pdf");
+ const body = (try s.cursor()).?;
+ const tag = (try s.where("docs/design.pdf [1/"))[1];
+ try s.keys(":");
+ const on_tag = (try s.cursor()).?[1];
+ try std.testing.expect(on_tag == tag or on_tag == tag + 1);
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal "));
+ try s.keys(":");
+ try std.testing.expectEqual(body, (try s.cursor()).?);
+ // The leader shows its keys at the row's end until one it has not.
+ try s.keys(" ");
+ try std.testing.expect(std.mem.endsWith(u8, std.mem.trimEnd(u8, try screenRow(&s, body[1]), " "), " SPC"));
+ try s.keys("!");
+ try std.testing.expect(!std.mem.endsWith(u8, std.mem.trimEnd(u8, try screenRow(&s, body[1]), " "), " SPC"));
+ try s.keys("/");
+ try std.testing.expect(!std.meta.eql(body, (try s.cursor()).?));
+ try std.testing.expectEqual(n, try s.focused());
+ try s.keys("\x1b");
+ try std.testing.expectEqual(body, (try s.cursor()).?);
+ try std.testing.expectEqual(n, try s.focused());
+}
diff --git a/test/behaviour/limits.zig b/test/behaviour/limits.zig
index 08c864eb..d84d4490 100644
--- a/test/behaviour/limits.zig
+++ b/test/behaviour/limits.zig
@@ -16,3 +16,25 @@ test "limits: a builtin that needs a pane says so when every slot is taken" {
try std.testing.expectEqualStrings("help: no space for a pane: 64 max", s.said);
try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "help: no space for a pane") != null);
}
+
+test "limits: a ctl line over 1 MiB is refused once, EINVAL, and its tail is not run as a line of its own" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const ctl = try s.hold(s.at("/pane/{d}/ctl", .{n}), 1);
+ const chunk: [4096]u8 = @splat('z');
+ var refused: usize = 0;
+ for (0..270) |_| {
+ const errno = try s.writeFid(ctl, &chunk);
+ if (errno != 0) {
+ refused += 1;
+ try std.testing.expectEqual(@as(u16, 22), errno);
+ }
+ }
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(ctl, "zzz\nEdit ,d\n"));
+ s.clunk(ctl);
+ try std.testing.expectEqual(@as(usize, 1), refused);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "unknown control message") == null);
+ // What came after the long line's newline ran.
+ try s.expect(s.at("/pane/{d}/body", .{n}), "");
+}
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig
index 98cab342..0d8056da 100644
--- a/test/behaviour/look_and_exec.zig
+++ b/test/behaviour/look_and_exec.zig
@@ -323,3 +323,393 @@ test "look-and-exec: a +PdfSections row's first number is the page: a section no
_ = try s.refused(look, "design.pdf:1:999\n");
try expectEqual(@as(usize, 2), try errs(&s));
}
+
+test "look-and-exec: a look's miss repeats the path whole up to 256 bytes, then gives up its middle to an ellipsis" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const long = "some/deeply/nested/directory/that/goes/on/and/on/with/a_rather_long_file_name.txt";
+ try s.write("/look", long ++ "\n");
+ try std.testing.expect(has(try s.read("/log"), "look: no match for \"" ++ long ++ "\"\n"));
+ const huge = std.mem.asBytes(&@as([150][2]u8, @splat("é".*))); // 300 bytes: its middle cut to fit 256, between characters
+ const kept = std.mem.asBytes(&@as([63][2]u8, @splat("é".*)));
+ try s.write("/look", huge ++ "\n");
+ try std.testing.expect(has(try s.read("/log"), "look: no match for \"" ++ kept ++ "…" ++ kept ++ "\"\n"));
+}
+
+test "look-and-exec: @p<serial>:<address> takes any sam address; a miss and an unknown serial are errs" {
+ var s = try Session.initFile(std.testing.allocator, "foo x foo y\nbar\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ const Case = struct { []const u8, u32, u32 };
+ for ([_]Case{
+ .{ "0/foo/", 0, 3 },
+ .{ "/foo/", 6, 9 },
+ .{ "#12,#15", 12, 15 },
+ .{ "$", 16, 16 },
+ .{ "1,2", 0, 16 },
+ // Backward, as in addr: from the dot's start, wrapping to the last.
+ .{ "?foo?", 6, 9 },
+ .{ "$-?y?", 10, 11 },
+ }) |c| {
+ try s.write("/look", s.at("@p{d}:{s}\n", .{ n, c[0] }));
+ try expectEqual(.{ c[1], c[2] }, try s.range(dot));
+ }
+ try s.write("/look", s.at("@p{d}:/zzqq/\n", .{n}));
+ try std.testing.expect(has(try s.read("/log"), ": no match for regexp"));
+ try s.expect("/look", "");
+ try s.write("/look", "@p999:/foo/\n");
+ try std.testing.expect(has(try s.read("/log"), "look: no pane @p999"));
+ try s.expect("/look", "");
+ // A line address to no pane is a miss too, not the active pane.
+ try s.write("/look", "@p77:1\n");
+ try std.testing.expect(has(try s.read("/log"), "look: no pane @p77"));
+ try s.expect("/look", "");
+}
+
+test "look-and-exec: a look at file:3:0 is refused as addr 3:0 is, a column counting from 1" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/addr", .{n}), "3:0"));
+ const by_addr = s.said;
+ try expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/look", .{n}), "/test.txt:3:0\n"));
+ try std.testing.expectEqualStrings(by_addr, s.said);
+ try s.write(s.at("/pane/{d}/look", .{n}), "/test.txt:3:1\n");
+}
+
+test "look-and-exec: a look of ./x, x or /abs/x that is not there is a miss: answered, the err logged" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const look = s.at("/pane/{d}/look", .{try s.focused()});
+ for ([_][]const u8{ "./zzq-nosuch.txt\n", "zzq-nosuch.txt\n", "/zzq-nosuch.txt\n" }) |line| try s.write(look, line);
+ try std.testing.expect(has(try s.read("/log"), "look: ./zzq-nosuch.txt: no such file"));
+}
+
+test "look-and-exec: a look at a ./ or ../ name that is not there is a miss naming the file; a plain one is looked for as text" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.createDirPath(std.testing.io, "many");
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/many/a.txt\n", .{dir}));
+ for ([_][]const u8{ "./zz.txt", "../zz.txt" }) |name| {
+ try s.write(s.at("/pane/{d}/look", .{n}), s.at("{s}\n", .{name}));
+ try std.testing.expect(has(try s.read("/log"), s.at("look: {s}: no such file", .{name})));
+ }
+ try s.write(s.at("/pane/{d}/look", .{n}), "zz.txt\n");
+ try std.testing.expect(has(try s.read("/log"), "look: no match for \"zz.txt\""));
+}
+
+test "look-and-exec: a look at file:addr whose file is not there is one miss, quoting what was written, in a terminal too" {
+ var s = try Session.initTerm(std.testing.allocator);
+ defer s.deinit();
+ const look = s.at("/pane/{d}/look", .{try s.focused()});
+ const before = try errs(&s);
+ for ([_][]const u8{ "zzq:#3", "zzq:2", "zzq:/re/" }) |written| {
+ try s.write(look, s.at("{s}\n", .{written}));
+ try expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/log"), s.at("look: no match for \"{s}\"\n", .{written})));
+ }
+ try expectEqual(before + 3, try errs(&s));
+}
+
+test "look-and-exec: a builtin that needs its argument, written bare to an exec, is EINVAL as through ctl" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{try s.focused()}), "/tagexec" }) |path| {
+ try expectEqual(@as(u16, 22), try s.refused(path, "Mount\n"));
+ try std.testing.expectEqualStrings("wrong #args in control message \"Mount\"", s.said);
+ }
+}
+
+test "look-and-exec: a builtin that takes no argument, written with one to an exec, is refused wrong #args, as at a ctl" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{try s.focused()}) }) |path| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| {
+ try expectEqual(@as(u16, 22), try s.refused(path, line));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "wrong #args in control message"));
+ };
+}
+
+/// A fresh directory's absolute path, kept until deinit.
+fn tmpPath(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 {
+ var buf: [4096]u8 = undefined;
+ return s.at("{s}", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]});
+}
+
+test "look-and-exec: a look opens spaced paths and locations without editing the source pane" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "two words.zig", .data = "first\nsecond\nthird\n" });
+ var s = try Session.initFile(std.testing.allocator, "source stays intact\n");
+ defer s.deinit();
+ const path = s.at("{s}/two words.zig", .{try tmpPath(&s, &tmp)});
+ const source = try s.focused();
+ const ctl = try s.read(s.at("/pane/{d}/ctl", .{source}));
+ try s.write(s.at("/pane/{d}/dot", .{source}), "3 3");
+ try s.write(s.at("/pane/{d}/look", .{source}), s.at("{s}:2:3\n", .{path}));
+ const opened = try s.focused();
+ try std.testing.expect(opened != source);
+ try s.expect(s.at("/pane/{d}/name", .{opened}), s.at("{s}\n", .{path}));
+ try s.expect(s.at("/pane/{d}/body", .{opened}), "first\nsecond\nthird\n");
+ try expectEqual(@as(u32, 8), (try s.range(s.at("/pane/{d}/dot", .{opened})))[0]); // line 2, column 3
+ // The source: its text, its undo steps and its cursor as they were.
+ try s.expect(s.at("/pane/{d}/body", .{source}), "source stays intact\n");
+ const after = try s.read(s.at("/pane/{d}/ctl", .{source}));
+ try std.testing.expectEqualStrings(ctl[0..60], after[0..60]);
+ var fields = std.mem.tokenizeScalar(u8, after, ' ');
+ for (0..8) |_| _ = fields.next();
+ try std.testing.expectEqualStrings("0", fields.next().?); // still no undo step
+ try expectEqual(.{ @as(u32, 3), @as(u32, 3) }, try s.range(s.at("/pane/{d}/dot", .{source})));
+ try s.expect("/look", s.at("{d}\n", .{opened}));
+ // From the root, with the source focused: the same pane, moved.
+ try s.write("/focus", s.at("{d}\n", .{source}));
+ try s.write("/look", s.at("{s}:3:2\n", .{path}));
+ try expectEqual(opened, try s.focused());
+ try expectEqual(@as(u32, 14), (try s.range(s.at("/pane/{d}/dot", .{opened})))[0]); // line 3, column 2
+ try s.expect("/look", s.at("{d}\n", .{opened}));
+}
+
+test "look-and-exec: a look validates the whole batch before opening virtual files" {
+ var s = try Session.initFile(std.testing.allocator, "source\n");
+ defer s.deinit();
+ const source = try s.focused();
+ const look = s.at("/pane/{d}/look", .{source});
+ const index = try s.read("/index");
+ for ([_][]const u8{ "/virtual/index\x00ignored", "/virtual/index\n/virtual/\x01index\n" }) |invalid| {
+ try expectEqual(@as(u16, 22), try s.refused(look, invalid));
+ try s.expect("/index", index);
+ try expectEqual(source, try s.focused());
+ try s.expect(s.at("/pane/{d}/body", .{source}), "source\n");
+ }
+ try s.write(look, "/n/self/index\n");
+ const opened = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{opened}), "/virtual/index\n");
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/body", .{opened})), "/test.txt"));
+ try s.expect(s.at("/pane/{d}/body", .{source}), "source\n");
+}
+
+test "look-and-exec: status reads the editor, and look and exec validate whole batches" {
+ var s = try Session.initFile(std.testing.allocator, "Msg root\n");
+ defer s.deinit();
+ const status = try s.read("/status");
+ var rows = std.mem.tokenizeScalar(u8, status, '\n');
+ try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "pid "));
+ try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "version "));
+ try std.testing.expectEqualStrings(s.at("panes {d}", .{lines(try s.read("/index"))}), rows.next().?);
+ try std.testing.expect(rows.next() == null);
+ const st = try s.stat("/status");
+ try expectEqual(@as(u64, status.len), st.size);
+ try expectEqual(@as(u16, 0o444), st.mode & 0o777);
+ try expectEqual(@as(u16, 1), try s.refused("/status", "anything\n"));
+ try s.expect("/exec", "");
+ const index = try s.read("/index");
+ for ([_][]const u8{ "Msg a\x00b", "Msg x\nMsg \x01y\n" }) |invalid| {
+ try expectEqual(@as(u16, 22), try s.refused("/exec", invalid));
+ try s.expect("/index", index);
+ }
+ // An empty write is a no-op, not a command.
+ try s.write("/exec", "\n \n");
+ try s.expect("/exec", "");
+ try s.expect("/status", status);
+ const n = try s.focused();
+ try s.write("/exec", "Msg hello there\n");
+ try std.testing.expect(has(try s.read("/log"), s.at("msg {d} hello there\n", .{n})));
+ try s.expect("/exec", s.at("{d}\n", .{n}));
+ try s.write("/look", "/virtual/index\n");
+ const opened = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{opened}), "/virtual/index\n");
+ try s.expect("/look", s.at("{d}\n", .{opened}));
+ try s.write("/exec", "New\n");
+ const made = try s.focused();
+ try std.testing.expect(made != opened);
+ try s.expect("/exec", s.at("{d}\n", .{made}));
+}
+
+test "look-and-exec: a look at a file it may not read fails the write naming the file" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "locked.txt", .data = "secret\n", .flags = .{ .permissions = .fromMode(0o000) } });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const path = s.at("{s}/locked.txt", .{try tmpPath(&s, &tmp)});
+ if (try s.refused("/look", s.at("{s}\n", .{path})) == 0) return error.SkipZigTest; // root reads anything
+ try std.testing.expectEqualStrings(s.at("look: {s}: permission denied", .{path}), s.said);
+}
+
+test "look-and-exec: a look line's trailing colon is dropped, and a look whose address fails never leaves its file open" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const before = lines(try s.read("/index"));
+ // Failing addresses: nothing opened, the write still answered.
+ for ([_][]const u8{ s.at("{s}/a.txt:/nomatch/\n", .{dir}), s.at("{s}/a.txt:9:\n", .{dir}) }) |line| {
+ _ = try s.refused("/look", line);
+ try expectEqual(before, lines(try s.read("/index")));
+ }
+ // `a.txt:2:3:` is `a.txt:2:3`: it opens there.
+ try s.write("/look", s.at("{s}/a.txt:2:3:\n", .{dir}));
+ try expectEqual(before + 1, lines(try s.read("/index")));
+ const opened = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{opened}), s.at("{s}/a.txt\n", .{dir}));
+ try expectEqual(@as(u32, 6), (try s.range(s.at("/pane/{d}/dot", .{opened})))[0]);
+}
+
+test "look-and-exec: a look that misses file:/re/ names the file, and is logged as its pane's" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "alpha\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const first = try s.focused();
+ try s.write("/look", s.at("{s}/f.txt\n", .{dir}));
+ const f = try s.focused();
+ _ = try s.refused(s.at("/pane/{d}/look", .{first}), s.at("{s}/f.txt:/zzqq/\n", .{dir}));
+ try std.testing.expect(has(try s.read("/log"), s.at("err {d} look: {s}/f.txt: no match for regexp", .{ f, dir })));
+}
+
+test "look-and-exec: a look that goes to another pane leaves the looking pane's dot alone" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f one\nf two\n" });
+ var s = try Session.initFile(std.testing.allocator, "alpha bravo\ncharlie\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const source = try s.focused();
+ const other = try s.newPane();
+ try s.write(s.at("/pane/{d}/body", .{other}), "one\ntwo\nthree\n");
+ for ([_][]const u8{ s.at("@p{d}:2\n", .{other}), s.at("@p{d}:/three/\n", .{other}), s.at("{s}/f.txt:2\n", .{dir}) }) |line| {
+ try s.write(s.at("/pane/{d}/dot", .{source}), "6 11");
+ try s.write(s.at("/pane/{d}/look", .{source}), line);
+ try std.testing.expect(try s.focused() != source);
+ try expectEqual(.{ @as(u32, 6), @as(u32, 11) }, try s.range(s.at("/pane/{d}/dot", .{source})));
+ }
+}
+
+test "look-and-exec: a looked word is found in its own pane, next place after the dot, wrapping, and opens no pane; LookWord list lists it in +Search" {
+ var s = try Session.initFile(std.testing.allocator, "foo x foo y\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const look = s.at("/pane/{d}/look", .{n});
+ const index = try s.read("/index");
+ for ([_]u32{ 0, 6, 0 }) |at| {
+ try s.write(look, "foo\n");
+ try expectEqual(.{ at, at + 3 }, try s.range(s.at("/pane/{d}/dot", .{n})));
+ }
+ try s.expect("/index", index);
+ try s.write("/ctl", "LookWord list\n");
+ try s.write(look, "foo\n");
+ try std.testing.expect(lines(try s.read("/index")) > lines(index));
+ // ...and look reads back that +Search pane, where the places are.
+ const search = try paneNamed(&s, "/+Search");
+ try std.testing.expect(has(try s.read(look), s.at("{d}\n", .{search})));
+}
+
+test "look-and-exec: a second LookWord list look in a directory refills its +Search rather than stacking another" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "words.txt", .data = "alpha beta\nalpha beta\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/words.txt\n", .{try tmpPath(&s, &tmp)}));
+ try s.write(s.at("/pane/{d}/exec", .{n}), "Get\n");
+ try s.write("/ctl", "LookWord list\n");
+ try s.write(s.at("/pane/{d}/look", .{n}), "alpha\n");
+ const first = try paneNamed(&s, "/+Search");
+ try s.write(s.at("/pane/{d}/look", .{n}), "beta\n");
+ try expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/index"), "/+Search "));
+ try expectEqual(first, try paneNamed(&s, "/+Search"));
+ // Refilled with beta's places (columns 7-10), not alpha's.
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/body", .{first})), "words.txt:1:7-10\n"));
+}
+
+test "look-and-exec: `@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`" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const look = s.at("/pane/{d}/look", .{n});
+ const before = try errs(&s);
+ try s.write(look, s.at("@p{d}:\n", .{n}));
+ try expectEqual(before, try errs(&s));
+ try s.write(look, ":99999\n");
+ try s.write(look, "/test.txt:99999\n");
+ try std.testing.expect(has(try s.read("/log"), "/test.txt:99999 has no line 99999 (x2)\n"));
+}
+
+test "look-and-exec: an exec line over the command limit fails the write and says the limit; a builtin's may be longer" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const long = "echo " ++ &@as([1024]u8, @splat('y')) ++ "\n";
+ try expectEqual(@as(u16, 22), try s.refused("/exec", long));
+ try std.testing.expectEqualStrings("invalid command line: a command line is at most 1024 bytes", s.said);
+ try std.testing.expect(has(try s.read("/log"), s.at("err {d} exec: invalid command line: a command line is at most 1024 bytes", .{n})));
+ _ = try s.refused("/exec", "echo a\x01b\n");
+ try std.testing.expectEqualStrings("invalid command line: it holds a control character (or DEL) other than a tab", s.said);
+ try std.testing.expect(has(try s.read("/log"), s.at("err {d} exec: invalid command line: it holds", .{n})));
+ try s.write("/exec", "Msg " ++ &@as([1100]u8, @splat('z')) ++ "\n");
+}
+
+test "look-and-exec: a builtin that fails through exec, tagexec or a column's exec fails the write with one err and no msg" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ // Another failure first: the pane's `new` is logged after it.
+ _ = try s.refused("/ctl", "Unmount yyy\n");
+ for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{n}), "/tagexec", s.at("/col/{d}/exec", .{try s.column(0)}) }) |path| {
+ try std.testing.expect(try s.refused(path, "Unmount zzz\n") != 0);
+ try std.testing.expect(has(s.said, "Unmount: no such mount zzz"));
+ }
+ const log = try s.read("/log");
+ try std.testing.expect(!has(log, "msg "));
+ // The root's exec ran at the pane, so its err and the pane's exec's are
+ // the same record, counted.
+ try expectEqual(@as(usize, 3), std.mem.count(u8, log, "Unmount: no such mount zzz"));
+ try std.testing.expect(has(log, "mount zzz (x2)"));
+ // A control character is refused with its reason.
+ try expectEqual(@as(u16, 22), try s.refused("/exec", "Msg a\x01b\n"));
+ try std.testing.expectEqualStrings("invalid command line: it holds a control character (or DEL) other than a tab", s.said);
+ // A look miss: one err, no msg; the same miss again is that record counted.
+ try s.write("/look", "zzqqnotthere\n");
+ try std.testing.expect(has(try s.read("/log"), "look: no match for \"zzqqnotthere\""));
+ try std.testing.expect(!has(try s.read("/log"), "msg "));
+ try s.write("/look", "zzqqnotthere\n");
+ try std.testing.expect(has(try s.read("/log"), "look: no match for \"zzqqnotthere\" (x2)\n"));
+}
+
+test "look-and-exec: a served-tree pane spoils no Grep, and Look . from a gone directory is ENOENT, not /virtual/" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "hit.txt", .data = "needle here\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const first = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{first}), s.at("{s}/other.txt\n", .{try tmpPath(&s, &tmp)}));
+ // A pane of the served tree, and one named its root, whose directory is `/`.
+ try s.write(s.at("/pane/{d}/name", .{try s.newPane()}), "/virtual/index\n");
+ try s.write(s.at("/pane/{d}/name", .{try s.newPane()}), "/virtual\n");
+ try s.write(s.at("/pane/{d}/exec", .{first}), "Grep needle\n");
+ // `.` from a pane whose directory is gone.
+ const gone = try s.newPane();
+ try s.write(s.at("/pane/{d}/name", .{gone}), "/tmp/pardes-no-such-dir-zz/f.txt\n");
+ try expectEqual(@as(u16, 2), try s.refused(s.at("/pane/{d}/look", .{gone}), ".\n"));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "look: /tmp/pardes-no-such-dir-zz: no such directory"));
+}
+
+test "look-and-exec: a pane's tagexec runs a word as a click in its tag, and reads back what it touched" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const tagexec = s.at("/pane/{d}/tagexec", .{n});
+ try s.write(tagexec, "Msg from the tag\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "from the tag") != null);
+ try s.expect(tagexec, s.at("{d}\n", .{n}));
+}
diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig
index 06bcac98..ba792086 100644
--- a/test/behaviour/modes.zig
+++ b/test/behaviour/modes.zig
@@ -101,3 +101,385 @@ test "modes: Esc back into a file leaves its view where it was, and a look centr
const drawn_at = line - try topLine(&s, "/test.txt");
try std.testing.expect(drawn_at + 1 >= rows / 2 and drawn_at <= rows / 2 + 1);
}
+
+/// Three panes named /a.txt (left column), /b.txt over /c.txt (right),
+/// the keyboard on /a.txt; their serials.
+fn threePanes(s: *Session) ![3]u32 {
+ const a = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{a}), "/a.txt\n");
+ try s.write("/ctl", "Newcol\n");
+ try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n");
+ const b = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{b}), "New\n");
+ const c = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{b}), "/b.txt\n");
+ try s.write(s.at("/pane/{d}/name", .{c}), "/c.txt\n");
+ try s.write("/focus", s.at("{d}\n", .{a}));
+ return .{ a, b, c };
+}
+
+/// The panes whose tag (`name Save`) is drawn in `lit`, the outline's colour.
+fn outlined(s: *Session, lit: []const u8, names: []const []const u8) ![]const u8 {
+ var found: []const u8 = "";
+ for (names) |name| {
+ const x, const y = try s.where(s.at("{s} Save", .{name}));
+ if (std.mem.eql(u8, lit, try s.bg(x, y))) found = s.at("{s}{s}", .{ found, name });
+ }
+ return found;
+}
+
+test "modes: Ctrl-w outlines a pane, h j k l move the outline, and Enter, Esc, : or a pane's letter gives it the keyboard" {
+ var s = try Session.initFile(std.testing.allocator, "left\n");
+ defer s.deinit();
+ const a, const b, const c = try threePanes(&s);
+ const names = &[_][]const u8{ "/a.txt", "/b.txt", "/c.txt" };
+ try s.keys("\x17");
+ const x, const y = try s.where("/a.txt Save");
+ const lit = try s.bg(x, y);
+ try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names));
+ // Each pane's box shows its letter: the left column's is a.
+ try std.testing.expectEqualStrings("a /a.txt", (try s.screen())[y * 81 ..][0.."a /a.txt".len]);
+ try s.keys("l");
+ try std.testing.expectEqualStrings("/b.txt", try outlined(&s, lit, names));
+ try s.keys("j");
+ try std.testing.expectEqualStrings("/c.txt", try outlined(&s, lit, names));
+ try expectEqual(a, try s.focused());
+ try s.keys("\n");
+ try expectEqual(c, try s.focused());
+ try std.testing.expectEqualStrings("", try outlined(&s, lit, names));
+ // SPC w enters it too, and Esc leaves it on the outlined pane.
+ try s.keys(" wh\x1b");
+ try expectEqual(a, try s.focused());
+ // Other keys change nothing.
+ try s.keys("\x17!");
+ try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names));
+ try s.keys("\x1b");
+ // `:` gives the outlined pane's tag the keyboard.
+ try s.keys("\x17l:");
+ try expectEqual(b, try s.focused());
+ try expectEqual((try s.where("/b.txt Save"))[1], (try s.cursor()).?[1]);
+ try s.keys("\x1b");
+ // A letter goes straight there.
+ try s.keys("\x17a");
+ try expectEqual(a, try s.focused());
+ try std.testing.expectEqualStrings("", try outlined(&s, lit, names));
+}
+
+fn listed(s: *Session, n: u32) !bool {
+ var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n');
+ while (rows.next()) |row| if (std.mem.startsWith(u8, row, s.at("{d} ", .{n}))) return true;
+ return false;
+}
+
+test "modes: in window mode d deletes the outlined pane, asking k or j between two, c collapses it, and the mode stays on" {
+ var s = try Session.initFile(std.testing.allocator, "top\n");
+ defer s.deinit();
+ // The neighbours below are what is under test: each New right under its asker.
+ try s.write("/ctl", "Placement pardes\n");
+ const top = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{top}), "New\n");
+ const mid = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{mid}), "New\n");
+ const low = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{mid}), "/mid\n");
+ try s.write(s.at("/pane/{d}/name", .{low}), "/low\n");
+ const names = &[_][]const u8{ "/test.txt", "/mid", "/low" };
+ const row_top = (try s.where("/test.txt Save"))[1];
+ const row_mid = (try s.where("/mid Save"))[1];
+ const row_low = (try s.where("/low Save"))[1];
+ // From the bottom pane, the outline up to the middle one.
+ const mx, const my = try s.where("/mid Save");
+ const plain = try s.bg(mx, my);
+ try s.keys("\x17k");
+ const lit = try s.bg(mx, my);
+ try std.testing.expect(!std.mem.eql(u8, plain, lit));
+ try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names));
+ // c folds it to its tag and back, the mode staying.
+ try s.keys("c");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") != null);
+ try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names));
+ try s.keys("c");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") == null);
+ try expectEqual(row_low, (try s.where("/low Save"))[1]);
+ // d between two panes asks, as SPC d does; Esc takes it back, the
+ // outline where it was.
+ try s.keys("d");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("ask {d} del k j\n", .{mid})) != null);
+ try s.keys("\x1b");
+ try std.testing.expect(try listed(&s, mid));
+ try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names));
+ // j: the pane below takes the rows, and the outline goes with them.
+ try s.keys("dj");
+ try std.testing.expect(!try listed(&s, mid));
+ try expectEqual(row_top, (try s.where("/test.txt Save"))[1]);
+ try expectEqual(row_mid, (try s.where("/low Save"))[1]);
+ try std.testing.expectEqualStrings("/low", try outlined(&s, lit, &.{ "/test.txt", "/low" }));
+ // With one neighbour nothing is asked: d closes it, the outline on the
+ // pane that grew.
+ try s.keys("d");
+ try std.testing.expect(!try listed(&s, low));
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("ask {d} ", .{low})) == null);
+ try std.testing.expectEqualStrings("/test.txt", try outlined(&s, lit, &.{"/test.txt"}));
+ // Enter leaves the mode on it.
+ try s.keys("\n");
+ try expectEqual(top, try s.focused());
+ try std.testing.expectEqualStrings("", try outlined(&s, lit, &.{"/test.txt"}));
+}
+
+test "modes: window keys walk from a pane up through its column's tag and the workspace's, across, and back down" {
+ var s = try Session.initFile(std.testing.allocator, "body\n");
+ defer s.deinit();
+ const a = try s.focused();
+ try s.write("/ctl", "Newcol\n");
+ try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n");
+ try s.write("/focus", s.at("{d}\n", .{a}));
+ const right = 40; // two columns on 80 cells: the right one's first
+ // Up from the top pane: its column's tag, in normal mode (w moves).
+ try s.keys("\x17k");
+ try s.expect("/focus", "");
+ const x0, const y0 = (try s.cursor()).?;
+ try expectEqual(@as(usize, 1), y0);
+ try std.testing.expect(x0 < right);
+ const tag = s.at("/col/{d}/tag", .{try s.column(0)});
+ const words = try s.read(tag);
+ try s.keys("w");
+ try s.expect(tag, words);
+ const remembered = (try s.cursor()).?;
+ try std.testing.expect(remembered[0] > x0);
+ // Across to the right column's tag, and back to where the caret was.
+ try s.keys("\x17l");
+ try std.testing.expect((try s.cursor()).?[0] >= right);
+ try s.keys("\x17h");
+ try expectEqual(remembered, (try s.cursor()).?);
+ // Up again: the workspace tag; down, the column's, then the pane.
+ try s.keys("\x17k");
+ try expectEqual(@as(usize, 0), (try s.cursor()).?[1]);
+ try s.keys("\x17j");
+ try expectEqual(@as(usize, 1), (try s.cursor()).?[1]);
+ try s.keys("\x17j");
+ try expectEqual(a, try s.focused());
+ // `:` in a column's tag is the way back to the body.
+ try s.keys("\x17k:");
+ try expectEqual(a, try s.focused());
+ try expectEqual((try s.where("body"))[1], (try s.cursor()).?[1]);
+ try s.expect(s.at("/pane/{d}/body", .{a}), "body\n");
+}
+
+/// The jump tests' session: a pane a letter of `order`, A and B each a file
+/// of 100 lines, C a Zerox of A, O the +Help output (no file behind it),
+/// and the jumplist `order`, a letter a place, each letter's n-th place its
+/// line 1 + 40n ("ABABA" is A1 B1 A41 B41 A81): each made by moving its
+/// pane's dot there and giving it the keyboard, as a jump does (a new
+/// pane's first, where it opens). The shell the session started with is
+/// closed after, its places with it.
+const Jumps = struct {
+ s: Session,
+ ids: [4]u32 = @splat(0),
+
+ const letters = "ABCO";
+
+ fn init(order: []const u8) !Jumps {
+ var t: Jumps = .{ .s = try Session.initTerm(std.testing.allocator) };
+ errdefer t.s.deinit();
+ const s = &t.s;
+ const shell = try s.focused();
+ var seen: [4]u32 = @splat(0);
+ for (order) |letter| {
+ const which = std.mem.indexOfScalar(u8, letters, letter).?;
+ if (t.ids[which] == 0) t.ids[which] = switch (letter) {
+ 'O' => o: {
+ try s.write(s.at("/pane/{d}/exec", .{shell}), "Help\n");
+ break :o try s.focused();
+ },
+ else => made: {
+ // C is A's twin, and A C's when C came first.
+ const twin = t.ids[if (letter == 'A') 2 else if (letter == 'C') 0 else 1];
+ if (letter != 'B' and twin != 0) {
+ try s.write(s.at("/pane/{d}/exec", .{twin}), "Zerox\n");
+ break :made try s.focused();
+ }
+ const n = try s.newPane();
+ try s.write(s.at("/pane/{d}/name", .{n}), if (letter == 'B') "/b.txt\n" else "/a.txt\n");
+ try s.write(s.at("/pane/{d}/body", .{n}), std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))));
+ break :made n;
+ },
+ };
+ const n = t.ids[which];
+ try s.write(s.at("/pane/{d}/addr", .{n}), s.at("{d}\n", .{1 + 40 * seen[which]}));
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "dot=addr\n");
+ try s.write("/focus", s.at("{d}\n", .{n}));
+ seen[which] += 1;
+ }
+ try s.write(s.at("/pane/{d}/ctl", .{shell}), "delete\n");
+ return t;
+ }
+
+ /// Where the keyboard is: its pane's letter and the dot's line, `A50`.
+ fn here(t: *Jumps) ![]const u8 {
+ const s = &t.s;
+ const n = try s.focused();
+ const at, _ = try s.range(s.at("/pane/{d}/dot", .{n}));
+ const body = try s.read(s.at("/pane/{d}/body", .{n}));
+ const which = std.mem.indexOfScalar(u32, &t.ids, n).?;
+ return s.at("{c}{d}", .{ letters[which], std.mem.count(u8, body[0..at], "\n") + 1 });
+ }
+
+ const Way = enum { key, leader, builtin };
+
+ /// Steps back or on until the list ends that way, as it says; the
+ /// places landed on, "A50 A10 B10".
+ fn walk(t: *Jumps, way: Way, back: bool) ![]const u8 {
+ const s = &t.s;
+ var out: []const u8 = "";
+ for (0..64) |_| {
+ const before = try t.here();
+ switch (way) {
+ .key => try s.keys(if (back) "\x0f" else "\u{F017}i"),
+ .leader => try s.keys(if (back) " jo" else " ji"),
+ .builtin => try s.write("/exec", if (back) "Back\n" else "Forward\n"),
+ }
+ const now = try t.here();
+ if (std.mem.eql(u8, before, now)) break;
+ out = if (out.len == 0) now else s.at("{s} {s}", .{ out, now });
+ } else return error.NoEnd;
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), if (back) "nothing further back" else "nothing further on") != null);
+ return out;
+ }
+};
+
+test "modes: Ctrl-o keeps to the focused file (JumpScope file), A41 then A1, and leaves it only once it runs out that way; Ctrl-i mirrors it" {
+ var t = try Jumps.init("BABABA");
+ defer t.s.deinit();
+ try std.testing.expect(std.mem.indexOf(u8, try t.s.read("/ctl"), "\nJumpScope file\n") != null);
+ // B81, B41 passed over, kept in their places: A has nothing older than
+ // A1, so the step after it is the nearest place of any file, B1.
+ try std.testing.expectEqualStrings("A41 A1 B1", try t.walk(.key, true));
+ // Forward is the mirror, from B1 in B: B's own places first, then A81,
+ // the newest, where the Backs started.
+ try std.testing.expectEqualStrings("B41 B81 A81", try t.walk(.key, false));
+}
+
+test "modes: Ctrl-i retraces a run of Ctrl-o inside one file step for step, back to where it began" {
+ var t = try Jumps.init("ABABA");
+ defer t.s.deinit();
+ // A1 B1 A41 B41 A81 from A81: nothing older than A1 at all.
+ try std.testing.expectEqualStrings("A41 A1", try t.walk(.key, true));
+ try std.testing.expectEqualStrings("A41 A81", try t.walk(.key, false));
+ // One back, one on: the same place, whichever were passed over.
+ try t.s.keys("\x0f");
+ try std.testing.expectEqualStrings("A41", try t.here());
+ try t.s.keys("\u{F017}i");
+ try std.testing.expectEqualStrings("A81", try t.here());
+ // And the steps made no places of their own.
+ try std.testing.expectEqualStrings("A41 A1", try t.walk(.key, true));
+}
+
+test "modes: with JumpScope all, Ctrl-o and Ctrl-i take every place in the order it was jumped to, and bare JumpScope is file again" {
+ var t = try Jumps.init("ABABA");
+ defer t.s.deinit();
+ try t.s.write("/ctl", "JumpScope all\n");
+ try std.testing.expectEqualStrings("B41 A41 B1 A1", try t.walk(.key, true));
+ try std.testing.expectEqualStrings("B1 A41 B41 A81", try t.walk(.key, false));
+ try t.s.write("/ctl", "JumpScope\n");
+ try std.testing.expect(std.mem.indexOf(u8, try t.s.read("/ctl"), "\nJumpScope file\n") != null);
+}
+
+test "modes: from a pane with no file, Ctrl-o and Ctrl-i step through every place" {
+ var t = try Jumps.init("OAOBO");
+ defer t.s.deinit();
+ // O81 keeps to nothing: B1, the next older of all. From B, nothing of
+ // B is older, so O41; from O, A1; from A, O1.
+ try std.testing.expectEqualStrings("B1 O41 A1 O1", try t.walk(.key, true));
+ try std.testing.expectEqualStrings("A1 O41 B1 O81", try t.walk(.key, false));
+}
+
+test "modes: Ctrl-o in a file shown in two panes keeps to its own pane first, then the file in the other" {
+ // C is A's file in a second pane: C1 B1 A1 C41 A41.
+ var t = try Jumps.init("CBACA");
+ defer t.s.deinit();
+ // From A41: A1 in this pane, over the nearer C41; then none of A's own
+ // is older, so the file's in C, C1, over B1.
+ try std.testing.expectEqualStrings("A1 C1", try t.walk(.key, true));
+ // From C1 in C: C41, its own, then the file's newest, A41.
+ try std.testing.expectEqualStrings("C41 A41", try t.walk(.key, false));
+}
+
+test "modes: Back and Forward take the same steps from Ctrl-o and Ctrl-i, SPC j o and SPC j i, and the builtins" {
+ for ([_]Jumps.Way{ .key, .leader, .builtin }) |way| {
+ var t = try Jumps.init("BABABA");
+ defer t.s.deinit();
+ try std.testing.expectEqualStrings("A41 A1 B1", try t.walk(way, true));
+ try std.testing.expectEqualStrings("B41 B81 A81", try t.walk(way, false));
+ }
+}
+
+test "modes: Ctrl-o and Ctrl-i drop the selections, select mode and the extra cursors, and land where the place was left" {
+ const rows = std.mem.asBytes(&@as([97][4]u8, @splat("row\n".*)));
+ var s = try Session.initFile(std.testing.allocator, "alpha beta\ngamma delta\nepsilon zeta\n" ++ rows);
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ // A place on line 3, at its eighth column (byte 30), then line 60.
+ try s.write(s.at("/pane/{d}/addr", .{n}), "#30\n");
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "dot=addr\n");
+ try s.keys("60G");
+ // Each step lands on the cursor the place was left with.
+ var back_to: u32 = 30;
+ for ([_][]const u8{ "\x0f", "\u{F017}i" }) |key| {
+ // A line selected, a second cursor under it, select mode on.
+ try s.keys("xCv");
+ try std.testing.expectEqualStrings("select", try mode(&s, n));
+ const leaving = (try s.range(dot))[1] - 1; // the cursor: its last character
+ try s.keys(key);
+ try std.testing.expectEqualStrings("normal", try mode(&s, n));
+ try std.testing.expectEqual(back_to, (try s.range(dot))[0]);
+ back_to = leaving;
+ try s.expect(s.at("/pane/{d}/sel", .{n}), "");
+ // One cursor: a Z typed goes in once.
+ try s.keys("iZ\x1b");
+ try expectEqual(@as(usize, 1), std.mem.count(u8, try s.read(s.at("/pane/{d}/body", .{n})), "Z"));
+ try s.keys("u");
+ }
+ // No place further on: said, and the selection left as it was.
+ try s.keys("x");
+ const sel = try s.read(s.at("/pane/{d}/sel", .{n}));
+ try s.keys("\u{F017}i");
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "nothing further on") != null);
+ try s.expect(s.at("/pane/{d}/sel", .{n}), sel);
+}
+
+test "modes: hopping between two panes by Esc, window mode or a click makes no places, so one Ctrl-o goes back across and the next has nowhere to go" {
+ var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))));
+ defer s.deinit();
+ // Two panes of room, not acme's fit to the doc.
+ try s.write("/ctl", "Placement pardes\n");
+ const doc = try s.focused();
+ try s.keys("\u{F015}n"); // a shell under the doc
+ const shell = try s.focused();
+ if (std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{shell})), "mode:tty") != null) try s.keys("\x02");
+ for (0..8) |_| {
+ const was = try s.focused();
+ try s.keys("\x1b");
+ try expectEqual(if (was == doc) shell else doc, try s.focused());
+ }
+ for (0..8) |_| {
+ const want = if (try s.focused() == doc) shell else doc;
+ try s.keys(if (want == shell) " wj\n" else " wk\n");
+ try expectEqual(want, try s.focused());
+ }
+ const doc_row = (try s.where("row"))[1];
+ const shell_row = (try s.where("Tty Save Mode"))[1] + 1;
+ for (0..8) |_| {
+ const other = if (try s.focused() == doc) shell else doc;
+ const row = if (other == doc) doc_row else shell_row;
+ try s.write("/mousein", s.at("m 10 {d} 1\nm 10 {d} 0\n", .{ row, row }));
+ try expectEqual(other, try s.focused());
+ }
+ const before = try s.focused();
+ try s.keys("\x0f");
+ try std.testing.expect(before != try s.focused());
+ const after = try s.focused();
+ try s.keys("\x0f");
+ try expectEqual(after, try s.focused());
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "nothing further back") != null);
+}
diff --git a/test/behaviour/mounts.zig b/test/behaviour/mounts.zig
index 57685a38..c05166bc 100644
--- a/test/behaviour/mounts.zig
+++ b/test/behaviour/mounts.zig
@@ -23,3 +23,10 @@ test "mounts: Mount with no dial is wrong #args, any other x!y a bad dial addres
try std.testing.expect(has(s.said, "no such mount"));
}
}
+
+test "mounts: a Mount dial with a network it does not know is a bad dial address, EINVAL" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try expectEqual(@as(u16, 22), try s.refused("/ctl", "Mount peer nowhere!x\n"));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "Mount: bad dial address: nowhere!x"));
+}
diff --git a/test/behaviour/mouse.zig b/test/behaviour/mouse.zig
index 0abe15dc..d7da46e8 100644
--- a/test/behaviour/mouse.zig
+++ b/test/behaviour/mouse.zig
@@ -131,3 +131,68 @@ test "mouse: a B1 sweep over several lines is a stream, as acme's, in a body and
try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 0\n", .{ tx + 3, ty, lx + 1, ly, lx + 1, ly, lx + 1, ly });
try s.expect(tag, "/test.txt Save Tty Colok Edit");
}
+
+test "mouse: a click on either half of a wide character lands before it, in the text and on a tag's path, and the caret steps over it whole" {
+ var s = try Session.initFile(std.testing.allocator, "a界e\u{301}z\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ const x, const y = try s.where("a界");
+ // 界 is two cells, bytes 1 to 4; é two runes, bytes 4 to 7.
+ for ([_]usize{ 1, 2 }) |into| {
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + into, y, x + into, y });
+ try std.testing.expectEqual(.{ @as(u32, 1), @as(u32, 1) }, try s.range(dot));
+ }
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + 4, y, x + 4, y });
+ try std.testing.expectEqual(.{ @as(u32, 7), @as(u32, 7) }, try s.range(dot));
+ // On the tag's path, the second half of 界 drafts the name with its
+ // caret before it; Right steps a whole grapheme, two cells then one.
+ try s.write(s.at("/pane/{d}/name", .{n}), "/界e\u{301}.txt\n");
+ const px, const py = try s.where("/界");
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ px + 2, py, px + 2, py });
+ try std.testing.expectEqual(.{ px + 1, py }, (try s.cursor()).?);
+ try s.keys("\u{F012}");
+ try std.testing.expectEqual(.{ px + 3, py }, (try s.cursor()).?);
+ try s.keys("\u{F012}");
+ try std.testing.expectEqual(.{ px + 4, py }, (try s.cursor()).?);
+ try s.keys("\x1b\x1b");
+ try s.expect(s.at("/pane/{d}/name", .{n}), "/界e\u{301}.txt\n");
+ // Typed past the tag's words, a two-byte λ goes in and one backspace
+ // takes it out whole.
+ const tag = try s.read(s.at("/pane/{d}/tag", .{n}));
+ try s.click("Collapse Del", "Collapse Del".len + 1, 1);
+ const caret = (try s.cursor()).?;
+ // A clicked tag is in normal mode: `i` types at the caret.
+ try s.keys("iλ");
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/tag", .{n})), "λ"));
+ try std.testing.expectEqual(.{ caret[0] + 1, caret[1] }, (try s.cursor()).?);
+ try s.keys("\x08");
+ try std.testing.expectEqual(caret, (try s.cursor()).?);
+ try s.expect(s.at("/pane/{d}/tag", .{n}), tag);
+}
+
+test "mouse: a sweep pressed on the line numbers takes only the text: drawn while held and once let go, looked for by a click in it, cut by a chord" {
+ var s = try Session.initFile(std.testing.allocator, "alpha beta\ngamma delta\nalpha beta\ngamma\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const x, const y = try s.where("alpha");
+ const plain = try s.bg(x - 2, y);
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\n", .{ x - 2, y, x + 4, y + 1 });
+ for (0..2) |released| {
+ // The number pressed on, and the room after the line, stay unlit.
+ try std.testing.expectEqualStrings(plain, try s.bg(x - 2, y));
+ try std.testing.expectEqualStrings(plain, try s.bg(x - 2, y + 1));
+ const lit = try s.bg(x, y);
+ try std.testing.expect(!std.mem.eql(u8, plain, lit));
+ try std.testing.expectEqualStrings(lit, try s.bg(x + 4, y + 1));
+ try std.testing.expectEqualStrings(plain, try s.bg(x + 5, y + 1));
+ if (released == 0) try mouse(&s, "m {d} {d} 0\n", .{ x + 4, y + 1 });
+ }
+ // A Look clicked in it looks for the text swept: its next place, the
+ // third and fourth lines.
+ try mouse(&s, "m {d} {d} 4\nm {d} {d} 0\n", .{ x + 1, y, x + 1, y });
+ try std.testing.expectEqual(.{ @as(u32, 23), @as(u32, 39) }, try s.range(s.at("/pane/{d}/dot", .{n})));
+ // A chord cuts what was swept: the text, no number.
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 1\nm {d} {d} 0\n", .{ x - 2, y, x + 4, y + 1, x + 4, y + 1, x + 4, y + 1, x + 4, y + 1 });
+ try s.expect(s.at("/pane/{d}/body", .{n}), " delta\nalpha beta\ngamma\n");
+}
diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig
index ef1fab7e..701f4f14 100644
--- a/test/behaviour/other_files.zig
+++ b/test/behaviour/other_files.zig
@@ -80,3 +80,249 @@ test "other-files: /recent keeps a PDF as it keeps a file: open, then closed" {
try s.write(s.at("/pane/{d}/ctl", .{n}), "Del\n");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("closed {s}\n", .{name})) != null);
}
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+/// A fresh directory's absolute path, kept until deinit.
+fn tmpPath(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 {
+ var buf: [4096]u8 = undefined;
+ return s.at("{s}", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]});
+}
+
+/// The serials /index lists with a name ending `suffix`.
+fn named(s: *Session, suffix: []const u8) ![]u32 {
+ var out: std.ArrayList(u32) = .empty;
+ var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n');
+ while (rows.next()) |line| {
+ const name = line[0 .. std.mem.lastIndexOfScalar(u8, line, ' ') orelse continue];
+ if (std.mem.endsWith(u8, name, suffix)) try out.append(s.arena.allocator(), try std.fmt.parseInt(u32, line[0..std.mem.indexOfScalar(u8, line, ' ').?], 10));
+ }
+ return out.items;
+}
+
+/// The body of the pane a root exec of `word` answers (Recent, Jumplist).
+fn listing(s: *Session, word: []const u8) ![]const u8 {
+ try s.write("/exec", s.at("{s}\n", .{word}));
+ return s.read(s.at("/pane/{s}/body", .{std.mem.trimEnd(u8, try s.read("/exec"), "\n")}));
+}
+
+test "other-files: Jumplist fills its one +Jumps again, as Recent does, never a second" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ for (0..2) |_| {
+ try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Jumplist\n");
+ try std.testing.expectEqual(@as(usize, 1), (try named(&s, "/+Jumps")).len);
+ }
+}
+
+test "other-files: a Jumplist entry is (closed) only while no pane has its file open" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "two\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ try s.write("/look", s.at("{s}/a.txt\n", .{dir}));
+ const a = try s.focused();
+ try s.write("/look", s.at("{s}/b.txt\n", .{dir}));
+ try s.write(s.at("/pane/{d}/ctl", .{a}), "Del\n");
+ try std.testing.expect(has(try listing(&s, "Jumplist"), "(closed)"));
+ // Open again, by a look: no entry is closed any more.
+ try s.write("/look", s.at("{s}/a.txt\n", .{dir}));
+ try std.testing.expect(!has(try listing(&s, "Jumplist"), "(closed)"));
+}
+
+test "other-files: Recent's row for a file still open is where its dot is now, not where it last closed" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try s.write("/look", s.at("{s}/a.txt:3\n", .{try tmpPath(&s, &tmp)}));
+ try s.write(s.at("/pane/{d}/dot", .{try s.focused()}), "6 6"); // line 2, column 3
+ // A query pane under the file (line 1 `Recent `), its rows said from
+ // its directory.
+ const rows = try listing(&s, "Recent");
+ try std.testing.expect(std.mem.startsWith(u8, rows, "Recent \n"));
+ try std.testing.expect(has(rows, "\na.txt:2:3 open\n"));
+}
+
+test "other-files: a closed file is found again: Recent and /recent list it closed, a look at its row reopens it at its dot, and a jump back does too" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "bee\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const a = s.at("{s}/a.txt", .{dir});
+ // Opened, its dot on line 3, then closed.
+ try s.write("/look", s.at("{s}:3\n", .{a}));
+ const opened = try s.focused();
+ try std.testing.expect(has(try s.read("/recent"), s.at("open {s}\n", .{a})));
+ // Another file, so the jumplist has somewhere to come back from.
+ try s.write("/look", s.at("{s}/b.txt\n", .{dir}));
+ try s.write(s.at("/pane/{d}/ctl", .{opened}), "Del\n");
+ try std.testing.expect(has(try s.read("/recent"), s.at("closed {s}\n", .{a})));
+ // Recent lists it, closed, at its dot; a look at the row opens it there.
+ const rows = try listing(&s, "Recent");
+ const recent = std.mem.trimEnd(u8, try s.read("/exec"), "\n");
+ const at = std.mem.indexOf(u8, rows, "\na.txt:3:").? + 1;
+ const row = rows[at..std.mem.indexOfScalarPos(u8, rows, at, '\n').?];
+ try std.testing.expect(std.mem.endsWith(u8, row, " (closed)"));
+ try s.write(s.at("/pane/{s}/look", .{recent}), s.at("{s}\n", .{row[0 .. row.len - " (closed)".len]}));
+ const back = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{back}), s.at("{s}\n", .{a}));
+ try std.testing.expectEqual(@as(u32, 8), (try s.range(s.at("/pane/{d}/dot", .{back})))[0]);
+ // Closed again; the jumplist keeps its entry, closed, and a jump back
+ // to it opens it again.
+ try s.write(s.at("/pane/{d}/ctl", .{back}), "Del\n");
+ try std.testing.expect(has(try listing(&s, "Jumplist"), "(closed)"));
+ // Every entry in order (JumpScope all): which file has the focus after
+ // a Del is the layout's to choose, and Back keeps to it first.
+ try s.write("/ctl", "JumpScope all\n");
+ for (0..8) |_| {
+ if ((try named(&s, "/a.txt")).len > 0) break;
+ try s.write("/exec", "Back\n");
+ }
+ try s.expect(s.at("/pane/{d}/name", .{try s.focused()}), s.at("{s}\n", .{a}));
+}
+
+test "other-files: Back and Forward over a closed file's entries: one reopen is that file's pane in every entry, so the next step moves" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "bee\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.txt", .data = "sea\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ try s.write("/look", s.at("{s}/b.txt\n", .{dir}));
+ const b = try s.focused();
+ // Two entries for a.txt, far apart in it.
+ try s.write("/look", s.at("{s}/a.txt:1\n", .{dir}));
+ const a = try s.focused();
+ try s.write("/look", s.at("{s}/a.txt:90\n", .{dir}));
+ try s.write("/look", s.at("{s}/c.txt\n", .{dir}));
+ const c = try s.focused();
+ try s.write(s.at("/pane/{d}/ctl", .{a}), "Del\n");
+ try s.write("/focus", s.at("{d}\n", .{c}));
+ try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, try listing(&s, "Jumplist"), "(closed)"));
+ try s.write("/focus", s.at("{d}\n", .{c}));
+ // Back reopens it at line 90: both its entries are that pane now.
+ try s.write("/exec", "Back\n");
+ const re = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{re}), s.at("{s}/a.txt\n", .{dir}));
+ try std.testing.expectEqual(@as(u32, 89), (try s.range(s.at("/pane/{d}/dot", .{re})))[0] / 4);
+ try std.testing.expect(!has(try listing(&s, "Jumplist"), "(closed)"));
+ try s.write("/focus", s.at("{d}\n", .{re}));
+ // Back again goes to its line 1, in the same pane, then to b.
+ try s.write("/exec", "Back\n");
+ try std.testing.expectEqual(re, try s.focused());
+ try std.testing.expectEqual(@as(u32, 0), (try s.range(s.at("/pane/{d}/dot", .{re})))[0] / 4);
+ try s.write("/exec", "Back\n");
+ try std.testing.expectEqual(b, try s.focused());
+ // And Forward walks it all again, to c.
+ try s.write("/exec", "Forward\n");
+ try s.write("/exec", "Forward\n");
+ try std.testing.expectEqual(@as(u32, 89), (try s.range(s.at("/pane/{d}/dot", .{re})))[0] / 4);
+ try s.write("/exec", "Forward\n");
+ try std.testing.expectEqual(c, try s.focused());
+}
+
+test "other-files: Recent keeps only files on disk: not a name never saved, nor the served tree's" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "real.txt", .data = "real\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const names = [_][]const u8{ s.at("{s}/c", .{dir}), "/virtual/zz", s.at("{s}/real.txt", .{dir}) };
+ for (names) |name| {
+ const made = try s.newPane();
+ try s.write(s.at("/pane/{d}/name", .{made}), s.at("{s}\n", .{name}));
+ // Asked once if it is a file with text to lose; gone either way.
+ _ = try s.refused(s.at("/pane/{d}/ctl", .{made}), "Del\n");
+ _ = s.refused(s.at("/pane/{d}/ctl", .{made}), "Del\n") catch 0;
+ }
+ const recent = try s.read("/recent");
+ try std.testing.expect(!has(recent, s.at(" {s}\n", .{names[0]})));
+ try std.testing.expect(!has(recent, " /virtual/zz\n"));
+ try std.testing.expect(has(recent, s.at(" {s}\n", .{names[2]})));
+}
+
+test "other-files: Back over a closed file deleted since skips it, says so, and goes on to the place before" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ for ([_][]const u8{ "a.txt", "gone.txt", "c.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "text\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ try s.write("/look", s.at("{s}/a.txt\n", .{dir}));
+ const a = try s.focused();
+ try s.write("/look", s.at("{s}/gone.txt\n", .{dir}));
+ const gone = try s.focused();
+ try s.write("/look", s.at("{s}/c.txt\n", .{dir}));
+ const c = try s.focused();
+ try s.write(s.at("/pane/{d}/ctl", .{gone}), "Del\n");
+ try tmp.dir.deleteFile(std.testing.io, "gone.txt");
+ try s.write("/focus", s.at("{d}\n", .{c}));
+ try s.write("/exec", "Back\n");
+ try std.testing.expectEqual(a, try s.focused());
+ try std.testing.expect(has(try s.read("/log"), "gone.txt: deleted, skipped"));
+}
+
+test "other-files: a remembered place is clamped to the file as it is now, its selection's two ends kept where they fit" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.txt", .data = "one\ntwo\nthree\nfour\nfive\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ try s.write("/look", s.at("{s}/c.txt:2\n", .{dir}));
+ const c = try s.focused();
+ // A selection over lines 2 to 4, then closed.
+ try s.write(s.at("/pane/{d}/dot", .{c}), "4 19");
+ try s.write(s.at("/pane/{d}/ctl", .{c}), "Del\n");
+ // The file shrinks to two lines while it is closed.
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.txt", .data = "one\ntwo\n" });
+ const rows = try listing(&s, "Recent");
+ const recent = std.mem.trimEnd(u8, try s.read("/exec"), "\n");
+ const at = std.mem.indexOf(u8, rows, "c.txt:").?;
+ const row = rows[at..std.mem.indexOfScalarPos(u8, rows, at, '\n').?];
+ // Both ends are in the row, a range.
+ try std.testing.expect(std.mem.indexOfScalar(u8, row, '-') != null);
+ const loc = s.at("{s}/{s}\n", .{ dir, row[0..std.mem.indexOfScalar(u8, row, ' ').?] });
+ // A look at it opens the file, never a miss, clamped to its last line.
+ try s.write(s.at("/pane/{s}/look", .{recent}), loc);
+ const back = try s.focused();
+ try s.expect(s.at("/pane/{d}/name", .{back}), s.at("{s}/c.txt\n", .{dir}));
+ // Its ends clamped to the last character, `two`'s `o`, not its newline.
+ const dot = try s.range(s.at("/pane/{d}/dot", .{back}));
+ try std.testing.expect(dot[0] < dot[1] and dot[1] <= 7);
+ try std.testing.expect(has(try s.read("/log"), "c.txt has 2 lines now: at its last"));
+ // The same row with the file open: the same place, said the same way.
+ try s.write(s.at("/pane/{s}/look", .{recent}), loc);
+ try std.testing.expectEqual(back, try s.focused());
+ try std.testing.expectEqual(dot, try s.range(s.at("/pane/{d}/dot", .{back})));
+}
+
+test "other-files: /index and /recent show a name's own backslash doubled, so `\\n` written in a name reads back unlike a newline" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "back\\nslash", .data = "x\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const n = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/back\\nslash\n", .{dir}));
+ const index = try s.read("/index");
+ try std.testing.expect(has(index, s.at("{s}/back\\\\nslash ", .{dir})));
+ try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, index, "\n"));
+ try s.write(s.at("/pane/{d}/exec", .{n}), "Get\n");
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "Del\n");
+ try std.testing.expect(has(try s.read("/recent"), s.at("closed {s}/back\\\\nslash\n", .{dir})));
+}
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig
index a46f8432..0c0edbf9 100644
--- a/test/behaviour/panes.zig
+++ b/test/behaviour/panes.zig
@@ -363,3 +363,544 @@ test "panes: a Mini that cannot read its file leaves the panes, the last Mini's
try s.expect("/index", index);
try s.expect(s.at("/pane/{d}/body", .{mini}), body);
}
+
+test "panes: Mini with no argument is wrong #args, EINVAL, as every word that needs one" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/ctl", .{try s.focused()}), "Mini\n"));
+ try std.testing.expectEqualStrings("wrong #args in control message \"Mini\"", s.said);
+}
+
+test "panes: the ctl word name with nothing after it says it names nothing" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/ctl", .{try s.focused()}), "name \n"));
+ try std.testing.expectEqualStrings("invalid file name: name takes the name, and there is none", s.said);
+}
+
+test "panes: ctl reads acme's fields in acme's order, undo and redo flags included, then pardes's own" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ const field = struct {
+ fn at(text: []const u8, i: usize) []const u8 {
+ var it = std.mem.tokenizeScalar(u8, text, ' ');
+ for (0..i) |_| _ = it.next();
+ return it.next().?;
+ }
+ }.at;
+ try std.testing.expectEqualStrings("0", field(try s.read(ctl), 8)); // nothing to undo
+ try std.testing.expectEqualStrings("0", field(try s.read(ctl), 9)); // nothing to redo
+ const current = field(try s.read(ctl), 10);
+ try std.testing.expect(std.mem.eql(u8, current, "current") or std.mem.eql(u8, current, "notcurrent"));
+ try s.write(s.at("/pane/{d}/body", .{n}), "two\n");
+ try std.testing.expectEqualStrings("1", field(try s.read(ctl), 8));
+ try s.write(ctl, "Undo\n");
+ try std.testing.expectEqualStrings("1", field(try s.read(ctl), 9));
+}
+
+/// A fresh directory's absolute path, kept until deinit.
+fn tmpPath(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 {
+ var buf: [4096]u8 = undefined;
+ return s.at("{s}", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]});
+}
+
+/// The `i`th blank-separated field of a pane's ctl read.
+fn ctlField(s: *Session, n: u32, i: usize) ![]const u8 {
+ var it = std.mem.tokenizeScalar(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), ' ');
+ for (0..i) |_| _ = it.next();
+ return it.next() orelse error.NoField;
+}
+
+test "panes: get reloads the pane from disk and reports a missing file without losing dirty contents" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "note.txt", .data = "from disk\n" });
+ var s = try Session.initFile(std.testing.allocator, "in memory\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const n = try s.focused();
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ const body = s.at("/pane/{d}/body", .{n});
+ try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/note.txt\n", .{dir}));
+ try s.write(ctl, "get\n");
+ try s.expect(body, "from disk\n");
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n");
+ try std.testing.expectEqualStrings("1", try ctlField(&s, n, 8)); // an undo step
+ // Renamed but never edited, it was clean: nothing thrown away, nothing
+ // logged as reloaded over edits.
+ try std.testing.expect(!has(try s.read("/log"), s.at("changed {d} reloaded\n", .{n})));
+ try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/missing.txt\n", .{dir}));
+ try s.write(body, "unsaved\n");
+ // Unsaved text is asked about once, as acme's get asks winclean.
+ try std.testing.expectEqual(@as(u16, 5), try s.refused(ctl, "get\n"));
+ try std.testing.expect(std.mem.endsWith(u8, s.said, ": Modified (get again to discard)"));
+ try std.testing.expect(has(try s.read("/log"), s.at("unsaved {d} {s}/missing.txt\n", .{ n, dir })));
+ try std.testing.expectEqual(@as(u16, 2), try s.refused(ctl, "get\n"));
+ try s.expect(body, "from disk\nunsaved\n");
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "1\n");
+}
+
+test "panes: Get reads the pane's file again, refusing unsaved edits once, and Get file loads that file into the pane" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "note.txt", .data = "from disk\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "other.txt", .data = "the other\n" });
+ var s = try Session.initFile(std.testing.allocator, "in memory\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const n = try s.focused();
+ const exec = s.at("/pane/{d}/exec", .{n});
+ const body = s.at("/pane/{d}/body", .{n});
+ try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/note.txt\n", .{dir}));
+ try s.write(exec, "Get\n");
+ try s.expect(body, "from disk\n");
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n");
+ // Edited: asked once, then read again.
+ try s.write(body, "unsaved\n");
+ try std.testing.expect(try s.refused(exec, "Get\n") != 0);
+ try s.expect(body, "from disk\nunsaved\n");
+ try s.write(exec, "Get\n");
+ try s.expect(body, "from disk\n");
+ // Get file: that file, by a name from the pane's directory.
+ try s.write(exec, "Get other.txt\n");
+ try s.expect(body, "the other\n");
+ try s.expect(s.at("/pane/{d}/name", .{n}), s.at("{s}/other.txt\n", .{dir}));
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n");
+}
+
+test "panes: 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 = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "other.txt", .data = "other\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "keep.txt", .data = "keep\n" });
+ for ([_][]const u8{ "Get keep.txt\n", "Edit e keep.txt\n" }) |load| {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const n = try s.focused();
+ const exec = s.at("/pane/{d}/exec", .{n});
+ const body = s.at("/pane/{d}/body", .{n});
+ const name = s.at("/pane/{d}/name", .{n});
+ const dirty = s.at("/pane/{d}/dirty", .{n});
+ try s.write(name, s.at("{s}/other.txt\n", .{dir}));
+ try s.write(exec, "Get\n");
+ try s.expect(body, "other\n");
+ try s.expect(dirty, "0\n");
+ // Loaded: keep.txt's text under its name.
+ try s.write(exec, load);
+ try s.expect(body, "keep\n");
+ try s.expect(name, s.at("{s}/keep.txt\n", .{dir}));
+ if (std.mem.startsWith(u8, load, "Get")) try s.expect(dirty, "0\n");
+ // Undo: other.txt's text, other.txt's name, clean as it was.
+ try s.write(exec, "Undo\n");
+ try s.expect(body, "other\n");
+ try s.expect(name, s.at("{s}/other.txt\n", .{dir}));
+ try s.expect(dirty, "0\n");
+ // Putall saves nothing, and nothing lands on keep.txt.
+ try s.write("/ctl", "Putall\n");
+ try std.testing.expectEqual(@as(usize, 0), s.saved);
+ // Redo: keep.txt again.
+ try s.write(exec, "Redo\n");
+ try s.expect(name, s.at("{s}/keep.txt\n", .{dir}));
+ try s.expect(body, "keep\n");
+ }
+}
+
+test "panes: a Get file that fails changes nothing: no such file, a directory, or unsaved edits asked about once" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "here.txt", .data = "here\n" });
+ try tmp.dir.createDirPath(std.testing.io, "sub");
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const n = try s.focused();
+ const exec = s.at("/pane/{d}/exec", .{n});
+ const body = s.at("/pane/{d}/body", .{n});
+ const name = s.at("/pane/{d}/name", .{n});
+ const here = s.at("{s}/here.txt\n", .{dir});
+ try s.write(name, here);
+ try s.write(exec, "Get\n");
+ for ([_][]const u8{ "Get nosuch.txt\n", "Get sub\n" }) |line| {
+ try std.testing.expect(try s.refused(exec, line) != 0);
+ try s.expect(name, here);
+ try s.expect(body, "here\n");
+ }
+ // No undo step left by them: one Undo takes back the first Get.
+ try s.write(exec, "Undo\n");
+ try s.expect(body, "x\n");
+ try s.write(exec, "Redo\n");
+ // Edited, the first Get asks and renames nothing.
+ try s.write(body, "more\n");
+ try std.testing.expect(try s.refused(exec, "Get other.txt\n") != 0);
+ try s.expect(name, here);
+ try s.expect(body, "here\nmore\n");
+}
+
+/// The serials /index lists with a name ending `suffix`, in its order.
+fn panesNamed(s: *Session, suffix: []const u8) ![]u32 {
+ var out: std.ArrayList(u32) = .empty;
+ var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n');
+ while (rows.next()) |line| {
+ const name = line[0 .. std.mem.lastIndexOfScalar(u8, line, ' ') orelse continue];
+ if (std.mem.endsWith(u8, name, suffix)) try out.append(s.arena.allocator(), try std.fmt.parseInt(u32, line[0..std.mem.indexOfScalar(u8, line, ' ').?], 10));
+ }
+ return out.items;
+}
+
+test "panes: Zerox makes a second pane on one buffer: one text, undo and dirty state, its own cursor; Del of one asks nothing" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const a = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{a}), s.at("{s}/z.txt\n", .{dir}));
+ try s.write(s.at("/pane/{d}/exec", .{a}), "Zerox\n");
+ // Both in the index, each its serial, one name.
+ const twins = try panesNamed(&s, "/z.txt");
+ try std.testing.expectEqual(@as(usize, 2), twins.len);
+ const b = if (twins[0] == a) twins[1] else twins[0];
+ // b's cursor on `three`; a line written above it in a moves it down.
+ try s.write(s.at("/pane/{d}/dot", .{b}), "9 9");
+ try s.write(s.at("/pane/{d}/addr", .{a}), "0");
+ try s.write(s.at("/pane/{d}/data", .{a}), "zero\n");
+ try s.expect(s.at("/pane/{d}/body", .{b}), "zero\none\ntwo\nthree\n");
+ try std.testing.expectEqual(.{ @as(u32, 14), @as(u32, 14) }, try s.range(s.at("/pane/{d}/dot", .{b})));
+ try s.expect(s.at("/pane/{d}/dirty", .{a}), "1\n");
+ try s.expect(s.at("/pane/{d}/dirty", .{b}), "1\n");
+ // A write through b is a's too; Undo in a takes it back from both.
+ try s.write(s.at("/pane/{d}/body", .{b}), "four\n");
+ try s.expect(s.at("/pane/{d}/body", .{a}), "zero\none\ntwo\nthree\nfour\n");
+ try s.write(s.at("/pane/{d}/exec", .{a}), "Undo\n");
+ try s.expect(s.at("/pane/{d}/body", .{b}), "zero\none\ntwo\nthree\n");
+ // Del of a asks nothing: b holds the text.
+ try s.write(s.at("/pane/{d}/ctl", .{a}), "Del\n");
+ try std.testing.expectEqualSlices(u32, &.{b}, try panesNamed(&s, "/z.txt"));
+ try s.expect(s.at("/pane/{d}/dirty", .{b}), "1\n");
+ try s.expect(s.at("/pane/{d}/body", .{b}), "zero\none\ntwo\nthree\n");
+ // Alone now, it is no twin; Del asks about it as about any pane.
+ try std.testing.expect(try s.refused(s.at("/pane/{d}/ctl", .{b}), "Del\n") != 0);
+ try std.testing.expectEqualSlices(u32, &.{b}, try panesNamed(&s, "/z.txt"));
+}
+
+test "panes: a twin renamed logs a rename for each twin" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const a = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{a}), "Zerox\n");
+ const twins = try panesNamed(&s, "/test.txt");
+ try std.testing.expectEqual(@as(usize, 2), twins.len);
+ try s.write(s.at("/pane/{d}/name", .{a}), "/tmp/pardes-twin-renamed.txt\n");
+ for (twins) |n| try std.testing.expect(has(try s.read("/log"), s.at("rename {d} /tmp/pardes-twin-renamed.txt\n", .{n})));
+}
+
+test "panes: small refusals: one name an open, small scratches loaded over unasked, twins saved once, and errnos in words a mount reads" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "noread.txt", .data = "secret\n" });
+ try tmp.dir.createDirPath(std.testing.io, "sub");
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const n = try s.focused();
+ const name = s.at("/pane/{d}/name", .{n});
+ const exec = s.at("/pane/{d}/exec", .{n});
+ // One name an open: a second line, in the write or after, is refused.
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "/tmp/pardes-a\nb"));
+ const f = try s.hold(name, 1);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(f, "/tmp/pardes-one.txt\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(f, "b"));
+ s.clunk(f);
+ try s.expect(name, "/tmp/pardes-one.txt\n");
+ // Errnos a mount reads from the words.
+ try s.write(name, s.at("{s}/f.txt\n", .{dir}));
+ try s.write(exec, "Get\n");
+ try std.testing.expectEqual(@as(u16, 21), try s.refused(exec, "Get sub\n")); // EISDIR
+ const noread = s.at("{s}/noread.txt\x00", .{dir});
+ _ = std.c.chmod(noread[0 .. noread.len - 1 :0], 0);
+ try std.testing.expectEqual(@as(u16, 13), try s.refused(exec, "Get noread.txt\n")); // EACCES
+ try std.testing.expectEqual(@as(u16, 20), try s.refused(exec, s.at("Incl {s}/f.txt\n", .{dir}))); // ENOTDIR
+ _ = try s.refused(s.at("/pane/{d}/look", .{n}), "/dev/zero\n");
+ try std.testing.expect(has(try s.read("/log"), "not a regular file"));
+ // Twins saved once by Putall.
+ try s.write(s.at("/pane/{d}/body", .{n}), "edited\n");
+ try s.write(exec, "Zerox\n");
+ const saved = s.saved;
+ try s.write("/ctl", "Putall\n");
+ try std.testing.expectEqual(saved + 1, s.saved);
+ // A scratch of 2 bytes is loaded over unasked.
+ try s.write(exec, "New\n");
+ const scratch = try s.focused();
+ try s.write(s.at("/pane/{d}/body", .{scratch}), "hi");
+ try s.write(s.at("/pane/{d}/exec", .{scratch}), s.at("Get {s}/f.txt\n", .{dir}));
+ try s.expect(s.at("/pane/{d}/body", .{scratch}), "f\n");
+}
+
+test "panes: Get of a file not there says so without asking about unsaved edits" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const dir = try tmpPath(&s, &tmp);
+ const n = try s.focused();
+ try s.write(s.at("/pane/{d}/body", .{n}), "unsaved\n");
+ _ = try s.refused(s.at("/pane/{d}/exec", .{n}), "Get /tmp/pardes-surely-no-such-file.txt\n");
+ const log = try s.read("/log");
+ try std.testing.expect(has(log, "no such file"));
+ try std.testing.expect(!has(log, "again to discard"));
+ // Not asked, so the next Get of a file there is asked about, not run.
+ try std.testing.expect(try s.refused(s.at("/pane/{d}/exec", .{n}), s.at("Get {s}/f.txt\n", .{dir})) != 0);
+ try s.expect(s.at("/pane/{d}/body", .{n}), "x\nunsaved\n");
+}
+
+test "panes: a pane's ctl takes acme's words: done by the files that replace them, or refused with why" {
+ var s = try Session.initFile(std.testing.allocator, "one two\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ const dirty = s.at("/pane/{d}/dirty", .{n});
+ try s.write(ctl, "name /tmp/pardes-acme-ctl.txt\n");
+ try s.expect(s.at("/pane/{d}/name", .{n}), "/tmp/pardes-acme-ctl.txt\n");
+ try s.write(ctl, "dirty\n");
+ try s.expect(dirty, "1\n");
+ try s.write(ctl, "clean\n");
+ try s.expect(dirty, "0\n");
+ try s.write(s.at("/pane/{d}/addr", .{n}), "/two/");
+ try s.write(ctl, "dot=addr\nshow\nnomark\nmark\nlimit=addr\n");
+ try std.testing.expectEqual(@as(u32, 4), (try s.range(s.at("/pane/{d}/dot", .{n})))[0]);
+ try std.testing.expectEqual(.{ @as(u32, 4), @as(u32, 7) }, try s.range(s.at("/pane/{d}/limit", .{n})));
+ try s.write(ctl, "cleartag\n");
+ for ([_][]const u8{ "menu\n", "nomenu\n", "dump echo hi\n", "dumpdir /tmp\n", "font Go Mono\n" }) |line| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, line));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "invalid: acme's "));
+ }
+ // Checked whole: a refused word anywhere and nothing ran.
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "dirty\nmenu\n"));
+ try s.expect(dirty, "0\n");
+}
+
+test "panes: +Unsaved drops a pane once it has closed" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const a = try s.newPane();
+ try s.write(s.at("/pane/{d}/name", .{a}), "/tmp/pardes-unsaved-a.txt\n");
+ try s.write(s.at("/pane/{d}/body", .{a}), "edited\n");
+ const b = try s.newPane();
+ try s.write(s.at("/pane/{d}/name", .{b}), "/tmp/pardes-unsaved-b.txt\n");
+ try s.write(s.at("/pane/{d}/body", .{b}), "edited\n");
+ try std.testing.expect(try s.refused("/ctl", "Exit\n") != 0);
+ const list = s.at("/pane/{d}/body", .{(try panesNamed(&s, "/+Unsaved"))[0]});
+ try std.testing.expect(has(try s.read(list), "/tmp/pardes-unsaved-a.txt: Modified"));
+ // a closes (discarded): its row goes.
+ _ = try s.refused(s.at("/pane/{d}/ctl", .{a}), "Del\n");
+ try s.write(s.at("/pane/{d}/ctl", .{a}), "Del\n");
+ try std.testing.expectEqual(@as(usize, 0), (try panesNamed(&s, "/pardes-unsaved-a.txt")).len);
+ try std.testing.expect(!has(try s.read(list), "/tmp/pardes-unsaved-a.txt: Modified"));
+}
+
+test "panes: name refuses a directory, EISDIR, and leaves the name as it was" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const name = s.at("/pane/{d}/name", .{try s.focused()});
+ for ([_][]const u8{ "/\n", "/tmp/\n", "sub/\n", "/tmp\n" }) |dir| {
+ try std.testing.expectEqual(@as(u16, 21), try s.refused(name, dir));
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "is a directory") != null);
+ }
+ try s.expect(name, "/test.txt\n");
+}
+
+test "panes: a write of two lines to name is refused EINVAL, on a held open or not" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const name = s.at("/pane/{d}/name", .{try s.focused()});
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "/tmp/a\n/tmp/b\n"));
+ const h = try s.hold(name, 1);
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(h, "/tmp/a\n/tmp/b\n"));
+ s.clunk(h);
+ try s.expect(name, "/test.txt\n");
+ // Line by line, as bash writes it: the second line is refused.
+ const h2 = try s.hold(name, 1);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(h2, "/tmp/pardes-a\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(h2, "/tmp/pardes-b\n"));
+ s.clunk(h2);
+ try s.expect(name, "/tmp/pardes-a\n");
+}
+
+test "panes: a name with a component over 255 bytes is refused by the write that holds it" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const name = s.at("/pane/{d}/name", .{try s.focused()});
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "/tmp/" ++ &@as([256]u8, @splat('c')) ++ "/f.txt\n"));
+ try std.testing.expectEqualStrings("invalid file name: a component over 255 bytes", s.said);
+ const longest = "/tmp/" ++ &@as([255]u8, @splat('c'));
+ try s.write(name, longest ++ "\n");
+ // Held with no newline, it is refused by that write, and the close
+ // has nothing left to apply.
+ const held = try s.hold(name, 1);
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(held, "/tmp/" ++ &@as([256]u8, @splat('e'))));
+ s.clunk(held);
+ try s.expect(name, longest ++ "\n");
+}
+
+test "panes: a name cut across writes is one name, applied once at its newline or its close" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const name = s.at("/pane/{d}/name", .{try s.focused()});
+ const h = try s.hold(name, 1);
+ _ = try s.writeFid(h, "/tmp/pardes-na");
+ try s.expect(name, "/test.txt\n");
+ _ = try s.writeFid(h, "me.txt\n");
+ try s.expect(name, "/tmp/pardes-name.txt\n");
+ s.clunk(h);
+ // No newline: held, and applied at the close.
+ const h3 = try s.hold(name, 1);
+ _ = try s.writeFid(h3, "/tmp/pardes-closed.txt");
+ try s.expect(name, "/tmp/pardes-name.txt\n");
+ s.clunk(h3);
+ try s.expect(name, "/tmp/pardes-closed.txt\n");
+}
+
+test "panes: name reads the file name, and a write promotes a scratch without touching its body or its file" {
+ const gpa = std.testing.allocator;
+ var s = try Session.initFile(gpa, "opener\n");
+ defer s.deinit();
+ const n = try s.newPane();
+ const name = s.at("/pane/{d}/name", .{n});
+ const body = s.at("/pane/{d}/body", .{n});
+ const scratch = try s.read(name);
+ try std.testing.expect(std.mem.endsWith(u8, scratch, "/+New\n"));
+ try std.testing.expectEqual(@as(u64, scratch.len), (try s.stat(name)).size);
+ try s.write(body, "scratch ");
+ try s.write(body, "work\n");
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "renamed.zig", .data = "existing target\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ const path = s.at("{s}/renamed.zig", .{dir});
+ try s.write(name, s.at("{s}\n", .{path}));
+ try s.expect(body, "scratch work\n");
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "1\n");
+ try s.expect(name, s.at("{s}\n", .{path}));
+ var target_buf: [64]u8 = undefined;
+ try std.testing.expectEqualStrings("existing target\n", try tmp.dir.readFile(std.testing.io, "renamed.zig", &target_buf));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "\n"));
+ // One name, and what no file name holds: a second line, a NUL.
+ for ([_][2][]const u8{
+ .{ "two\nlines\n", "invalid file name: one name a write, on one line" },
+ .{ "nul\x00.zig\n", "bad character in file name: a NUL" },
+ }) |c| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(name, c[0]));
+ try std.testing.expectEqualStrings(c[1], s.said);
+ }
+ // Any other byte a file name holds is taken, and reads back as written:
+ // blanks at its ends, a tab, a control byte, DEL, C1, bytes not UTF-8.
+ for ([_][]const u8{ " lead.zig ", "tab\t.zig", "c\x01.zig", "del\x7f.zig", "c1\xc2\x85.zig", "bad\xff.zig" }) |odd| {
+ try s.write(name, s.at("{s}\n", .{odd}));
+ const read_back = std.mem.trimEnd(u8, try s.read(name), "\n");
+ try std.testing.expect(std.mem.endsWith(u8, read_back, odd));
+ try s.write(name, read_back);
+ try s.expect(name, s.at("{s}\n", .{read_back}));
+ }
+ // A name that is one line and UTF-8 is taken, é and all.
+ try s.write(name, "caf\xc3\xa9.zig\n");
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(name), "/caf\xc3\xa9.zig\n"));
+ try s.write(name, "two words.zig\n");
+ try s.expect(name, s.at("{s}/two words.zig\n", .{dir}));
+ // A rename is no edit: Undo takes back the last write.
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n");
+ try s.expect(body, "scratch ");
+}
+
+test "panes: relative names go from the file's directory and can name a new target" {
+ var s = try Session.initFile(std.testing.allocator, "retained body\n");
+ defer s.deinit();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "note.txt", .data = "from pane directory\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ const n = try s.focused();
+ const name = s.at("/pane/{d}/name", .{n});
+ try s.write(name, s.at("{s}/old.txt\n", .{dir}));
+ try s.write(name, "child/../note.txt\n");
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "get\n");
+ try s.expect(s.at("/pane/{d}/body", .{n}), "from pane directory\n");
+ try s.write(name, "./created.txt\n");
+ try s.expect(name, s.at("{s}/created.txt\n", .{dir}));
+ // A name alone is no edit.
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n");
+}
+
+test "panes: relative names follow a pane/new scratch's session directory, and a virtual one" {
+ var s = try Session.initFile(std.testing.allocator, "source body\n");
+ defer s.deinit();
+ const source = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{source}), "/elsewhere/source.zig\n");
+ // pane/new's scratch is the session's, not the active pane's.
+ const n = try s.newPane();
+ const name = s.at("/pane/{d}/name", .{n});
+ const session = std.fs.path.dirname(std.mem.trimEnd(u8, try s.read(name), "\n")).?;
+ try std.testing.expect(!std.mem.eql(u8, session, "/elsewhere"));
+ const up = std.fs.path.dirname(session) orelse "";
+ try s.write(name, "../out/./notes.txt\n");
+ try s.expect(name, s.at("{s}/out/notes.txt\n", .{up}));
+ try s.write(name, "again.txt\n");
+ try s.expect(name, s.at("{s}/out/again.txt\n", .{up}));
+ try s.write(name, s.at("/virtual/pane/{d}/./body\n", .{source}));
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "get\n");
+ try s.expect(s.at("/pane/{d}/body", .{n}), "source body\n");
+ try s.write(name, "./body\n");
+ try s.expect(name, s.at("/virtual/pane/{d}/body\n", .{source}));
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n");
+}
+
+test "panes: errors appends to one +Errors pane for the pane's directory" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Errors") == null);
+ try s.write(s.at("/pane/{d}/errors", .{n}), "boom\n");
+ try s.write(s.at("/pane/{d}/errors", .{n}), "again\n");
+ const index = try s.read("/index");
+ try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, index, " /+Errors "));
+ const at = std.mem.indexOf(u8, index, " /+Errors ").?;
+ const line = index[(if (std.mem.lastIndexOfScalar(u8, index[0..at], '\n')) |i| i + 1 else 0)..];
+ const serial = line[0..std.mem.indexOfScalar(u8, line, ' ').?];
+ try s.expect(s.at("/pane/{s}/body", .{serial}), "boom\nagain\n");
+}
+
+test "panes: truncating body empties it, and a stat says the length after" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const body = s.at("/pane/{d}/body", .{try s.focused()});
+ const h = try s.hold(body, 1);
+ try s.truncate(h);
+ try std.testing.expectEqual(@as(u64, 0), (try s.stat(body)).size);
+ try s.expect(body, "");
+ s.clunk(h);
+ try s.write(body, "new text\n");
+ try std.testing.expectEqual(@as(u64, 9), (try s.stat(body)).size);
+}
+
+test "panes: a rename colours a source its new name's language names, its text unchanged" {
+ if (!@import("pardes_config").syntax_highlighting) return error.SkipZigTest;
+ var s = try Session.initFile(std.testing.allocator, "fn check() void {}\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const x, const y = try s.where("fn check");
+ const screen = try s.screen();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0..std.mem.indexOfScalar(u8, screen, '\n').?]);
+ const plain = try s.styles();
+ try std.testing.expectEqualStrings(plain[y * cols + x], plain[y * cols + x + 3]);
+ try s.write(s.at("/pane/{d}/name", .{n}), "renamed.zig\n");
+ const coloured = try s.styles();
+ try std.testing.expectEqualStrings(coloured[y * cols + x], coloured[y * cols + x + 1]);
+ try std.testing.expect(!std.mem.eql(u8, coloured[y * cols + x], plain[y * cols + x]));
+ try s.expect(s.at("/pane/{d}/body", .{n}), "fn check() void {}\n");
+}
diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig
index 079b5a5e..3d261808 100644
--- a/test/behaviour/placement.zig
+++ b/test/behaviour/placement.zig
@@ -59,3 +59,113 @@ test "placement: Placement pardes puts a new pane right under the asking one, an
try s.write("/ctl", "Placement\n");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement acme\n") != null);
}
+
+test "placement: a look under pardes's placement, from a pane pane/new made after Delcol, opens its file in a column" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "file\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const first = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{first}), "Placement\n");
+ try s.write(s.at("/pane/{d}/exec", .{first}), "Delcol\n");
+ const made = try s.newPane();
+ try s.write(s.at("/pane/{d}/look", .{made}), s.at("{s}/f.txt:#4\n", .{dir}));
+ const opened = try s.focused();
+ try std.testing.expect(opened != made);
+ // The pane pane/new made is placed, and so is the one its look opened.
+ const cols = try s.columns();
+ for ([_]u32{ made, opened }) |n| try std.testing.expect(std.mem.indexOf(u8, cols, s.at(":{d}", .{n})) != null or std.mem.indexOf(u8, cols, s.at(",{d}", .{n})) != null);
+}
+
+/// Each pane's tag row and its rows down to the next tag, or the screen's
+/// end, as /screen draws them; `names` top to bottom in one column.
+fn spans(s: *Session, comptime n: usize, names: [n][]const u8) ![n][2]usize {
+ var out: [n][2]usize = undefined;
+ for (names, 0..) |name, i| out[i][0] = try tagRow(s, name);
+ const rows = std.mem.count(u8, try s.screen(), "\n") + 1;
+ for (0..n) |i| out[i][1] = (if (i + 1 < n) out[i + 1][0] else rows) - out[i][0];
+ return out;
+}
+
+test "placement: a look from a pane's text goes under its text when it has many blank rows, else halves the biggest pane" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ for ([_][]const u8{ "second.txt", "third.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n");
+ defer s.deinit();
+ s.detach();
+ // Wide enough that a tag with the test's temporary path stays one row,
+ // wherever the checkout is.
+ try s.write("/ctl", "size 200 60\n");
+ const top = try s.focused();
+ // Most of the pane is blank: the look starts under its three lines
+ // (makenewwindow, util.c:482-486).
+ try s.write(s.at("/pane/{d}/look", .{top}), s.at("{s}/second.txt\n", .{at}));
+ const second = try s.focused();
+ const shown = s.at("{s}/second.txt", .{at});
+ try std.testing.expectEqual((try tagRow(&s, "/test.txt")) + 1 + 3, try tagRow(&s, shown));
+ // Both full of text: no blank space is big, so the biggest is halved.
+ const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
+ for ([_]u32{ top, second }) |n| try s.replace(s.at("/pane/{d}/body", .{n}), full);
+ const was = try spans(&s, 2, .{ "/test.txt", shown });
+ const big: usize = if (was[1][1] >= was[0][1]) 1 else 0;
+ try s.write(s.at("/pane/{d}/look", .{second}), s.at("{s}/third.txt\n", .{at}));
+ const third = try s.focused();
+ const ids = [_]u32{ top, second };
+ try std.testing.expect(std.mem.indexOf(u8, try s.columns(), s.at("{d},{d}", .{ ids[big], third })) != null);
+ const made = s.at("{s}/third.txt", .{at});
+ const now = if (big == 1) try spans(&s, 3, .{ "/test.txt", shown, made }) else try spans(&s, 3, .{ "/test.txt", made, shown });
+ try std.testing.expectEqual(was[big][0] + was[big][1] / 2, now[big + 1][0]);
+ try std.testing.expectEqual(was[big][0] + was[big][1], now[big + 1][0] + now[big + 1][1]);
+}
+
+test "placement: a look from the middle of a column splits only the pane it came from, short ones round it kept short, through a Newcol too" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ for ([_][]const u8{ "mid", "low", "made" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ s.detach();
+ try s.write("/ctl", "size 100 60\n");
+ const top = try s.focused();
+ try s.write(s.at("/pane/{d}/look", .{top}), s.at("{s}/mid\n", .{at}));
+ const mid = try s.focused();
+ try s.write(s.at("/pane/{d}/look", .{mid}), s.at("{s}/low\n", .{at}));
+ const low = try s.focused();
+ const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
+ for ([_]u32{ top, mid, low }) |n| try s.replace(s.at("/pane/{d}/body", .{n}), full);
+ // Short names, so a narrowed column draws each tag on one row.
+ try s.write(s.at("/pane/{d}/name", .{mid}), "/mid\n");
+ try s.write(s.at("/pane/{d}/name", .{low}), "/low\n");
+ const names = [_][]const u8{ "/test.txt", "/mid", "/low", "/made" };
+ // The top and bottom panes dragged by their boxes to two and three
+ // rows, under a placement's minimum; the middle one full of text, so
+ // the one halved.
+ const rows = std.mem.count(u8, try s.screen(), "\n") + 1;
+ const r = try spans(&s, 3, names[0..3].*);
+ try s.write("/mousein", s.at("m 0 {d} 1\nm 0 {d} 1\nm 0 {d} 0\n", .{ r[1][0], r[0][0] + 2, r[0][0] + 2 }));
+ try s.write("/mousein", s.at("m 0 {d} 1\nm 0 {d} 1\nm 0 {d} 0\n", .{ r[2][0], rows - 3, rows - 3 }));
+ const was = try spans(&s, 3, names[0..3].*);
+ try std.testing.expectEqual(@as(usize, 2), was[0][1]);
+ try std.testing.expectEqual(@as(usize, 3), was[2][1]);
+ try s.write(s.at("/pane/{d}/look", .{mid}), s.at("{s}/made\n", .{at}));
+ const made = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{made}), "/made\n");
+ try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d},{d}", .{ try s.column(0), top, mid, made, low }), try s.columns());
+ const now = try spans(&s, 4, .{ names[0], names[1], names[3], names[2] });
+ try std.testing.expectEqual(was[0], now[0]);
+ try std.testing.expectEqual(was[2], now[3]);
+ // A new column narrows this one, and the short panes keep their rows.
+ try s.write(s.at("/pane/{d}/exec", .{made}), "Newcol\n");
+ try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, try s.columns(), ":"));
+ const narrowed = try spans(&s, 4, .{ names[0], names[1], names[3], names[2] });
+ try std.testing.expectEqual(was[0][1], narrowed[0][1]);
+ try std.testing.expectEqual(was[2][1], narrowed[3][1]);
+}
diff --git a/test/behaviour/repls.zig b/test/behaviour/repls.zig
new file mode 100644
index 00000000..44c53361
--- /dev/null
+++ b/test/behaviour/repls.zig
@@ -0,0 +1,11 @@
+//! docs/typ/reference.typ, REPLs <repls>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "repls: Repl with no such language is invalid, EINVAL, and names a few whole and how many more" {
+ var s = try Session.initTerm(std.testing.allocator);
+ defer s.deinit();
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/ctl", .{try s.focused()}), "Repl zzlang\n"));
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "Repl: invalid language \"zzlang\"; - or one like zig ada bash c c_sharp clojure (") != null);
+ try std.testing.expect(std.mem.endsWith(u8, s.said, " more)"));
+}
diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig
index 90838d90..12f2b56a 100644
--- a/test/behaviour/root_ctl.zig
+++ b/test/behaviour/root_ctl.zig
@@ -85,3 +85,59 @@ test "root-ctl: the root ctl reads the settings as a write takes them, and takes
try std.testing.expect(std.mem.startsWith(u8, s.said, "Mount x: /tmp/pardes-no-such-sock-zz: no such socket"));
try std.testing.expect(has(try s.read("/ctl"), "Verbose on\n"));
}
+
+test "root-ctl: Kill with a name and nothing running says so and does not fail, as bare Kill does" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try s.write("/ctl", "Kill zzz\n");
+ try std.testing.expect(has(try s.read("/log"), "Kill: nothing running"));
+}
+
+test "root-ctl: a bad Tab width and a bad Incl directory are refused invalid, changing nothing" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const before = try s.read("/ctl");
+ // Bare, Incl lists its directories.
+ try s.write("/ctl", "Incl\n");
+ const listed = try lastIncl(&s);
+ for ([_][]const u8{ "Tab 0\n", "Tab 17\n", "Tab x\n" }) |line| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", line));
+ // Run from a pane, as a tag click runs it: said invalid too.
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), line));
+ try std.testing.expect(has(s.said, "invalid tab width"));
+ }
+ try s.expect("/ctl", before);
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Incl rel/dir\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Incl - /usr/include\n"));
+ try std.testing.expectEqual(@as(u16, 2), try s.refused("/ctl", "Incl /tmp/pardes-surely-no-such-dir\n"));
+ // The same list again: none taken.
+ try s.write("/ctl", "Incl\n");
+ try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, try s.read("/log"), listed));
+ // Bare Tab on the root ctl says the width, as from a pane.
+ try s.write("/ctl", "Tab\n");
+}
+
+/// The log's one `msg - Incl:` record, whole.
+fn lastIncl(s: *Session) ![]const u8 {
+ const log = try s.read("/log");
+ const at = std.mem.indexOf(u8, log, "\nmsg - Incl:") orelse return error.NoIncl;
+ return log[at .. std.mem.indexOfScalarPos(u8, log, at + 1, '\n').? + 1];
+}
+
+test "root-ctl: Joincol with no column to the right and Theme with no such theme say so; a theme's name is any case" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try std.testing.expect(try s.refused("/ctl", "Joincol\n") != 0);
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "Joincol: no column to the right"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Theme drak\n"));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "bad value in control message; like it: "));
+ try std.testing.expect(has(s.said, ": dr"));
+ try std.testing.expect(std.mem.endsWith(u8, s.said, "\"drak\""));
+ // Within the 128 bytes an Rerror carries, the quoted line kept.
+ try std.testing.expect(s.said.len <= 128);
+ // A click on the word says it in the log.
+ _ = try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Theme drak\n");
+ try std.testing.expect(has(try s.read("/log"), "no theme \"drak\""));
+ try s.write("/ctl", "Theme DRACULA\n");
+ try std.testing.expect(has(try s.read("/ctl"), "\nTheme dracula\n"));
+}
diff --git a/test/behaviour/rules.zig b/test/behaviour/rules.zig
index 4b853a40..8f5597ae 100644
--- a/test/behaviour/rules.zig
+++ b/test/behaviour/rules.zig
@@ -37,3 +37,25 @@ test "rules: body reads at any offset and writes append; a stat says its length,
try std.testing.expect((try s.stat(body)).version != st.version);
try std.testing.expectEqual(@as(u32, 0), (try s.stat(s.at("/pane/{d}/tag", .{try s.focused()}))).version);
}
+
+test "rules: every EINVAL a write gets says why, in its err record too; DEL is a control character in a line" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ for ([_][2][]const u8{
+ .{ "/exec", "echo a\x7fb\n" },
+ .{ "/look", "a\x7fb\n" },
+ }) |c| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(c[0], c[1]));
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "control character") != null);
+ }
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/name", .{n}), "\n"));
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "an empty name") != null);
+ const log = try s.hold("/log", 2);
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(log, "bogus\n"));
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "takes `follow`") != null);
+ s.clunk(log);
+ const text = try s.read("/log");
+ try std.testing.expect(std.mem.indexOf(u8, text, "Invalid argument") == null);
+ try std.testing.expect(std.mem.indexOf(u8, text, "an empty name") != null);
+}
diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig
index ff24704a..a24a3010 100644
--- a/test/behaviour/settings.zig
+++ b/test/behaviour/settings.zig
@@ -101,3 +101,171 @@ test "settings: Config without a configuration directory says so and opens nothi
try s.expect("/index", index);
try expectHas(try s.read("/log"), "Config: no startup file here: no configuration directory");
}
+
+test "settings: a bad setting value is quoted, so two different bad values log as two records, never one counted twice" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ _ = try s.refused("/ctl", "Verbose maybe\n");
+ _ = try s.refused("/ctl", "Verbose nope\n");
+ const log = try s.read("/log");
+ try std.testing.expect(has(log, "takes on, off \"maybe\"\n"));
+ try std.testing.expect(has(log, "takes on, off \"nope\"\n"));
+ try std.testing.expect(!has(log, "(x2)"));
+}
+
+test "settings: a setting this frontend cannot show says GUI-only, never run as a command, and DumpDir reads back" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ if (comptime @import("pardes_config").platform != .gui) {
+ _ = try s.refused("/ctl", "Lift on\n");
+ try std.testing.expectEqualStrings("Lift is GUI-only, invalid here \"Lift\"", s.said);
+ _ = try s.refused("/ctl", "GripWidth 120\n");
+ try std.testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", s.said);
+ // A builtin the GUI alone has, written to a ctl or an exec, never
+ // runs as a shell command.
+ _ = try s.refused("/ctl", "Fonts\n");
+ try std.testing.expectEqualStrings("Fonts is GUI-only, invalid here \"Fonts\"", s.said);
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/exec", "Fonts\n"));
+ try std.testing.expectEqualStrings("Fonts is GUI-only, invalid here", s.said);
+ }
+ _ = try s.refused("/ctl", "Liftt on\n");
+ try std.testing.expectEqualStrings("unknown control message \"Liftt\"", s.said);
+ try std.testing.expect(has(try s.read("/ctl"), "\nDumpDir /"));
+}
+
+test "settings: Back and Forward written to exec keep to the focused file, and JumpScope all, written to ctl, takes every place in order" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ // Each a look, as a user's jumps are: b1 a1 b40 a40 b80 a80.
+ for ([_][]const u8{ "b.txt:1", "a.txt:1", "b.txt:40", "a.txt:40", "b.txt:80", "a.txt:80" }) |place| try s.write("/look", s.at("{s}/{s}\n", .{ dir, place }));
+ const Step = struct { []const u8, []const u8, u32 };
+ const walk = struct {
+ fn run(q: *Session, steps: []const Step) !void {
+ for (steps) |st| {
+ try q.write("/exec", q.at("{s}\n", .{st[0]}));
+ const n = try q.focused();
+ try std.testing.expect(std.mem.endsWith(u8, try q.read(q.at("/pane/{d}/name", .{n})), q.at("{s}\n", .{st[1]})));
+ // Each line is `row\n`: the line the dot is on.
+ try std.testing.expectEqual(st[2] - 1, (try q.range(q.at("/pane/{d}/dot", .{n})))[0] / 4);
+ }
+ }
+ }.run;
+ // a's places first, b only once a has none older; Forward mirrors it
+ // from b and ends at a80, where it began.
+ try walk(&s, &.{
+ .{ "Back", "/a.txt", 40 },
+ .{ "Back", "/a.txt", 1 },
+ .{ "Back", "/b.txt", 1 },
+ .{ "Forward", "/b.txt", 40 },
+ .{ "Forward", "/b.txt", 80 },
+ .{ "Forward", "/a.txt", 80 },
+ });
+ try s.write("/ctl", "JumpScope all\n");
+ try std.testing.expect(has(try s.read("/ctl"), "JumpScope all\n"));
+ try walk(&s, &.{
+ .{ "Back", "/b.txt", 80 },
+ .{ "Back", "/a.txt", 40 },
+ .{ "Forward", "/b.txt", 80 },
+ });
+}
+
+const syntax = @import("pardes_config").syntax_highlighting;
+
+/// The style /screen draws the cell `into` cells into the first place
+/// `text` is drawn.
+fn styleOf(s: *Session, text: []const u8, into: usize) ![]const u8 {
+ const x, const y = try s.where(text);
+ const screen = try s.screen();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0..std.mem.indexOfScalar(u8, screen, '\n').?]);
+ return (try s.styles())[y * cols + x + into];
+}
+
+/// How many ` fn ` and ` if ` keywords the screen draws, each of whose two
+/// cells must be drawn in `want`.
+fn keywordsIn(s: *Session, want: []const u8) !usize {
+ const screen = try s.screen();
+ const styles = try s.styles();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0..std.mem.indexOfScalar(u8, screen, '\n').?]);
+ var seen: usize = 0;
+ var rows = std.mem.splitScalar(u8, screen, '\n');
+ var y: usize = 0;
+ while (rows.next()) |row| : (y += 1) for ([_][]const u8{ " fn ", " if " }) |word| {
+ var from: usize = 0;
+ while (std.mem.indexOfPos(u8, row, from, word)) |i| : (from = i + 1) {
+ const x = try std.unicode.utf8CountCodepoints(row[0..i]) + 1;
+ for (0..2) |k| try std.testing.expectEqualStrings(want, styles[y * cols + x + k]);
+ seen += 1;
+ }
+ };
+ return seen;
+}
+
+test "settings: Colors off draws a source plain, and on again colours its keywords, the layout as it was, an edit made while off included" {
+ if (!syntax) return error.SkipZigTest;
+ for ([_]bool{ false, true }) |edit_while_off| {
+ var s = try Session.initFile(std.testing.allocator, "pub fn first() void { if (true) {} }\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{n}), "/colors.zig\n");
+ var ident: []const u8 = "first";
+ if (edit_while_off) {
+ try std.testing.expect(!std.mem.eql(u8, try styleOf(&s, " fn ", 1), try styleOf(&s, "first", 0)));
+ try s.write("/ctl", "Colors off\n");
+ try s.replace(s.at("/pane/{d}/body", .{n}), "pub fn edited() void { if (false) {} }\n");
+ ident = "edited";
+ } else try s.write("/ctl", "Colors off\n");
+ try std.testing.expectEqual(@as(usize, 2), try keywordsIn(&s, try styleOf(&s, ident, 0)));
+ const layout = try s.read("/layout");
+ try s.write("/ctl", "Colors on\n");
+ try s.expect("/layout", layout);
+ const kw = try styleOf(&s, " fn ", 1);
+ try std.testing.expect(!std.mem.eql(u8, kw, try styleOf(&s, ident, 0)));
+ try std.testing.expect(!has(kw, "\"bold\":true"));
+ try std.testing.expectEqual(@as(usize, 2), try keywordsIn(&s, kw));
+ }
+}
+
+test "settings: SyntaxBold keywords stay coloured and bold in every row a pane grows into" {
+ if (!syntax) return error.SkipZigTest;
+ var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&@as([100][33]u8, @splat("pub fn f() void { if (true) {} }\n".*))));
+ defer s.deinit();
+ try s.write(s.at("/pane/{d}/name", .{try s.focused()}), "/resize.zig\n");
+ try s.write("/ctl", "SyntaxBold on\n");
+ s.detach();
+ try s.write("/ctl", "size 80 8\n");
+ const kw = try styleOf(&s, " fn ", 1);
+ try std.testing.expect(has(kw, "\"bold\":true"));
+ for ([_]usize{ 50, 12, 70 }) |rows| {
+ try s.write("/ctl", s.at("size 80 {d}\n", .{rows}));
+ try std.testing.expect(try keywordsIn(&s, kw) >= 2 * (rows - 4));
+ }
+}
+
+test "settings: every on/off setting the root ctl reads flips when its word is written bare, and Theme and Shell take a value" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ var lines = std.mem.tokenizeScalar(u8, try s.read("/ctl"), '\n');
+ var flipped: usize = 0;
+ while (lines.next()) |line| {
+ const space = std.mem.indexOfScalar(u8, line, ' ') orelse continue;
+ const word, const was = .{ line[0..space], line[space + 1 ..] };
+ const on = std.mem.eql(u8, was, "on");
+ if (!on and !std.mem.eql(u8, was, "off")) continue;
+ try s.write("/ctl", s.at("{s}\n", .{word}));
+ try std.testing.expectEqualStrings(s.at("{s} {s}", .{ word, if (on) "off" else "on" }), try setting(&s, word));
+ flipped += 1;
+ }
+ try std.testing.expect(flipped > 20);
+ for ([_][]const u8{ "Colors off", "Wrap off", "Tagbottom on", "Debug on" }) |want|
+ try std.testing.expectEqualStrings(want, try setting(&s, want[0..std.mem.indexOfScalar(u8, want, ' ').?]));
+ try s.write("/ctl", "Theme acme\n");
+ try s.write("/ctl", "Shell /bin/sh\n");
+ try std.testing.expectEqualStrings("Theme acme", try setting(&s, "Theme"));
+ try std.testing.expectEqualStrings("Shell /bin/sh", try setting(&s, "Shell"));
+}
diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig
index 7cfa054f..8609e134 100644
--- a/test/behaviour/tags.zig
+++ b/test/behaviour/tags.zig
@@ -415,3 +415,87 @@ test "tags: a click on a tag puts its cursor there in normal mode: a letter is a
try std.testing.expect(std.mem.indexOf(u8, try tag(&s, n), " SaQve ") != null);
try s.expect(s.at("/pane/{d}/body", .{n}), "body\n");
}
+
+test "tags: a pane's tag reads whole, its path first, and a write appends to its own text up to 4096 bytes" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const path = s.at("/pane/{d}/tag", .{n});
+ const whole = try tag(&s, n);
+ try std.testing.expect(std.mem.startsWith(u8, whole, "/test.txt"));
+ try std.testing.expect(std.mem.indexOf(u8, whole, "Del") != null);
+ try std.testing.expectEqual(@as(u64, whole.len), (try s.stat(path)).size);
+ try s.write(path, " Mine");
+ try std.testing.expectEqualStrings(s.at("{s} Mine", .{whole}), try tag(&s, n));
+ // A tag is a text like the body: a newline written to it stays one.
+ try s.write(path, "\nNext Line");
+ try std.testing.expectEqualStrings(s.at("{s} Mine\nNext Line", .{whole}), try tag(&s, n));
+ // Full, it takes not a byte more.
+ try s.replace(path, &@as([4096]u8, @splat('x')));
+ try std.testing.expectEqual(@as(u16, 28), try s.refused(path, "x"));
+}
+
+test "tags: truncating a tag clears its own text, u in the tag undoes it, and > drops the one newline ending it" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const path = s.at("/pane/{d}/tag", .{n});
+ try s.write(path, " Mine");
+ // Done at the first read or write after it (or the close).
+ const h = try s.hold(path, 1);
+ try s.truncate(h);
+ try std.testing.expect(std.mem.indexOf(u8, try tag(&s, n), "Mine") == null);
+ s.clunk(h);
+ try std.testing.expectEqualStrings("/test.txt", std.mem.trimEnd(u8, try tag(&s, n), " "));
+ // The tag keeps its undo: undoing in it brings back what was cleared.
+ try s.keys(":u:");
+ try std.testing.expect(std.mem.endsWith(u8, try tag(&s, n), " Mine"));
+ // Written back without a leading space, the text still stands apart
+ // from the path, and a click on its first letter lands on it.
+ try s.replace(path, "Get");
+ try std.testing.expectEqualStrings("/test.txt Get", try tag(&s, n));
+ try s.click("Get", 0, 1);
+ try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt"));
+ // `echo Make > tag`: the newline ending the truncating write's text is
+ // dropped, one only; a newline between its writes stays.
+ const m = try s.hold(path, 1);
+ try s.truncate(m);
+ _ = try s.writeFid(m, "Make\n");
+ _ = try s.writeFid(m, "More\n\n");
+ s.clunk(m);
+ try std.testing.expectEqualStrings("/test.txt Make\nMore\n", try tag(&s, n));
+ // `>>` keeps what it is given.
+ try s.write(path, " Tail\n");
+ try std.testing.expectEqualStrings("/test.txt Make\nMore\n Tail\n", try tag(&s, n));
+}
+
+test "tags: a pane tag's file name is tinted, its directory, dirty marker and words not, the tag at the top or the bottom" {
+ for ([_]bool{ false, true }) |bottom| {
+ var s = try Session.initFile(std.testing.allocator, "body\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try s.write("/ctl", "FocusTint off\n");
+ if (bottom) try s.write("/ctl", "Tagbottom\n");
+ try s.write(s.at("/pane/{d}/name", .{n}), "/project/界file.zig\n");
+ try s.write(s.at("/pane/{d}/dirty", .{n}), "1");
+ const x0, const y = try s.where("/project/");
+ const screen = try s.screen();
+ const styles = try s.styles();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0..std.mem.indexOfScalar(u8, screen, '\n').?]);
+ var rows = std.mem.splitScalar(u8, screen, '\n');
+ for (0..y) |_| _ = rows.next();
+ var cells = (try std.unicode.Utf8View.init(rows.next().?)).iterator();
+ var x: usize = 0;
+ var tinted: ?[]const u8 = null;
+ var ink: ?[]const u8 = null;
+ while (cells.nextCodepointSlice()) |cell| : (x += 1) {
+ if (x < x0 or std.mem.eql(u8, cell, " ")) continue;
+ // `界file.zig`: the wide glyph's two cells, then eight.
+ const in_name = x >= x0 + "/project/".len and x < x0 + "/project/".len + 10;
+ const want = if (in_name) &tinted else &ink;
+ if (want.* == null) want.* = styles[y * cols + x];
+ try std.testing.expectEqualStrings(want.*.?, styles[y * cols + x]);
+ }
+ try std.testing.expect(!std.mem.eql(u8, tinted.?, ink.?));
+ }
+}
diff --git a/test/output.zig b/test/output.zig
index 3cfece45..876cd8fc 100644
--- a/test/output.zig
+++ b/test/output.zig
@@ -389,7 +389,9 @@ test "result stepping reaches an unterminated last row" {
try std.testing.expectEqual(@as(i32, 1), result.body.cur_row);
}
-test "Mini uses OS source precedence and refreshes one independent snapshot" {
+// What it shows and when it refreshes is test/behaviour/builtins.zig's;
+// the watch it never asks for is an effect, unseen through 9P.
+test "Mini asks for no watch on its pane" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "x\n" });
@@ -401,27 +403,11 @@ test "Mini uses OS source precedence and refreshes one independent snapshot" {
try std.testing.expect(p.executeBuiltinLine(0, "Mini build.zig"));
const id = p.active;
try std.testing.expect(id != 0);
- const mini = p.panes[id].?;
- try std.testing.expect(mini.terminal == null);
- try std.testing.expectEqualStrings("⠁\n", mini.file.?.content);
- try std.testing.expect(std.mem.startsWith(u8, mini.file.?.mini.?.source, dir));
- const next = p.freeSlot();
- const body = mini.file.?.content.ptr;
- try std.testing.expect(p.executeBuiltinLine(id, "Mini build.zig"));
- try std.testing.expectEqual(id, p.active);
- try std.testing.expectEqual(body, mini.file.?.content.ptr);
- try std.testing.expectEqual(next, p.freeSlot());
- try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "xx\n" });
- try std.testing.expectEqualStrings("⠁\n", mini.file.?.content);
try std.testing.expect(p.executeBuiltinLine(id, "Mini build.zig"));
- try std.testing.expectEqual(id, p.active);
- try std.testing.expectEqualStrings("⠉\n", mini.file.?.content);
while (p.nextEffect()) |effect| switch (effect) {
.watch => |watch| try std.testing.expect(watch.pane != id),
else => {},
};
- try std.testing.expect(p.executeBuiltinLine(id, "Save"));
- try std.testing.expect(mini.prompt == .save);
}
test "Mini dump preserves its exact virtual snapshot and body writes detach colors" {
@@ -617,7 +603,7 @@ test "EffectCode lists readable virtual sources used by this backend" {
try std.testing.expectEqualStrings(pardes.filesystem.sourceBytes(backend_source["/virtual/".len..]).?, source.content);
}
-test "every enabled setting builtin mutates the State Config reports" {
+test "a window's setting builtins (TaglineSize, Font, transitions, scene passes) reach the report DumpConfig writes" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
p.locations_config.layout = .@"inline";
@@ -653,14 +639,8 @@ test "every enabled setting builtin mutates the State Config reports" {
try std.testing.expect(p.executeBuiltinLine(p.active, "DumpConfig"));
const report = p.panes[p.active].?.file.?.content;
- for ([_][]const u8{
- "Colors off\n",
- "Wrap off\n",
- "Tagbottom on\n",
- "Debug on\n",
- "Theme acme\n",
- "Shell fish\n",
- }) |line| try std.testing.expect(std.mem.indexOf(u8, report, line) != null);
+ // The toggles, Theme and Shell are test/behaviour/settings.zig's, through
+ // the root ctl; what is left is a window's (fonts, transitions, passes).
const transition = if (!builtins.viewCapabilities(p).panel_transitions)
"PanelSlide unsupported\n"
else if (p.settings.panel_transition == .off)
@@ -821,7 +801,7 @@ test "LookNext/LookPrev selects one output location per row and opens nothing" {
try std.testing.expectEqual(panes.Output.Grain.word, panes.Output.grain(p.panes[p.active].?.file.?.output));
}
-test "LookNext/LookPrev resumes the result output whose Look moved focus away" {
+test "LookNext/LookPrev keeps the result output a Look chose through a no-match answer, and a stale serial once it is deleted" {
if (platform == .web) return;
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
@@ -844,12 +824,8 @@ test "LookNext/LookPrev resumes the result output whose Look moved focus away" {
try std.testing.expect(results.look_at != null);
try std.testing.expectEqual(results.serial, p.look_walk_owner orelse return error.MissingLookOwner);
- lookKey(p, 'n');
- try std.testing.expectEqual(rid, p.active);
- try std.testing.expectEqual(first + 1, results.body.cur_row);
- lookKey(p, 'N');
- try std.testing.expectEqual(first, results.body.cur_row);
-
+ // The walk on and back from it is test/behaviour/keys.zig's; what is
+ // left needs answers put in by fillResults.
// A later no-match answer has no position to resume and therefore cannot
// steal the provenance established by the Look above.
const owner = results.serial;
@@ -924,34 +900,6 @@ test "LookPrev exactly reverses LookNext across output panes and the ring seam"
try std.testing.expect(saw_first and saw_second);
}
-test "LookNext/LookPrev selects command outputs by whole row" {
- if (platform == .web) return;
- var cwd_buf: [4096]u8 = undefined;
- var path_buf: [4096]u8 = undefined;
- const paths = try projectPaths(&cwd_buf, &path_buf);
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 40, .file = paths.boot });
- defer p.deinit();
- p.update(.{ .resize = .{ .cols = 100, .rows = 40 } });
-
- try std.testing.expect(p.executeBuiltinLine(p.active, "Themes"));
- const tid = p.panes[p.active].?.search_pane orelse return error.MissingThemeList;
- const themes = p.panes[tid].?;
- try std.testing.expect(panes.Output.fileTraits(themes.file.?.output).commands);
- lookKey(p, 'n');
- const row0 = std.mem.trimEnd(u8, modal.lineSlice(themes.file.?.content, 1), " \t\r");
- try std.testing.expectEqualStrings(row0, selectedOutputText(themes) orelse "");
- const theme_before = p.settings.theme;
- lookKey(p, 'n');
- p.update(.{ .key = .{ .cp = Key.tab } });
- try std.testing.expect(p.settings.theme != theme_before);
-
- try std.testing.expect(p.executeBuiltinLine(0, "Look build.zig"));
- p.update(.tick);
- try std.testing.expect(p.active != 0);
- lookKey(p, 'n');
- try std.testing.expectEqual(@as(usize, 0), p.active);
-}
-
test "identical result refresh keeps warm content caches without allocation" {
var allocator: std.testing.FailingAllocator = .init(std.testing.allocator, .{});
const p = try Pardes.init(allocator.allocator(), .{ .tty_only = true, .cols = 80, .rows = 24 });
diff --git a/test/panes.zig b/test/panes.zig
index 3b842c59..6b2af760 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -790,75 +790,8 @@ const JumpSelectionTests = struct {
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col1, .row = row1 } });
}
- fn exercise(prefix: []const u8, wrap: bool, reverse: bool, first_col: u16, last_col: u16, expected: ?[]const u8) !void {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 34, .rows = 10 });
- defer p.deinit();
- p.settings.wrap = wrap;
- const text = try std.fmt.allocPrint(p.gpa, "{s}{s}", .{ prefix, std.mem.asBytes(&@as([80][27]u8, @splat("unrelated destination text\n".*))) });
- defer p.gpa.free(text);
- const pane = try p.setTestFile(text);
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- if (wrap) try std.testing.expectEqual(pane.wrap_line[0], pane.wrap_line[1]);
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = p.bodyTop(pane, rect);
- if (reverse)
- drag(p, x + last_col, y + 1, x + first_col, y)
- else
- drag(p, x + first_col, y, x + last_col, y + 1);
-
- const selected = try p.gpa.dupe(u8, pardes.exec.heldSelection(p, 0) orelse return error.MissingMouseSelection);
- defer p.gpa.free(selected);
- if (expected) |want| try std.testing.expectEqualStrings(want, selected);
- try std.testing.expect(std.mem.indexOfScalar(u8, selected, '\n') != null);
- if (wrap) try std.testing.expect(std.mem.indexOf(u8, selected, "界") != null);
-
- // Seed two actual locations after the drag, so both history directions
- // must scroll and discard the previous selection.
- p.njumps = 2;
- p.jcur = 1;
- p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 60, .col = 1 };
- p.jumps[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 };
- p.update(.{ .key = .{ .cp = 'o', .ctrl = true } });
- _ = frame.reset(.retain_capacity);
- _ = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 0), p.jcur);
- try std.testing.expect(pane.file.?.scroll > 20);
- try LookResetTests.cleared(pane);
- try std.testing.expect(!pane.body.vsel.active);
- try std.testing.expect(pardes.exec.heldSelection(p, 0) == null);
- try std.testing.expectEqual(@as(i32, 59), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col);
-
- // A selection created after Back must also disappear on Forward.
- // Back announces itself, so the body sits under a notice band now.
- const y2 = p.bodyTop(pane, p.rects[0]);
- drag(p, x + 1, y2, x + 3, y2 + 1);
- try std.testing.expect(pardes.exec.heldSelection(p, 0) != null);
- p.update(.{ .key = .{ .cp = 'i', .ctrl = true } });
- _ = frame.reset(.retain_capacity);
- _ = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 1), p.jcur);
- try std.testing.expectEqual(@as(usize, 0), pane.file.?.scroll);
- try LookResetTests.cleared(pane);
- try std.testing.expect(!pane.body.vsel.active);
- try std.testing.expect(pardes.exec.heldSelection(p, 0) == null);
- try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col);
- }
-
- test "jump selection clears copied sweeps in both history directions" {
- for ([_]bool{ false, true }) |reverse|
- try exercise("alpha\nbravo\n", false, reverse, 1, 3, "lpha\nbrav");
- }
-
- test "jump selection clears wrapped Unicode and tab rectangles" {
- for ([_]bool{ false, true }) |reverse|
- try exercise("界\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n", true, reverse, 0, 8, null);
- }
-
+ // One pane's Back and Forward are test/behaviour/keys.zig's; this
+ // one seeds held selections in two panes, which only internals reach.
test "jump selection clears source and destination state across panes" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
defer p.deinit();
@@ -949,7 +882,9 @@ const TagNameTintTests = struct {
return visible_name;
}
- test "tag filename tint excludes directories dirty marker and output commands" {
+ // A file pane's is test/behaviour/tags.zig's; a search pane's needs
+ // results put in through fillResults.
+ test "tag filename tint of a search pane excludes its directory and command" {
for ([_]bool{ false, true }) |bottom| {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 24 });
defer p.deinit();
@@ -961,7 +896,6 @@ const TagNameTintTests = struct {
configure(p);
defer p.custom_theme = null;
p.settings.tag_bottom = bottom;
- try std.testing.expect((try check(p, 0, pane.file.?.path)) > 0);
try panes.Output.fillResults(p, 0, "/project", .search, "tint", try p.gpa.dupe(u8, "no matches\n"), null);
const id = pane.search_pane.?;
p.update(.tick);
@@ -1399,11 +1333,13 @@ test "a prompt that cannot be opened leaves the open one as it was" {
}
}
-test "Save's prompt starts from the pane's directory" {
+// A file's directory is test/behaviour/keys.zig's; an owned directory (a
+// shell's) ending in a slash, or none, only a real shell gives.
+test "Save's prompt starts from an owned directory ending in a slash, or none" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
const pane = try p.setTestFile("one\n");
- for ([_][]const u8{ "/dír space", "/dír space/", "" }) |dir| {
+ for ([_][]const u8{ "/dír space/", "" }) |dir| {
try pane.setOwnedCwd(dir);
const slash = if (dir.len == 0 or dir[dir.len - 1] != '/') "/" else "";
p.startPrompt(pane, &pane.body, .save);
@@ -3774,101 +3710,6 @@ test "cancelled normal gestures leave no count or subprefix through raw tty mode
}
}
-test "Colors restores syntax after rendering disabled files and disabled edits" {
- if (!syntax.enabled) return error.SkipZigTest;
- const gpa = std.testing.allocator;
- for ([_]bool{ false, true }) |edit_while_disabled| {
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("pub fn first() void { if (true) {} }\n");
- const file = &pane.file.?;
- gpa.free(file.path);
- file.path = try gpa.dupe(u8, "/colors.zig");
- p.settings.colors = edit_while_disabled;
- p.presentation.enabled = false;
- var frame = std.heap.ArenaAllocator.init(gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- if (edit_while_disabled) {
- try std.testing.expect(file.highlights.len > 0);
- p.update(.{ .command = "Colors" });
- panes.File.setContent(p, file, try gpa.dupe(u8, "pub fn edited() void { if (false) {} }\n"));
- _ = frame.reset(.retain_capacity);
- _ = try p.render(frame.allocator());
- }
- try std.testing.expect(!p.settings.colors);
- try std.testing.expectEqual(@as(usize, 0), file.highlights.len);
- try std.testing.expect(!file.syntax_dirty);
- const rect = p.rects[0];
- const cols = pane.cols;
- const rows = pane.rows;
- p.update(.{ .command = "Colors" });
- try std.testing.expectEqual(rect, p.rects[0]);
- try std.testing.expectEqual(cols, pane.cols);
- try std.testing.expectEqual(rows, pane.rows);
- _ = frame.reset(.retain_capacity);
- const surface = try p.render(frame.allocator());
- try std.testing.expect(p.settings.colors);
- try std.testing.expect(file.highlights.len > 0);
- try std.testing.expect(!file.syntax_dirty);
- var seen: usize = 0;
- for (surface.cells[0 .. surface.cells.len - 1], 0..) |*first, i| {
- const second = &surface.cells[i + 1];
- if (!(std.mem.eql(u8, first.grapheme(), "f") and std.mem.eql(u8, second.grapheme(), "n")) and
- !(std.mem.eql(u8, first.grapheme(), "i") and std.mem.eql(u8, second.grapheme(), "f"))) continue;
- seen += 1;
- for ([_]*pardes.Cell{ first, second }) |cell| {
- try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, cell.style.fg);
- try std.testing.expect(!cell.style.bold);
- }
- }
- try std.testing.expectEqual(@as(usize, 2), seen);
- }
-}
-
-test "growing a file pane colors every newly visible Zig keyword" {
- if (!syntax.enabled) return error.SkipZigTest;
- const gpa = std.testing.allocator;
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 8 });
- defer p.deinit();
- const pane = try p.setTestFile(std.mem.asBytes(&@as([100][33]u8, @splat("pub fn f() void { if (true) {} }\n".*))));
- const file = &pane.file.?;
- gpa.free(file.path);
- file.path = try gpa.dupe(u8, "/resize.zig");
- p.update(.{ .command = "SyntaxBold" });
- try std.testing.expect(p.settings.syntax_bold);
- p.settings.colors = true;
- p.presentation.enabled = false;
- var frame = std.heap.ArenaAllocator.init(gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const initial_end = file.highlight_start + file.highlights.len;
- for ([_]u16{ 50, 12, 70 }) |rows| {
- p.update(.{ .resize = .{ .cols = 80, .rows = rows } });
- _ = frame.reset(.retain_capacity);
- const surface = try p.render(frame.allocator());
- const rect = p.rects[0];
- const body_y = bodyY(p, rect);
- var seen: usize = 0;
- for (body_y..body_y + bodyH(p, rect)) |y| {
- for (rect.x + config.GUTTER..rect.x + rect.w - 1) |x| {
- const first = surface.at(@intCast(x), @intCast(y));
- const second = surface.at(@intCast(x + 1), @intCast(y));
- if (!(std.mem.eql(u8, first.grapheme(), "f") and std.mem.eql(u8, second.grapheme(), "n")) and
- !(std.mem.eql(u8, first.grapheme(), "i") and std.mem.eql(u8, second.grapheme(), "f"))) continue;
- seen += 1;
- for ([_]*pardes.Cell{ first, second }) |cell| {
- try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, cell.style.fg);
- try std.testing.expect(cell.style.bold);
- }
- }
- }
- try std.testing.expect(seen >= 2 * (rows - 4));
- try std.testing.expect(file.highlight_start + file.highlights.len > initial_end);
- try std.testing.expect(!file.syntax_dirty);
- }
-}
-
test "Zig keywords keep every rendered byte colored across line-number widths" {
if (!syntax.enabled) return error.SkipZigTest;
const gpa = std.testing.allocator;
diff --git a/test/pdf.zig b/test/pdf.zig
index a068fc40..16522af6 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -1146,34 +1146,6 @@ fn copySourceRect(
return out;
}
-test "PDF normal mode keeps `:`, SPC and `/` on their shared paths" {
- if (!pdf_enabled or platform == .web) return;
-
- const p = try Pardes.init(std.testing.allocator, .{
- .file = "docs/design.pdf",
- .cols = 80,
- .rows = 24,
- });
- defer p.deinit();
- const pane = p.panes[0].?;
- p.native_images = false;
-
- // Cross-pane BODY-NORMAL actions keep their established shared paths.
- p.update(.{ .key = .{ .cp = ':' } });
- try std.testing.expect(pane.focus == .tag);
- try std.testing.expectEqual(Mode.normal, pane.body.mode);
- p.update(.{ .key = .{ .cp = ':' } });
- try std.testing.expect(pane.focus == .body);
- p.update(.{ .key = .{ .cp = ' ' } });
- try std.testing.expect(p.leader_on);
- p.update(.{ .key = .{ .cp = '!' } });
- try std.testing.expect(!p.leader_on);
- p.update(.{ .key = .{ .cp = '/' } });
- try std.testing.expect(pane.prompt == .search and pane.focus == .body);
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(pane.prompt == .none);
-}
-
test "Escape cancels PDF chrome in place, then leaves the pane; Shift-Escape leaves at once" {
if (!pdf_enabled or platform == .web) return;
diff --git a/test/session.zig b/test/session.zig
index 16a131fd..f572a4b1 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -314,6 +314,35 @@ pub const Session = struct {
var it = std.mem.splitScalar(u8, tag[lo + 2 .. close], '/');
return .{ try std.fmt.parseInt(u32, it.next().?, 10), try std.fmt.parseInt(u32, it.next() orelse return error.NoPage, 10) };
}
+
+ // pane2:
+
+ /// Each cell's style as /screen draws it, as JSON text (compare two
+ /// cells by it), row-major as `screen` draws the cells: row `y`'s cell
+ /// `x` is `[y * cols + x]`.
+ pub fn styles(s: *Session) ![]const []const u8 {
+ const a = s.arena.allocator();
+ const json = try std.json.parseFromSliceLeaky(std.json.Value, a, try s.read("/screen"), .{});
+ const kinds = json.object.get("styles").?.array.items;
+ const named = try a.alloc([]const u8, kinds.len);
+ for (kinds, named) |style, *text| text.* = try std.json.Stringify.valueAlloc(a, style, .{});
+ const cells = json.object.get("cells").?.array.items;
+ const out = try a.alloc([]const u8, cells.len);
+ for (cells, out) |cell, *style| style.* = named[@intCast(cell.array.items[1].integer)];
+ return out;
+ }
+
+ // core2:
+
+ /// The background /screen draws at a cell, as its JSON (`{"rgb":[255,255,255]}`).
+ pub fn bg(s: *Session, col: usize, row: usize) ![]const u8 {
+ const a = s.arena.allocator();
+ const json = try std.json.parseFromSliceLeaky(std.json.Value, a, try s.read("/screen"), .{});
+ const cols: usize = @intCast(json.object.get("cols").?.integer);
+ const cell = json.object.get("cells").?.array.items[row * cols + col];
+ const style = json.object.get("styles").?.array.items[@intCast(cell.array.items[1].integer)];
+ return std.json.Stringify.valueAlloc(a, style.object.get("bg").?, .{});
+ }
};
fn refusal(path: []const u8, r: Reply) error{Refused} {