From 7bbcd971a761def328fb9eeb881301bf45fb4783 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:28:11 -0300 Subject: test: twenty-one of src/ninep/ctl.zig's tests through the 9P tree alone: in test/behaviour/look_and_exec.zig a look's miss quoting up to 256 bytes then an ellipsis, @p:
taking any sam address (a miss and an unknown serial errs), file:3:0 refused as addr 3:0 is, ./x, ../x, x and /abs/x misses, a terminal's file:addr miss logged once, and an exec's builtin refused wrong #args bare or with an argument it takes none of; in flags.zig Undo and Redo stepping the body and saying when there is none (counted), dirty back to 0 at the saved text; in edit.zig an Edit rename one undo step and a failed one changing nothing; in panes.zig Mini bare, the name word bare, and ctl's undo and redo fields; in addresses.zig malformed addresses and a terminal's addr, dot and limit refused; in event.zig a bad record's words; in the new repls.zig Repl with no such language; in settings.zig two bad values logged as two; in root_ctl.zig Kill with a name and nothing running; in mounts.zig an unknown network a bad dial address; the old Unmount test dropped, mounts.zig's first test covering it; each checked to fail against a break (miss_path_cap 200, "no pane at", captured's wrong #args words, Redo's and Kill's messages, the name word's refusal, an event's backwards-range words, e_syntax, Repl's "others)", Mount's bad dial words, a splice back to the saved text left dirty, Edit's no substitution words, a setting's refusal quoting "x", zeroColumn missing a column 0, a look's no such file words, a terminal's text miss unquoted, ctl's undo flag needing two edits) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour.zig | 1 + 1 file changed, 1 insertion(+) (limited to 'test/behaviour.zig') diff --git a/test/behaviour.zig b/test/behaviour.zig index d9b15183..72806b21 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -18,6 +18,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"); -- cgit v1.3 From 350e7cc22b85130cbe95a114c668945b1dc12fd7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:52:24 -0300 Subject: test: twenty-two more of src/ninep/ctl.zig's tests through the 9P tree alone: in test/behaviour/look_and_exec.zig a look opening a spaced path at its line and column leaving the source as it was, a batch validated whole before any virtual file opens, /status's lines, mode and refusal with look and exec validating batches and reading back their panes, a look at a file it may not read, a trailing colon dropped and a failed address opening nothing, a file:/re/ miss logged as its file's pane, a look into another pane leaving the source's dot, a word looked for in its own pane (wrapping, then LookWord list's +Search), a second LookWord list look refilling its +Search, @pN: and a line past the end said one way, an exec over the command limit, a builtin failing through exec, tagexec and a column's exec with one err and no msg, and Look . from a gone directory; in rules.zig every EINVAL's words, the log's too; in limits.zig a ctl line over 1 MiB refused once; in panes.zig acme's ctl words and +Unsaved dropping a closed pane's row; in the new from_acme.zig Put, Delete and acme's words refused; in settings.zig GUI-only settings and DumpDir read back; in root_ctl.zig Joincol and Theme's refusals and a theme's name in any case; in placement.zig a look from a pane made after Delcol placed in a column; in edit.zig Edit ,p logged with no room for +Errors; the status test kept for its window's pointer line, and Joincol's for themesNear's unit checks, each trimmed; each checked to fail against a break (status's pane count, a look's open failure words, the trailing colon kept, e_no_match, the empty name's words, the 1 MiB cap doubled, acme's Put renamed, the GUI-only words, themeIndex by case, command_max 1023, a repeat counted by two, Look .'s no such directory words, dropUnsaved doing nothing, lookWord not wrapping, limit=addr not taking, Edit's text not logged when unplaced, @pN: with no address a miss, a look into another pane clearing the source's dot, a column taken as the cursor's, the batch's control-character check and command's checking pass both skipped, LookWord's +Search never shared, atFoot placing nothing) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/ninep/ctl.zig | 558 +-------------------------------------- test/behaviour.zig | 1 + test/behaviour/edit.zig | 12 + test/behaviour/from_acme.zig | 28 ++ test/behaviour/limits.zig | 22 ++ test/behaviour/look_and_exec.zig | 261 ++++++++++++++++++ test/behaviour/panes.zig | 45 ++++ test/behaviour/placement.zig | 20 ++ test/behaviour/root_ctl.zig | 18 ++ test/behaviour/rules.zig | 22 ++ test/behaviour/settings.zig | 20 ++ 11 files changed, 458 insertions(+), 549 deletions(-) create mode 100644 test/behaviour/from_acme.zig (limited to 'test/behaviour.zig') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index fc09c730..f23f2579 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1466,118 +1466,16 @@ test "commands lists every builtin with its argument and the ctl that takes it" } -test "status reads the editor, and look and exec validate whole batches" { - const gpa = testing.allocator; - const p = try withFile(gpa, "Msg root\n"); +test "status in a window says whether the pointer is over it" { + // The rest of status is test/behaviour/look_and_exec.zig's: a session + // there is a terminal's view. + const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); - // A terminal's view first (a window's build starts windowed). - p.windowed = false; - const status = rd(p, root_status, 0, 4096); - try testing.expectEqual(Status.ok, status.reply.status); - var lines = std.mem.tokenizeScalar(u8, status.bytes, '\n'); - try testing.expect(std.mem.startsWith(u8, lines.next().?, "pid ")); - var expected: [64]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "version {s}", .{pardes.version}), lines.next().?); - var live: usize = 0; - for (p.panes) |slot| live += @intFromBool(slot != null); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "panes {d}", .{live}), lines.next().?); - try testing.expect(lines.next() == null); - // A window says whether the pointer is over it. p.windowed = true; - var again = std.mem.tokenizeScalar(u8, rd(p, root_status, 0, 4096).bytes, '\n'); - for (0..3) |_| _ = again.next(); - try testing.expectEqualStrings("pointer out", again.next().?); + var lines = std.mem.tokenizeScalar(u8, rd(p, root_status, 0, 4096).bytes, '\n'); + for (0..3) |_| _ = lines.next(); + try testing.expectEqualStrings("pointer out", lines.next().?); p.windowed = false; - const stat = call(p, .{ .tag = 1, .op = .getattr, .node = root_status }); - try testing.expectEqual(@as(u64, status.bytes.len), stat.reply.attr.size); - try testing.expectEqual(@as(u16, 0o444), stat.reply.attr.mode); - try testing.expectEqual(E.PERM, wr(p, root_status, "anything\n").errno()); - try testing.expectEqualStrings("", rd(p, root_exec, 0, 4096).bytes); - - const serial = p.next_serial; - for ([_][]const u8{ "Msg a\x00b", "Msg x\nMsg \x01y\n" }) |invalid| { - try testing.expectEqual(E.INVAL, wr(p, root_exec, invalid).errno()); - try testing.expectEqual(serial, p.next_serial); - } - // An empty write is a no-op, not a command. - try testing.expectEqual(Status.ok, wr(p, root_exec, "\n \n").reply.status); - try testing.expectEqualStrings("", rd(p, root_exec, 0, 4096).bytes); - try testing.expectEqualStrings(status.bytes, rd(p, root_status, 0, 4096).bytes); - - const pane = p.panes[0].?; - try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg hello there\n").reply.status); - try testing.expectEqualStrings("hello there", pane.msg[0..pane.msg_len]); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{pane.serial}), rd(p, root_exec, 0, 4096).bytes); - - try testing.expectEqual(Status.ok, wr(p, root_look, "/virtual/index\n").reply.status); - const opened = p.panes[p.active].?; - try testing.expectEqualStrings("/virtual/index", opened.file.?.path); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes); - - try testing.expectEqual(Status.ok, wr(p, root_exec, "New\n").reply.status); - const made = p.panes[p.active].?; - try testing.expect(made.serial != opened.serial); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{made.serial}), rd(p, root_exec, 0, 4096).bytes); -} - -test "look opens spaced paths and locations without editing the source pane" { - if (!fs.platform_has_fs) return error.SkipZigTest; - const gpa = testing.allocator; - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "two words.zig", .data = "first\nsecond\nthird\n" }); - var path_buf: [4096]u8 = undefined; - const path = path_buf[0..try tmp.dir.realPathFile(testing.io, "two words.zig", &path_buf)]; - const p = try withFile(gpa, "source stays intact\n"); - defer p.deinit(); - const source = p.panes[0].?; - const look_node = Node.of(source.serial, .look); - const revision = source.file.?.revision; - const undo_len = source.file.?.history.undo_len; - source.body.cur_col = 3; - var clicked: [4200]u8 = undefined; - try testing.expectEqual(Status.ok, wr(p, look_node, try std.fmt.bufPrint(&clicked, "{s}:2:3\n", .{path})).reply.status); - const opened = p.panes[p.active].?; - try testing.expect(opened != source); - try testing.expectEqualStrings(path, opened.file.?.path); - try testing.expectEqualStrings("first\nsecond\nthird\n", opened.file.?.content); - try testing.expectEqual(@as(i32, 1), opened.body.cur_row); - try testing.expectEqual(@as(i32, 2), opened.body.cur_col); - try testing.expectEqualStrings("source stays intact\n", source.file.?.content); - try testing.expectEqual(revision, source.file.?.revision); - try testing.expectEqual(undo_len, source.file.?.history.undo_len); - try testing.expectEqual(@as(i32, 3), source.body.cur_col); - var expected: [16]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes); - - p.active = 0; - try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&clicked, "{s}:3:2\n", .{path})).reply.status); - try testing.expect(p.panes[p.active].? == opened); - try testing.expectEqual(@as(i32, 2), opened.body.cur_row); - try testing.expectEqual(@as(i32, 1), opened.body.cur_col); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes); -} - -test "look validates the whole batch before opening virtual files" { - const gpa = testing.allocator; - const p = try withFile(gpa, "source\n"); - defer p.deinit(); - const source = p.panes[0].?; - const look_node = Node.of(source.serial, .look); - const serial = p.next_serial; - for ([_][]const u8{ - "/virtual/index\x00ignored", "/virtual/index\n/virtual/\x01index\n", - }) |invalid| { - try testing.expectEqual(E.INVAL, wr(p, look_node, invalid).errno()); - try testing.expectEqual(serial, p.next_serial); - try testing.expectEqual(@as(usize, 0), p.active); - try testing.expectEqualStrings("source\n", source.file.?.content); - } - try testing.expectEqual(Status.ok, wr(p, look_node, "/n/self/index\n").reply.status); - const opened = p.panes[p.active].?; - try testing.expectEqualStrings("/virtual/index", opened.file.?.path); - try testing.expect(std.mem.indexOf(u8, opened.file.?.content, "/test.txt") != null); - try testing.expectEqualStrings("source\n", source.file.?.content); } @@ -1795,55 +1693,6 @@ test "a refusal's +Unsaved goes in the session's directory when the active pane' try testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(unsaved).?); } -test "a look at a file it may not read fails the write naming the file" { - if (comptime !pardes.hosted) return; - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "locked.txt", .data = "secret\n", .flags = .{ .permissions = .fromMode(0o000) } }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - const path = try std.fmt.bufPrint(&line, "{s}/locked.txt", .{dir}); - var want: [4200]u8 = undefined; - const expected = try std.fmt.bufPrint(&want, "look: {s}: permission denied", .{path}); - var with_newline: [4300]u8 = undefined; - const refused = wr(p, root_look, try std.fmt.bufPrint(&with_newline, "{s}\n", .{path})); - if (refused.reply.status == .ok) return error.SkipZigTest; // root reads anything - try testing.expectEqualStrings(expected, refused.reply.ename); -} - -test "a look line's trailing colon is dropped, and a look whose address fails never leaves its file open" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - const count = struct { - fn of(pp: *Pardes) usize { - var n: usize = 0; - for (pp.panes) |slot| n += @intFromBool(slot != null); - return n; - } - }.of; - const before = count(p); - // Failing addresses: nothing opened, the write still answered. - inline for ([_][]const u8{ "{s}/a.txt:/nomatch/\n", "{s}/a.txt:9:\n" }) |fmt| { - _ = wr(p, root_look, try std.fmt.bufPrint(&line, fmt, .{dir})); - try testing.expectEqual(before, count(p)); - } - // `a.txt:2:3:` is `a.txt:2:3`: it opens there. - try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:2:3:\n", .{dir})).reply.status); - try testing.expectEqual(before + 1, count(p)); - const opened = p.panes[p.active].?; - try testing.expect(std.mem.endsWith(u8, opened.file.?.path, "/a.txt")); - try testing.expectEqual(@as(i32, 1), opened.body.cur_row); -} - test "a builtin's Verbose announcement is logged only when it succeeds, its failure said now or by the host later" { const gpa = testing.allocator; @@ -2019,32 +1868,10 @@ test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path, try testing.expectEqual(Status.ok, wr(p, root_ctl, "ThemeFile " ++ path ++ "\n").reply.status); } -test "Joincol with no column to the right and Theme with no such theme say so" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - const joined = wr(p, root_ctl, "Joincol\n"); - try testing.expectEqual(tree.Status.err, joined.reply.status); - try testing.expectStringStartsWith(joined.reply.ename, "Joincol: no column to the right"); - const themed = wr(p, root_ctl, "Theme drak\n"); - try testing.expectEqual(E.INVAL, themed.errno()); - try testing.expectStringStartsWith(themed.reply.ename, "bad value in control message; like it: "); - try testing.expect(std.mem.indexOf(u8, themed.reply.ename, ": dr") != null); - try testing.expect(std.mem.endsWith(u8, themed.reply.ename, "\"drak\"")); - // A click on the word says it on the message row. - _ = wr(p, Node.of(serialOf(p), .exec), "Theme drak\n"); - const pane = p.panes[p.active].?; - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "no theme \"drak\"") != null); - // Within the 128 bytes an Rerror carries, the quoted line kept. - try testing.expect(themed.reply.ename.len <= 128); - // A name in any case is the theme. - try testing.expectEqual(Status.ok, wr(p, root_ctl, "Theme DRACULA\n").reply.status); - try testing.expectEqualStrings("dracula", pardes.themes[p.settings.theme].name); - // A misspelling far from any first letter's list still finds its like. +test "themesNear finds a misspelling's like far from any first letter, and every theme sharing the first letter when they fit" { + // Joincol and Theme's refusals are test/behaviour/root_ctl.zig's. var near: [170]u8 = undefined; try testing.expect(std.mem.indexOf(u8, pardes.colors.themesNear(&near, "9dracula"), "dracula") != null); - // Every theme sharing the first letter, when they fit. var tested = false; for ("abcdefghijklmnopqrstuvwxyz") |letter| { var count: usize = 0; @@ -2081,26 +1908,6 @@ test "a look whose pane is refused a place fails with that alone, not a missing try testing.expectEqual(@as(usize, 1), th.logCount(p, "\nerr ")); } -test "a look under pardes's placement, from a pane pane/new made after Delcol, opens its file" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "file\n" }); - var dir: [4096]u8 = undefined; - const at = dir[0..try tmp.dir.realPath(testing.io, &dir)]; - var line: [4200]u8 = undefined; - const first = serialOf(p); - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(first, .exec), "Placement\n").reply.status); - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(first, .exec), "Delcol\n").reply.status); - const made = try th.newPane(p); - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(made, .look), try std.fmt.bufPrint(&line, "{s}/f.txt:#4\n", .{at})).reply.status); - // The pane pane/new made is placed, and so is the one its look opened. - for (p.panes, 0..) |slot, i| if (slot != null) try testing.expect(layout.findPane(p, i) != null); - try testing.expect(p.panes[p.active].?.serial != made); -} - test "a Restore of a file that is no dump fails the write before any warning, and a failed Dump fails its write" { if (comptime !pardes.hosted) return error.SkipZigTest; const p = try withFile(testing.allocator, "x\n"); @@ -2133,58 +1940,6 @@ test "a Restore of a file that is no dump fails the write before any warning, an try testing.expectEqualStrings("Dump /dev/null/pardes.dump.zon: /dev/null is not a directory", p.fs.late_failure[0..p.fs.late_failure_len]); } -test "a setting this frontend cannot show says GUI-only, and DumpDir reads back the directory in effect" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - if (!builtins.viewCapabilities(p).lift) { - try testing.expectEqualStrings("Lift is GUI-only, invalid here \"Lift\"", wr(p, root_ctl, "Lift on\n").reply.ename); - try testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", wr(p, root_ctl, "GripWidth 120\n").reply.ename); - // A builtin the GUI alone has, written to a ctl or an exec, never - // runs as a shell command. - if (comptime !pardes.font_picker) { - try testing.expectEqualStrings("Fonts is GUI-only, invalid here \"Fonts\"", wr(p, root_ctl, "Fonts\n").reply.ename); - const ran = wr(p, root_exec, "Fonts\n"); - try testing.expectEqual(E.INVAL, ran.errno()); - try testing.expectEqualStrings("Fonts is GUI-only, invalid here", ran.reply.ename); - } - } - try testing.expectEqualStrings("unknown control message \"Liftt\"", wr(p, root_ctl, "Liftt on\n").reply.ename); - var buf: [900]u8 = undefined; - if (pardes.dump.directory(&buf, "")) |dir| { - var want: [920]u8 = undefined; - const line = try std.fmt.bufPrint(&want, "\nDumpDir {s}\n", .{dir}); - try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, line) != null); - } -} - -test "an exec line over the command limit fails the write and says the limit; a builtin's may be longer" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const long = "echo " ++ &@as([pardes.exec.command_max]u8, @splat('y')) ++ "\n"; - const refused = wr(p, root_exec, long); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expectEqualStrings(e_too_long, refused.reply.ename); - var rec: [96]u8 = undefined; - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: a command line is at most 1024 bytes", .{serialOf(p)}))); - try testing.expectEqualStrings(e_control, wr(p, root_exec, "echo a\x01b\n").reply.ename); - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: it holds", .{serialOf(p)}))); - try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg " ++ &@as([1100]u8, @splat('z')) ++ "\n").reply.status); -} - -test "Edit's p and = never fail for want of room for +Errors: the text is logged instead" { - const p = try withFile(testing.allocator, "one\ntwo\n"); - defer p.deinit(); - p.update(.{ .resize = .{ .cols = 80, .rows = 6 } }); - const ctl_node = Node.of(serialOf(p), .ctl); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "Edit ,p\n").reply.status); - try testing.expect(th.logHas(p, " one\n") and th.logHas(p, " two\n")); - p.sync(); - var count: usize = 0; - for (p.panes) |slot| count += @intFromBool(slot != null); - try testing.expectEqual(@as(usize, 1), count); // the +Errors that had no room is gone -} - test "Mount dials its peer and fails, mounting nothing, when none answers; a look through a peer gone says dial failed" { const p = try withFile(testing.allocator, "x\n"); @@ -2560,31 +2315,6 @@ test "Grep, Symbols and Diagnostics share their directory's one +Search" { try testing.expectEqual(@as(usize, 1), searches); } -test "+Unsaved drops a pane once it has closed" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const a = try th.newPane(p); - _ = wr(p, Node.of(a, .name), "/tmp/pardes-unsaved-a.txt\n"); - _ = wr(p, Node.of(a, .body), "edited\n"); - const b = try th.newPane(p); - _ = wr(p, Node.of(b, .name), "/tmp/pardes-unsaved-b.txt\n"); - _ = wr(p, Node.of(b, .body), "edited\n"); - const root_ctl = @backingInt(tree.TopFile.ctl); - try testing.expectEqual(Status.err, wr(p, root_ctl, "Exit\n").reply.status); - var listed: ?*pardes.Pane = null; - for (p.panes) |slot| if (slot) |q| if (q.file) |f| if (f.output) |o| if (o.from == .unsaved) { - listed = q; - }; - const list = listed.?; - try testing.expect(std.mem.indexOf(u8, list.file.?.content, "/tmp/pardes-unsaved-a.txt: Modified") != null); - // a closes (discarded): its row goes; b's stays. - _ = wr(p, Node.of(a, .ctl), "Del\n"); - _ = wr(p, Node.of(a, .ctl), "Del\n"); - p.sync(); - try testing.expect(p.paneBySerial(a) == null); - try testing.expect(std.mem.indexOf(u8, list.file.?.content, "/tmp/pardes-unsaved-a.txt: Modified") == null); -} - test "a buffer whose file was deleted on disk is dirty, and Del asks first" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -2609,23 +2339,6 @@ test "a failure said while a 9P write waits on it posts no msg, only the write's try testing.expect(p.fs.late_failure_len > 0); } -test "a look that misses file:/re/ names the file, and is logged as its pane's" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "alpha\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir})); - p.sync(); - const f_serial = p.panes[p.active].?.serial; - _ = wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "{s}/f.txt:/zzqq/\n", .{dir})); - var want: [4300]u8 = undefined; - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "err {d} look: {s}/f.txt: no match for regexp", .{ f_serial, dir }))); -} - test "with no pane at all, the root look opens its file and the root exec runs in the session's directory" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -2730,61 +2443,6 @@ test "a Restore of a name in the DumpDir asks for, and logs, the whole path it r } -test "acme's words run as pardes's (Put is Save, Delete a Del that does not ask) or are refused, never run as commands" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - for ([_][]const u8{ "Snarf\n", "Indent\n", "Local\n", "Abort\n" }) |line| { - for ([_]u64{ Node.of(serial, .ctl), Node.of(serial, .exec) }) |node| { - const r = wr(p, node, line); - try testing.expectEqual(E.INVAL, r.errno()); - try testing.expect(std.mem.indexOf(u8, r.reply.ename, "is not a pardes builtin") != null); - } - } - // Load is Restore: whatever it says, never acme's word refused. - const load = wr(p, Node.of(serial, .exec), "Load /tmp/pardes-surely-no-dump.zon\n"); - try testing.expect(std.mem.indexOf(u8, load.reply.ename, "is not a pardes builtin") == null); - // Put saves, as Save does. - _ = wr(p, Node.of(serial, .name), "/tmp/pardes-put.txt\n"); - const put = wr(p, Node.of(serial, .exec), "Put\n"); - try testing.expectEqual(Status.ok, put.reply.status); - try testing.expect(put.saved); - // Delete closes an edited pane without asking. - const made = try th.newPane(p); - _ = wr(p, Node.of(made, .name), "/tmp/pardes-delete.txt\n"); - _ = wr(p, Node.of(made, .body), "edited\n"); - try testing.expectEqual(Status.ok, wr(p, Node.of(made, .ctl), "Delete\n").reply.status); - p.sync(); - try testing.expect(p.paneBySerial(made) == null); -} - -test "a pane's ctl takes acme's words: done by the files that replace them, or refused with why" { - const p = try withFile(testing.allocator, "one two\n"); - defer p.deinit(); - const serial = serialOf(p); - const ctl_node = Node.of(serial, .ctl); - const pane = p.panes[p.paneBySerial(serial).?].?; - try testing.expectEqual(Status.ok, wr(p, ctl_node, "name /tmp/pardes-acme-ctl.txt\n").reply.status); - try testing.expectEqualStrings("/tmp/pardes-acme-ctl.txt", pane.file.?.path); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "dirty\n").reply.status); - try testing.expectEqualStrings("1", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "clean\n").reply.status); - try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); - _ = wr(p, Node.of(serial, .addr), "/two/"); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "dot=addr\nshow\nnomark\nmark\nlimit=addr\n").reply.status); - try testing.expectEqual(@as(u32, 4), pane_files.dotOf(pane).q0); - try testing.expect(pane.fs.limit != null); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "cleartag\n").reply.status); - for ([_][]const u8{ "menu", "nomenu", "dump echo hi", "dumpdir /tmp", "font Go Mono" }) |line| { - const r = wr(p, ctl_node, line); - try testing.expectEqual(E.INVAL, r.errno()); - try testing.expect(std.mem.startsWith(u8, r.reply.ename, "invalid: acme's ")); - } - // Checked whole: a refused word anywhere and nothing ran. - try testing.expectEqual(E.INVAL, wr(p, ctl_node, "dirty\nmenu\n").errno()); - try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); -} - test "a write to addr, limit or mark asks for no frame; one to body does" { const p = try withFile(testing.allocator, "one\n"); defer p.deinit(); @@ -2799,28 +2457,6 @@ test "a write to addr, limit or mark asks for no frame; one to body does" { try testing.expect(p.needs_frame); } -test "every EINVAL a write gets says why, in its err record too; DEL is a control character in a line" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - const log = @backingInt(tree.TopFile.log); - const h = call(p, .{ .tag = 1, .op = .open, .node = log, .omode = 2 }).reply.handle; - const Case = struct { node: u64, data: []const u8, words: []const u8, handle: u32 = 0 }; - for ([_]Case{ - .{ .node = root_exec, .data = "echo a\x7fb\n", .words = "control character" }, - .{ .node = root_look, .data = "a\x7fb\n", .words = "control character" }, - .{ .node = Node.of(serial, .name), .data = "\n", .words = "an empty name" }, - .{ .node = log, .data = "bogus\n", .words = "takes `follow`", .handle = h }, - }) |c| { - const refused = call(p, .{ .tag = 2, .op = .write, .node = c.node, .handle = c.handle, .data = c.data }); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expect(std.mem.indexOf(u8, refused.reply.ename, c.words) != null); - } - _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); - try testing.expect(!th.logHas(p, "Invalid argument")); - try testing.expect(th.logHas(p, "an empty name")); -} - test "/index shows a name as the log does: a newline in it is \\n, a control byte, C1 or byte not UTF-8 \\xNN" { const p = try th.withTerm(testing.allocator); defer p.deinit(); @@ -2841,31 +2477,6 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null); } -test "a served-tree pane spoils no Grep, and Look . from a gone directory is ENOENT, not /virtual/" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "hit.txt", .data = "needle here\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - _ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/other.txt\n", .{dir})); - // A pane of the served tree. - const virtual = try th.newPane(p); - _ = wr(p, Node.of(virtual, .name), "/virtual/index\n"); - // One named the served tree's root, whose directory is `/`. - const top = try th.newPane(p); - _ = wr(p, Node.of(top, .name), "/virtual\n"); - try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Grep needle\n").reply.status); - // `.` from a pane whose directory is gone. - const gone = try th.newPane(p); - _ = wr(p, Node.of(gone, .name), "/tmp/pardes-no-such-dir-zz/f.txt\n"); - const looked = wr(p, Node.of(gone, .look), ".\n"); - try testing.expectEqual(E.NOENT, looked.errno()); - try testing.expectStringStartsWith(looked.reply.ename, "look: /tmp/pardes-no-such-dir-zz: no such directory"); -} - test "a column takes panes until their documented minimums fill it, not until none can be halved" { const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 }); defer p.deinit(); @@ -3335,39 +2946,6 @@ test "a file changed on disk under unsaved edits is not reloaded: it says so, ge try testing.expect(wr(p, Node.of(serial, .ctl), "Save\n").saved); } -test "a looked word is found in its own pane, next place after the dot, wrapping, and opens no pane" { - const p = try withFile(testing.allocator, "foo x foo y\n"); - defer p.deinit(); - const serial = serialOf(p); - const look_node = Node.of(serial, .look); - const dot = Node.of(serial, .dot); - var count: usize = 0; - for (p.panes) |slot| count += @intFromBool(slot != null); - for ([_][]const u8{ " 0 3 ", " 6 9 ", " 0 3 " }) |want| { - try testing.expectEqual(Status.ok, wr(p, look_node, "foo\n").reply.status); - try testing.expectEqualStrings(want, rd(p, dot, 0, 64).bytes); - } - var after: usize = 0; - for (p.panes) |slot| after += @intFromBool(slot != null); - try testing.expectEqual(count, after); - // LookWord list: the +Search listing, as before. - try testing.expect(p.executeBuiltinLine(0, "LookWord list")); - try testing.expectEqual(Status.ok, wr(p, look_node, "foo\n").reply.status); - after = 0; - for (p.panes) |slot| after += @intFromBool(slot != null); - try testing.expect(after > count); - // ...and look reads back that +Search pane, where the places are. - var listed = false; - var rows = std.mem.tokenizeScalar(u8, rd(p, look_node, 0, 256).bytes, '\n'); - while (rows.next()) |row| { - const made = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, row, 10)).?].?; - if (made.file) |f| if (f.output) |o| if (o.from == .search) { - listed = true; - }; - } - try testing.expect(listed); -} - test "every word's /commands description is its own doc comment's first sentence, no citation" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -3478,37 +3056,6 @@ test "get names the path it could not read, logs the edits it threw away, and a _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); } -test "a builtin that fails through exec, tagexec or a column's exec fails the write with one err and no msg" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - p.update(.tick); // the pane's `new` is logged first - while (p.nextEffect()) |_| {} - const serial = serialOf(p); - for ([_]u64{ root_exec, Node.of(serial, .exec), @backingInt(tree.TopFile.tagexec), Node.ofCol(pardes.layout.columnSerial(p, 0), .exec) }) |node| { - const failed = wr(p, node, "Unmount zzz\n"); - try testing.expectEqual(Status.err, failed.reply.status); - try testing.expect(std.mem.indexOf(u8, failed.reply.ename, "Unmount: no such mount zzz") != null); - } - const log = @backingInt(tree.TopFile.log); - const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; - const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes; - try testing.expect(std.mem.indexOf(u8, text, "msg ") == null); - // The root's exec ran at the pane, so its err and the pane's exec's are - // the same record, counted. - try testing.expectEqual(@as(usize, 3), std.mem.count(u8, text, "Unmount: no such mount zzz")); - try testing.expect(std.mem.indexOf(u8, text, "mount zzz (x2)") != null); - _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); - // A control character is refused with its reason. - try testing.expectEqualStrings(e_control, wr(p, root_exec, "Msg a\x01b\n").reply.ename); - // A look miss: one err, no msg. - _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n"); - try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\"")); - try testing.expect(!th.logHas(p, "msg 1 Look: no match")); - // The same miss again is that record counted, as any repeated err is. - _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n"); - try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\" (x2)\n")); -} - test "a word written to a raw terminal's look is listed as in normal mode" { const p = try th.withTerm(testing.allocator); defer p.deinit(); @@ -3522,30 +3069,6 @@ test "a word written to a raw terminal's look is listed as in normal mode" { try testing.expect(made.file.?.output.?.from == .search); } -test "a look that goes to another pane leaves the looking pane's dot alone" { - const p = try withFile(testing.allocator, "alpha bravo\ncharlie\n"); - defer p.deinit(); - const source = serialOf(p); - const other = try th.newPane(p); - _ = wr(p, Node.of(other, .body), "one\ntwo\nthree\n"); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "f one\nf two\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - for ([_][]const u8{ "@p{d}:2", "@p{d}:/three/", "{s}/f.txt:2" }) |form| { - @import("pane.zig").setDot(p.panes[p.paneBySerial(source).?].?, .{ .q0 = 6, .q1 = 11 }); - const text = if (form[0] == '@') - (if (std.mem.eql(u8, form, "@p{d}:2")) try std.fmt.bufPrint(&line, "@p{d}:2\n", .{other}) else try std.fmt.bufPrint(&line, "@p{d}:/three/\n", .{other})) - else - try std.fmt.bufPrint(&line, "{s}/f.txt:2\n", .{dir}); - try testing.expectEqual(Status.ok, wr(p, Node.of(source, .look), text).reply.status); - try testing.expect(p.active != p.paneBySerial(source).?); - try testing.expectEqualStrings(" 6 11 ", rd(p, Node.of(source, .dot), 0, 64).bytes); - } -} - test "@p:
takes any address over the terminal's lines, selecting the match" { const p = try th.withTerm(testing.allocator); defer p.deinit(); @@ -3713,45 +3236,6 @@ test "Edit on an image pane is refused as a data write there is, EINVAL, before try testing.expectEqual(E.INVAL, wr(p, Node.of(doc.serial, .name), "/tmp/other.ppm\n").errno()); } -test "`@pN:` looks at pane N as `a.txt:` looks at a.txt, and a line past the end is said one way, `:N` or `file:N`" { - const p = try withFile(testing.allocator, "one\ntwo\n"); - defer p.deinit(); - const s = serialOf(p); - var buf: [64]u8 = undefined; - p.look_missed = false; - pardes.look.lookAt(p, 0, try std.fmt.bufPrint(&buf, "@p{d}:", .{s})); - try testing.expect(!p.look_missed); - const f = pane_files.fileOf(p.panes[0].?).?; - for ([_][]const u8{ ":99999", try std.fmt.bufPrint(&buf, "{s}:99999", .{f.path}) }) |looked| { - pardes.look.lookAt(p, 0, looked); - const said = p.panes[0].?.msg[0..p.panes[0].?.msg_len]; - try testing.expect(std.mem.endsWith(u8, said, "/test.txt:99999 has no line 99999")); - } -} - -test "a second LookWord list look in a directory refills its +Search rather than stacking another" { - if (comptime !pardes.hosted) return; - const gpa = testing.allocator; - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "words.txt", .data = "alpha beta\nalpha beta\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var path_buf: [4200]u8 = undefined; - const path = try std.fmt.bufPrint(&path_buf, "{s}/words.txt", .{dir}); - const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 }); - defer p.deinit(); - _ = wr(p, @backingInt(tree.TopFile.ctl), "LookWord list\n"); - pardes.look.lookAt(p, 0, "alpha"); - pardes.look.lookAt(p, 0, "beta"); - var searches: usize = 0; - for (p.panes) |slot| if (slot) |pn| if (pn.file) |f| if (std.mem.endsWith(u8, f.path, "+Search")) { - searches += 1; - try testing.expectEqualStrings("beta", f.output.?.arg()); - }; - try testing.expectEqual(@as(usize, 1), searches); -} - test "Petscii, Palette and Ascii take the state their tag word names, set rather than flipped" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -3828,30 +3312,6 @@ test "Lspinfo's answer is the +Lsp pane it fills, as a Rename preview's is its + } -test "a ctl line over 1 MiB is refused once, EINVAL, and its tail is not run as a line of its own" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const node = Node.of(serialOf(p), .ctl); - const h = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle; - const chunk: [4096]u8 = @splat('z'); - var refused: usize = 0; - var off: u64 = 0; - for (0..270) |_| { - const r = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .off = off, .data = &chunk }); - if (r.reply.status == .err) { - refused += 1; - try testing.expectEqual(E.INVAL, r.errno()); - } - off += chunk.len; - } - try testing.expectEqual(Status.ok, call(p, .{ .tag = 3, .op = .write, .node = node, .handle = h, .off = off, .data = "zzz\nEdit ,d\n" }).reply.status); - try testing.expectEqual(@as(usize, 1), refused); - try testing.expect(!th.logHas(p, "unknown control message")); - // What came after the long line's newline ran. - try testing.expectEqualStrings("", pane_files.fileOf(p.panes[0].?).?.content); - _ = call(p, .{ .tag = 4, .op = .release, .node = node, .handle = h }); -} - test "DumpDir refuses a relative directory and one that may not be written, up front; a Dump there says permission denied" { if (comptime !pardes.hosted) return; const p = try withFile(testing.allocator, "x\n"); diff --git a/test/behaviour.zig b/test/behaviour.zig index 72806b21..c6e1dc9d 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -8,6 +8,7 @@ test { _ = @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"); diff --git a/test/behaviour/edit.zig b/test/behaviour/edit.zig index bfb17533..83b1b464 100644 --- a/test/behaviour/edit.zig +++ b/test/behaviour/edit.zig @@ -45,3 +45,15 @@ test "edit: Edit through a pane's ctl renames every foo in one undo step, and a 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/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 . +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/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 360055d2..2ce95354 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -433,3 +433,264 @@ test "look-and-exec: a builtin that takes no argument, written with one to an ex 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"); + try std.testing.expectEqualStrings(ctl[0..60], (try s.read(s.at("/pane/{d}/ctl", .{source})))[0..60]); + 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")); +} + +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 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")); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 9103508c..7bcf13d0 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -657,3 +657,48 @@ test "panes: Get of a file not there says so without asking about unsaved edits" 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")); +} diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig index 079b5a5e..893cd9a4 100644 --- a/test/behaviour/placement.zig +++ b/test/behaviour/placement.zig @@ -59,3 +59,23 @@ 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); +} diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig index 3e546237..12f2b56a 100644 --- a/test/behaviour/root_ctl.zig +++ b/test/behaviour/root_ctl.zig @@ -123,3 +123,21 @@ fn lastIncl(s: *Session) ![]const u8 { 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 b850a532..f3ed57de 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -112,3 +112,23 @@ test "settings: a bad setting value is quoted, so two different bad values log a 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 /")); +} -- cgit v1.3 From a5504e6e808c5b147e114d43b5c165bbe714f3c3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 11:09:10 -0300 Subject: test: test/output.zig's Mini, setting and command-output LookNext tests through the 9P tree alone: in a new test/behaviour/builtins.zig (docs/typ/builtins.typ) Mini mapping a file of the pane's directory over pardes's own of that name, one pane for it, a snapshot refreshed only by the next Mini, and Save on it writing nothing (the old test trimmed to the watch it never asks for, an effect); in test/behaviour/settings.zig every on/off setting the root ctl reads flipping when its word is written bare, and Theme and Shell taking a value (the old test trimmed to a window's fonts, transitions and passes in DumpConfig's report); in test/behaviour/keys.zig SPC j n in a command output (+Themes) selecting its whole row, Tab running it, and from a pane a Look took the keyboard to walking on in it, and SPC j n and SPC j p walking on and back from the place a Look's +Search listing chose (the old test trimmed to its fillResults answers); each checked to fail against a break (Mini making a new pane each time, a setting's bare word not flipping it, a command output's grain a word, the walk's owner forgotten) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour.zig | 1 + test/behaviour/builtins.zig | 35 +++++++++++++++++++++++ test/behaviour/keys.zig | 49 +++++++++++++++++++++++++++++++ test/behaviour/settings.zig | 23 +++++++++++++++ test/output.zig | 70 ++++++--------------------------------------- 5 files changed, 117 insertions(+), 61 deletions(-) create mode 100644 test/behaviour/builtins.zig (limited to 'test/behaviour.zig') diff --git a/test/behaviour.zig b/test/behaviour.zig index d9b15183..2e2ca864 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -4,6 +4,7 @@ //! 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"); diff --git a/test/behaviour/builtins.zig b/test/behaviour/builtins.zig new file mode 100644 index 00000000..6f029072 --- /dev/null +++ b/test/behaviour/builtins.zig @@ -0,0 +1,35 @@ +//! 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.expectEqual(@as(usize, 0), s.saved); +} diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig index 41a2821a..e659b369 100644 --- a/test/behaviour/keys.zig +++ b/test/behaviour/keys.zig @@ -225,3 +225,52 @@ 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: SPC j n in a command output selects its whole row, Tab runs it, and from where a Look took the keyboard it walks on there" { + 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.keys(" jn\t"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nTheme dusk\n") != null); + 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"); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig index ff24704a..027fd1c9 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -101,3 +101,26 @@ 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: 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/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 }); -- cgit v1.3