From 4d4d9fcba44798340184f865d119e49c63709b70 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:09:37 -0300 Subject: test: test/panes.zig's eight tag-navigation tests through the 9P tree alone (test/behaviour/tags.zig, guide.typ's Tags): s and S in a tag selecting its own text (a c changing both S's) while / searches the body (its +Search lists the match), ms and md read back from the tag file, the path the keyboard reaches, yanks (pasted into the body) and cannot edit, a name drafted by typing into it, a tag remembering its cursor across panes and a prompt, starting on Save and moved by a click, Tab and Enter from a tag giving the body the keyboard back (a Save counted, the next keys typed into the body), the cursor after a rename and a shorter tag, window keys from a tag, a tag's normal and insert modes; Session.cursor (the screen's cursor cell, read from /screen) and Session.replace (a write truncating first, a shell's >); each checked to fail against a break (a tag's s prompt answering for the body, ms closing a character early, a tag edit into the path taken, enterTag always landing on Save, a truncated tag's cursor left at 0, the execute key leaving the tag the keyboard, a tag the keyboard left keeping it) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/session.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/session.zig') diff --git a/test/session.zig b/test/session.zig index b55987eb..f3d96918 100644 --- a/test/session.zig +++ b/test/session.zig @@ -188,6 +188,24 @@ pub const Session = struct { pub fn where(s: *Session, text: []const u8) !struct { usize, usize } { return s.find(text); } + + /// The cell the screen's cursor is drawn on, its column and row. + pub fn cursor(s: *Session) !struct { usize, usize } { + const json = try std.json.parseFromSliceLeaky(std.json.Value, s.arena.allocator(), try s.read("/screen"), .{}); + const c = json.object.get("cursor").?; + if (c != .object) return error.NoCursor; + return .{ @intCast(c.object.get("x").?.integer), @intCast(c.object.get("y").?.integer) }; + } + + /// `data` written to `path` truncated first, as a shell's `>` does. + pub fn replace(s: *Session, path: []const u8, data: []const u8) !void { + const node, const h = try s.open(path, 1); + defer _ = s.serve(.{ .tag = 0, .op = .release, .node = node, .handle = h, .opened = true }); + const t = s.serve(.{ .tag = 0, .op = .setattr, .node = node, .handle = h, .truncate = true }); + if (t.status != .ok) return refusal(path, t); + const w = s.serve(.{ .tag = 0, .op = .write, .node = node, .handle = h, .data = data }); + if (w.status != .ok) return refusal(path, w); + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { -- cgit v1.3