summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 10:28:16 -0300
committerGabriel Schneider <[email protected]>2026-11-04 10:42:43 -0300
commit52bfa3f2aa8f8158d4d7ca720d81ea0c654f94bf (patch)
treebaa2c90f77caac09fe27fb5c6d07997d78628fb2
parentf697bb13c3599db3ce30fac059932242597acdf6 (diff)
downloadpardes-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
-rw-r--r--src/pardes.zig112
-rw-r--r--test/behaviour/columns_and_tags.zig57
-rw-r--r--test/behaviour/mouse.zig64
-rw-r--r--test/session.zig12
4 files changed, 133 insertions, 112 deletions
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();
diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig
index d485ee6e..ac8e7034 100644
--- a/test/behaviour/columns_and_tags.zig
+++ b/test/behaviour/columns_and_tags.zig
@@ -233,3 +233,60 @@ test "columns-and-tags: a refused Delcol changes nothing: no pane, no focus" {
try s.expect("/focus", focus);
try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "unsaved ") != null);
}
+
+/// Column `i`'s x and width, from /layout.
+fn columnBox(s: *Session, i: usize) !struct { usize, usize } {
+ var lines = std.mem.tokenizeScalar(u8, try s.read("/layout"), '\n');
+ for (0..i) |_| _ = lines.next();
+ var fields = std.mem.tokenizeScalar(u8, lines.next().?, ' ');
+ _ = fields.next(); // serial
+ _ = fields.next(); // index
+ return .{ try std.fmt.parseInt(usize, fields.next().?, 10), try std.fmt.parseInt(usize, fields.next().?, 10) };
+}
+
+test "columns-and-tags: a column tag lights the word under the mouse, is clicked and swept into, typed at its caret, and scrolls from its column's edge" {
+ var s = try Session.initFile(std.testing.allocator, "untouched\n");
+ defer s.deinit();
+ const file = try s.focused();
+ try s.write("/ctl", "Newcol\n");
+ try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n");
+ for (0..2) |i| {
+ const tag = s.at("/col/{d}/tag", .{try s.column(i)});
+ const left, const w = try columnBox(&s, i);
+ // Its text starts two cells into the column.
+ const x = left + 2;
+ const width = w - 2;
+ const plain = try s.bg(x, 1);
+ try s.write("/mousein", s.at("m {d} 1 0\n", .{x}));
+ const lit = try s.bg(x, 1);
+ try std.testing.expect(!std.mem.eql(u8, plain, lit));
+ try expectEqualStrings(plain, try s.bg(x + 4, 1)); // Tty, another word
+ // Pressed, the keyboard is on the tag, its caret where it was pressed.
+ try s.write("/mousein", s.at("m {d} 1 1\n", .{x}));
+ try s.expect("/focus", "");
+ try std.testing.expectEqual(.{ x, @as(usize, 1) }, (try s.cursor()).?);
+ // Swept over three cells: those three in the selection's colour.
+ try s.write("/mousein", s.at("m {d} 1 1\nm {d} 1 0\n", .{ x + 3, x + 3 }));
+ for (0..3) |k| try expectEqualStrings(lit, try s.bg(x + k, 1));
+ try std.testing.expect(!std.mem.eql(u8, lit, try s.bg(x + 3, 1)));
+ try s.keys("\u{F00D}Help ");
+ try std.testing.expect(std.mem.startsWith(u8, try s.read(tag), "Help New Tty"));
+ try std.testing.expectEqual(x + 5, (try s.cursor()).?[0]);
+ // A tag one short of its room: its caret at the end is drawn on the
+ // last cell, and one more letter scrolls the text, never the caret.
+ const as: [80]u8 = @splat('a');
+ const row = as[0 .. width - 1];
+ try s.replace(tag, row);
+ try s.keys("\u{F018}");
+ try std.testing.expectEqual(x + width - 1, (try s.cursor()).?[0]);
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), row) != null);
+ try s.keys("b");
+ try std.testing.expectEqual(x + width - 1, (try s.cursor()).?[0]);
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), s.at("{s}b", .{row[1..]})) != null);
+ try s.keys("\u{F00D}");
+ try std.testing.expectEqual(x, (try s.cursor()).?[0]);
+ try s.keys("\x1b\x1b");
+ try s.write("/mousein", "m 0 23 0\n");
+ }
+ try s.expect(s.at("/pane/{d}/body", .{file}), "untouched\n");
+}
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");
+}
diff --git a/test/session.zig b/test/session.zig
index 16a131fd..5dd506ec 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -314,6 +314,18 @@ pub const Session = struct {
var it = std.mem.splitScalar(u8, tag[lo + 2 .. close], '/');
return .{ try std.fmt.parseInt(u32, it.next().?, 10), try std.fmt.parseInt(u32, it.next() orelse return error.NoPage, 10) };
}
+
+ // core2:
+
+ /// The background /screen draws at a cell, as its JSON (`{"rgb":[255,255,255]}`).
+ pub fn bg(s: *Session, col: usize, row: usize) ![]const u8 {
+ const a = s.arena.allocator();
+ const json = try std.json.parseFromSliceLeaky(std.json.Value, a, try s.read("/screen"), .{});
+ const cols: usize = @intCast(json.object.get("cols").?.integer);
+ const cell = json.object.get("cells").?.array.items[row * cols + col];
+ const style = json.object.get("styles").?.array.items[@intCast(cell.array.items[1].integer)];
+ return std.json.Stringify.valueAlloc(a, style.object.get("bg").?, .{});
+ }
};
fn refusal(path: []const u8, r: Reply) error{Refused} {