diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 10:28:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 10:42:43 -0300 |
| commit | 52bfa3f2aa8f8158d4d7ca720d81ea0c654f94bf (patch) | |
| tree | baa2c90f77caac09fe27fb5c6d07997d78628fb2 /test/behaviour/mouse.zig | |
| parent | f697bb13c3599db3ce30fac059932242597acdf6 (diff) | |
| download | pardes-52bfa3f2aa8f8158d4d7ca720d81ea0c654f94bf.tar.gz pardes-52bfa3f2aa8f8158d4d7ca720d81ea0c654f94bf.zip | |
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)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/mouse.zig')
| -rw-r--r-- | test/behaviour/mouse.zig | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/behaviour/mouse.zig b/test/behaviour/mouse.zig index 0abe15dc..aba0f2d5 100644 --- a/test/behaviour/mouse.zig +++ b/test/behaviour/mouse.zig @@ -131,3 +131,67 @@ test "mouse: a B1 sweep over several lines is a stream, as acme's, in a body and 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"); } + +test "mouse: a click on either half of a wide character lands before it, in the text and on a tag's path, and the caret steps over it whole" { + var s = try Session.initFile(std.testing.allocator, "a界e\u{301}z\n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + const x, const y = try s.where("a界"); + // 界 is two cells, bytes 1 to 4; é two runes, bytes 4 to 7. + for ([_]usize{ 1, 2 }) |into| { + try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + into, y, x + into, y }); + try std.testing.expectEqual(.{ @as(u32, 1), @as(u32, 1) }, try s.range(dot)); + } + try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + 4, y, x + 4, y }); + try std.testing.expectEqual(.{ @as(u32, 7), @as(u32, 7) }, try s.range(dot)); + // On the tag's path, the second half of 界 drafts the name with its + // caret before it; Right steps a whole grapheme, two cells then one. + try s.write(s.at("/pane/{d}/name", .{n}), "/界e\u{301}.txt\n"); + const px, const py = try s.where("/界"); + try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ px + 2, py, px + 2, py }); + try std.testing.expectEqual(.{ px + 1, py }, (try s.cursor()).?); + try s.keys("\u{F012}"); + try std.testing.expectEqual(.{ px + 3, py }, (try s.cursor()).?); + try s.keys("\u{F012}"); + try std.testing.expectEqual(.{ px + 4, py }, (try s.cursor()).?); + try s.keys("\x1b\x1b"); + try s.expect(s.at("/pane/{d}/name", .{n}), "/界e\u{301}.txt\n"); + // Typed past the tag's words, a two-byte λ goes in and one backspace + // takes it out whole. + const tag = try s.read(s.at("/pane/{d}/tag", .{n})); + try s.click("Collapse Del", "Collapse Del".len + 1, 1); + const caret = (try s.cursor()).?; + try s.keys("λ"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/tag", .{n})), "λ")); + try std.testing.expectEqual(.{ caret[0] + 1, caret[1] }, (try s.cursor()).?); + try s.keys("\x08"); + try std.testing.expectEqual(caret, (try s.cursor()).?); + try s.expect(s.at("/pane/{d}/tag", .{n}), tag); +} + +test "mouse: a sweep pressed on the line numbers takes only the text: drawn while held and once let go, looked for by a click in it, cut by a chord" { + var s = try Session.initFile(std.testing.allocator, "alpha beta\ngamma delta\nalpha beta\ngamma\n"); + defer s.deinit(); + const n = try s.focused(); + const x, const y = try s.where("alpha"); + const plain = try s.bg(x - 2, y); + try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\n", .{ x - 2, y, x + 4, y + 1 }); + for (0..2) |released| { + // The number pressed on, and the room after the line, stay unlit. + try std.testing.expectEqualStrings(plain, try s.bg(x - 2, y)); + try std.testing.expectEqualStrings(plain, try s.bg(x - 2, y + 1)); + const lit = try s.bg(x, y); + try std.testing.expect(!std.mem.eql(u8, plain, lit)); + try std.testing.expectEqualStrings(lit, try s.bg(x + 4, y + 1)); + try std.testing.expectEqualStrings(plain, try s.bg(x + 5, y + 1)); + if (released == 0) try mouse(&s, "m {d} {d} 0\n", .{ x + 4, y + 1 }); + } + // A Look clicked in it looks for the text swept: its next place, the + // third and fourth lines. + try mouse(&s, "m {d} {d} 4\nm {d} {d} 0\n", .{ x + 1, y, x + 1, y }); + try std.testing.expectEqual(.{ @as(u32, 23), @as(u32, 39) }, try s.range(s.at("/pane/{d}/dot", .{n}))); + // A chord cuts what was swept: the text, no number. + 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 - 2, y, x + 4, y + 1, x + 4, y + 1, x + 4, y + 1, x + 4, y + 1 }); + try s.expect(s.at("/pane/{d}/body", .{n}), " delta\nalpha beta\ngamma\n"); +} |
