diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-03 17:01:04 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-03 17:03:48 -0300 |
| commit | 63e62131aaedb91a8fa995b8e00ced808e053519 (patch) | |
| tree | cddcb8f17ea2139eb69893321beb0e78ac02e105 /test/behaviour | |
| parent | d1273bbd99daf9b1855d82bf315db8ede20abde5 (diff) | |
| download | pardes-63e62131aaedb91a8fa995b8e00ced808e053519.tar.gz pardes-63e62131aaedb91a8fa995b8e00ced808e053519.zip | |
test: five of test/panes.zig's mouse tests through the 9P tree alone (test/behaviour/mouse.zig, guide.typ's The mouse): a double-click's word, bracketed, quoted and line selections (read from sel) and in a tag (yanked and pasted into the body), a B1 chord's cut and paste one undo step (one Undo gives back the text before the cut), a click past a line's or the file's end and on a tab's or a wide glyph's second cell (dot, then the Z insert types), a B1 sweep over several lines a stream in a body and a tag (a B1-B2 cut of it); Session.where, the screen cell text is first drawn at; each checked to fail against a break (double-click selecting nothing, chord_hold no longer folding the chord's undo steps, the click clamp a column short of the line's end, every grapheme one cell wide to a click, a sweep's start at the lesser of its two columns)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/mouse.zig | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/test/behaviour/mouse.zig b/test/behaviour/mouse.zig new file mode 100644 index 00000000..27185409 --- /dev/null +++ b/test/behaviour/mouse.zig @@ -0,0 +1,127 @@ +//! docs/typ/guide.typ, The mouse <mouse>. +const std = @import("std"); +const Session = @import("session").Session; + +/// The mouse as `/mousein` lines say it, `m col row buttons` each. +fn mouse(s: *Session, comptime lines: []const u8, args: anytype) !void { + try s.write("/mousein", s.at(lines, args)); +} + +test "mouse: a double-click selects a word, a line, a bracketed or quoted text, as acme's" { + var s = try Session.initFile(std.testing.allocator, "call foo_bar(a, b)\nsay \"hi there\"\n"); + defer s.deinit(); + const n = try s.focused(); + const sel = s.at("/pane/{d}/sel", .{n}); + for ([_]struct { at: []const u8, into: usize, want: []const u8 }{ + .{ .at = "foo_bar", .into = 2, .want = "foo_bar" }, + .{ .at = "(a, b)", .into = 1, .want = "a, b" }, + .{ .at = "call", .into = 0, .want = "call foo_bar(a, b)\n" }, + .{ .at = "\"hi", .into = 1, .want = "hi there" }, + }) |w| { + try s.click(w.at, w.into, 1); + try s.click(w.at, w.into, 1); + try s.expect(sel, w.want); + // A third click is a plain click again: the caret, no selection. + try s.click(w.at, w.into, 1); + try s.expect(sel, ""); + } + // In the tag too: what it selected is what a yank takes. + try s.click("Collapse Del", "Collapse D".len, 1); + try s.click("Collapse Del", "Collapse D".len, 1); + try s.keys("\x1by:ggP"); + try s.expect(s.at("/pane/{d}/body", .{n}), "Delcall foo_bar(a, b)\nsay \"hi there\"\n"); +} + +test "mouse: everything a B1 chord does while B1 is down is one undo step" { + var s = try Session.initFile(std.testing.allocator, "one two three\n"); + defer s.deinit(); + const n = try s.focused(); + const body = s.at("/pane/{d}/body", .{n}); + const x, const y = try s.where("one two"); + // B1-B2 then B1-B3: cut, then paste back: a copy, one step. + try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 1\nm {d} {d} 5\nm {d} {d} 1\nm {d} {d} 0\n", .{ x + 4, y, x + 6, y, x + 6, y, x + 6, y, x + 6, y, x + 6, y, x + 6, y }); + try s.expect(body, "one two three\n"); + // Undone in one step, it is the text before the cut, not after it. + try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n"); + try s.expect(body, "one two three\n"); + // A cut alone comes back with one Undo. + try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 1\nm {d} {d} 0\n", .{ x + 4, y, x + 6, y, x + 6, y, x + 6, y, x + 6, y }); + try s.expect(body, "one three\n"); + try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n"); + try s.expect(body, "one two three\n"); +} + +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" }, + }) |case| { + var s = try Session.initFile(std.testing.allocator, case.text); + defer s.deinit(); + const n = try s.focused(); + if (bottom_tag) try s.write("/ctl", "Tagbottom on\n"); + if (already_insert) try s.keys("i"); + // The first line's number, then a blank, then its text. + 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}))); + 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 s.keys("Z"); + try s.expect(s.at("/pane/{d}/body", .{n}), case.result); + } + } + } +} + +test "mouse: a click on a tab's or a wrapped wide glyph's cells puts the caret on it" { + for ([_]bool{ false, true }) |already_insert| { + for ([_]bool{ false, true }) |wrap| { + const source = if (wrap) "012345678901234567890123456789界tail\n" else "\t界tail\n"; + var s = try Session.initFile(std.testing.allocator, source); + defer s.deinit(); + s.detach(); + try s.write("/ctl", "size 24 12\n"); + const n = try s.focused(); + if (!wrap) try s.write("/ctl", "Wrap off\n"); + if (already_insert) try s.keys("i"); + const x, const y = try s.where("界"); + if (wrap) try std.testing.expect(y > (try s.where("1 "))[1]); + // The glyph's second cell. + 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}))); + if (!already_insert) try s.keys("i"); + 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..] })); + } + } +} + +test "mouse: a B1 sweep over several lines is a stream, as acme's, in a body and a tag" { + var s = try Session.initFile(std.testing.allocator, "alpha\nbravo\ncharlie\n"); + defer s.deinit(); + const n = try s.focused(); + const body = s.at("/pane/{d}/body", .{n}); + const x, const y = try s.where("alpha"); + // From the press to the end of its line, the line between whole, the + // last from its start: no line numbers, no rectangle. B2 cuts it. + try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 0\n", .{ x + 2, y, x + 1, y + 2, x + 1, y + 2, x + 1, y + 2 }); + try s.expect(body, "alarlie\n"); + try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n"); + // Upward, the same text. + try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 0\n", .{ x + 1, y + 2, x + 2, y, x + 2, y, x + 2, y }); + try s.expect(body, "alarlie\n"); + // A tag of several rows sweeps the same way. + const tag = s.at("/pane/{d}/tag", .{n}); + try s.write(tag, "\nLook Edit"); + const tx, const ty = try s.where("Collapse"); + const lx, const ly = try s.where("Look Edit"); + try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 0\n", .{ tx + 3, ty, lx + 1, ly, lx + 1, ly, lx + 1, ly }); + try s.expect(tag, "/test.txt Save Tty Colok Edit"); +} |
