From 5cc02232d522d5cd5a453caedd1e592ca20471ea Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:09:53 -0300 Subject: test: eleven more of src/pardes.zig's tests through the 9P tree alone (test/behaviour/columns_and_tags, modes, tags, panes): a click past a column tag's text typing after it, a newline there a space and a long tag scrolled to its caret, Enter and Tab in a tag running the word under the cursor, Esc alternating two panes of a kind, Esc out of a column or the workspace tag, Shift-Esc out of every mode, a name typed into the tag's path pending past Esc, an unsaved file's tag its name alone, a question ended in the log when its pane closes, focus on a closed pane to the one taking its place; Session's cursor (/screen's); each checked to fail against a break (flatten keeping newlines, the header drawn unscrolled, Enter in a header a Look, Esc in normal mode not running Last, Esc in a header not leaving it, Shift-Esc leaving insert on, the first Esc on a drafted name dropping it, a dirty tag marked ' *', del_side left out of noteRetire's answer, removeColumn's focus to any pane) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 231 ------------------------------------ test/behaviour.zig | 2 + test/behaviour/columns_and_tags.zig | 39 ++++++ test/behaviour/modes.zig | 65 ++++++++++ test/behaviour/panes.zig | 63 ++++++++++ test/behaviour/tags.zig | 19 +++ test/session.zig | 10 ++ 7 files changed, 198 insertions(+), 231 deletions(-) create mode 100644 test/behaviour/modes.zig create mode 100644 test/behaviour/tags.zig diff --git a/src/pardes.zig b/src/pardes.zig index ea8b52df..3d29dfcd 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1462,21 +1462,6 @@ test "dragging a column's only pane to another leaves that column in place, empt try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); } -test "an unsaved file's tag is its name alone: the grip, not a mark, says it is unsaved" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - const pane = try p.setTestFile("before\n"); - const clean = try tagline.tagText(p, p.scratch.allocator(), pane); - panes.File.setContent(p, &pane.file.?, try gpa.dupe(u8, "after\n")); - const dirty = try tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expectEqualStrings(clean, dirty); - try std.testing.expect(std.mem.indexOf(u8, dirty, " *") == null); - // The dirty file and index's flag still say it. - try std.testing.expect(ctlfs.pane.dirtyOf(pane)); -} - test "unknown Exec from a document runs as a command pane in its directory, typed into no terminal" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{}); @@ -3180,33 +3165,6 @@ fn pardes_ctlfs_ctlText(p: *Pardes, pane: *Pane) []const u8 { return th.rd(p, ctlfs.Node.of(pane.serial, .ctl), 0, 4096).bytes; } -test "a name typed into the tag's path survives Esc, pending, and the next Enter renames; a second Esc drops it" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("x\n"); - for ([_]bool{ true, false }) |enter| { - tagline.enterTag(p, pane); - pane.tag.mode = .insert; - pane.tag.cur_row = 0; - pane.tag.cur_col = 1; - p.update(.{ .key = .{ .cp = 'z', .text = "z" } }); - try std.testing.expect(pane.prompt == .name); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt == .name); - // A stray key changes nothing while it waits. - p.update(.{ .key = .{ .cp = 'q', .text = "q" } }); - if (enter) { - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqualStrings("/ztest.txt", pane.file.?.path); - } else { - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt != .name); - try std.testing.expectEqualStrings("/ztest.txt", pane.file.?.path); - } - } -} - test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 }); @@ -3389,43 +3347,6 @@ test "column tag first-cell execution keeps New local to the clicked column" { try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content); } -test "header clicks beyond text append and long UTF-8 tags reveal their caret" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "New"); - p.acknowledgePanelPresentation(&.{}); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .key = .{ .cp = 'x', .text = " extended" } }); - try std.testing.expectEqualStrings("New extended", tagline.columnTag(p, 0)); - p.update(.{ .paste = " 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界" }); - const frame = try p.render(p.scratch.allocator()); - try std.testing.expect(p.header_scroll > 0); - try std.testing.expect(frame.cursor != null); - try std.testing.expectEqual(TOPBAR_H, frame.cursor.?.y); - try std.testing.expect(frame.cursor.?.x < p.screen_w); - p.update(.{ .key = .{ .cp = Key.home } }); - _ = try p.render(p.scratch.allocator()); - try std.testing.expectEqual(@as(usize, 0), p.header_scroll); -} - -test "a newline typed into a column tag is a space: the tag stays one row" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "New"); - p.acknowledgePanelPresentation(&.{}); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - p.update(.{ .key = .{ .cp = 'S', .text = "Snarf" } }); - _ = try p.render(p.scratch.allocator()); - try std.testing.expectEqualStrings("New Snarf", tagline.columnTag(p, 0)); - try std.testing.expectEqual(COLBAR_H, p.columnBarHeight()); - try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.rects[0].y); -} - test "tiny screens keep pane space before adding a column tag" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 8, .rows = 2, .tty_only = true }); defer p.deinit(); @@ -3456,18 +3377,6 @@ test "a screen too short for the column row releases a column tag's focus withou try std.testing.expectEqualStrings("unchanged body\n", pane.file.?.content); } -test "a header's execute key runs the word under its cursor and lets go of the keyboard first" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - tagline.enterHeader(p, null); - p.global_tag.cur_col = @intCast(std.mem.indexOf(u8, config.topbar_str, "Dump").?); - p.update(.{ .key = .{ .cp = Key.tab } }); - try std.testing.expect(!p.header_focus); - try std.testing.expect(p.dump_out != null); - try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); -} - test "s in a header selects in the header's own text" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); defer p.deinit(); @@ -3487,20 +3396,6 @@ test "s in a header selects in the header's own text" { try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); } -test "Enter in a header runs the word under its cursor, as the execute key does" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - tagline.enterHeader(p, null); - p.global_tag.cur_col = @intCast(std.mem.indexOf(u8, config.topbar_str, "Newcol").?); - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - // and the workspace tag lets go of the keyboard: the new, empty - // column's tag has it - try std.testing.expect(p.header_focus and p.header_column.? == 1); -} - test "window keys walk from a pane up through the column and workspace tags and back" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true }); defer p.deinit(); @@ -8272,31 +8167,6 @@ pub const Pardes = struct { } }; -test "Esc alternates between two panes of the SAME kind" { - if (platform == .web) return; - const gpa = std.testing.allocator; - var cwdbuf: [4096]u8 = undefined; - const cwd = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwdbuf, cwdbuf.len) orelse return))); - var pathbuf: [4096]u8 = undefined; - const boot = try std.fmt.bufPrint(&pathbuf, "{s}/mise.toml", .{cwd}); - - const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 40, .file = boot }); - defer p.deinit(); - p.update(.{ .resize = .{ .cols = 80, .rows = 40 } }); - const a = p.active; - exec.runBuiltin(p, .Look, a, "", "build.zig"); - p.sync(); - const b = p.active; - try std.testing.expect(b != a); - try std.testing.expect(!p.panes[a].?.isTerminal() and !p.panes[b].?.isTerminal()); - - for (0..6) |_| { - const was = p.active; - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expectEqual(if (was == a) b else a, p.active); - } -} - test "a boot file that will not open boots an errors pane rather than failing the launch" { if (platform == .web) return; const gpa = std.testing.allocator; @@ -8676,49 +8546,6 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" { try std.testing.expect(p.panes[low] == null); } -test "focus on a closed pane goes to the pane that takes its place, not the one focused before" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); - defer p.deinit(); - const shell = p.active; - p.newColumn(shell); - p.newScratchIn(shell, p.activeColumn().?); - const right = p.active; - p.sync(); - p.newScratchBelow(shell); - const low = p.active; - p.sync(); - // The dogfood case: `right` was focused just before `low`, but `shell` - // grows into `low`'s rows, so `shell` gets the focus. - try std.testing.expect(p.executeBuiltinLine(low, "Del")); - p.sync(); - try std.testing.expect(p.panes[low] == null); - try std.testing.expectEqual(shell, p.active); - - // Closing a pane that has no focus leaves the focus where it is. - p.newScratchBelow(shell); - const other = p.active; - p.sync(); - p.active = right; - p.sync(); - try std.testing.expect(p.executeBuiltinLine(other, "Del")); - try std.testing.expectEqual(right, p.active); - - // Delcol: the column that takes the width holds, level with the closed - // pane, the pane that takes its place; `right` was focused just before. - p.newScratchBelow(right); - const right_low = p.active; - p.newScratchBelow(shell); - const left_low = p.active; - p.active = right; - p.sync(); - p.active = left_low; - p.sync(); - try p.removeColumn(layout.findPane(p, left_low).?.col); - p.sync(); - try std.testing.expectEqual(right_low, p.active); -} - test "the bare tty startup opens a text pane under the shell, unfocused" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .boot = .tty }); @@ -8892,43 +8719,6 @@ test "with ProgramEsc raw tty Escape only leaves at a shell prompt" { try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); } -test "Shift-Esc backs out to the previous pane in every mode, never into raw" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); - defer p.deinit(); - p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc - const shell = p.active; - const sp = p.panes[shell].?; - // A terminal in normal mode: out, still normal, never raw. - if (sp.body.mode == .tty) p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); - try std.testing.expectEqual(Text.Mode.normal, sp.body.mode); - p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(Text.Mode.normal, sp.body.mode); - // A text pane in insert mode: out of insert, and out of the pane. - const doc = p.panes[0].?; - p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); - try std.testing.expectEqual(Text.Mode.insert, doc.body.mode); - p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); - try std.testing.expectEqual(Text.Mode.normal, doc.body.mode); - try std.testing.expect(p.active != 0); -} - -test "Esc in a column or the workspace tag gives the keyboard back to a pane, as Shift-Esc does" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); - defer p.deinit(); - p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a pane to go back to - for ([_]?usize{ 0, null }) |column| { - tagline.enterHeader(p, column); - try std.testing.expect(tagline.focusedHeader(p) != null); - const was = p.active; - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(tagline.focusedHeader(p) == null); - try std.testing.expect(p.active != was); - } -} - test "window mode moves an outline and focuses it on Enter, Esc or a label" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 }); defer p.deinit(); @@ -9870,27 +9660,6 @@ test "core animation keeps wall time at 60, 120 and 144 Hz and across a stall" { try std.testing.expectEqual(@as(?u64, null), p.nextWake()); } -test "a pane closed while its question stands ends the question in the log" { - const th = @import("ninep/testing.zig"); - const p = try th.withFile(std.testing.allocator, "x\n"); - defer p.deinit(); - p.settings.placement = .pardes; - p.newScratchBelow(0); - const closing = p.active; - p.newScratchBelow(closing); - p.sync(); - p.active = closing; // a middle pane: Del from a key asks which side - const serial = p.panes[closing].?.serial; - p.update(.{ .key = .{ .cp = ' ' } }); - p.update(.{ .key = .{ .cp = 'd' } }); - try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[closing].?.prompt); - // A bare answer says what this question takes. - try std.testing.expectEqualStrings("answer takes k j or -", th.wr(p, ctlfs.Node.of(serial, .ctl), "answer\n").reply.ename); - try p.removePane(closing, null); - var want: [64]u8 = undefined; - try std.testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "answer {d} -\ndel {d}", .{ serial, serial }))); -} - test "a Save the host could not do logs no save record" { const th = @import("ninep/testing.zig"); const p = try th.withFile(std.testing.allocator, "x\n"); diff --git a/test/behaviour.zig b/test/behaviour.zig index 32138f94..902ef520 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -6,7 +6,9 @@ test { _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); _ = @import("behaviour/look_and_exec.zig"); + _ = @import("behaviour/modes.zig"); _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/root_ctl.zig"); + _ = @import("behaviour/tags.zig"); } diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig index 80f9c710..5b78a6c8 100644 --- a/test/behaviour/columns_and_tags.zig +++ b/test/behaviour/columns_and_tags.zig @@ -149,3 +149,42 @@ test "columns-and-tags: New is a column tag's word, in no pane's tag nor the wor } try expectEqualStrings("New Tty Find Grep Joincol Delcol", try s.read(s.at("/col/{d}/tag", .{try s.column(0)}))); } + +test "columns-and-tags: a click past a column tag's text types after it, a newline typed there a space, and a long tag scrolls to its caret" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const tag = s.at("/col/{d}/tag", .{try s.column(0)}); + // Its row, then the pane's tag: the column's stays one row. + const rows = " New Tty Find Grep Joincol Delcol"; + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " ") != null); + try s.click("Delcol", 20, 1); + try s.keys("\nSnarf"); + try expectEqualStrings("New Tty Find Grep Joincol Delcol Snarf", try s.read(tag)); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " Snarf ") != null); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "\n /test.txt Save") != null); + // Wider than the screen: the tag scrolls to keep its caret drawn. + try s.keys(" 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界"); + const col, const row = (try s.cursor()).?; + try std.testing.expectEqual(@as(usize, 1), row); + try std.testing.expect(col < 80); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows) == null); + try s.keys("\u{F00D}"); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows) != null); +} + +test "columns-and-tags: Enter in a tag in normal mode runs the word under its cursor, and Tab does too, letting go of the keyboard first" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const first = try s.focused(); + try s.click("Newcol", 1, 1); + try s.keys("\x1b\n"); + try expectEqualStrings(s.at("{d}:{d} {d}:", .{ try s.column(0), first, try s.column(1) }), try s.columns()); + // The workspace tag lets go of the keyboard: the new, empty column's + // tag has it. + try s.expect("/focus", ""); + try s.keys("iMine\x1b"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/col/{d}/tag", .{try s.column(1)})), "Mine") != null); + try s.click("Tutor", 1, 1); + try s.keys("\x1b\t"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/name", .{try s.focused()})), "/+Tutor\n")); +} diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig new file mode 100644 index 00000000..cdcf1be6 --- /dev/null +++ b/test/behaviour/modes.zig @@ -0,0 +1,65 @@ +//! docs/typ/guide.typ, Modes . +const std = @import("std"); +const Session = @import("session").Session; +const expectEqual = std.testing.expectEqual; + +fn mode(s: *Session, pane: u32) ![]const u8 { + const ctl = try s.read(s.at("/pane/{d}/ctl", .{pane})); + const at = std.mem.lastIndexOf(u8, ctl, " mode:").? + " mode:".len; + return std.mem.trimEnd(u8, ctl[at..], " "); +} + +test "modes: Esc in normal mode alternates between two panes of the same kind" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "a\n"); + defer s.deinit(); + const a = try s.focused(); + try s.write("/look", s.at("{s}/b.txt\n", .{at})); + const b = try s.focused(); + try std.testing.expect(a != b); + for (0..6) |_| { + const was = try s.focused(); + try s.keys("\x1b"); + try expectEqual(if (was == a) b else a, try s.focused()); + } +} + +test "modes: Esc in a column or the workspace tag gives the keyboard back to a pane, as Shift-Esc does" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + _ = try s.newPane(); + for ([_][]const u8{ "New Tty", "Newcol" }) |tag| { + const was = try s.focused(); + // A click types into the tag; Esc is normal mode there, the next + // one is out of it. + try s.click(tag, 0, 1); + try s.keys("\x1b"); + try s.expect("/focus", ""); + try s.keys("\x1b"); + try std.testing.expect(was != try s.focused()); + } +} + +test "modes: Shift-Esc backs out to the previous pane in every mode, never into raw" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const doc = try s.focused(); + try s.keys("\u{F015}n"); // a shell under the doc + const shell = try s.focused(); + if (std.mem.eql(u8, try mode(&s, shell), "tty")) try s.keys("\x02"); + try std.testing.expectEqualStrings("normal", try mode(&s, shell)); + // A terminal in normal mode: out, still normal, never raw. + try s.keys("\u{F016}\x1b"); + try expectEqual(doc, try s.focused()); + try std.testing.expectEqualStrings("normal", try mode(&s, shell)); + // A text pane in insert mode: out of insert, and out of the pane. + try s.keys("i"); + try std.testing.expectEqualStrings("insert", try mode(&s, doc)); + try s.keys("\u{F016}\x1b"); + try std.testing.expectEqualStrings("normal", try mode(&s, doc)); + try std.testing.expect(doc != try s.focused()); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 01820a07..d0773bfb 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -49,3 +49,66 @@ test "panes: Putall saves every pane with unsaved edits to a file, one each, and try s.write("/ctl", "Putall\n"); try std.testing.expectEqual(@as(usize, 1), s.saved); } + +test "panes: an unsaved file's tag is its name alone, its dirty file says it is unsaved" { + var s = try Session.initFile(std.testing.allocator, "before\n"); + defer s.deinit(); + const n = try s.focused(); + const tag = s.at("/pane/{d}/tag", .{n}); + const clean = try s.read(tag); + try s.write(s.at("/pane/{d}/body", .{n}), "after\n"); + try std.testing.expectEqualStrings(clean, try s.read(tag)); + try std.testing.expect(std.mem.indexOf(u8, clean, " *") == null); + try s.expect(s.at("/pane/{d}/dirty", .{n}), "1\n"); +} + +test "panes: a pane closed while its question stands ends the question in the log" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "Placement pardes\n"); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + const closing = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{closing}), "New\n"); + // A middle pane: Del from a key asks which side. + try s.write("/focus", s.at("{d}\n", .{closing})); + try s.keys(" d"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("ask {d} del k j\n", .{closing})) != null); + // A bare answer says what this question takes. + const ctl = s.at("/pane/{d}/ctl", .{closing}); + _ = try s.refused(ctl, "answer\n"); + try std.testing.expectEqualStrings("answer takes k j or -", s.said); + try s.write(ctl, "Del\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("answer {d} -\ndel {d}", .{ closing, closing })) != null); +} + +test "panes: focus on a closed pane goes to the pane that takes its place, not the one focused before" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const left = try s.focused(); + try s.write("/ctl", "Newcol\n"); + try s.write(s.at("/col/{d}/ctl", .{try s.column(1)}), "New\n"); + const right = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const low = try s.focused(); + // `right` was focused just before `low`, but `left` grows into `low`'s + // rows, so `left` gets the focus. + try s.write(s.at("/pane/{d}/ctl", .{low}), "Del\n"); + try std.testing.expectEqual(left, try s.focused()); + // Closing a pane that has no focus leaves the focus where it is. + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const other = try s.focused(); + try s.write("/focus", s.at("{d}\n", .{right})); + try s.write(s.at("/pane/{d}/ctl", .{other}), "Del\n"); + try std.testing.expectEqual(right, try s.focused()); + // Delcol: the column that takes the width holds, level with the closed + // pane, the pane that takes its place; `right` was focused just before. + try s.write(s.at("/pane/{d}/exec", .{right}), "New\n"); + const right_low = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const left_low = try s.focused(); + try s.write("/focus", s.at("{d}\n", .{right})); + try s.write("/focus", s.at("{d}\n", .{left_low})); + try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Delcol\n"); + try std.testing.expectEqual(right_low, try s.focused()); +} diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig new file mode 100644 index 00000000..ab109b78 --- /dev/null +++ b/test/behaviour/tags.zig @@ -0,0 +1,19 @@ +//! docs/typ/guide.typ, Tags . +const std = @import("std"); +const Session = @import("session").Session; + +test "tags: a name typed into the tag's path survives Esc, pending, and the next Enter renames; a second Esc drops it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + const name = s.at("/pane/{d}/name", .{n}); + // A click on the path types into it; a stray key while it waits + // changes nothing. + try s.click("/test.txt", 1, 1); + try s.keys("z\x1bq\n"); + try s.expect(name, "/ztest.txt\n"); + try s.click("/ztest.txt", 1, 1); + try s.keys("z\x1bq\x1b"); + try s.expect(name, "/ztest.txt\n"); + try std.testing.expect(std.mem.startsWith(u8, try s.read(s.at("/pane/{d}/tag", .{n})), "/ztest.txt ")); +} diff --git a/test/session.zig b/test/session.zig index c4ed0db2..f67f3b25 100644 --- a/test/session.zig +++ b/test/session.zig @@ -210,6 +210,16 @@ pub const Session = struct { const col = cols.next() orelse return error.NoColumn; return std.fmt.parseInt(u32, col[0..std.mem.indexOfScalar(u8, col, ':').?], 10); } + + /// Where /screen draws the cursor, column and row; null when it draws none. + 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 = switch (json.object.get("cursor").?) { + .object => |o| o, + else => return null, + }; + return .{ @intCast(c.get("x").?.integer), @intCast(c.get("y").?.integer) }; + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { -- cgit v1.3