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/behaviour.zig | 1 + test/behaviour/tags.zig | 193 ++++++++++++++++++++++++++++++++++ test/panes.zig | 274 ------------------------------------------------ test/session.zig | 18 ++++ 4 files changed, 212 insertions(+), 274 deletions(-) create mode 100644 test/behaviour/tags.zig diff --git a/test/behaviour.zig b/test/behaviour.zig index 46fa8402..17d753fb 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -10,4 +10,5 @@ test { _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/root_ctl.zig"); + _ = @import("behaviour/tags.zig"); } diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig new file mode 100644 index 00000000..e9b33cb0 --- /dev/null +++ b/test/behaviour/tags.zig @@ -0,0 +1,193 @@ +//! docs/typ/guide.typ, Tags . +const std = @import("std"); +const Session = @import("session").Session; + +const home = "\u{F00D}"; +const right = "\u{F012}"; +const window = "\x17"; // Ctrl-w + +/// The pane's tag file. +fn tag(s: *Session, n: u32) ![]const u8 { + return s.read(s.at("/pane/{d}/tag", .{n})); +} + +/// The column of the screen's cursor in the tag drawn starting with +/// `path`, which must be on its row. +fn tagCol(s: *Session, path: []const u8) !usize { + const x, const y = try s.where(path); + const cx, const cy = try s.cursor(); + try std.testing.expectEqual(y, cy); + return cx - x; +} + +test "tags: s and S in a tag answer for the tag's own text; / still searches the body" { + var s = try Session.initFile(std.testing.allocator, "Some body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.replace(s.at("/pane/{d}/tag", .{n}), " Save Del Snarf"); + // The tag's line, its S's selected, then changed: both are the tag's. + try s.keys(":xsS\ncZ\x1b"); + try std.testing.expectEqualStrings("/test.txt Zave Del Znarf", try tag(&s, n)); + try s.expect(s.at("/pane/{d}/body", .{n}), "Some body\n"); + // `/` from the tag is the body's search, as acme's Look from a tag is. + // Its places list the body's match. + try s.keys(",/body\n"); + _ = try s.where("test.txt:1:6-9"); +} + +test "tags: ms and md edit a tag's own text, and the text the edit made is read back whole" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.keys(":miwms("); + try std.testing.expectEqualStrings("/test.txt (Save) Tty Collapse Del", try tag(&s, n)); + try s.keys("md("); + try std.testing.expectEqualStrings("/test.txt Save Tty Collapse Del", try tag(&s, n)); +} + +test "tags: the keyboard reaches a tag's path, which it can select and yank but not edit" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + const before = try tag(&s, n); + // `0` is the line's start, as in acme, where the name is ordinary text. + try s.keys(":0"); + try std.testing.expectEqual(@as(usize, 0), try tagCol(&s, "/test.txt")); + // An edit that reaches into it is refused, the cursor with it. + try s.keys("Eyd"); + try std.testing.expectEqualStrings(before, try tag(&s, n)); + try std.testing.expectEqual(@as(usize, "/test.tx".len), try tagCol(&s, "/test.txt")); + // Typed into, the path drafts a name there, as a click on it does. + try s.keys(";0ix"); + _ = try s.where("x/test.txt"); + // Esc keeps the draft pending; a second drops it. + try s.keys("\x1b\x1b"); + try s.expect(s.at("/pane/{d}/name", .{n}), "/test.txt\n"); + // After the path, the text is the tag's own to edit. + try s.keys(":A!\x1b"); + try std.testing.expectEqualStrings("/test.txt Save Tty Collapse Del!", try tag(&s, n)); + // What it yanked was the path. + try s.keys(":P"); + try s.expect(s.at("/pane/{d}/body", .{n}), "/test.txtbody\n"); +} + +test "tags: a tag remembers its cursor, starts on Save, and a click moves it" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const first = try s.focused(); + try s.write("/ctl", "Newcol\n"); + const second = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{second}), "/second.txt"); + const focus = s.at("{d}", .{first}); + const other = s.at("{d}", .{second}); + try s.write("/focus", focus); + // Nothing to remember yet: `:` lands on Save. + try s.keys(":"); + try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt")); + // Home is the line's start, the path's: the keyboard reaches it. + try s.keys(home ++ right ++ right ++ right); + try std.testing.expectEqual(@as(usize, 3), try tagCol(&s, "/test.txt")); + // `:` in the tag's normal mode is the way back to the body. + try s.keys(":"); + try std.testing.expect((try s.cursor())[1] != (try s.where("/test.txt"))[1]); + try s.write("/focus", other); + try s.keys(":" ++ home ++ right ++ right ++ right ++ right ++ right ++ ":"); + try s.write("/focus", focus); + try s.keys(":"); + try std.testing.expectEqual(@as(usize, 3), try tagCol(&s, "/test.txt")); + try s.keys(":"); + try s.write("/focus", other); + try s.keys(":"); + try std.testing.expectEqual(@as(usize, 5), try tagCol(&s, "/second.txt")); + try s.keys(":"); + // A click in the tag puts its cursor there, the pane's keyboard with it. + try s.click("Save Tty", 6, 1); + try std.testing.expectEqual(first, try s.focused()); + try std.testing.expectEqual(@as(usize, "/test.txt Save T".len), try tagCol(&s, "/test.txt")); + // A prompt opened and left from the body leaves it there. + try s.keys("\x1b:/\x1b:"); + try std.testing.expectEqual(@as(usize, "/test.txt Save T".len), try tagCol(&s, "/test.txt")); + try s.keys(":"); + try s.expect(s.at("/pane/{d}/body", .{first}), "body\n"); +} + +test "tags: executing a word from the tag runs it and gives the keyboard back to the body" { + for ([_][]const u8{ "\t", "\n" }) |chord| { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.keys("ix\x1b"); + // `:` lands on Save; the execute key runs it, the look key looks + // it up. Either way the tag lets go of the keyboard first. + try s.keys(":"); + try s.keys(chord); + try std.testing.expectEqual(@as(usize, if (chord[0] == '\t') 1 else 0), s.saved); + try s.keys("iQ\x1b"); + try s.expect(s.at("/pane/{d}/body", .{n}), "xQbody\n"); + // ...and the tag still knows where it was. + try s.keys(":"); + try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt")); + } +} + +test "tags: a renamed path moves the tag's cursor with the text after it and a shorter tag pulls it back" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.keys("::"); // on Save, and back + try s.write(s.at("/pane/{d}/name", .{n}), "/界.zig"); + try s.keys(":"); + try std.testing.expectEqual(@as(usize, "/界.zig ".len - 1), try tagCol(&s, "/界")); + try s.keys(":"); + try s.replace(s.at("/pane/{d}/tag", .{n}), "é"); + try s.keys(":"); + // `/界.zig é`: the cursor is pulled back onto the last character. + try std.testing.expectEqual(@as(usize, "/界.zig ".len - 1), try tagCol(&s, "/界")); + try s.expect(s.at("/pane/{d}/body", .{n}), "body\n"); +} + +test "tags: window keys move between panes from a tag and each tag keeps its cursor" { + for ([_]bool{ false, true }) |bottom| { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + if (bottom) try s.write("/ctl", "Tagbottom on\n"); + const first = try s.focused(); + const second = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{second}), "/second.txt"); + try s.write("/focus", s.at("{d}", .{first})); + try s.keys(":" ++ home ++ "ll" ++ window ++ "j\n"); + try std.testing.expectEqual(second, try s.focused()); + try s.keys(":" ++ home ++ "llll" ++ window ++ "k\n"); + try std.testing.expectEqual(first, try s.focused()); + try s.keys(":"); + try std.testing.expectEqual(@as(usize, 2), try tagCol(&s, "/test.txt")); + try s.keys(window ++ "j\n:"); + try std.testing.expectEqual(@as(usize, 4), try tagCol(&s, "/second.txt")); + } +} + +test "tags: a tag's normal mode is the body's: motions stay in the tag and insert types into it" { + for ([_]bool{ false, true }) |bottom| { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + if (bottom) try s.write("/ctl", "Tagbottom on\n"); + const first = try s.focused(); + try s.write("/ctl", "Newcol\n"); + const right_pane = try s.newPane(); + try s.write("/focus", s.at("{d}", .{first})); + try s.keys(":" ++ home ++ "l"); + try std.testing.expectEqual(@as(usize, 1), try tagCol(&s, "/test.txt")); + try s.keys("hkj"); + try std.testing.expectEqual(@as(usize, 0), try tagCol(&s, "/test.txt")); + try std.testing.expectEqual(first, try s.focused()); + try s.keys(window ++ "l\n"); + try std.testing.expectEqual(right_pane, try s.focused()); + try s.keys(window ++ "h\n"); + try std.testing.expectEqual(first, try s.focused()); + try s.keys(":i\u{F018}hjklHJKL:"); + try std.testing.expectEqualStrings("/test.txt Save Tty Collapse DelhjklHJKL:", try tag(&s, first)); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{first})), " mode:normal ")); + try s.expect(s.at("/pane/{d}/body", .{first}), "body\n"); + try std.testing.expectEqual(first, try s.focused()); + } +} diff --git a/test/panes.zig b/test/panes.zig index 6970cbb5..e1be67b9 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -296,279 +296,6 @@ test "a tag with more lines than rows scrolls to keep its caret in view" { try std.testing.expect(std.mem.indexOfScalar(u8, p.col_tags[0].own.?, '\n') == null); } -const TagNavigationTests = struct { - fn key(p: *Pardes, cp: u21) void { - p.update(.{ .key = .{ .cp = cp } }); - } - - test "s, S and | in a tag answer for the tag's own text; / still searches the body" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const pane = try p.setTestFile("Some body\n"); - try setTag(pane, " Save Del Snarf"); - key(p, ':'); - key(p, 'x'); // the tag's line - key(p, 's'); - try std.testing.expect(pane.prompt == .search and pane.prompt_for == .tag and pane.focus == .tag); - p.update(.{ .key = .{ .cp = 'S', .text = "S" } }); - key(p, Key.enter); - try std.testing.expect(pane.focus == .tag and pane.prompt == .none); - var ranges: [panes.Text.max_selections]modal.Selection = undefined; - const text = try pardes.edit.flatSurface(p, &pane.tag); - const got = pane.tag.ranges(text, 0, &ranges); - try std.testing.expectEqual(@as(usize, 2), got.n); - for (ranges[0..got.n]) |range| try std.testing.expectEqualStrings("S", text[@min(range.anchor, range.head)..@max(range.anchor, range.head)]); - // the body's selection is its own - try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); - // `/` from the tag is the body's search, as acme's Look from a tag is - key(p, ','); - key(p, '/'); - try std.testing.expect(pane.prompt == .search and pane.prompt_for == .body and pane.focus == .body); - key(p, Key.escape); - try std.testing.expect(pane.prompt == .none and pane.focus == .body); - } - - test "ms and md edit a tag's own text, and the text the edit made is read back whole" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.update(.tick); - key(p, ':'); // the tag, on `Save` the first time - for ("miwms(") |cp| key(p, cp); - try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), "(Save)") != null); - for ("md(") |cp| key(p, cp); - try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), " Save ") != null); - try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), "(") == null); - } - - test "the keyboard reaches a tag's path, which it can select and yank but not edit" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.update(.tick); - key(p, ':'); - // `0` is the line's start, as in acme, where the name is ordinary text - key(p, '0'); - try std.testing.expectEqual(@as(i32, 0), pane.tag.cur_col); - key(p, 'E'); - key(p, 'y'); - try std.testing.expectEqualStrings("/test.txt", p.registers.text(p.gpa, '"').?); - // an edit that reaches into it is refused, the cursor with it - const before = try std.testing.allocator.dupe(u8, try pardes.edit.flatSurface(p, &pane.tag)); - defer std.testing.allocator.free(before); - const cursor = pane.tag.cur_col; - key(p, 'd'); - try std.testing.expectEqualStrings(before, try pardes.edit.flatSurface(p, &pane.tag)); - try std.testing.expectEqual(cursor, pane.tag.cur_col); - try std.testing.expect(pane.tag.vsel.active); - // typed into, the path drafts a name there, as a click on it does - key(p, ';'); - key(p, '0'); - key(p, 'i'); - p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); - try std.testing.expect(pane.prompt == .name); - try std.testing.expectEqualStrings("x/test.txt", pane.input.own.?); - // Esc keeps the draft pending; a second drops it. - key(p, Key.escape); - key(p, Key.escape); - try std.testing.expect(pane.prompt == .none); - try std.testing.expectEqualStrings("/test.txt", pane.file.?.path); - // after the path, the text is the tag's own to edit - key(p, ':'); - key(p, 'A'); - p.update(.{ .key = .{ .cp = '!', .text = "!" } }); - try std.testing.expect(std.mem.endsWith(u8, pardes.tagline.curTail(pane), "!")); - try std.testing.expectEqualStrings("body\n", pane.file.?.content); - } - - fn window(p: *Pardes, letter: u21) void { - p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - key(p, letter); - key(p, Key.enter); - } - - test "a tag remembers its cursor, starts on Save, and a click moves it" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const first = try p.setTestFile("body\n"); - p.presentation.enabled = false; - try std.testing.expect(p.executeBuiltinLine(0, "New")); - const second_id = p.active; - const second = p.panes[second_id].?; - try std.testing.expect(layout.splitColumn(p, second_id, second_id, false)); - p.update(.tick); - p.active = 0; - // Nothing to remember yet: `:` lands on Save, in normal mode. - key(p, ':'); - try std.testing.expect(first.focus == .tag and first.tag.mode == .normal); - const shown = try pardes.edit.flatSurface(p, &first.tag); - try std.testing.expectEqualStrings("Save", shown[@intCast(first.tag.cur_col)..][0..4]); - // Home is the line's start, the path's: the keyboard reaches it. - key(p, Key.home); - for (0..3) |_| key(p, Key.right); - try std.testing.expectEqual(@as(i32, 3), first.tag.cur_col); - // `:` in the tag's normal mode is the way back to the body. - key(p, ':'); - try std.testing.expect(first.focus == .body); - p.active = second_id; - key(p, ':'); - key(p, Key.home); - for (0..5) |_| key(p, Key.right); - key(p, ':'); - p.active = 0; - key(p, ':'); - try std.testing.expectEqual(@as(i32, 3), first.tag.cur_col); - key(p, ':'); - p.active = second_id; - key(p, ':'); - try std.testing.expectEqual(@as(i32, 5), second.tag.cur_col); - key(p, ':'); - var frame = std.heap.ArenaAllocator.init(p.gpa); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - const rect = p.rects[0]; - const y = tagY(p, rect); - const prefix: u16 = @intCast(panes.File.displayWidth(try pardes.tagline.tagPrefix(p, first))); - ClickCursorTests.click(p, .left, rect.x + pardes.TAG_TEXT_INSET + prefix + 6, y); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expect(first.focus == .tag and first.tag.mode == .insert); - try std.testing.expectEqual(@as(i32, prefix + 6), first.tag.cur_col); - key(p, Key.escape); - key(p, ':'); - p.startPrompt(first, &first.body, .{ .search = config.search_marker }); - key(p, Key.escape); - key(p, ':'); - try std.testing.expectEqual(@as(i32, prefix + 6), first.tag.cur_col); - key(p, ':'); - try std.testing.expectEqualStrings("body\n", first.file.?.content); - } - - test "executing a word from the tag runs it and gives the keyboard back to the body" { - for ([_]u21{ Key.tab, Key.enter }) |chord| { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.update(.{ .key = .{ .cp = 'i' } }); - p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); - p.update(.{ .key = .{ .cp = Key.escape } }); - while (p.nextEffect()) |_| {} - // `:` lands on Save; the execute key runs it, the look key looks - // it up. Either way the tag lets go of the keyboard first. - key(p, ':'); - try std.testing.expect(pane.focus == .tag); - key(p, chord); - try std.testing.expect(pane.focus == .body); - try std.testing.expectEqual(.normal, pane.body.mode); - var saved = false; - while (p.nextEffect()) |effect| { - if (effect == .save_file) saved = true; - } - try std.testing.expectEqual(chord == Key.tab, saved); - // ...and the tag still knows where it was. - key(p, ':'); - try std.testing.expectEqualStrings("Save", (try pardes.edit.flatSurface(p, &pane.tag))[@intCast(pane.tag.cur_col)..][0..4]); - } - } - - test "a renamed path moves the tag's cursor with the text after it and a shorter tag pulls it back" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 14 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - key(p, ':'); // on Save - key(p, ':'); - p.gpa.free(pane.file.?.path); - pane.file.?.path = try p.gpa.dupe(u8, "/界.zig"); - p.update(.tick); - key(p, ':'); - const shown = try pardes.edit.flatSurface(p, &pane.tag); - try std.testing.expectEqualStrings("Save", shown[@intCast(pane.tag.cur_col)..][0..4]); - key(p, ':'); - try setTag(pane, "é"); - p.update(.tick); - key(p, ':'); - // `/界.zig é`: the cursor is pulled back onto the last character - try std.testing.expectEqual(@as(i32, "/界.zig ".len), pane.tag.cur_col); - try std.testing.expectEqualStrings("body\n", pane.file.?.content); - } - - test "window keys move between panes from a tag and each tag keeps its cursor" { - for ([_]bool{ false, true }) |bottom| { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - const first = try p.setTestFile("body\n"); - p.presentation.enabled = false; - p.settings.tag_bottom = bottom; - try std.testing.expect(p.executeBuiltinLine(0, "New")); - const second_id = p.active; - const second = p.panes[second_id].?; - p.update(.tick); - p.active = 0; - key(p, ':'); - key(p, Key.home); - key(p, 'l'); - key(p, 'l'); - window(p, 'j'); - try std.testing.expectEqual(second_id, p.active); - try std.testing.expect(first.focus == .body and second.focus == .body); - key(p, ':'); - key(p, Key.home); - for (0..4) |_| key(p, 'l'); - window(p, 'k'); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expect(second.focus == .body); - key(p, ':'); - try std.testing.expectEqual(@as(i32, 2), first.tag.cur_col); - window(p, 'j'); - key(p, ':'); - try std.testing.expectEqual(@as(i32, 4), second.tag.cur_col); - } - } - - test "a tag's normal mode is the body's: motions stay in the tag and insert types into it" { - for ([_]bool{ false, true }) |bottom| { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - p.presentation.enabled = false; - p.settings.tag_bottom = bottom; - try std.testing.expect(p.executeBuiltinLine(0, "New")); - const right = p.active; - try std.testing.expect(layout.splitColumn(p, right, right, false)); - p.update(.tick); - p.active = 0; - key(p, ':'); - const pane = p.panes[0].?; - key(p, Key.home); - key(p, 'l'); - try std.testing.expectEqual(@as(i32, 1), pane.tag.cur_col); - key(p, 'h'); - key(p, 'k'); - key(p, 'j'); - try std.testing.expectEqual(@as(i32, 0), pane.tag.cur_col); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expect(pane.focus == .tag and !p.header_focus); - window(p, 'l'); - try std.testing.expectEqual(right, p.active); - try std.testing.expect(pane.focus == .body and p.panes[right].?.focus == .body); - window(p, 'h'); - try std.testing.expectEqual(@as(usize, 0), p.active); - key(p, ':'); - key(p, 'i'); - key(p, Key.end); - const before = pardes.tagline.curTail(pane).len; - try std.testing.expect(pane.focus == .tag and pane.tag.mode == .insert and pane.body.mode == .normal); - for ("hjklHJKL:") |letter| { - const text = [_]u8{letter}; - p.update(.{ .key = .{ .cp = letter, .text = &text } }); - try std.testing.expect(pane.focus == .tag and pane.tag.mode == .insert); - } - try std.testing.expectEqualStrings("hjklHJKL:", pardes.tagline.curTail(pane)[before..]); - try std.testing.expectEqualStrings("body\n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 0), p.active); - } - } -}; - const BodyHitTests = struct { fn mouse(layer: *const pardes.Layer, row: u16, col: u16, kind: pardes.Mouse.Kind) pardes.Mouse { const width: f32 = if (row < layer.context_rows) 8 else 10; @@ -4414,7 +4141,6 @@ const TerminalTests = struct { }; test { - _ = TagNavigationTests; _ = TagLayerTests; _ = TagNameTintTests; _ = TreeContextTests; 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