summaryrefslogtreecommitdiff
path: root/test/behaviour/addresses.zig
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 /test/behaviour/addresses.zig
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 'test/behaviour/addresses.zig')
-rw-r--r--test/behaviour/addresses.zig65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/behaviour/addresses.zig b/test/behaviour/addresses.zig
new file mode 100644
index 00000000..a1474c3d
--- /dev/null
+++ b/test/behaviour/addresses.zig
@@ -0,0 +1,65 @@
+//! docs/typ/reference.typ, Addresses and data <addresses>.
+const std = @import("std");
+const Session = @import("session").Session;
+const expectEqual = std.testing.expectEqual;
+
+test "addresses: data and xdata read from addr, data moving it, and a write goes through it" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const addr = s.at("/pane/{d}/addr", .{n});
+ const data = s.at("/pane/{d}/data", .{n});
+ try s.write(addr, "#0");
+ try std.testing.expectEqualStrings("one", try s.readAt(data, 0, 3));
+ try expectEqual(.{ @as(u32, 3), @as(u32, 3) }, try s.range(addr));
+ try s.write(addr, "1");
+ try s.expect(s.at("/pane/{d}/xdata", .{n}), "one\n");
+ try s.write(addr, "1");
+ try s.expect(data, "one\ntwo\n");
+ try s.write(addr, "1");
+ try s.write(data, "ONE\n");
+ try s.expect(s.at("/pane/{d}/body", .{n}), "ONE\ntwo\n");
+ try expectEqual(@as(u32, 4), (try s.range(addr))[0]);
+}
+
+test "addresses: sel reads the selection, and a write to sel replaces it and is selected" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const addr = s.at("/pane/{d}/addr", .{n});
+ const dot = s.at("/pane/{d}/dot", .{n});
+ const sel = s.at("/pane/{d}/sel", .{n});
+ const body = s.at("/pane/{d}/body", .{n});
+ // 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.
+ try s.write(addr, "#0,#3");
+ try s.write(dot, " 0 3 ");
+ try s.expect(dot, " 0 3 ");
+ try expectEqual(@as(u64, 24), (try s.stat(dot)).size);
+ try s.expect(sel, "one");
+ try expectEqual(@as(u64, 3), (try s.stat(sel)).size);
+ try s.write(addr, "#0");
+ try s.write(addr, " 0 3 ");
+ try expectEqual(.{ @as(u32, 0), @as(u32, 3) }, try s.range(addr));
+ // A truncation empties dot once its open goes, nothing written after
+ // it; an address expression addresses it.
+ const h = try s.hold(dot, 1);
+ try s.truncate(h);
+ try s.expect(sel, "one");
+ s.clunk(h);
+ try s.expect(sel, "");
+ try s.write(dot, "#0,#3");
+ try s.write(sel, "ONE");
+ try s.expect(body, "ONE\ntwo\n");
+ // What was written is selected, as acme's wrsel leaves it.
+ try s.expect(sel, "ONE");
+ // A write of another open replaces it; one open's writes run on.
+ try s.write(sel, "!");
+ try s.expect(body, "!\ntwo\n");
+ const w = try s.hold(sel, 1);
+ try expectEqual(@as(u16, 0), try s.writeFid(w, "a"));
+ try expectEqual(@as(u16, 0), try s.writeFid(w, "b"));
+ s.clunk(w);
+ try s.expect(body, "ab\ntwo\n");
+ try s.expect(sel, "ab");
+}