From 52bfa3f2aa8f8158d4d7ca720d81ea0c654f94bf Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:28:16 -0300 Subject: test: three of src/pardes.zig's tests through the 9P tree alone: in test/behaviour/columns_and_tags.zig a column tag lighting the word under the mouse, taking the caret where pressed, sweeping three cells in the selection's colour, typed at its caret (Home, Help) and scrolling its text from the column's edge, never its caret (each column); in test/behaviour/mouse.zig a click on either half of a wide character landing before it in the text (dot) and on a tag's path (a name drafted, Right stepping a grapheme, two cells then one), a two-byte λ typed in a tag and taken out by one backspace, and a sweep pressed on the line numbers taking only the text (unlit numbers, a Look in it finding its next place, a chord cutting it); Session's bg (a cell's background from /screen's styles); each checked to fail against a break (no tag hover, the header scrolled one cell too far, byteAtDisplay rounding a wide glyph's second half past it, Right stepping a byte in insert, the three clamps that keep a sweep's first row off the line numbers dropped) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 112 --------------------------------------------------------- 1 file changed, 112 deletions(-) (limited to 'src/pardes.zig') diff --git a/src/pardes.zig b/src/pardes.zig index b47119c4..70bcf7c9 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -2918,48 +2918,6 @@ test "every line of the board's boot buffer renders whole" { // ---- the boundary types ---- -test "Unicode display cells map back to body and tag byte cursors" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("a界e\u{301}z\n"); - const f = &pane.file.?; - p.gpa.free(f.path); - f.path = try p.gpa.dupe(u8, "界e\u{301}.txt"); - - var frame = std.heap.ArenaAllocator.init(gpa); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - const rect = p.rects[0]; - const text_x = rect.x + config.GUTTER + config.PREFIX_W; - const body_y = rect.y + BOX_H; - // The second screen cell is the trailing half of the wide CJK grapheme. - // Both halves map to its one byte boundary. - p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = text_x + 2, .row = body_y } }); - p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = text_x + 2, .row = body_y } }); - try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); - - // A click in the wide path glyph drafts a name with its caret at the - // grapheme start; arrow motion then advances by the full UTF-8 cluster. - tagline.draftName(p, pane, 1); - try std.testing.expectEqual(@as(i32, 0), pane.input.cur_col); - edit.insertKey(p, &pane.input, .{ .cp = Key.right }); - try std.testing.expectEqual(@as(i32, 3), pane.input.cur_col); - edit.insertKey(p, &pane.input, .{ .cp = Key.right }); - try std.testing.expectEqual(@as(i32, 6), pane.input.cur_col); - pane.closePrompt(); - - const before = try gpa.dupe(u8, tagline.curTail(pane)); - defer gpa.free(before); - tagline.enterTag(p, pane); - const insertion = pane.tag.cur_col; - edit.insertKey(p, &pane.tag, .{ .cp = 'λ', .text = "λ" }); - try std.testing.expectEqual(insertion + 2, pane.tag.cur_col); - edit.insertKey(p, &pane.tag, .{ .cp = Key.backspace }); - try std.testing.expectEqual(insertion, pane.tag.cur_col); - try std.testing.expectEqualStrings(before, tagline.curTail(pane)); -} - test "Tab N draws every pane's tab N cells wide and clicks count past it; bare Tab says the width; the ctl read and a Dump keep it" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 }); @@ -3106,63 +3064,6 @@ test "editable workspace and column tags are typed into and persist" { try std.testing.expectEqualStrings("", tagline.columnTag(empty, 0)); } -test "column tags render edit hover and scroll from the column edge" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("untouched\n"); - p.newColumn(0); - p.newScratchIn(0, p.activeColumn().?); - p.sync(); - p.acknowledgePanelPresentation(&.{}); - var frame = std.heap.ArenaAllocator.init(std.testing.allocator); - defer frame.deinit(); - for (0..p.ncol) |column| { - const x = p.col_x[column] + TAG_TEXT_INSET; - const width = p.col_w[column] - TAG_TEXT_INSET; - const initial = try p.render(frame.allocator()); - for ("New", 0..) |byte, offset| - try std.testing.expectEqual(byte, initial.at(x + @as(u16, @intCast(offset)), TOPBAR_H).text[0]); - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = x, .row = TOPBAR_H } }); - const hovered = try p.render(frame.allocator()); - try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, hovered.at(x, TOPBAR_H).style.bg); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = TOPBAR_H } }); - try std.testing.expectEqual(column, p.header_column.?); - try std.testing.expectEqual(@as(i32, 0), tagline.focusedHeader(p).?.cur_col); - const at_start = try p.render(frame.allocator()); - try std.testing.expectEqual(x, at_start.cursor.?.x); - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = x + 3, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x + 3, .row = TOPBAR_H } }); - const selected = try p.render(frame.allocator()); - for (0..3) |offset| - try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, selected.at(x + @as(u16, @intCast(offset)), TOPBAR_H).style.bg); - p.update(.{ .key = .{ .cp = Key.home } }); - p.update(.{ .key = .{ .cp = 'H', .text = "Help " } }); - try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, column), "Help New Tty")); - const edited = try p.render(frame.allocator()); - try std.testing.expectEqual(x + 5, edited.cursor.?.x); - // Only the text viewport participates in caret reveal. - const long: [80]u8 = @splat('a'); - if (p.col_tags[column].own) |own| p.gpa.free(own); - p.col_tags[column].own = try p.gpa.dupe(u8, long[0 .. width - 1]); - p.update(.{ .key = .{ .cp = Key.end } }); - const at_end = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 0), p.header_scroll); - try std.testing.expectEqual(x + width - 1, at_end.cursor.?.x); - p.update(.{ .key = .{ .cp = 'b', .text = "b" } }); - const revealed = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 1), p.header_scroll); - try std.testing.expectEqual(x + width - 1, revealed.cursor.?.x); - p.update(.{ .key = .{ .cp = Key.home } }); - const home = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 0), p.header_scroll); - try std.testing.expectEqual(x, home.cursor.?.x); - p.update(.{ .key = .{ .cp = Key.escape } }); - p.update(.pointer_leave); - _ = frame.reset(.retain_capacity); - } - try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content); -} - test "column tag first-cell execution keeps New local to the clicked column" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true }); defer p.deinit(); @@ -9180,19 +9081,6 @@ test "board heap: every allocation failure during boot is a clean OutOfMemory" { ); } -test "a sweep pressed on the line numbers copies only the text" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("alpha beta\ngamma delta\n"); - const numbers: i32 = panes.File.gutterWidth(pane); - const top: i32 = pane.tag_rows; - pane.sel[0] = .{ .state = .done, .c0 = 1, .c1 = numbers + 4, .r0 = top, .r1 = top + 1 }; - // Live, while the drag is held, and captured, once it is released. - try std.testing.expectEqualStrings("alpha beta\ngamma", try edit.selectionText(p, pane, pane.sel[0])); - try edit.capturePointerSelection(p, pane, 0); - try std.testing.expectEqualStrings("alpha beta\ngamma", try edit.selectionText(p, pane, pane.sel[0])); -} - test "jump history clears selections and lands at the recorded cursor" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); defer p.deinit(); -- cgit v1.3 From a0ec419725ebb4094d811f5206eb0d95bbc5add0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:45:49 -0300 Subject: test: src/pardes.zig's three window-mode tests through the 9P tree alone, in test/behaviour/modes.zig (guide.typ's Modes): Ctrl-w outlining the pane with the keyboard (its tag in the outline's colour, each box its letter), h j k l moving only the outline, Enter, Esc (after SPC w), : (its tag the keyboard's) and a letter giving a pane the keyboard, other keys changing nothing; d deleting the outlined pane (between two it waits for k or j, Esc taking it back; the rows and the outline going to the pane that took them, one neighbour closing at once), c collapsing and restoring it (the ctl read's collapsed), the mode staying on until Enter; window keys walking from the top pane up to its column's tag (normal mode, w moving its caret), across columns and back to the caret it had, up to the workspace tag, down again, and : back to the body; each checked to fail against a break (h j k l moving the keyboard too, a letter choosing nothing, the outline's tint not painted, the outline dropped after d, c not collapsing, k past a column's top pane doing nothing) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 151 --------------------------------------------- test/behaviour/modes.zig | 157 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 151 deletions(-) (limited to 'src/pardes.zig') diff --git a/src/pardes.zig b/src/pardes.zig index 70bcf7c9..ba09b3b6 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -3133,45 +3133,6 @@ test "s in a header selects in the header's own text" { try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); } -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(); - _ = try p.setTestFile("body\n"); - p.newColumn(0); - p.newScratchIn(0, p.activeColumn().?); - p.sync(); - p.active = p.col_panes[0][0]; - const window = struct { - fn key(core: *Pardes, letter: u21) void { - core.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - core.update(.{ .key = .{ .cp = letter } }); - } - }; - // Up from the top pane: its column's tag, in normal mode; `:` there is - // the way back to the body. - window.key(p, 'k'); - try std.testing.expect(p.header_focus and p.header_column.? == 0); - try std.testing.expectEqual(Text.Mode.normal, p.col_tags[0].mode); - p.update(.{ .key = .{ .cp = 'w' } }); - try std.testing.expect(p.col_tags[0].cur_col > 0); - const remembered = p.col_tags[0].cur_col; - window.key(p, 'l'); - try std.testing.expect(p.header_focus and p.header_column.? == 1); - window.key(p, 'h'); - try std.testing.expectEqual(remembered, p.col_tags[0].cur_col); - window.key(p, 'k'); - try std.testing.expect(p.header_focus and p.header_column == null); - window.key(p, 'j'); - try std.testing.expect(p.header_focus and p.header_column.? == 0); - window.key(p, 'j'); - try std.testing.expect(!p.header_focus); - try std.testing.expectEqual(p.col_panes[0][0], p.active); - window.key(p, 'k'); - p.update(.{ .key = .{ .cp = ':' } }); - try std.testing.expect(!p.header_focus and p.panes[p.active].?.focus == .body); - try std.testing.expectEqualStrings("body\n", p.panes[0].?.file.?.content); -} - pub const Mouse = struct { /// The host has inverted a compact body layer. Physical col/row still /// route pane chrome; these coordinates address the pane's logical text. @@ -8409,63 +8370,6 @@ test "with ProgramEsc raw tty Escape only leaves at a shell prompt" { try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); } -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(); - _ = try p.setTestFile("left\n"); - _ = try p.newShell(1, ""); - try std.testing.expect(layout.splitColumn(p, 0, 1, false)); - p.newScratchBelow(1); - p.sync(); - const lower = for (p.panes, 0..) |slot, id| { - if (slot != null and id > 1) break id; - } else return error.TestExpectedScratch; - p.active = 0; - // Ctrl-w enters it; h/j/k/l move only the outline. - p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - try std.testing.expectEqual(@as(?usize, 0), p.window_pick); - p.update(.{ .key = .{ .cp = 'l', .text = "l" } }); - try std.testing.expect(p.window_pick != null and p.window_pick.? != 0); - p.update(.{ .key = .{ .cp = 'j', .text = "j" } }); - try std.testing.expectEqual(@as(?usize, lower), p.window_pick); - try std.testing.expectEqual(@as(usize, 0), p.active); - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqual(lower, p.active); - try std.testing.expect(p.window_pick == null); - // SPC w enters it too, and Esc also leaves it on the outlined pane. - p.update(.{ .key = .{ .cp = ' ', .text = " " } }); - p.update(.{ .key = .{ .cp = 'w', .text = "w" } }); - p.update(.{ .key = .{ .cp = 'h', .text = "h" } }); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expect(p.window_pick == null); - // Other keys change nothing. - p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - p.update(.{ .key = .{ .cp = '!', .text = "!" } }); - try std.testing.expectEqual(@as(?usize, 0), p.window_pick); - p.update(.{ .key = .{ .cp = Key.escape } }); - // `:` focuses the outlined pane's tag. - p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - p.update(.{ .key = .{ .cp = 'l', .text = "l" } }); - p.update(.{ .key = .{ .cp = ':', .text = ":" } }); - try std.testing.expect(p.active != 0 and p.panes[p.active].?.focus == .tag); - p.update(.{ .key = .{ .cp = Key.escape } }); - // A label goes straight there: the left column's pane is "a". - try std.testing.expectEqual(@as(?u8, 'a'), layout.windowLabel(p, 0)); - try std.testing.expect(p.executeBuiltinLine(p.active, "Window")); - p.update(.{ .key = .{ .cp = 'a', .text = "a" } }); - try std.testing.expectEqual(@as(usize, 0), p.active); - // Painted: the outlined tag's band in the selection colour, each pane's - // letter in its tag's box. - try std.testing.expect(p.executeBuiltinLine(p.active, "Window")); - var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); - defer arena.deinit(); - const shown = try p.render(arena.allocator()); - try std.testing.expectEqual(p.theme().sel_bg, shown.tag_layers[0].bg); - const box = shown.at(p.rects[0].x, p.tagTop(p.panes[0].?, p.rects[0])); - try std.testing.expectEqualStrings("a", box.text[0..box.len]); -} - test "the Del question shows only once its delay is up: a quick SPC d j never sees it" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 }); @@ -8516,61 +8420,6 @@ test "the Del question shows only once its delay is up: a quick SPC d j never se try std.testing.expect(p.panes[mid] == null); } -test "window mode d deletes the outlined pane and asks k or j, c collapses it, and the mode stays" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 }); - defer p.deinit(); - p.settings.placement = .pardes; // the neighbours below are what is under test - const top = p.active; - p.newScratchBelow(top); - const mid = p.active; - p.newScratchBelow(mid); - const low = p.active; - p.sync(); - const h = [_]u16{ p.rects[top].h, p.rects[mid].h, p.rects[low].h }; - // Neither key is a pane's label. - try std.testing.expect(std.mem.indexOfAny(u8, layout.window_labels, "hjkldc") == null); - - // Ctrl-w from the bottom pane, the outline up to the middle one. - p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - p.update(.{ .key = .{ .cp = 'k', .text = "k" } }); - try std.testing.expectEqual(@as(?usize, mid), p.window_pick); - // c folds the outlined pane to its tag and back, the mode staying. - p.update(.{ .key = .{ .cp = 'c', .text = "c" } }); - try std.testing.expect(p.panes[mid].?.collapsed); - try std.testing.expectEqual(@as(?usize, mid), p.window_pick); - p.update(.{ .key = .{ .cp = 'c', .text = "c" } }); - try std.testing.expect(!p.panes[mid].?.collapsed); - p.sync(); - try std.testing.expectEqual(h[1], p.rects[mid].h); - - // d with panes above and below asks, as SPC d does; Esc takes it back - // and the outline stays where it was. - p.update(.{ .key = .{ .cp = 'd', .text = "d" } }); - try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[mid].?.prompt); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(p.panes[mid] != null and p.panes[mid].?.prompt == .none); - try std.testing.expectEqual(@as(?usize, mid), p.window_pick); - // j: the pane below takes the rows, and the outline goes with them. - p.update(.{ .key = .{ .cp = 'd', .text = "d" } }); - p.update(.{ .key = .{ .cp = 'j', .text = "j" } }); - p.sync(); - try std.testing.expect(p.panes[mid] == null); - try std.testing.expectEqual(h[0], p.rects[top].h); - try std.testing.expectEqual(h[1] + h[2], p.rects[low].h); - try std.testing.expectEqual(@as(?usize, low), p.window_pick); - // With one neighbour there is nothing to ask: d closes it at once, - // the outline on the pane that grew. - p.update(.{ .key = .{ .cp = 'd', .text = "d" } }); - p.sync(); - try std.testing.expect(p.panes[low] == null); - try std.testing.expectEqual(@as(?usize, top), p.window_pick); - // Enter leaves the mode on it. - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expect(p.window_pick == null); - try std.testing.expectEqual(top, p.active); -} - test "raw tty Ctrl-B switches to editor mode without sending child input" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" }); diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig index dde3ffb6..f29a4b56 100644 --- a/test/behaviour/modes.zig +++ b/test/behaviour/modes.zig @@ -102,3 +102,160 @@ test "modes: Esc back into a file leaves its view where it was, and a look centr const drawn_at = line - try topLine(&s, "/test.txt"); try std.testing.expect(drawn_at + 1 >= rows / 2 and drawn_at <= rows / 2 + 1); } + +/// Three panes named /a.txt (left column), /b.txt over /c.txt (right), +/// the keyboard on /a.txt; their serials. +fn threePanes(s: *Session) ![3]u32 { + const a = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{a}), "/a.txt\n"); + try s.write("/ctl", "Newcol\n"); + try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n"); + const b = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{b}), "New\n"); + const c = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{b}), "/b.txt\n"); + try s.write(s.at("/pane/{d}/name", .{c}), "/c.txt\n"); + try s.write("/focus", s.at("{d}\n", .{a})); + return .{ a, b, c }; +} + +/// The panes whose tag (`name Save`) is drawn in `lit`, the outline's colour. +fn outlined(s: *Session, lit: []const u8, names: []const []const u8) ![]const u8 { + var found: []const u8 = ""; + for (names) |name| { + const x, const y = try s.where(s.at("{s} Save", .{name})); + if (std.mem.eql(u8, lit, try s.bg(x, y))) found = s.at("{s}{s}", .{ found, name }); + } + return found; +} + +test "modes: Ctrl-w outlines a pane, h j k l move the outline, and Enter, Esc, : or a pane's letter gives it the keyboard" { + var s = try Session.initFile(std.testing.allocator, "left\n"); + defer s.deinit(); + const a, const b, const c = try threePanes(&s); + const names = &[_][]const u8{ "/a.txt", "/b.txt", "/c.txt" }; + try s.keys("\x17"); + const x, const y = try s.where("/a.txt Save"); + const lit = try s.bg(x, y); + try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names)); + // Each pane's box shows its letter: the left column's is a. + try std.testing.expectEqualStrings("a /a.txt", (try s.screen())[y * 81 ..][0.."a /a.txt".len]); + try s.keys("l"); + try std.testing.expectEqualStrings("/b.txt", try outlined(&s, lit, names)); + try s.keys("j"); + try std.testing.expectEqualStrings("/c.txt", try outlined(&s, lit, names)); + try expectEqual(a, try s.focused()); + try s.keys("\n"); + try expectEqual(c, try s.focused()); + try std.testing.expectEqualStrings("", try outlined(&s, lit, names)); + // SPC w enters it too, and Esc leaves it on the outlined pane. + try s.keys(" wh\x1b"); + try expectEqual(a, try s.focused()); + // Other keys change nothing. + try s.keys("\x17!"); + try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names)); + try s.keys("\x1b"); + // `:` gives the outlined pane's tag the keyboard. + try s.keys("\x17l:"); + try expectEqual(b, try s.focused()); + try expectEqual((try s.where("/b.txt Save"))[1], (try s.cursor()).?[1]); + try s.keys("\x1b"); + // A letter goes straight there. + try s.keys("\x17a"); + try expectEqual(a, try s.focused()); + try std.testing.expectEqualStrings("", try outlined(&s, lit, names)); +} + +fn listed(s: *Session, n: u32) !bool { + var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n'); + while (rows.next()) |row| if (std.mem.startsWith(u8, row, s.at("{d} ", .{n}))) return true; + return false; +} + +test "modes: in window mode d deletes the outlined pane, asking k or j between two, c collapses it, and the mode stays on" { + var s = try Session.initFile(std.testing.allocator, "top\n"); + defer s.deinit(); + // The neighbours below are what is under test: each New right under its asker. + try s.write("/ctl", "Placement pardes\n"); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + const mid = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{mid}), "New\n"); + const low = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{mid}), "/mid\n"); + try s.write(s.at("/pane/{d}/name", .{low}), "/low\n"); + const names = &[_][]const u8{ "/test.txt", "/mid", "/low" }; + const row_top = (try s.where("/test.txt Save"))[1]; + const row_mid = (try s.where("/mid Save"))[1]; + const row_low = (try s.where("/low Save"))[1]; + // From the bottom pane, the outline up to the middle one. + const mx, const my = try s.where("/mid Save"); + const plain = try s.bg(mx, my); + try s.keys("\x17k"); + const lit = try s.bg(mx, my); + try std.testing.expect(!std.mem.eql(u8, plain, lit)); + try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names)); + // c folds it to its tag and back, the mode staying. + try s.keys("c"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") != null); + try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names)); + try s.keys("c"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") == null); + try expectEqual(row_low, (try s.where("/low Save"))[1]); + // d between two panes asks, as SPC d does; Esc takes it back, the + // outline where it was. + try s.keys("d\x1b"); + try std.testing.expect(try listed(&s, mid)); + try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names)); + // j: the pane below takes the rows, and the outline goes with them. + try s.keys("dj"); + try std.testing.expect(!try listed(&s, mid)); + try expectEqual(row_top, (try s.where("/test.txt Save"))[1]); + try expectEqual(row_mid, (try s.where("/low Save"))[1]); + try std.testing.expectEqualStrings("/low", try outlined(&s, lit, &.{ "/test.txt", "/low" })); + // With one neighbour nothing is asked: d closes it, the outline on the + // pane that grew. + try s.keys("d"); + try std.testing.expect(!try listed(&s, low)); + try std.testing.expectEqualStrings("/test.txt", try outlined(&s, lit, &.{"/test.txt"})); + // Enter leaves the mode on it. + try s.keys("\n"); + try expectEqual(top, try s.focused()); + try std.testing.expectEqualStrings("", try outlined(&s, lit, &.{"/test.txt"})); +} + +test "modes: window keys walk from a pane up through its column's tag and the workspace's, across, and back down" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const a = try s.focused(); + try s.write("/ctl", "Newcol\n"); + try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n"); + try s.write("/focus", s.at("{d}\n", .{a})); + const right = 40; // two columns on 80 cells: the right one's first + // Up from the top pane: its column's tag, in normal mode (w moves). + try s.keys("\x17k"); + try s.expect("/focus", ""); + const x0, const y0 = (try s.cursor()).?; + try expectEqual(@as(usize, 1), y0); + try std.testing.expect(x0 < right); + try s.keys("w"); + const remembered = (try s.cursor()).?; + try std.testing.expect(remembered[0] > x0); + // Across to the right column's tag, and back to where the caret was. + try s.keys("\x17l"); + try std.testing.expect((try s.cursor()).?[0] >= right); + try s.keys("\x17h"); + try expectEqual(remembered, (try s.cursor()).?); + // Up again: the workspace tag; down, the column's, then the pane. + try s.keys("\x17k"); + try expectEqual(@as(usize, 0), (try s.cursor()).?[1]); + try s.keys("\x17j"); + try expectEqual(@as(usize, 1), (try s.cursor()).?[1]); + try s.keys("\x17j"); + try expectEqual(a, try s.focused()); + // `:` in a column's tag is the way back to the body. + try s.keys("\x17k:"); + try expectEqual(a, try s.focused()); + try expectEqual((try s.where("body"))[1], (try s.cursor()).?[1]); + try s.expect(s.at("/pane/{d}/body", .{a}), "body\n"); +} -- cgit v1.3 From 273cbd0df9d8edf4725fdff5f9da560b35b63058 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:52:01 -0300 Subject: test: src/pardes.zig's jump tests through the 9P tree alone, in test/behaviour/modes.zig (guide.typ's Modes, Ctrl-o and Ctrl-i): a jumplist made as a user makes one (each place a pane's dot moved there and the keyboard given it; A and B files, C a Zerox twin, O the +Help output; the starting shell deleted, its places with it), walked by Ctrl-o, Ctrl-i (Kctl i), SPC j o and SPC j i, and the Back and Forward builtins, read from /focus and the dot's line, each walk's end said on screen: JumpScope file keeping to the focused file and leaving it only once it runs out, Ctrl-i its mirror and retracing a run of Ctrl-o, JumpScope all in jump order (bare JumpScope file again), a pane with no file stepping globally, a file in two panes keeping to its own pane first, every way taking the same steps, a step dropping the selections, select mode and the extra cursors and landing on the cursor the place was left with (nothing further on leaving the selection), and hopping two panes by Esc, window mode and clicks making no places; the old test of a missing entry's skip kept trimmed (its entries injected), and the side-button and jumpBy one kept, /mousein having no side buttons; each checked to fail against a break (JumpScope file off, JumpScope all ignored, a pane's own places not first, an output pane keeping to itself, Forward always global, Forward stepping back, the hop merge off, the source's selection not cleared) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 155 ++------------------------------- test/behaviour/modes.zig | 219 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+), 146 deletions(-) (limited to 'src/pardes.zig') diff --git a/src/pardes.zig b/src/pardes.zig index ba09b3b6..2b4fef70 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -8517,56 +8517,6 @@ test "a Rename the language server finds nothing for says so, and changes nothin try std.testing.expectEqualStrings("const value=1;\n", pane.file.?.content); } -test "hopping between two panes does not grow the jump stack" { - if (platform == .web) return; - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); - p.settings.placement = .pardes; // two panes of room, not acme's fit to the doc's two lines - defer p.deinit(); - p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); - p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc - const doc = 0; - const shell = p.active; - try std.testing.expect(shell != doc); - const depth = p.njumps; - - // Esc is Last — the everyday two-pane hop. Each press used to - // append, so sixty-four of them left the stack remembering nothing else. - for (0..8) |_| { - const was = p.active; - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(p.active != was); - } - try std.testing.expectEqual(depth, p.njumps); - - // ...and so are the other two ways to switch panes. - for (0..8) |_| { - const want = if (p.active == doc) shell else doc; - const dir: u21 = if (p.active == doc) 'j' else 'k'; - p.update(.{ .key = .{ .cp = ' ' } }); - p.update(.{ .key = .{ .cp = 'w' } }); - p.update(.{ .key = .{ .cp = dir } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqual(want, p.active); - } - try std.testing.expectEqual(depth, p.njumps); - - for (0..8) |_| { - const other = if (p.active == doc) shell else doc; - const r = p.rects[other]; - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = r.x + config.GUTTER + 1, .row = r.y + BOX_H + 1 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = r.x + config.GUTTER + 1, .row = r.y + BOX_H + 1 } }); - try std.testing.expectEqual(other, p.active); - } - try std.testing.expectEqual(depth, p.njumps); - - const before = p.active; - exec.runBuiltin(p, .Back, p.active, "", null); - p.sync(); - try std.testing.expect(p.active != before); - try std.testing.expectEqual(depth, p.njumps); -} - /// Every `.write` a keystroke produced, joined — what the pane's program would /// actually have read off its pty. fn drainWrites(p: *Pardes, buf: []u8) []const u8 { @@ -8930,35 +8880,15 @@ test "board heap: every allocation failure during boot is a clean OutOfMemory" { ); } -test "jump history clears selections and lands at the recorded cursor" { +test "jump history skips an entry whose pane slot or serial is gone, leaving the selection" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); defer p.deinit(); const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n"); p.njumps = 2; p.jcur = 1; - p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 3, .col = 8 }; p.jumps[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 }; - for ([_]u21{ 'o', 'i' }, 0..) |key, index| { - pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); - pane.sel[0] = .{ .state = .done, .c0 = 2, .c1 = 5, .r0 = 1, .r1 = 1 }; - try edit.capturePointerSelection(p, pane, 0); - pane.body.select = true; - p.update(.{ .key = .{ .cp = key, .ctrl = true } }); - try std.testing.expectEqual(index, p.jcur); - try std.testing.expectEqual(@as(usize, 2), p.njumps); - try std.testing.expectEqual(@as(u32, 3), p.jumps[0].line); - try std.testing.expect(!pane.body.vsel.active and !pane.body.msel.active and !pane.body.select); - try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); - try std.testing.expectEqual(.none, pane.sel[0].state); - try std.testing.expect(pane.pointer_selections[0] == null); - try std.testing.expectEqual(@as(i32, if (index == 0) 2 else 0), pane.body.cur_row); - try std.testing.expectEqual(@as(i32, if (index == 0) 7 else 0), pane.body.cur_col); - } pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); const selected = pane.body.primaryRange(pane.file.?.content, 0); - p.jumpBy(1); // No forward entry: selection stays untouched. - try std.testing.expectEqualDeep(selected, pane.body.primaryRange(pane.file.?.content, 0)); - try std.testing.expect(std.mem.indexOf(u8, p.panes[p.active].?.msg[0..p.panes[p.active].?.msg_len], "nothing further on") != null); for ([_]Loc{ .{ .pane = 15, .serial = pane.serial, .line = 1, .col = 1 }, .{ .pane = 0, .serial = pane.serial + 1, .line = 1, .col = 1 }, @@ -8970,7 +8900,7 @@ test "jump history clears selections and lands at the recorded cursor" { } } -/// A session for the JumpScope tests: four panes of 100 lines in one +/// A session for the side-button jump test: four panes of 100 lines in one /// column, A (pane 0) and B each on a file of its own, C on A's file, and O /// an output buffer, no file behind it. `order` is the jumplist, a letter a /// place, each letter's n-th place its line 10 + 40n: "ABABA" is A10 B10 A50 @@ -8980,7 +8910,7 @@ const JumpsTest = struct { ids: [4]usize = .{ 0, 0, 0, 0 }, const letters = "ABCO"; - const Way = enum { call, key, builtin, mouse }; + const Way = enum { call, mouse }; fn init(order: []const u8) !JumpsTest { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 80 }); @@ -9021,14 +8951,12 @@ const JumpsTest = struct { return t; } - /// One step `delta` through `way`: the function, Ctrl-o or Ctrl-i, the - /// mouse's side button pressed and let go, or the builtin's word. + /// One step `delta` through `way`: the function, or the mouse's side + /// button pressed and let go. fn step(t: JumpsTest, way: Way, delta: i32) void { const back = delta < 0; switch (way) { .call => t.p.jumpBy(delta), - .key => t.p.update(.{ .key = .{ .cp = if (back) 'o' else 'i', .ctrl = true } }), - .builtin => _ = t.p.executeBuiltinLine(t.p.active, if (back) "Back" else "Forward"), .mouse => for ([_]Mouse.Kind{ .press, .release }) |kind| t.p.update(.{ .mouse = .{ .button = if (back) .back else .forward, .kind = kind, .col = 0, .row = 0 } }), } @@ -9054,75 +8982,10 @@ const JumpsTest = struct { } }; -test "JumpScope file: Back keeps to the focused file, A50 then A10, and leaves it only once it runs out that way" { - const t = try JumpsTest.init("BABABA"); - defer t.p.deinit(); - try std.testing.expectEqual(config.Runtime.JumpScope.file, t.p.settings.jump_scope); - var buf: [128]u8 = undefined; - // B90, B50 passed over, kept in their places: A has nothing older than - // A10, so the step after it is the nearest place of any file, B10. - try std.testing.expectEqualStrings("A50 A10 B10", try t.walk(.call, -1, &buf)); - try std.testing.expectEqual(@as(usize, 6), t.p.njumps); - // Forward is the mirror, from B10 in B: B's own places first, then A90, - // the newest, where the Backs started. - try std.testing.expectEqualStrings("B50 B90 A90", try t.walk(.call, 1, &buf)); - try std.testing.expectEqual(@as(usize, 5), t.p.jcur); -} - -test "JumpScope file: Forward retraces a run of Backs inside one file step for step, back to where it began" { - const t = try JumpsTest.init("ABABA"); - defer t.p.deinit(); - var buf: [128]u8 = undefined; - // A1 B1 A2 B2 A3 from A3: nothing older than A1 at all, so Back ends there. - try std.testing.expectEqualStrings("A50 A10", try t.walk(.call, -1, &buf)); - try std.testing.expectEqual(@as(usize, 0), t.p.jcur); - try std.testing.expectEqualStrings("A50 A90", try t.walk(.call, 1, &buf)); - try std.testing.expectEqual(@as(usize, 4), t.p.jcur); - // One Back, one Forward: the same entry, whichever were passed over. - t.step(.call, -1); - try std.testing.expectEqual(@as(usize, 2), t.p.jcur); - t.step(.call, 1); - try std.testing.expectEqual(@as(usize, 4), t.p.jcur); - try std.testing.expectEqual(@as(usize, 5), t.p.njumps); -} - -test "JumpScope all: Back and Forward take every place in the order it was jumped to" { - const t = try JumpsTest.init("ABABA"); - defer t.p.deinit(); - try std.testing.expect(t.p.executeBuiltinLine(t.p.active, "JumpScope all")); - try std.testing.expectEqual(config.Runtime.JumpScope.all, t.p.settings.jump_scope); - var buf: [128]u8 = undefined; - try std.testing.expectEqualStrings("B50 A50 B10 A10", try t.walk(.call, -1, &buf)); - try std.testing.expectEqualStrings("B10 A50 B50 A90", try t.walk(.call, 1, &buf)); - // Bare, the word steps back to file. - try std.testing.expect(t.p.executeBuiltinLine(t.p.active, "JumpScope")); - try std.testing.expectEqual(config.Runtime.JumpScope.file, t.p.settings.jump_scope); -} - -test "JumpScope file: from a pane with no file, Back and Forward are global" { - const t = try JumpsTest.init("OAOBO"); - defer t.p.deinit(); - var buf: [128]u8 = undefined; - // O90 keeps to nothing: B10, the next older of all. From B, nothing of - // B is older, so O50; from O, A10; from A, O10. - try std.testing.expectEqualStrings("B10 O50 A10 O10", try t.walk(.call, -1, &buf)); - try std.testing.expectEqualStrings("A10 O50 B10 O90", try t.walk(.call, 1, &buf)); -} - -test "JumpScope file: a file in two panes keeps to the pane first, then the file in the other pane" { - // C is A's file in a second pane: C10 B10 A10 C50 A50. - const t = try JumpsTest.init("CBACA"); - defer t.p.deinit(); - var buf: [128]u8 = undefined; - // From A50: A10 in this pane, over the nearer C50; then none of A's - // own is older, so the file's in C, C10, over B10. - try std.testing.expectEqualStrings("A10 C10", try t.walk(.call, -1, &buf)); - // From C10 in C: C50, its own, then the file's newest, A50. - try std.testing.expectEqualStrings("C50 A50", try t.walk(.call, 1, &buf)); -} - -test "Back and Forward take the same steps from Ctrl-o and Ctrl-i, the mouse's side buttons, the builtins and jumpBy" { - for ([_]JumpsTest.Way{ .call, .key, .builtin, .mouse }) |way| { +// The keys and builtins are test/behaviour/modes.zig's; a mouse's side +// buttons have no /mousein bits. +test "Back and Forward take the same steps from the mouse's side buttons and jumpBy" { + for ([_]JumpsTest.Way{ .call, .mouse }) |way| { const t = try JumpsTest.init("BABABA"); defer t.p.deinit(); var buf: [128]u8 = undefined; diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig index f29a4b56..b1641c6f 100644 --- a/test/behaviour/modes.zig +++ b/test/behaviour/modes.zig @@ -259,3 +259,222 @@ test "modes: window keys walk from a pane up through its column's tag and the wo try expectEqual((try s.where("body"))[1], (try s.cursor()).?[1]); try s.expect(s.at("/pane/{d}/body", .{a}), "body\n"); } + +/// The jump tests' session: a pane a letter of `order`, A and B each a file +/// of 100 lines, C a Zerox of A, O the +Help output (no file behind it), +/// and the jumplist `order`, a letter a place, each letter's n-th place its +/// line 1 + 40n ("ABABA" is A1 B1 A41 B41 A81): each made by moving its +/// pane's dot there and giving it the keyboard, as a jump does (a new +/// pane's first, where it opens). The shell the session started with is +/// closed after, its places with it. +const Jumps = struct { + s: Session, + ids: [4]u32 = @splat(0), + + const letters = "ABCO"; + + fn init(order: []const u8) !Jumps { + var t: Jumps = .{ .s = try Session.initTerm(std.testing.allocator) }; + errdefer t.s.deinit(); + const s = &t.s; + const shell = try s.focused(); + var seen: [4]u32 = @splat(0); + for (order) |letter| { + const which = std.mem.indexOfScalar(u8, letters, letter).?; + if (t.ids[which] == 0) t.ids[which] = switch (letter) { + 'O' => o: { + try s.write(s.at("/pane/{d}/exec", .{shell}), "Help\n"); + break :o try s.focused(); + }, + else => made: { + // C is A's twin, and A C's when C came first. + const twin = t.ids[if (letter == 'A') 2 else if (letter == 'C') 0 else 1]; + if (letter != 'B' and twin != 0) { + try s.write(s.at("/pane/{d}/exec", .{twin}), "Zerox\n"); + break :made try s.focused(); + } + const n = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{n}), if (letter == 'B') "/b.txt\n" else "/a.txt\n"); + try s.write(s.at("/pane/{d}/body", .{n}), std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*)))); + break :made n; + }, + }; + const n = t.ids[which]; + try s.write(s.at("/pane/{d}/addr", .{n}), s.at("{d}\n", .{1 + 40 * seen[which]})); + try s.write(s.at("/pane/{d}/ctl", .{n}), "dot=addr\n"); + try s.write("/focus", s.at("{d}\n", .{n})); + seen[which] += 1; + } + try s.write(s.at("/pane/{d}/ctl", .{shell}), "delete\n"); + return t; + } + + /// Where the keyboard is: its pane's letter and the dot's line, `A50`. + fn here(t: *Jumps) ![]const u8 { + const s = &t.s; + const n = try s.focused(); + const at, _ = try s.range(s.at("/pane/{d}/dot", .{n})); + const body = try s.read(s.at("/pane/{d}/body", .{n})); + const which = std.mem.indexOfScalar(u32, &t.ids, n).?; + return s.at("{c}{d}", .{ letters[which], std.mem.count(u8, body[0..at], "\n") + 1 }); + } + + const Way = enum { key, leader, builtin }; + + /// Steps back or on until the list ends that way, as it says; the + /// places landed on, "A50 A10 B10". + fn walk(t: *Jumps, way: Way, back: bool) ![]const u8 { + const s = &t.s; + var out: []const u8 = ""; + for (0..64) |_| { + const before = try t.here(); + switch (way) { + .key => try s.keys(if (back) "\x0f" else "\u{F017}i"), + .leader => try s.keys(if (back) " jo" else " ji"), + .builtin => try s.write("/exec", if (back) "Back\n" else "Forward\n"), + } + const now = try t.here(); + if (std.mem.eql(u8, before, now)) break; + out = if (out.len == 0) now else s.at("{s} {s}", .{ out, now }); + } else return error.NoEnd; + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), if (back) "nothing further back" else "nothing further on") != null); + return out; + } +}; + +test "modes: Ctrl-o keeps to the focused file (JumpScope file), A41 then A1, and leaves it only once it runs out that way; Ctrl-i mirrors it" { + var t = try Jumps.init("BABABA"); + defer t.s.deinit(); + try std.testing.expect(std.mem.indexOf(u8, try t.s.read("/ctl"), "\nJumpScope file\n") != null); + // B81, B41 passed over, kept in their places: A has nothing older than + // A1, so the step after it is the nearest place of any file, B1. + try std.testing.expectEqualStrings("A41 A1 B1", try t.walk(.key, true)); + // Forward is the mirror, from B1 in B: B's own places first, then A81, + // the newest, where the Backs started. + try std.testing.expectEqualStrings("B41 B81 A81", try t.walk(.key, false)); +} + +test "modes: Ctrl-i retraces a run of Ctrl-o inside one file step for step, back to where it began" { + var t = try Jumps.init("ABABA"); + defer t.s.deinit(); + // A1 B1 A41 B41 A81 from A81: nothing older than A1 at all. + try std.testing.expectEqualStrings("A41 A1", try t.walk(.key, true)); + try std.testing.expectEqualStrings("A41 A81", try t.walk(.key, false)); + // One back, one on: the same place, whichever were passed over. + try t.s.keys("\x0f"); + try std.testing.expectEqualStrings("A41", try t.here()); + try t.s.keys("\u{F017}i"); + try std.testing.expectEqualStrings("A81", try t.here()); + // And the steps made no places of their own. + try std.testing.expectEqualStrings("A41 A1", try t.walk(.key, true)); +} + +test "modes: with JumpScope all, Ctrl-o and Ctrl-i take every place in the order it was jumped to, and bare JumpScope is file again" { + var t = try Jumps.init("ABABA"); + defer t.s.deinit(); + try t.s.write("/ctl", "JumpScope all\n"); + try std.testing.expectEqualStrings("B41 A41 B1 A1", try t.walk(.key, true)); + try std.testing.expectEqualStrings("B1 A41 B41 A81", try t.walk(.key, false)); + try t.s.write("/ctl", "JumpScope\n"); + try std.testing.expect(std.mem.indexOf(u8, try t.s.read("/ctl"), "\nJumpScope file\n") != null); +} + +test "modes: from a pane with no file, Ctrl-o and Ctrl-i step through every place" { + var t = try Jumps.init("OAOBO"); + defer t.s.deinit(); + // O81 keeps to nothing: B1, the next older of all. From B, nothing of + // B is older, so O41; from O, A1; from A, O1. + try std.testing.expectEqualStrings("B1 O41 A1 O1", try t.walk(.key, true)); + try std.testing.expectEqualStrings("A1 O41 B1 O81", try t.walk(.key, false)); +} + +test "modes: Ctrl-o in a file shown in two panes keeps to its own pane first, then the file in the other" { + // C is A's file in a second pane: C1 B1 A1 C41 A41. + var t = try Jumps.init("CBACA"); + defer t.s.deinit(); + // From A41: A1 in this pane, over the nearer C41; then none of A's own + // is older, so the file's in C, C1, over B1. + try std.testing.expectEqualStrings("A1 C1", try t.walk(.key, true)); + // From C1 in C: C41, its own, then the file's newest, A41. + try std.testing.expectEqualStrings("C41 A41", try t.walk(.key, false)); +} + +test "modes: Back and Forward take the same steps from Ctrl-o and Ctrl-i, SPC j o and SPC j i, and the builtins" { + for ([_]Jumps.Way{ .key, .leader, .builtin }) |way| { + var t = try Jumps.init("BABABA"); + defer t.s.deinit(); + try std.testing.expectEqualStrings("A41 A1 B1", try t.walk(way, true)); + try std.testing.expectEqualStrings("B41 B81 A81", try t.walk(way, false)); + } +} + +test "modes: Ctrl-o and Ctrl-i drop the selections, select mode and the extra cursors, and land where the place was left" { + const rows = std.mem.asBytes(&@as([97][4]u8, @splat("row\n".*))); + var s = try Session.initFile(std.testing.allocator, "alpha beta\ngamma delta\nepsilon zeta\n" ++ rows); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + // A place on line 3, at its eighth column (byte 30), then line 60. + try s.write(s.at("/pane/{d}/addr", .{n}), "#30\n"); + try s.write(s.at("/pane/{d}/ctl", .{n}), "dot=addr\n"); + try s.keys("60G"); + // Each step lands on the cursor the place was left with. + var back_to: u32 = 30; + for ([_][]const u8{ "\x0f", "\u{F017}i" }) |key| { + // A line selected, a second cursor under it, select mode on. + try s.keys("xCv"); + try std.testing.expectEqualStrings("select", try mode(&s, n)); + const leaving = (try s.range(dot))[1] - 1; // the cursor: its last character + try s.keys(key); + try std.testing.expectEqualStrings("normal", try mode(&s, n)); + try std.testing.expectEqual(back_to, (try s.range(dot))[0]); + back_to = leaving; + try s.expect(s.at("/pane/{d}/sel", .{n}), ""); + // One cursor: a Z typed goes in once. + try s.keys("iZ\x1b"); + try expectEqual(@as(usize, 1), std.mem.count(u8, try s.read(s.at("/pane/{d}/body", .{n})), "Z")); + try s.keys("u"); + } + // No place further on: said, and the selection left as it was. + try s.keys("x"); + const sel = try s.read(s.at("/pane/{d}/sel", .{n})); + try s.keys("\u{F017}i"); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "nothing further on") != null); + try s.expect(s.at("/pane/{d}/sel", .{n}), sel); +} + +test "modes: hopping between two panes by Esc, window mode or a click makes no places, so one Ctrl-o goes back across and the next has nowhere to go" { + var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*)))); + defer s.deinit(); + // Two panes of room, not acme's fit to the doc. + try s.write("/ctl", "Placement pardes\n"); + const doc = try s.focused(); + try s.keys("\u{F015}n"); // a shell under the doc + const shell = try s.focused(); + if (std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{shell})), "mode:tty") != null) try s.keys("\x02"); + for (0..8) |_| { + const was = try s.focused(); + try s.keys("\x1b"); + try expectEqual(if (was == doc) shell else doc, try s.focused()); + } + for (0..8) |_| { + const want = if (try s.focused() == doc) shell else doc; + try s.keys(if (want == shell) " wj\n" else " wk\n"); + try expectEqual(want, try s.focused()); + } + const doc_row = (try s.where("row"))[1]; + const shell_row = (try s.where("Tty Save Mode"))[1] + 1; + for (0..8) |_| { + const other = if (try s.focused() == doc) shell else doc; + const row = if (other == doc) doc_row else shell_row; + try s.write("/mousein", s.at("m 10 {d} 1\nm 10 {d} 0\n", .{ row, row })); + try expectEqual(other, try s.focused()); + } + const before = try s.focused(); + try s.keys("\x0f"); + try std.testing.expect(before != try s.focused()); + const after = try s.focused(); + try s.keys("\x0f"); + try expectEqual(after, try s.focused()); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "nothing further back") != null); +} -- cgit v1.3 From fa3031d6ded24d4ba7ab5bab21e17387e48306aa Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 11:05:00 -0300 Subject: test: src/pardes.zig's two acme-placement tests through the 9P tree alone, in test/behaviour/placement.zig: a look from a pane's text going under its three lines when most of it is blank, and, both panes full, halving the biggest (the new pane after it in /layout, its tag at the old pane's middle row, its bottom the old pane's); a look from the middle of a column (its top and bottom panes dragged by their boxes to two and three rows, under a placement's minimum) splitting only the pane it came from, the short ones keeping their rows, through a Newcol too; geometry read from where /screen draws each tag, on a 100x60 screen set by size; each checked to fail against a break (no placement under the text, the biggest split at a third, every pane in the column reweighted at a split) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 73 ------------------------------------ test/behaviour/placement.zig | 88 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 73 deletions(-) (limited to 'src/pardes.zig') diff --git a/src/pardes.zig b/src/pardes.zig index 2b4fef70..f78c2c0d 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1195,79 +1195,6 @@ test "first document keeps its originating shell and only opens a column when it } } -test "acme placement: under a pane's text when it has many blank rows, else halving the biggest" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 }); - defer p.deinit(); - const top = p.active; - _ = try p.setTestFile("one\ntwo\nthree\n"); - p.sync(); - p.setActiveColumn(0); - // Most of the pane is blank: a document looked from it starts under its - // three lines (makenewwindow, util.c:482-486). - const second = p.freeSlot().?; - _ = try p.openTutorView(second); - exec.placeNew(p, top, top, second, .doc); - p.sync(); - const text_end = p.bodyTop(p.panes[top].?, p.rects[top]) + 3; - try std.testing.expectEqual(text_end, p.rects[second].y); - // Fill both with text: no blank space is big, so the biggest pane is - // halved. - const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*))); - for ([_]usize{ top, second }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full)); - p.sync(); - const big = if (p.rects[second].h >= p.rects[top].h) second else top; - const was = p.rects[big]; - const third = p.freeSlot().?; - _ = try p.openTutorView(third); - exec.placeNew(p, second, second, third, .doc); - p.sync(); - try std.testing.expectEqual(big, p.col_panes[0][layout.findPane(p, third).?.idx - 1]); - try std.testing.expectEqual(was.y + was.h / 2, p.rects[third].y); - try std.testing.expectEqual(was.y + was.h, p.rects[third].y + p.rects[third].h); -} - -test "acme placement: a pane made from the middle of a column moves only the one it splits, short ones round it kept short" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 }); - defer p.deinit(); - const top = p.active; - _ = try p.setTestFile("one\n"); - p.sync(); - p.setActiveColumn(0); - const middle = p.freeSlot().?; - _ = try p.openTutorView(middle); - exec.placeNew(p, top, top, middle, .doc); - const bottom = p.freeSlot().?; - _ = try p.openTutorView(bottom); - exec.placeNew(p, middle, middle, bottom, .doc); - p.sync(); - // A short pane above and below, dragged under a placement's minimum, - // and the middle one full of text, so it is the one halved. - const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*))); - for ([_]usize{ top, middle, bottom }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full)); - try std.testing.expectEqualSlices(usize, &.{ top, middle, bottom }, p.col_panes[0][0..3]); - const total = p.rects[top].h + p.rects[middle].h + p.rects[bottom].h; - p.panes[top].?.vweight = 2; - p.panes[bottom].?.vweight = 2; - p.panes[middle].?.vweight = @floatFromInt(total - 4); - p.sync(); - const was_top = p.rects[top]; - const was_bottom = p.rects[bottom]; - try std.testing.expect(was_top.h < layout.minRows(p, top)); - const made = p.freeSlot().?; - _ = try p.openTutorView(made); - exec.placeNew(p, middle, middle, made, .doc); - p.sync(); - try std.testing.expectEqual(layout.findPane(p, middle).?.idx + 1, layout.findPane(p, made).?.idx); - try std.testing.expectEqual(was_top, p.rects[top]); - try std.testing.expectEqual(was_bottom, p.rects[bottom]); - // A new column narrows this one, and the short panes keep their rows. - try std.testing.expect(p.executeBuiltinLine(made, "Newcol")); - p.sync(); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(was_top.h, p.rects[top].h); - try std.testing.expectEqual(was_bottom.h, p.rects[bottom].h); -} - test "an empty column shows its theme's empty_col under its tag: acme's white, else the border" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 20 }); defer p.deinit(); diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig index 079b5a5e..5b2d55c7 100644 --- a/test/behaviour/placement.zig +++ b/test/behaviour/placement.zig @@ -59,3 +59,91 @@ test "placement: Placement pardes puts a new pane right under the asking one, an try s.write("/ctl", "Placement\n"); try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement acme\n") != null); } + +/// Each pane's tag row and its rows down to the next tag, or the screen's +/// end, as /screen draws them; `names` top to bottom in one column. +fn spans(s: *Session, comptime n: usize, names: [n][]const u8) ![n][2]usize { + var out: [n][2]usize = undefined; + for (names, 0..) |name, i| out[i][0] = try tagRow(s, name); + const rows = std.mem.count(u8, try s.screen(), "\n") + 1; + for (0..n) |i| out[i][1] = (if (i + 1 < n) out[i + 1][0] else rows) - out[i][0]; + return out; +} + +test "placement: a look from a pane's text goes under its text when it has many blank rows, else halves the biggest pane" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + for ([_][]const u8{ "second.txt", "third.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\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, "one\ntwo\nthree\n"); + defer s.deinit(); + s.detach(); + try s.write("/ctl", "size 100 60\n"); + const top = try s.focused(); + // Most of the pane is blank: the look starts under its three lines + // (makenewwindow, util.c:482-486). + try s.write(s.at("/pane/{d}/look", .{top}), s.at("{s}/second.txt\n", .{at})); + const second = try s.focused(); + const shown = s.at("{s}/second.txt", .{at}); + try std.testing.expectEqual((try tagRow(&s, "/test.txt")) + 1 + 3, try tagRow(&s, shown)); + // Both full of text: no blank space is big, so the biggest is halved. + const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*))); + for ([_]u32{ top, second }) |n| try s.replace(s.at("/pane/{d}/body", .{n}), full); + const was = try spans(&s, 2, .{ "/test.txt", shown }); + const big: usize = if (was[1][1] >= was[0][1]) 1 else 0; + try s.write(s.at("/pane/{d}/look", .{second}), s.at("{s}/third.txt\n", .{at})); + const third = try s.focused(); + const ids = [_]u32{ top, second }; + try std.testing.expect(std.mem.indexOf(u8, try s.columns(), s.at("{d},{d}", .{ ids[big], third })) != null); + const made = s.at("{s}/third.txt", .{at}); + const now = if (big == 1) try spans(&s, 3, .{ "/test.txt", shown, made }) else try spans(&s, 3, .{ "/test.txt", made, shown }); + try std.testing.expectEqual(was[big][0] + was[big][1] / 2, now[big + 1][0]); + try std.testing.expectEqual(was[big][0] + was[big][1], now[big + 1][0] + now[big + 1][1]); +} + +test "placement: a look from the middle of a column splits only the pane it came from, short ones round it kept short, through a Newcol too" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + for ([_][]const u8{ "mid", "low", "made" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\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, "one\n"); + defer s.deinit(); + s.detach(); + try s.write("/ctl", "size 100 60\n"); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/look", .{top}), s.at("{s}/mid\n", .{at})); + const mid = try s.focused(); + try s.write(s.at("/pane/{d}/look", .{mid}), s.at("{s}/low\n", .{at})); + const low = try s.focused(); + const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*))); + for ([_]u32{ top, mid, low }) |n| try s.replace(s.at("/pane/{d}/body", .{n}), full); + // Short names, so a narrowed column draws each tag on one row. + try s.write(s.at("/pane/{d}/name", .{mid}), "/mid\n"); + try s.write(s.at("/pane/{d}/name", .{low}), "/low\n"); + const names = [_][]const u8{ "/test.txt", "/mid", "/low", "/made" }; + // The top and bottom panes dragged by their boxes to two and three + // rows, under a placement's minimum; the middle one full of text, so + // the one halved. + const rows = std.mem.count(u8, try s.screen(), "\n") + 1; + const r = try spans(&s, 3, names[0..3].*); + try s.write("/mousein", s.at("m 0 {d} 1\nm 0 {d} 1\nm 0 {d} 0\n", .{ r[1][0], r[0][0] + 2, r[0][0] + 2 })); + try s.write("/mousein", s.at("m 0 {d} 1\nm 0 {d} 1\nm 0 {d} 0\n", .{ r[2][0], rows - 3, rows - 3 })); + const was = try spans(&s, 3, names[0..3].*); + try std.testing.expectEqual(@as(usize, 2), was[0][1]); + try std.testing.expectEqual(@as(usize, 3), was[2][1]); + try s.write(s.at("/pane/{d}/look", .{mid}), s.at("{s}/made\n", .{at})); + const made = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{made}), "/made\n"); + try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d},{d}", .{ try s.column(0), top, mid, made, low }), try s.columns()); + const now = try spans(&s, 4, .{ names[0], names[1], names[3], names[2] }); + try std.testing.expectEqual(was[0], now[0]); + try std.testing.expectEqual(was[2], now[3]); + // A new column narrows this one, and the short panes keep their rows. + try s.write(s.at("/pane/{d}/exec", .{made}), "Newcol\n"); + try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, try s.columns(), ":")); + const narrowed = try spans(&s, 4, .{ names[0], names[1], names[3], names[2] }); + try std.testing.expectEqual(was[0][1], narrowed[0][1]); + try std.testing.expectEqual(was[2][1], narrowed[3][1]); +} -- cgit v1.3