diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-03 16:38:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-03 16:39:22 -0300 |
| commit | a0320c49c1288e8e74f18983f18988a024952bb8 (patch) | |
| tree | 5134488431aad3a2555198cc96ba9955e2cdad91 | |
| parent | d197289c331365081295cb44f27ee2893294cffa (diff) | |
| download | pardes-a0320c49c1288e8e74f18983f18988a024952bb8.tar.gz pardes-a0320c49c1288e8e74f18983f18988a024952bb8.zip | |
test: four more of src/ninep/ctl.zig's tests through the 9P tree alone (test/behaviour/look_and_exec, columns_and_tags, root_ctl): a look's leading blanks and exec's trim, a bare :N look from a pane's look, the root's and an event write-back (dot read from the dot file), a look after Newcol (the column read from /layout), size of a detached session (the screen read from /screen); Session's range and detach; each checked to fail against a break (a look's blanks trimmed, size taking a screen too small for its panes)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | docs/next-tests.md | 7 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 75 | ||||
| -rw-r--r-- | test/behaviour.zig | 3 | ||||
| -rw-r--r-- | test/behaviour/columns_and_tags.zig | 33 | ||||
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 38 | ||||
| -rw-r--r-- | test/behaviour/root_ctl.zig | 31 | ||||
| -rw-r--r-- | test/session.zig | 11 |
7 files changed, 121 insertions, 77 deletions
diff --git a/docs/next-tests.md b/docs/next-tests.md index 7dbbff60..9e234dfa 100644 --- a/docs/next-tests.md +++ b/docs/next-tests.md @@ -106,11 +106,14 @@ after; M as the inventory classed them): | file | M at the start | moved | checked against | |---|---|---|---| -| src/ninep/ctl.zig | 82 | 5 | `collapsed ` left off the ctl read; Putall saving nothing | +| src/ninep/ctl.zig | 82 | 9, 1 X kept | `collapsed ` left off the ctl read; Putall saving nothing; a look's blanks trimmed; size taking a screen too small | Migrated so far, in test/behaviour/: other_files (kbdin, mousein), panes (collapsed, name's leading blank, Putall), edit (an Edit block to a pane's -ctl, the root's and exec, one left open at its clunk an err in the log). +ctl, the root's and exec, one left open at its clunk an err in the log), +look_and_exec (a look's leading blanks, a bare :N), columns_and_tags (a +look after Newcol), root_ctl (size). X, left where it is: a failure said +while a 9P write waits (it checks the 9P server's own flags). ## Phases diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 69a0e791..4a3d753c 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2493,24 +2493,6 @@ test "a look line's trailing colon is dropped, and a look whose address fails ne try testing.expectEqual(@as(i32, 1), opened.body.cur_row); } -test "a bare :N or :N:M look addresses the pane itself, from its look, the root's and event write-back" { - const p = try withFile(testing.allocator, "alpha\nbeta\ngamma\n"); - defer p.deinit(); - const serial = serialOf(p); - const pane = p.panes[p.paneBySerial(serial).?].?; - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), ":2\n").reply.status); - try testing.expectEqual(pane_files.State.Range{ .q0 = 6, .q1 = 11 }, pane_files.dotOf(pane)); - try testing.expectEqual(Status.ok, wr(p, root_look, ":3\n").reply.status); - try testing.expectEqual(pane_files.State.Range{ .q0 = 11, .q1 = 17 }, pane_files.dotOf(pane)); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), ":3:2\n").reply.status); - try testing.expectEqual(@as(u32, 12), pane_files.dotOf(pane).q0); - // Written back by an event reader, the same. - const event = Node.of(serial, .event); - const h = call(p, .{ .tag = 1, .op = .open, .node = event }).reply.handle; - defer _ = call(p, .{ .tag = 9, .op = .release, .node = event, .handle = h }); - try testing.expectEqual(Status.ok, wr(p, event, "ML0 0 0 2 :1\n").reply.status); - try testing.expectEqual(pane_files.State.Range{ .q0 = 0, .q1 = 6 }, pane_files.dotOf(pane)); -} test "a refused Del written back through event fails that write, EIO, with its err" { const gpa = testing.allocator; @@ -2806,25 +2788,6 @@ test "Joincol with no column to the right and Theme with no such theme say so" { try testing.expect(tested); } -test "a look after Newcol fills the empty column the keyboard is on" { - 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; - // Newcol makes an empty column and gives its tag the keyboard; no pane - // has it, so focus reads empty. - try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n").reply.status); - try testing.expectEqual(@as(usize, 0), p.col_n[p.ncol - 1]); - try testing.expectEqualStrings("", rd(p, @backingInt(tree.TopFile.focus), 0, 64).bytes); - try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.look), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{at})).reply.status); - try testing.expectEqual(@as(usize, 1), p.col_n[p.ncol - 1]); - try testing.expectEqual(p.active, p.col_panes[p.ncol - 1][0]); -} 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); @@ -2999,27 +2962,6 @@ test "Edit's p and = never fail for want of room for +Errors: the text is logged try testing.expectEqual(@as(usize, 1), count); // the +Errors that had no room is gone } -test "size sets the screen of a session no frontend is attached to, and only of one" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - try testing.expectEqual(E.INVAL, wr(p, root_ctl, "size 120 40\n").errno()); // a frontend's - p.unattended = true; - try testing.expectEqual(Status.ok, wr(p, root_ctl, "size 120 40\n").reply.status); - try testing.expectEqual(@as(u16, 120), p.screen_w); - try testing.expectEqual(@as(u16, 40), p.screen_h); - try testing.expectEqual(E.INVAL, wr(p, root_ctl, "size 120\n").errno()); - try testing.expectEqual(E.INVAL, wr(p, root_ctl, "size\n").errno()); - try testing.expect(std.mem.indexOf(u8, wr(p, root_ctl, "size 5 2\n").reply.ename, "at least 20x6, at most 4096x4096") != null); - // The bad value quoted, never the word size. - try testing.expect(std.mem.endsWith(u8, wr(p, root_ctl, "size 5 2\n").reply.ename, "\"5 2\"")); - // Too small for the panes it has, each its tag and two rows: refused, - // the size as it was. - for (0..4) |_| p.newScratchBelow(p.active); - p.sync(); - try testing.expect(std.mem.indexOf(u8, wr(p, root_ctl, "size 80 8\n").reply.ename, "too small for the panes") != null); - try testing.expectEqual(@as(u16, 40), p.screen_h); -} 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"); @@ -3578,23 +3520,6 @@ test "a restored pane whose file is gone from disk comes back dirty, and Del ask try testing.expect(std.mem.indexOf(u8, r.reply.ename, "Modified") != null); } -test "a 9P look keeps its leading blanks, a blank-only look included, and exec still trims" { - const p = try withFile(testing.allocator, "a indented\nb\n indented\n \n"); - defer p.deinit(); - const serial = serialOf(p); - const pane = p.panes[p.paneBySerial(serial).?].?; - pane_files.setDot(pane, .{ .q0 = 0, .q1 = 0 }); - // The indented line, not the `indented` after `a `. - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), " indented\n").reply.status); - try testing.expectEqual(pane_files.State.Range{ .q0 = 13, .q1 = 25 }, pane_files.dotOf(pane)); - // Blanks alone are text to find too. - pane_files.setDot(pane, .{ .q0 = 26, .q1 = 26 }); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), " \n").reply.status); - try testing.expectEqual(pane_files.State.Range{ .q0 = 26, .q1 = 30 }, pane_files.dotOf(pane)); - // exec's line is still trimmed: ` Msg hi` runs Msg. - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), " Msg blanks trimmed\n").reply.status); - try testing.expect(th.logHas(p, "blanks trimmed")); -} test "a focus moved over 9P tells the programs that asked for focus reports, as a click does" { const p = try Pardes.init(testing.allocator, .{ .cols = 90, .rows = 30, .shells = 2 }); diff --git a/test/behaviour.zig b/test/behaviour.zig index 31da19a1..32138f94 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -3,7 +3,10 @@ //! named by the label first. This module imports test/session.zig alone, //! so a test sees the session as a 9P client does. test { + _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); + _ = @import("behaviour/look_and_exec.zig"); _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); + _ = @import("behaviour/root_ctl.zig"); } diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig new file mode 100644 index 00000000..25ba4c64 --- /dev/null +++ b/test/behaviour/columns_and_tags.zig @@ -0,0 +1,33 @@ +//! docs/typ/reference.typ, Columns and tags <columns-and-tags>. +const std = @import("std"); +const Session = @import("session").Session; + +/// /layout's line for the last column. +fn lastColumn(s: *Session) ![]const u8 { + var lines = std.mem.splitScalar(u8, try s.read("/layout"), '\n'); + var last: []const u8 = ""; + while (lines.next()) |line| { + if (std.mem.startsWith(u8, line, "active") or line.len == 0) continue; + last = line; + } + return last; +} + +test "columns-and-tags: a look after Newcol fills the empty column the keyboard is on" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "file\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(); + // Newcol makes an empty column and gives its tag the keyboard; no pane + // has it, so focus reads empty. + try s.write("/ctl", "Newcol\n"); + try std.testing.expect(std.mem.indexOf(u8, try lastColumn(&s), " empty") != null); + try s.expect("/focus", ""); + try s.write("/look", s.at("{s}/f.txt\n", .{at})); + const col = try lastColumn(&s); + try std.testing.expect(std.mem.indexOf(u8, col, " full ") != null); + try std.testing.expect(std.mem.endsWith(u8, col, s.at(" {d}", .{try s.focused()}))); +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig new file mode 100644 index 00000000..2ff4345b --- /dev/null +++ b/test/behaviour/look_and_exec.zig @@ -0,0 +1,38 @@ +//! docs/typ/reference.typ, look and exec <look-and-exec>. +const std = @import("std"); +const Session = @import("session").Session; +const expectEqual = std.testing.expectEqual; + +test "look-and-exec: a 9P look keeps its leading blanks, a blank-only look included, and exec still trims" { + var s = try Session.initFile(std.testing.allocator, "a indented\nb\n indented\n \n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + try s.write(dot, "0 0"); + // The indented line, not the `indented` after `a `. + try s.write(s.at("/pane/{d}/look", .{n}), " indented\n"); + try expectEqual(.{ @as(u32, 13), @as(u32, 25) }, try s.range(dot)); + // Blanks alone are text to find too. + try s.write(dot, "26 26"); + try s.write(s.at("/pane/{d}/look", .{n}), " \n"); + try expectEqual(.{ @as(u32, 26), @as(u32, 30) }, try s.range(dot)); + // exec's line is still trimmed: ` Msg hi` runs Msg. + try s.write(s.at("/pane/{d}/exec", .{n}), " Msg blanks trimmed\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "blanks trimmed") != null); +} + +test "look-and-exec: a bare :N or :N:M look addresses the pane itself, from its look, the root's and event write-back" { + var s = try Session.initFile(std.testing.allocator, "alpha\nbeta\ngamma\n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + try s.write(s.at("/pane/{d}/look", .{n}), ":2\n"); + try expectEqual(.{ @as(u32, 6), @as(u32, 11) }, try s.range(dot)); + try s.write("/look", ":3\n"); + try expectEqual(.{ @as(u32, 11), @as(u32, 17) }, try s.range(dot)); + try s.write(s.at("/pane/{d}/look", .{n}), ":3:2\n"); + try expectEqual(@as(u32, 12), (try s.range(dot))[0]); + // Written back by an event reader, the same. + try s.write(s.at("/pane/{d}/event", .{n}), "ML0 0 0 2 :1\n"); + try expectEqual(.{ @as(u32, 0), @as(u32, 6) }, try s.range(dot)); +} diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig new file mode 100644 index 00000000..bdf912da --- /dev/null +++ b/test/behaviour/root_ctl.zig @@ -0,0 +1,31 @@ +//! docs/typ/reference.typ, The root ctl <root-ctl>. +const std = @import("std"); +const Session = @import("session").Session; + +/// The screen's size, as /screen draws it. +fn size(s: *Session) !struct { usize, usize } { + const screen = try s.screen(); + const cols = try std.unicode.utf8CountCodepoints(screen[0 .. std.mem.indexOfScalar(u8, screen, '\n') orelse screen.len]); + return .{ cols, std.mem.count(u8, screen, "\n") + 1 }; +} + +test "root-ctl: size sets the screen of a session no frontend is attached to, and only of one" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size 120 40\n")); // a frontend's + s.detach(); + try s.write("/ctl", "size 120 40\n"); + try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s)); + try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size 120\n")); + try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size\n")); + _ = try s.refused("/ctl", "size 5 2\n"); + try std.testing.expect(std.mem.indexOf(u8, s.said, "at least 20x6, at most 4096x4096") != null); + // The bad value quoted, never the word size. + try std.testing.expect(std.mem.endsWith(u8, s.said, "\"5 2\"")); + // Too small for the panes it has, each its tag and two rows: refused, + // the size as it was. + for (0..4) |_| _ = try s.newPane(); + _ = try s.refused("/ctl", "size 80 8\n"); + try std.testing.expect(std.mem.indexOf(u8, s.said, "too small for the panes") != null); + try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s)); +} diff --git a/test/session.zig b/test/session.zig index 28557322..8b3c5c41 100644 --- a/test/session.zig +++ b/test/session.zig @@ -120,6 +120,17 @@ pub const Session = struct { return out.items; } + /// A range file (`dot`, `addr`, `limit`) as its two offsets. + pub fn range(s: *Session, path: []const u8) !struct { u32, u32 } { + var it = std.mem.tokenizeScalar(u8, try s.read(path), ' '); + return .{ try std.fmt.parseInt(u32, it.next() orelse return error.NoRange, 10), try std.fmt.parseInt(u32, it.next() orelse return error.NoRange, 10) }; + } + + /// No frontend attached, as a detached session's daemon says. + pub fn detach(s: *Session) void { + pardesOf(s).unattended = true; + } + /// The serial of the pane with the keyboard. pub fn focused(s: *Session) !u32 { return std.fmt.parseInt(u32, std.mem.trim(u8, try s.read("/focus"), "\n"), 10); |
