summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:01:04 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:03:48 -0300
commit63e62131aaedb91a8fa995b8e00ced808e053519 (patch)
treecddcb8f17ea2139eb69893321beb0e78ac02e105 /test/panes.zig
parentd1273bbd99daf9b1855d82bf315db8ede20abde5 (diff)
downloadpardes-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/panes.zig')
-rw-r--r--test/panes.zig186
1 files changed, 0 insertions, 186 deletions
diff --git a/test/panes.zig b/test/panes.zig
index fc3f7804..6970cbb5 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -1119,159 +1119,6 @@ const ClickCursorTests = struct {
try std.testing.expect(std.mem.count(u8, got, "\n") > 20);
}
- test "everything a B1 chord does while B1 is down is one undo step" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("one two three\n");
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = p.bodyTop(pane, rect);
- const M = struct {
- fn ev(pp: *Pardes, b: pardes.Mouse.Button, k: pardes.Mouse.Kind, cx: u16, cy: u16) void {
- pp.update(.{ .mouse = .{ .button = b, .kind = k, .col = cx, .row = cy } });
- }
- };
- // B1-B2 then B1-B3: cut, then paste back: a copy, one step.
- const before = pane.file.?.history.undo_len;
- M.ev(p, .left, .press, x + 4, y);
- M.ev(p, .left, .drag, x + 6, y);
- M.ev(p, .middle, .press, x + 6, y);
- M.ev(p, .middle, .release, x + 6, y);
- M.ev(p, .right, .press, x + 6, y);
- M.ev(p, .right, .release, x + 6, y);
- M.ev(p, .left, .release, x + 6, y);
- try std.testing.expectEqualStrings("one two three\n", pane.file.?.content);
- try std.testing.expectEqualStrings("two", p.registers.text(p.gpa, '"').?);
- try std.testing.expect(pane.file.?.history.undo_len <= before + 1);
- // A cut alone comes back with one Undo.
- M.ev(p, .left, .press, x + 4, y);
- M.ev(p, .left, .drag, x + 6, y);
- M.ev(p, .middle, .press, x + 6, y);
- M.ev(p, .middle, .release, x + 6, y);
- M.ev(p, .left, .release, x + 6, y);
- try std.testing.expectEqualStrings("one three\n", pane.file.?.content);
- try std.testing.expect(p.executeBuiltinLine(0, "Undo"));
- try std.testing.expectEqualStrings("one two three\n", pane.file.?.content);
- }
-
- test "a double-click selects a word, a line, a bracketed or quoted text, as acme's" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("call foo_bar(a, b)\nsay \"hi there\"\n");
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = p.bodyTop(pane, rect);
- const Want = struct { col: u16, row: u16, text: []const u8 };
- for ([_]Want{
- .{ .col = 6, .row = 0, .text = "foo_bar" },
- .{ .col = 13, .row = 0, .text = "a, b" },
- .{ .col = 0, .row = 0, .text = "call foo_bar(a, b)\n" },
- .{ .col = 5, .row = 1, .text = "hi there" },
- }) |w| {
- click(p, .left, x + w.col, y + w.row);
- click(p, .left, x + w.col, y + w.row);
- try std.testing.expectEqualStrings(w.text, pardes.edit.currentSelText(p, pane).?);
- // A third click is a plain click again: the caret, no selection.
- click(p, .left, x + w.col, y + w.row);
- try std.testing.expect(!pane.body.vsel.active);
- }
- // In the tag too.
- const tag_text = try pardes.tagline.tagText(p, frame.allocator(), pane);
- const del: u16 = @intCast(std.mem.indexOf(u8, tag_text, "Del").? + 1);
- const tag_x = rect.x + pardes.TAG_TEXT_INSET + del;
- click(p, .left, tag_x, p.tagTop(pane, rect));
- click(p, .left, tag_x, p.tagTop(pane, rect));
- try std.testing.expect(pane.tag.vsel.active);
- const tag_now = try pardes.tagline.tagText(p, frame.allocator(), pane);
- const a = modal.offsetAt(tag_now, .{ .row = @intCast(pane.tag.vsel.row), .col = @intCast(pane.tag.vsel.col) });
- const h = modal.offsetAt(tag_now, .{ .row = @intCast(pane.tag.cur_row), .col = @intCast(pane.tag.cur_col) });
- try std.testing.expectEqualStrings("Del", tag_now[a .. h + 1]);
- }
-
- test "click cursor and insertion agree beyond line and file ends" {
- for ([_]bool{ false, true }) |already_insert| {
- for ([_]bool{ false, true }) |bottom_tag| {
- for ([_]struct { text: []const u8, click_row: u16, row: i32, col: i32, result: []const u8 }{
- .{ .text = "abc\nxy", .click_row = 0, .row = 0, .col = 3, .result = "abcZ\nxy" },
- .{ .text = "abc\nxy", .click_row = 5, .row = 1, .col = 2, .result = "abc\nxyZ" },
- .{ .text = "abc\n", .click_row = 5, .row = 1, .col = 0, .result = "abc\nZ" },
- .{ .text = "", .click_row = 5, .row = 0, .col = 0, .result = "Z" },
- }) |case| {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 });
- defer p.deinit();
- p.settings.tag_bottom = bottom_tag;
- const pane = try p.setTestFile(case.text);
- p.presentation.enabled = false;
- if (already_insert) p.update(.{ .key = .{ .cp = 'i' } });
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = bodyY(p, rect);
- click(p, .left, x + 15, y + case.click_row);
- try std.testing.expectEqual(case.row, pane.body.cur_row);
- try std.testing.expectEqual(case.col, pane.body.cur_col);
- const clicked = (try p.render(frame.allocator())).cursor orelse return error.MissingClickCursor;
- try std.testing.expectEqual(x + @as(u16, @intCast(case.col)), clicked.x);
- try std.testing.expectEqual(y + @as(u16, @intCast(case.row)), clicked.y);
- if (!already_insert) p.update(.{ .key = .{ .cp = 'i' } });
- try std.testing.expectEqual(panes.Text.Mode.insert, pane.body.mode);
- const insert = (try p.render(frame.allocator())).cursor orelse return error.MissingInsertCursor;
- try std.testing.expectEqual(clicked.x, insert.x);
- try std.testing.expectEqual(clicked.y, insert.y);
- p.update(.{ .key = .{ .cp = 'Z', .text = "Z" } });
- try std.testing.expectEqualStrings(case.result, pane.file.?.content);
- }
- }
- }
- }
-
- test "click cursor snaps tab and wrapped wide glyph cells before insertion" {
- for ([_]bool{ false, true }) |already_insert| {
- for ([_]bool{ false, true }) |wrap| {
- const source = if (wrap) "012345678901234567890123456789界tail\n" else "\t界tail\n";
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 24, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile(source);
- p.settings.wrap = wrap;
- p.presentation.enabled = false;
- if (already_insert) p.update(.{ .key = .{ .cp = 'i' } });
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- const surface = try p.render(frame.allocator());
- var target: ?struct { x: u16, y: u16 } = null;
- for (0..surface.rows) |row| for (0..surface.cols) |col| {
- if (std.mem.eql(u8, surface.at(@intCast(col), @intCast(row)).grapheme(), "界"))
- target = .{ .x = @intCast(col), .y = @intCast(row) };
- };
- const glyph = target orelse return error.MissingWideGlyph;
- if (wrap) try std.testing.expect(glyph.y > p.rects[0].y + pardes.BOX_H);
- click(p, .left, glyph.x + 1, glyph.y);
- const byte = std.mem.indexOf(u8, source, "界").?;
- try std.testing.expectEqual(@as(i32, @intCast(byte)), pane.body.cur_col);
- const clicked = (try p.render(frame.allocator())).cursor orelse return error.MissingClickCursor;
- try std.testing.expectEqual(glyph.x, clicked.x);
- try std.testing.expectEqual(glyph.y, clicked.y);
- if (!already_insert) p.update(.{ .key = .{ .cp = 'i' } });
- try std.testing.expectEqual(panes.Text.Mode.insert, pane.body.mode);
- const insert = (try p.render(frame.allocator())).cursor orelse return error.MissingInsertCursor;
- try std.testing.expectEqual(clicked.x, insert.x);
- try std.testing.expectEqual(clicked.y, insert.y);
- p.update(.{ .key = .{ .cp = 'Z', .text = "Z" } });
- const expected = try std.fmt.allocPrint(p.gpa, "{s}Z{s}", .{ source[0..byte], source[byte..] });
- defer p.gpa.free(expected);
- try std.testing.expectEqualStrings(expected, pane.file.?.content);
- }
- }
- }
-
test "click operands and hover follow the scrolled source selection" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 14 });
defer p.deinit();
@@ -1387,39 +1234,6 @@ const JumpSelectionTests = struct {
try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col);
}
- test "a B1 sweep over several lines is a stream, as acme's, in a body and a tag" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("alpha\nbravo\ncharlie\n");
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = p.bodyTop(pane, rect);
- // From the press to the end of its line, the line between whole, the
- // last from its start: no line numbers, no rectangle.
- drag(p, x + 2, y, x + 1, y + 2);
- try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.exec.heldSelection(p, 0).?);
- // Upward, the same text.
- drag(p, x + 1, y + 2, x + 2, y);
- try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.exec.heldSelection(p, 0).?);
- // A tag of several rows sweeps the same way.
- if (pane.tag.own) |own| p.gpa.free(own);
- pane.tag.own = try p.gpa.dupe(u8, "Save Del\nLook Edit");
- p.sync();
- _ = try p.render(frame.allocator());
- p.sync();
- try std.testing.expectEqual(@as(u16, 2), pane.tag_rows);
- const sl: panes.Pane.Sel = .{ .state = .done, .r0 = 0, .c0 = 3, .r1 = 1, .c1 = 1 };
- const text = try pardes.edit.paneText(p, pane);
- const swept = try pardes.edit.selectionText(p, pane, sl);
- const first_line = text[0 .. std.mem.indexOfScalar(u8, text, '\n') orelse text.len];
- const second = std.mem.sliceTo(text[first_line.len + 1 ..], '\n');
- const want = try std.fmt.allocPrint(frame.allocator(), "{s}\n{s}", .{ first_line[3..], second[0..@min(2, second.len)] });
- try std.testing.expectEqualStrings(want, swept);
- }
-
test "jump selection clears copied sweeps in both history directions" {
for ([_]bool{ false, true }) |reverse|
try exercise("alpha\nbravo\n", false, reverse, 1, 3, "lpha\nbrav");