summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:22:54 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:23:24 -0300
commit5e778c87a33688c0079c916023d9c337dc944a69 (patch)
tree315a6defd3ed7db0e3404042f5e92a91524cba56 /src/ninep
parentd20a480e5d556b522aedfc7ec67fa423f37c8d1d (diff)
downloadpardes-5e778c87a33688c0079c916023d9c337dc944a69.tar.gz
pardes-5e778c87a33688c0079c916023d9c337dc944a69.zip
test: six of src/ninep/pane.zig's tests through the 9P tree alone, in new test/behaviour/{tree,addresses,flags}.zig and rules.zig: /index's rows (kind, dirty, name, column; stat 0, mode 0444, read at an offset), a terminal listed as term under its directory and refused a rename, body read at offsets and appended to (its stat its length, its qid version moving with each edit, a tag's 0), data and xdata from addr (data moving it), sel and dot (a truncated dot emptied at its clunk, a write to sel selected, one open's writes running on), the dirty, mark and scroll flags; each checked to fail against a break: kind text written txt, term written terminal, body's version always 0, a data read leaving addr where it was, a truncated dot never emptied, mark always reading 1
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/pane.zig200
1 files changed, 0 insertions, 200 deletions
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 33f816fe..bf9dc381 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -1098,88 +1098,6 @@ const withFile = th.withFile;
const serialOf = th.serialOf;
const Status = tree.Status;
-test "index lists serial kind dirty flag and name, and stats 0, a view generated by each read" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "hello\nthere\n");
- defer p.deinit();
- const pane = p.panes[0].?;
- const index = @backingInt(tree.TopFile.index);
-
- const a = rd(p, index, 0, 4096);
- try testing.expectEqual(Status.ok, a.reply.status);
- var want: [64]u8 = undefined;
- const clean_row = try std.fmt.bufPrint(&want, "{d} text 0 /test.txt {d}\n", .{ pane.serial, columnOf(p, 0) });
- try testing.expect(std.mem.indexOf(u8, a.bytes, clean_row) != null);
- const at = std.mem.indexOf(u8, a.bytes, clean_row).?;
- const stat = call(p, .{ .tag = 1, .op = .getattr, .node = index });
- try testing.expectEqual(@as(u64, 0), stat.reply.attr.size);
- try testing.expectEqual(@as(u16, 0o444), stat.reply.attr.mode);
-
- pane.file.?.saved_revision = pane.file.?.revision -% 1;
- var dirty_want: [64]u8 = undefined;
- const dirty_row = try std.fmt.bufPrint(&dirty_want, "{d} text 1 /test.txt {d}\n", .{ pane.serial, columnOf(p, 0) });
- try testing.expect(std.mem.indexOf(u8, rd(p, index, 0, 4096).bytes, dirty_row) != null);
- const kind = at + std.mem.indexOfScalar(u8, clean_row, ' ').? + 1;
- try testing.expectEqualStrings("text", rd(p, index, kind, 4).bytes);
-
- const serial = try th.newPane(p);
- const both = rd(p, index, 0, 4096);
- var expected: [4200]u8 = undefined;
- const made = p.panes[p.paneBySerial(serial).?].?;
- try testing.expect(std.mem.endsWith(u8, both.bytes, try std.fmt.bufPrint(&expected, "\n{d} text 0 {s} {d}\n", .{ serial, nameOf(p, made), columnOf(p, p.paneBySerial(serial).?) })));
-}
-
-test "a terminal is listed as term with its directory as name" {
- const p = try th.withTerm(testing.allocator);
- defer p.deinit();
- const pane = p.panes[0].?;
- p.setCwd(0, "/work/dir");
- var want: [64]u8 = undefined;
- try testing.expect(std.mem.indexOf(
- u8,
- rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes,
- try std.fmt.bufPrint(&want, "{d} term 0 /work/dir {d}\n", .{ pane.serial, columnOf(p, 0) }),
- ) != null);
- try testing.expectEqualStrings("/work/dir\n", rd(p, Node.of(pane.serial, .name), 0, 4096).bytes);
- const refused = wr(p, Node.of(pane.serial, .name), "/elsewhere\n");
- try testing.expectEqual(E.INVAL, refused.errno());
- try testing.expect(std.mem.startsWith(u8, refused.reply.ename, "invalid rename: a terminal is named"));
-}
-
-test "body reads at any offset and writes append" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "one\ntwo\n");
- defer p.deinit();
- const serial = serialOf(p);
- const body = Node.of(serial, .body);
-
- try testing.expectEqualStrings("one\ntwo\n", rd(p, body, 0, 100).bytes);
- try testing.expectEqualStrings("two\n", rd(p, body, 4, 100).bytes);
- try testing.expectEqualStrings("wo", rd(p, body, 5, 2).bytes);
- try testing.expectEqualStrings("", rd(p, body, 999, 2).bytes);
- try testing.expect(rd(p, body, 0, 100).bytes.ptr == p.panes[0].?.file.?.content.ptr);
-
- const w = call(p, .{ .tag = 5, .op = .write, .node = body, .off = 0, .data = "three\n" });
- try testing.expectEqual(@as(u32, 6), w.reply.written);
- try testing.expectEqualStrings("one\ntwo\nthree\n", p.panes[0].?.file.?.content);
-
- const short = wr(p, body, "a\xC3");
- try testing.expectEqual(@as(u32, 1), short.reply.written);
- try testing.expectEqualStrings("one\ntwo\nthree\na", p.panes[0].?.file.?.content);
-
- const stat = call(p, .{ .tag = 6, .op = .getattr, .node = body });
- try testing.expectEqual(@as(u64, "one\ntwo\nthree\na".len), stat.reply.attr.size);
- try testing.expectEqual(@as(u16, 0o666), stat.reply.attr.mode);
- try testing.expect(stat.reply.attr.mtime >= p.fs.started);
-
- // The qid version is the pane's revision, so a stat sees an edit land.
- try testing.expectEqual(p.panes[0].?.file.?.revision, stat.reply.attr.version);
- _ = wr(p, body, "more\n");
- const later = call(p, .{ .tag = 7, .op = .getattr, .node = body });
- try testing.expect(later.reply.attr.version != stat.reply.attr.version);
- try testing.expectEqual(@as(u32, 0), call(p, .{ .tag = 8, .op = .getattr, .node = Node.of(serial, .tag) }).reply.attr.version);
-}
-
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 });
@@ -1228,32 +1146,6 @@ test "tag reads the whole tag and writes append to the editable tail" {
try testing.expectEqual(E.NOSPC, wr(p, node, "x").errno());
}
-test "data and xdata read from addr, move it, and write through it" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "one\ntwo\n");
- defer p.deinit();
- const serial = serialOf(p);
- const addr = Node.of(serial, .addr);
- const data = Node.of(serial, .data);
- const xdata = Node.of(serial, .xdata);
-
- _ = wr(p, addr, "#0");
- try testing.expectEqualStrings("one", rd(p, data, 0, 3).bytes);
- try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q0);
- try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q1);
-
- _ = wr(p, addr, "1");
- try testing.expectEqualStrings("one\n", rd(p, xdata, 0, 100).bytes);
- _ = wr(p, addr, "1");
- try testing.expectEqualStrings("one\ntwo\n", rd(p, data, 0, 100).bytes);
-
- _ = wr(p, addr, "1");
- const w = wr(p, data, "ONE\n");
- try testing.expectEqual(@as(u32, 4), w.reply.written);
- try testing.expectEqualStrings("ONE\ntwo\n", p.panes[0].?.file.?.content);
- try testing.expectEqual(@as(u32, 4), p.panes[0].?.fs.addr.q0);
-}
-
test "data never splits a rune, in either direction" {
const gpa = testing.allocator;
const p = try withFile(gpa, "\u{00e9}x\n");
@@ -1268,98 +1160,6 @@ test "data never splits a rune, in either direction" {
try testing.expectEqual(@as(u32, 1), wr(p, Node.of(serial, .data), "a\xC3").reply.written);
}
-test "sel reads the selection and writing sel replaces it" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "one\ntwo\n");
- defer p.deinit();
- const serial = serialOf(p);
- const addr_node = Node.of(serial, .addr);
- const dot = Node.of(serial, .dot);
- const sel = Node.of(serial, .sel);
-
- // Copying addr onto dot is the whole of acme's `dot=addr`, and back again
- // of `addr=dot`; each range file reads exactly what the other takes.
- _ = wr(p, addr_node, "#0,#3");
- try testing.expectEqual(Status.ok, wr(p, dot, " 0 3 ").reply.status);
- try testing.expectEqualStrings(" 0 3 ", rd(p, dot, 0, 100).bytes);
- try testing.expectEqual(range_len, call(p, .{ .tag = 1, .op = .getattr, .node = dot }).reply.attr.size);
- try testing.expectEqualStrings("one", rd(p, sel, 0, 100).bytes);
- try testing.expectEqual(@as(u64, 3), call(p, .{ .tag = 1, .op = .getattr, .node = sel }).reply.attr.size);
-
- _ = wr(p, addr_node, "#0");
- _ = wr(p, addr_node, " 0 3 ");
- try testing.expectEqual(@as(u32, 0), p.panes[0].?.fs.addr.q0);
- try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q1);
-
- // A truncation empties dot once its open goes, nothing written after
- // it; an address expression addresses it.
- const h = call(p, .{ .tag = 8, .op = .open, .node = dot, .omode = 1 }).reply.handle;
- _ = call(p, .{ .tag = 9, .op = .setattr, .node = dot, .truncate = true });
- try testing.expectEqualStrings("one", rd(p, sel, 0, 100).bytes);
- _ = call(p, .{ .tag = 10, .op = .release, .node = dot, .handle = h, .opened = true });
- try testing.expectEqualStrings("", rd(p, sel, 0, 100).bytes);
- try testing.expectEqual(Status.ok, wr(p, dot, "#0,#3").reply.status);
-
- try testing.expectEqual(Status.ok, wr(p, sel, "ONE").reply.status);
- try testing.expectEqualStrings("ONE\ntwo\n", p.panes[0].?.file.?.content);
- // What was written is selected, as acme's wrsel leaves it.
- try testing.expectEqualStrings("ONE", rd(p, sel, 0, 100).bytes);
- // A write of another open replaces it; one open's writes run on.
- _ = wr(p, sel, "!");
- try testing.expectEqualStrings("!\ntwo\n", p.panes[0].?.file.?.content);
- const hs = call(p, .{ .tag = 3, .op = .open, .node = sel, .omode = 1 }).reply.handle;
- _ = call(p, .{ .tag = 4, .op = .write, .node = sel, .handle = hs, .data = "a" });
- _ = call(p, .{ .tag = 5, .op = .write, .node = sel, .handle = hs, .data = "b" });
- _ = call(p, .{ .tag = 6, .op = .release, .node = sel, .handle = hs, .opened = true });
- try testing.expectEqualStrings("ab\ntwo\n", p.panes[0].?.file.?.content);
- try testing.expectEqualStrings("ab", rd(p, sel, 0, 100).bytes);
-}
-
-test "the flag files read and write the state acme kept behind ctl verbs" {
- const gpa = testing.allocator;
- const p = try withFile(gpa, "one\ntwo\n");
- defer p.deinit();
- const serial = serialOf(p);
- const pane = p.panes[0].?;
- const pf = &p.panes[0].?.fs;
- const dirty = Node.of(serial, .dirty);
- const mark = Node.of(serial, .mark);
- const scroll = Node.of(serial, .scroll);
-
- for ([_]u64{ dirty, mark, scroll }) |node| {
- try testing.expectEqual(@as(u64, 2), call(p, .{ .tag = 1, .op = .getattr, .node = node }).reply.attr.size);
- for ([_][]const u8{ "", "yes", "2", "0 1", "true" }) |bad| {
- try testing.expectEqual(E.INVAL, wr(p, node, bad).errno());
- try testing.expectEqualStrings("bad flag: takes 1 or 0", wr(p, node, bad).reply.ename);
- }
- }
-
- try testing.expectEqualStrings("0\n", rd(p, dirty, 0, 8).bytes);
- try testing.expectEqualStrings("1\n", rd(p, mark, 0, 8).bytes);
- try testing.expectEqualStrings("1\n", rd(p, scroll, 0, 8).bytes);
-
- try testing.expectEqual(Status.ok, wr(p, dirty, "1\n").reply.status);
- try testing.expect(dirtyOf(pane));
- try testing.expectEqualStrings("1\n", rd(p, dirty, 0, 8).bytes);
- _ = wr(p, dirty, "0");
- try testing.expect(!dirtyOf(pane));
-
- _ = wr(p, mark, "0");
- _ = wr(p, scroll, "0");
- try testing.expect(pf.nomark and pf.noscroll);
- try testing.expectEqualStrings("0\n", rd(p, mark, 0, 8).bytes);
- try testing.expectEqualStrings("0\n", rd(p, scroll, 0, 8).bytes);
- _ = wr(p, mark, "1");
- _ = wr(p, scroll, "1");
- try testing.expect(!pf.nomark and !pf.noscroll);
-
- // A terminal has no file, so its dirty flag is readable but not writable.
- const term = try th.withTerm(gpa);
- defer term.deinit();
- try testing.expectEqualStrings("0\n", rd(term, Node.of(serialOf(term), .dirty), 0, 8).bytes);
- try testing.expectEqual(E.INVAL, wr(term, Node.of(serialOf(term), .dirty), "1").errno());
-}
-
test "the writes of one open are one undo step, as bash's line-buffered printf makes them; the next open is another" {
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();