summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 00:52:52 -0300
committerGabriel Schneider <[email protected]>2026-11-09 01:28:28 -0300
commit5157579ff7f9ae0cfc3c7629e953da05bce340fc (patch)
tree02147789efdcea998981efcfe05d4bcb3e9bb7b0 /src/ninep
parent4c4b9bf54d77dbc0f9f4e2619746908e501c6001 (diff)
downloadpardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.tar.gz
pardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.zip
tests: at the end of their files: every top-level test block of the 46 files that had one mid-file (the locality analysis's 45 and test/hxdiff.zig; gui.zig, macos.zig, look, host_io, 9p_io, terminal, tui, mouse, fs, replica, layout among them, 11,429 test lines), with the functions only tests call, moved after the file's code in their order, a mechanical move (.scratch/suites/tests_to_end.py), zig fmt'd; the unit suites pass as before (tui 1486/1487, gui 1536/1537, core 956/956 on both), macos.zig only parse-checked here
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/cols.zig66
-rw-r--r--src/ninep/events.zig90
-rw-r--r--src/ninep/pane.zig64
-rw-r--r--src/ninep/tree.zig68
4 files changed, 144 insertions, 144 deletions
diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig
index 7eb08ba9..5218b937 100644
--- a/src/ninep/cols.zig
+++ b/src/ninep/cols.zig
@@ -36,7 +36,7 @@ pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) std.Io.Writer.Error!void {
const active = activeColumn(p);
for (0..p.view().ncol) |c| {
try w.print("{d} {d} {d} {d} {s} {s}", .{
- layout.columnSerial(p, c), c, v.col_x[c], v.col_w[c],
+ layout.columnSerial(p, c), c, v.col_x[c], v.col_w[c],
if (active == c) "current" else "notcurrent", if (v.cols[c].n == 0) "empty" else "full",
});
for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial});
@@ -212,6 +212,38 @@ pub fn writeExec(p: *Pardes, req: Req, serial: ?u32) Reply {
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
+/// Whether `line` names a builtin that acts on a pane (every one of pane
+/// scope, Edit too, which the root's ctl takes at the active pane) and is
+/// not one of `own`, the words its tag holds by default: those a tag no
+/// pane owns refuses, never doing them at the pane with the keyboard.
+fn paneWord(line: []const u8, own: []const u8) bool {
+ const cmd = pardes.exec.commandText(line);
+ const word = cmd[0 .. std.mem.indexOfAny(u8, cmd, " \t+") orelse cmd.len];
+ const b = std.meta.stringToEnum(pardes.builtins.registry.Builtin(), word) orelse return false;
+ if (pardes.builtins.registry.scope(b) == .session) return false;
+ // A new pane is every tag's to make, in the session's directory.
+ if (b == .New or b == .Term) return false;
+ var words = std.mem.tokenizeScalar(u8, own, ' ');
+ while (words.next()) |w| if (std.mem.eql(u8, w, word)) return false;
+ return true;
+}
+
+/// rmdir of a column closes it when it is empty; one with panes is
+/// refused, saying so (close them, or Delcol on its ctl, which asks first).
+pub fn remove(p: *Pardes, req: Req, serial: u32, file: tree.ColFile) Reply {
+ if (file != .dir) return Reply.fail(req.tag, E.PERM);
+ const col = layout.columnBySerial(p, serial) orelse return Reply.fail(req.tag, E.NOENT);
+ if (p.view().cols[col].n > 0) return tree.failText(req.tag, E.NOTEMPTY, "column not empty: close its panes, or write Delcol to its ctl");
+ layout.removeColumn(p, col) catch return Reply.fail(req.tag, E.IO);
+ return .{ .tag = req.tag };
+}
+
+// ---- tests ----
+
+const testing = std.testing;
+const th = @import("testing.zig");
+const Node = tree.Node;
+
test "New written to a column's exec makes its scratch in the session's directory, as tagexec's does" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -369,22 +401,6 @@ test "New written to a column's ctl reads back the new pane alone, as its exec d
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.view().active].?.serial}), th.rd(p, root_exec, 0, 64).bytes);
}
-/// Whether `line` names a builtin that acts on a pane (every one of pane
-/// scope, Edit too, which the root's ctl takes at the active pane) and is
-/// not one of `own`, the words its tag holds by default: those a tag no
-/// pane owns refuses, never doing them at the pane with the keyboard.
-fn paneWord(line: []const u8, own: []const u8) bool {
- const cmd = pardes.exec.commandText(line);
- const word = cmd[0 .. std.mem.indexOfAny(u8, cmd, " \t+") orelse cmd.len];
- const b = std.meta.stringToEnum(pardes.builtins.registry.Builtin(), word) orelse return false;
- if (pardes.builtins.registry.scope(b) == .session) return false;
- // A new pane is every tag's to make, in the session's directory.
- if (b == .New or b == .Term) return false;
- var words = std.mem.tokenizeScalar(u8, own, ' ');
- while (words.next()) |w| if (std.mem.eql(u8, w, word)) return false;
- return true;
-}
-
test "a pane's word written to /tagexec or a column's exec is refused, and acts on no pane" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -491,22 +507,6 @@ test "every pane word a tag no pane owns does not hold is refused there, Edit in
try testing.expectEqualStrings("keep me\n", p.panes[0].?.file.?.content);
}
-/// rmdir of a column closes it when it is empty; one with panes is
-/// refused, saying so (close them, or Delcol on its ctl, which asks first).
-pub fn remove(p: *Pardes, req: Req, serial: u32, file: tree.ColFile) Reply {
- if (file != .dir) return Reply.fail(req.tag, E.PERM);
- const col = layout.columnBySerial(p, serial) orelse return Reply.fail(req.tag, E.NOENT);
- if (p.view().cols[col].n > 0) return tree.failText(req.tag, E.NOTEMPTY, "column not empty: close its panes, or write Delcol to its ctl");
- layout.removeColumn(p, col) catch return Reply.fail(req.tag, E.IO);
- return .{ .tag = req.tag };
-}
-
-// ---- tests ----
-
-const testing = std.testing;
-const th = @import("testing.zig");
-const Node = tree.Node;
-
test "layout lists each column's place, panes and state, and the active one" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index b00df909..20cb4e6e 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -592,37 +592,6 @@ fn editSpan(old: []const u8, off: usize, len: usize, bytes: []const u8) Span {
return .{ .at = @intCast(head), .removed = @intCast(old.len - tail - head), .inserted = @intCast(n - tail - head) };
}
-test "an edit's span is where the texts before and after it differ" {
- const reference = struct {
- fn span(old: []const u8, new: []const u8) Span {
- const both = @min(old.len, new.len);
- var head: usize = 0;
- while (head < both and old[head] == new[head]) head += 1;
- var tail: usize = 0;
- while (tail < both - head and old[old.len - 1 - tail] == new[new.len - 1 - tail]) tail += 1;
- return .{ .at = @intCast(head), .removed = @intCast(old.len - tail - head), .inserted = @intCast(new.len - tail - head) };
- }
- }.span;
- var prng = std.Random.DefaultPrng.init(3);
- const r = prng.random();
- var old: [24]u8 = undefined;
- var new: [48]u8 = undefined;
- var bytes: [24]u8 = undefined;
- for (0..20000) |_| {
- const old_len = r.uintAtMost(usize, old.len);
- for (old[0..old_len]) |*c| c.* = "ab"[r.uintLessThan(usize, 2)];
- const off = r.uintAtMost(usize, old_len);
- const len = r.uintAtMost(usize, old_len - off);
- const n = r.uintAtMost(usize, bytes.len);
- for (bytes[0..n]) |*c| c.* = "ab"[r.uintLessThan(usize, 2)];
- @memcpy(new[0..off], old[0..off]);
- @memcpy(new[off..][0..n], bytes[0..n]);
- @memcpy(new[off + n ..][0 .. old_len - off - len], old[off + len .. old_len]);
- const new_len = old_len - len + n;
- try std.testing.expectEqual(reference(old[0..old_len], new[0..new_len]), editSpan(old[0..old_len], off, len, bytes[0..n]));
- }
-}
-
/// Records `<origin><action><q0> <q1> <flag> <n> <text>` for a pane a
/// script reads; a text of max_record_text and over is sent as none. One
/// that follows another with no place of its own (a chorded exec's
@@ -859,6 +828,51 @@ const serialOf = th.serialOf;
const Node = tree.Node;
const Status = tree.Status;
+fn drainEvents(p: *Pardes, node: u64, store: []u8, out: [][]const u8) [][]const u8 {
+ var used: usize = 0;
+ var n: usize = 0;
+ while (n < out.len) {
+ const a = rd(p, node, 0, 4096);
+ if (a.reply.status != .ok) break;
+ @memcpy(store[used..][0..a.bytes.len], a.bytes);
+ out[n] = store[used..][0..a.bytes.len];
+ used += a.bytes.len;
+ n += 1;
+ }
+ return out[0..n];
+}
+
+test "an edit's span is where the texts before and after it differ" {
+ const reference = struct {
+ fn span(old: []const u8, new: []const u8) Span {
+ const both = @min(old.len, new.len);
+ var head: usize = 0;
+ while (head < both and old[head] == new[head]) head += 1;
+ var tail: usize = 0;
+ while (tail < both - head and old[old.len - 1 - tail] == new[new.len - 1 - tail]) tail += 1;
+ return .{ .at = @intCast(head), .removed = @intCast(old.len - tail - head), .inserted = @intCast(new.len - tail - head) };
+ }
+ }.span;
+ var prng = std.Random.DefaultPrng.init(3);
+ const r = prng.random();
+ var old: [24]u8 = undefined;
+ var new: [48]u8 = undefined;
+ var bytes: [24]u8 = undefined;
+ for (0..20000) |_| {
+ const old_len = r.uintAtMost(usize, old.len);
+ for (old[0..old_len]) |*c| c.* = "ab"[r.uintLessThan(usize, 2)];
+ const off = r.uintAtMost(usize, old_len);
+ const len = r.uintAtMost(usize, old_len - off);
+ const n = r.uintAtMost(usize, bytes.len);
+ for (bytes[0..n]) |*c| c.* = "ab"[r.uintLessThan(usize, 2)];
+ @memcpy(new[0..off], old[0..off]);
+ @memcpy(new[off..][0..n], bytes[0..n]);
+ @memcpy(new[off + n ..][0 .. old_len - off - len], old[off + len .. old_len]);
+ const new_len = old_len - len + n;
+ try std.testing.expectEqual(reference(old[0..old_len], new[0..new_len]), editSpan(old[0..old_len], off, len, bytes[0..n]));
+ }
+}
+
test "a stream read at an offset inside its last answer gets the rest of it again, as bash's read seeks back" {
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
@@ -921,20 +935,6 @@ test "event records are acme's bytes, one per read, and .again when empty" {
try testing.expectEqual(@as(u16, 0), p.fs.listeners);
}
-fn drainEvents(p: *Pardes, node: u64, store: []u8, out: [][]const u8) [][]const u8 {
- var used: usize = 0;
- var n: usize = 0;
- while (n < out.len) {
- const a = rd(p, node, 0, 4096);
- if (a.reply.status != .ok) break;
- @memcpy(store[used..][0..a.bytes.len], a.bytes);
- out[n] = store[used..][0..a.bytes.len];
- used += a.bytes.len;
- n += 1;
- }
- return out[0..n];
-}
-
test "a write through the filesystem is reported once, attributed to the file it came through" {
const gpa = testing.allocator;
const p = try withFile(gpa, "one\ntwo\n");
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 58b14c92..519e5333 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -305,38 +305,6 @@ pub fn spliceBody(p: *Pardes, pane: *Pane, q0: usize, q1: usize, bytes: []const
return take;
}
-test "rows through the line index are the ones counting newlines gives, at every offset" {
- const p = try withFile(testing.allocator, "héllo\nwo\u{301}rld\n\n last line é\ntail");
- defer p.deinit();
- const pane = p.panes[0].?;
- const f = &pane.file.?;
- _ = try panes.File.lineIndex(p.gpa, f);
- const text = bodyOf(pane);
- try testing.expect(lineIndex(pane, text) != null);
- for (0..text.len + 2) |off| {
- try testing.expectEqual(modal.positionAt(text, off), positionAt(pane, text, off));
- try testing.expectEqual(modal.runePositionAt(text, off), runePositionAt(pane, text, off));
- }
- for (0..8) |row| for (0..16) |col| {
- const c: modal.Cursor = .{ .row = row, .col = col };
- try testing.expectEqual(modal.runeOffsetAt(text, c), runeOffsetAt(pane, text, c));
- };
-}
-
-test "a terminal's body stats as long as it reads" {
- const gpa = testing.allocator;
- const p = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
- defer p.deinit();
- while (p.nextEffect()) |_| {}
- const pane = p.panes[0].?;
- try testing.expect(pane.isTerminal());
- p.update(.{ .output = .{ .pane = 0, .bytes = "$ ls\r\nalpha beta\r\n$ " } });
- const body = Node.of(pane.serial, .body);
- const whole = rd(p, body, 0, 1 << 16);
- try testing.expect(whole.bytes.len > 0);
- try testing.expectEqual(@as(u64, whole.bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = body }).reply.attr.size);
-}
-
// ---- what stat reports ----
/// A range file's text: acme's addr format, two right-aligned offsets, so
@@ -1027,6 +995,38 @@ const withFile = th.withFile;
const serialOf = th.serialOf;
const Status = tree.Status;
+test "rows through the line index are the ones counting newlines gives, at every offset" {
+ const p = try withFile(testing.allocator, "héllo\nwo\u{301}rld\n\n last line é\ntail");
+ defer p.deinit();
+ const pane = p.panes[0].?;
+ const f = &pane.file.?;
+ _ = try panes.File.lineIndex(p.gpa, f);
+ const text = bodyOf(pane);
+ try testing.expect(lineIndex(pane, text) != null);
+ for (0..text.len + 2) |off| {
+ try testing.expectEqual(modal.positionAt(text, off), positionAt(pane, text, off));
+ try testing.expectEqual(modal.runePositionAt(text, off), runePositionAt(pane, text, off));
+ }
+ for (0..8) |row| for (0..16) |col| {
+ const c: modal.Cursor = .{ .row = row, .col = col };
+ try testing.expectEqual(modal.runeOffsetAt(text, c), runeOffsetAt(pane, text, c));
+ };
+}
+
+test "a terminal's body stats as long as it reads" {
+ const gpa = testing.allocator;
+ const p = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ while (p.nextEffect()) |_| {}
+ const pane = p.panes[0].?;
+ try testing.expect(pane.isTerminal());
+ p.update(.{ .output = .{ .pane = 0, .bytes = "$ ls\r\nalpha beta\r\n$ " } });
+ const body = Node.of(pane.serial, .body);
+ const whole = rd(p, body, 0, 1 << 16);
+ try testing.expect(whole.bytes.len > 0);
+ try testing.expectEqual(@as(u64, whole.bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = body }).reply.attr.size);
+}
+
test "a body write to a terminal pane types at its shell" {
const gpa = testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 10 });
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index dfcf7097..f7ca0cb7 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -519,29 +519,6 @@ pub fn fitErr(text: []const u8, out: []u8) []const u8 {
return std.fmt.bufPrint(out, "{s}" ++ ell ++ "{s}", .{ text[0..a], text[b..] }) catch text[0..out.len];
}
-test "a reason past 128 bytes keeps its end: the path in it gives up its middle" {
- var out: [128]u8 = undefined;
- const long = "Save /home/someone/projects/" ++ std.mem.asBytes(&@as([30][5]u8, @splat("deep/".*))) ++ "file.txt: no such directory";
- const fit = fitErr(long, &out);
- try testing.expect(fit.len <= 128);
- try testing.expect(std.mem.startsWith(u8, fit, "Save /home/someone/"));
- try testing.expect(std.mem.endsWith(u8, fit, "file.txt: no such directory"));
- try testing.expect(std.mem.indexOf(u8, fit, "…") != null);
- try testing.expect(std.unicode.utf8ValidateSlice(fit));
- // No path: the whole text's middle goes, the end stays.
- const words = std.mem.asBytes(&@as([40][4]u8, @splat("why ".*))) ++ "the reason";
- try testing.expect(std.mem.endsWith(u8, fitErr(words, &out), "the reason"));
- try testing.expectEqualStrings("short", fitErr("short", &out));
- // Through the tree: a look at a long ./ name not there, a miss, says
- // why at the end of its err record, the name giving up its middle.
- const p = try th.withFile(testing.allocator, "x\n");
- defer p.deinit();
- var line: [512]u8 = undefined;
- const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{std.mem.asBytes(&@as([20][12]u8, @splat("no-such-dir/".*)))}));
- try testing.expectEqual(Status.ok, r.reply.status);
- try testing.expect(th.logHas(p, "x.txt: no such file"));
-}
-
/// A refusal with no reason of its own said in Plan 9's words, not the C
/// library's (`Operation not permitted`); each maps back to its errno in
/// 9ns (enameToErrno), EPERM's to EACCES as Plan 9's does.
@@ -1383,17 +1360,6 @@ fn writeNow(p: *Pardes, req: Req, target: Target) Reply {
// ---- tests ----
-test {
- _ = events;
- _ = pane;
- _ = addr;
- _ = ctl;
- _ = pty;
- _ = cols;
- _ = sources;
- _ = screen;
-}
-
const testing = std.testing;
const th = @import("testing.zig");
const config = @import("../config.zig");
@@ -1405,6 +1371,40 @@ const look_up = th.look_up;
const withFile = th.withFile;
const serialOf = th.serialOf;
+test "a reason past 128 bytes keeps its end: the path in it gives up its middle" {
+ var out: [128]u8 = undefined;
+ const long = "Save /home/someone/projects/" ++ std.mem.asBytes(&@as([30][5]u8, @splat("deep/".*))) ++ "file.txt: no such directory";
+ const fit = fitErr(long, &out);
+ try testing.expect(fit.len <= 128);
+ try testing.expect(std.mem.startsWith(u8, fit, "Save /home/someone/"));
+ try testing.expect(std.mem.endsWith(u8, fit, "file.txt: no such directory"));
+ try testing.expect(std.mem.indexOf(u8, fit, "…") != null);
+ try testing.expect(std.unicode.utf8ValidateSlice(fit));
+ // No path: the whole text's middle goes, the end stays.
+ const words = std.mem.asBytes(&@as([40][4]u8, @splat("why ".*))) ++ "the reason";
+ try testing.expect(std.mem.endsWith(u8, fitErr(words, &out), "the reason"));
+ try testing.expectEqualStrings("short", fitErr("short", &out));
+ // Through the tree: a look at a long ./ name not there, a miss, says
+ // why at the end of its err record, the name giving up its middle.
+ const p = try th.withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ var line: [512]u8 = undefined;
+ const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{std.mem.asBytes(&@as([20][12]u8, @splat("no-such-dir/".*)))}));
+ try testing.expectEqual(Status.ok, r.reply.status);
+ try testing.expect(th.logHas(p, "x.txt: no such file"));
+}
+
+test {
+ _ = events;
+ _ = pane;
+ _ = addr;
+ _ = ctl;
+ _ = pty;
+ _ = cols;
+ _ = sources;
+ _ = screen;
+}
+
test "a listing read in chunks is what it was at the open, however the panes change between reads" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();