From 00629bd791b8e41204366a795b6f36a289a45a68 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:45:10 -0300 Subject: test: two checks the panes migration dropped though the 9P tree shows them, from a review: a look leaves select mode and the extra cursors behind (mode:normal on the pane's ctl after Cv and a look, a Z typed once), as the old test's cleared() asked of select and nsel; a click past a line's end and on a wide glyph's second cell draws the caret where it lands, and insert mode draws it there too (Session.cursor from /screen), as the old tests compared the render's cursor; each checked to fail against a break (clearNavigationSelection keeping select, keeping nsel; the insert-mode body caret drawn a cell right) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/look_and_exec.zig | 11 +++++++++++ test/behaviour/mouse.zig | 16 +++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'test/behaviour') diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index ec26b74f..3c76988e 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -43,9 +43,20 @@ test "look-and-exec: a look replaces the selection it was made from, for an addr const n = try s.focused(); const dot = s.at("/pane/{d}/dot", .{n}); const look = s.at("/pane/{d}/look", .{n}); + const ctl = s.at("/pane/{d}/ctl", .{n}); + const body = s.at("/pane/{d}/body", .{n}); try s.write(dot, "0 5"); + // A second cursor on the line below, and select mode. + try s.keys("Cv"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:select ")); try s.write(look, "/test.txt:3:2\n"); try expectEqual(.{ @as(u32, 13), @as(u32, 13) }, try s.range(dot)); + // Both are gone with it: normal mode, and what is typed goes in once. + try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:normal ")); + try s.keys("iZ\x1b"); + try s.expect(body, "alpha\nbravo\ncZharlie\nneedle\n"); + try s.write(ctl, "Undo\n"); + try s.expect(body, "alpha\nbravo\ncharlie\nneedle\n"); try s.write(dot, "0 5"); try s.write(look, "/test.txt:2:2-4\n"); try s.expect(s.at("/pane/{d}/sel", .{n}), "rav"); diff --git a/test/behaviour/mouse.zig b/test/behaviour/mouse.zig index 27185409..13c9b631 100644 --- a/test/behaviour/mouse.zig +++ b/test/behaviour/mouse.zig @@ -54,11 +54,11 @@ test "mouse: everything a B1 chord does while B1 is down is one undo step" { test "mouse: a click past a line's or the file's end puts the caret where insertion types" { for ([_]bool{ false, true }) |already_insert| { for ([_]bool{ false, true }) |bottom_tag| { - for ([_]struct { text: []const u8, click_row: usize, dot: u32, result: []const u8 }{ - .{ .text = "abc\nxy", .click_row = 0, .dot = 3, .result = "abcZ\nxy" }, - .{ .text = "abc\nxy", .click_row = 5, .dot = 6, .result = "abc\nxyZ" }, - .{ .text = "abc\n", .click_row = 5, .dot = 4, .result = "abc\nZ" }, - .{ .text = "", .click_row = 5, .dot = 0, .result = "Z" }, + for ([_]struct { text: []const u8, click_row: usize, dot: u32, col: usize, row: usize, result: []const u8 }{ + .{ .text = "abc\nxy", .click_row = 0, .dot = 3, .col = 3, .row = 0, .result = "abcZ\nxy" }, + .{ .text = "abc\nxy", .click_row = 5, .dot = 6, .col = 2, .row = 1, .result = "abc\nxyZ" }, + .{ .text = "abc\n", .click_row = 5, .dot = 4, .col = 0, .row = 1, .result = "abc\nZ" }, + .{ .text = "", .click_row = 5, .dot = 0, .col = 0, .row = 0, .result = "Z" }, }) |case| { var s = try Session.initFile(std.testing.allocator, case.text); defer s.deinit(); @@ -69,8 +69,11 @@ test "mouse: a click past a line's or the file's end puts the caret where insert const x, const y = try s.where("1 "); try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + 2 + 15, y + case.click_row, x + 2 + 15, y + case.click_row }); try std.testing.expectEqual(.{ case.dot, case.dot }, try s.range(s.at("/pane/{d}/dot", .{n}))); + // The caret is drawn where it is, and insertion draws it there too. + try std.testing.expectEqual(.{ x + 2 + case.col, y + case.row }, try s.cursor()); if (!already_insert) try s.keys("i"); try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:insert ")); + try std.testing.expectEqual(.{ x + 2 + case.col, y + case.row }, try s.cursor()); try s.keys("Z"); try s.expect(s.at("/pane/{d}/body", .{n}), case.result); } @@ -95,7 +98,10 @@ test "mouse: a click on a tab's or a wrapped wide glyph's cells puts the caret o try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + 1, y, x + 1, y }); const at: u32 = @intCast(try std.unicode.utf8CountCodepoints(source[0..std.mem.indexOf(u8, source, "界").?])); try std.testing.expectEqual(.{ at, at }, try s.range(s.at("/pane/{d}/dot", .{n}))); + // Drawn on the glyph's first cell, in insert mode too. + try std.testing.expectEqual(.{ x, y }, try s.cursor()); if (!already_insert) try s.keys("i"); + try std.testing.expectEqual(.{ x, y }, try s.cursor()); try s.keys("Z"); const byte = std.mem.indexOf(u8, source, "界").?; try s.expect(s.at("/pane/{d}/body", .{n}), s.at("{s}Z{s}", .{ source[0..byte], source[byte..] })); -- cgit v1.3