From 5e778c87a33688c0079c916023d9c337dc944a69 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:22:54 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/rules.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/behaviour/rules.zig') diff --git a/test/behaviour/rules.zig b/test/behaviour/rules.zig index a29db6f0..4b853a40 100644 --- a/test/behaviour/rules.zig +++ b/test/behaviour/rules.zig @@ -17,3 +17,23 @@ test "rules: a control character in a write to any ctl refuses the whole write, try std.testing.expect(std.mem.indexOf(u8, s.said, "\"bogus\"") != null); try std.testing.expect(std.mem.indexOfScalar(u8, s.said, '\t') == null); } + +test "rules: body reads at any offset and writes append; a stat says its length, and its version moves with each edit" { + var s = try Session.initFile(std.testing.allocator, "one\ntwo\n"); + defer s.deinit(); + const body = s.at("/pane/{d}/body", .{try s.focused()}); + try std.testing.expectEqualStrings("two\n", try s.readAt(body, 4, 100)); + try std.testing.expectEqualStrings("wo", try s.readAt(body, 5, 2)); + try std.testing.expectEqualStrings("", try s.readAt(body, 999, 2)); + try s.write(body, "three\n"); + try s.expect(body, "one\ntwo\nthree\n"); + // A rune cut at the write's end is not taken. + try s.write(body, "a\xC3"); + try s.expect(body, "one\ntwo\nthree\na"); + const st = try s.stat(body); + try std.testing.expectEqual(@as(u64, "one\ntwo\nthree\na".len), st.size); + try std.testing.expectEqual(@as(u16, 0o666), st.mode); + try s.write(body, "more\n"); + 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); +} -- cgit v1.3