diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-03 17:22:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-03 17:23:24 -0300 |
| commit | 5e778c87a33688c0079c916023d9c337dc944a69 (patch) | |
| tree | 315a6defd3ed7db0e3404042f5e92a91524cba56 /test/behaviour/tree.zig | |
| parent | d20a480e5d556b522aedfc7ec67fa423f37c8d1d (diff) | |
| download | pardes-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 'test/behaviour/tree.zig')
| -rw-r--r-- | test/behaviour/tree.zig | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/behaviour/tree.zig b/test/behaviour/tree.zig new file mode 100644 index 00000000..7f9b37a4 --- /dev/null +++ b/test/behaviour/tree.zig @@ -0,0 +1,44 @@ +//! docs/typ/reference.typ, The tree <tree>. +const std = @import("std"); +const Session = @import("session").Session; + +fn has(hay: []const u8, needle: []const u8) bool { + return std.mem.indexOf(u8, hay, needle) != null; +} + +/// The first column's serial, /layout's first word. +fn firstColumn(s: *Session) ![]const u8 { + return std.mem.sliceTo(try s.read("/layout"), ' '); +} + +test "tree: index lists serial kind dirty name column, and stats 0, a view generated by each read" { + var s = try Session.initFile(std.testing.allocator, "hello\nthere\n"); + defer s.deinit(); + const n = try s.focused(); + const col = try firstColumn(&s); + const clean = s.at("{d} text 0 /test.txt {s}\n", .{ n, col }); + const index = try s.read("/index"); + const at = std.mem.indexOf(u8, index, clean) orelse return error.NotListed; + const st = try s.stat("/index"); + try std.testing.expectEqual(@as(u64, 0), st.size); + try std.testing.expectEqual(@as(u16, 0o444), st.mode); + try s.write(s.at("/pane/{d}/body", .{n}), "more\n"); + try std.testing.expect(has(try s.read("/index"), s.at("{d} text 1 /test.txt {s}\n", .{ n, col }))); + // Read from an offset, as any file. + const kind = at + std.mem.indexOfScalar(u8, clean, ' ').? + 1; + try std.testing.expectEqualStrings("text", try s.readAt("/index", kind, 4)); + const made = try s.newPane(); + const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{made})), "\n"); + try std.testing.expect(std.mem.endsWith(u8, try s.read("/index"), s.at("\n{d} text 0 {s} {s}\n", .{ made, name, col }))); +} + +test "tree: a terminal is listed as term with its directory as name, which a write to name cannot change" { + var s = try Session.initTerm(std.testing.allocator); + defer s.deinit(); + const n = try s.focused(); + const dir = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n"); + try std.testing.expect(std.mem.startsWith(u8, dir, "/")); + try std.testing.expect(has(try s.read("/index"), s.at("{d} term 0 {s} {s}\n", .{ n, dir, try firstColumn(&s) }))); + try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/name", .{n}), "/elsewhere\n")); + try std.testing.expect(std.mem.startsWith(u8, s.said, "invalid rename: a terminal is named")); +} |
