summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 11:05:00 -0300
committerGabriel Schneider <[email protected]>2026-11-04 11:07:13 -0300
commitfa3031d6ded24d4ba7ab5bab21e17387e48306aa (patch)
tree0817370a9560696cadc6a5ef457aa1fbb0a713b4
parent273cbd0df9d8edf4725fdff5f9da560b35b63058 (diff)
downloadpardes-fa3031d6ded24d4ba7ab5bab21e17387e48306aa.tar.gz
pardes-fa3031d6ded24d4ba7ab5bab21e17387e48306aa.zip
test: src/pardes.zig's two acme-placement tests through the 9P tree alone, in test/behaviour/placement.zig: a look from a pane's text going under its three lines when most of it is blank, and, both panes full, halving the biggest (the new pane after it in /layout, its tag at the old pane's middle row, its bottom the old pane's); a look from the middle of a column (its top and bottom panes dragged by their boxes to two and three rows, under a placement's minimum) splitting only the pane it came from, the short ones keeping their rows, through a Newcol too; geometry read from where /screen draws each tag, on a 100x60 screen set by size; each checked to fail against a break (no placement under the text, the biggest split at a third, every pane in the column reweighted at a split)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/pardes.zig73
-rw-r--r--test/behaviour/placement.zig88
2 files changed, 88 insertions, 73 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 2b4fef70..f78c2c0d 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -1195,79 +1195,6 @@ test "first document keeps its originating shell and only opens a column when it
}
}
-test "acme placement: under a pane's text when it has many blank rows, else halving the biggest" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 });
- defer p.deinit();
- const top = p.active;
- _ = try p.setTestFile("one\ntwo\nthree\n");
- p.sync();
- p.setActiveColumn(0);
- // Most of the pane is blank: a document looked from it starts under its
- // three lines (makenewwindow, util.c:482-486).
- const second = p.freeSlot().?;
- _ = try p.openTutorView(second);
- exec.placeNew(p, top, top, second, .doc);
- p.sync();
- const text_end = p.bodyTop(p.panes[top].?, p.rects[top]) + 3;
- try std.testing.expectEqual(text_end, p.rects[second].y);
- // Fill both with text: no blank space is big, so the biggest pane is
- // halved.
- const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
- for ([_]usize{ top, second }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full));
- p.sync();
- const big = if (p.rects[second].h >= p.rects[top].h) second else top;
- const was = p.rects[big];
- const third = p.freeSlot().?;
- _ = try p.openTutorView(third);
- exec.placeNew(p, second, second, third, .doc);
- p.sync();
- try std.testing.expectEqual(big, p.col_panes[0][layout.findPane(p, third).?.idx - 1]);
- try std.testing.expectEqual(was.y + was.h / 2, p.rects[third].y);
- try std.testing.expectEqual(was.y + was.h, p.rects[third].y + p.rects[third].h);
-}
-
-test "acme placement: a pane made from the middle of a column moves only the one it splits, short ones round it kept short" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 });
- defer p.deinit();
- const top = p.active;
- _ = try p.setTestFile("one\n");
- p.sync();
- p.setActiveColumn(0);
- const middle = p.freeSlot().?;
- _ = try p.openTutorView(middle);
- exec.placeNew(p, top, top, middle, .doc);
- const bottom = p.freeSlot().?;
- _ = try p.openTutorView(bottom);
- exec.placeNew(p, middle, middle, bottom, .doc);
- p.sync();
- // A short pane above and below, dragged under a placement's minimum,
- // and the middle one full of text, so it is the one halved.
- const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
- for ([_]usize{ top, middle, bottom }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full));
- try std.testing.expectEqualSlices(usize, &.{ top, middle, bottom }, p.col_panes[0][0..3]);
- const total = p.rects[top].h + p.rects[middle].h + p.rects[bottom].h;
- p.panes[top].?.vweight = 2;
- p.panes[bottom].?.vweight = 2;
- p.panes[middle].?.vweight = @floatFromInt(total - 4);
- p.sync();
- const was_top = p.rects[top];
- const was_bottom = p.rects[bottom];
- try std.testing.expect(was_top.h < layout.minRows(p, top));
- const made = p.freeSlot().?;
- _ = try p.openTutorView(made);
- exec.placeNew(p, middle, middle, made, .doc);
- p.sync();
- try std.testing.expectEqual(layout.findPane(p, middle).?.idx + 1, layout.findPane(p, made).?.idx);
- try std.testing.expectEqual(was_top, p.rects[top]);
- try std.testing.expectEqual(was_bottom, p.rects[bottom]);
- // A new column narrows this one, and the short panes keep their rows.
- try std.testing.expect(p.executeBuiltinLine(made, "Newcol"));
- p.sync();
- try std.testing.expectEqual(@as(usize, 2), p.ncol);
- try std.testing.expectEqual(was_top.h, p.rects[top].h);
- try std.testing.expectEqual(was_bottom.h, p.rects[bottom].h);
-}
-
test "an empty column shows its theme's empty_col under its tag: acme's white, else the border" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 20 });
defer p.deinit();
diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig
index 079b5a5e..5b2d55c7 100644
--- a/test/behaviour/placement.zig
+++ b/test/behaviour/placement.zig
@@ -59,3 +59,91 @@ test "placement: Placement pardes puts a new pane right under the asking one, an
try s.write("/ctl", "Placement\n");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement acme\n") != null);
}
+
+/// Each pane's tag row and its rows down to the next tag, or the screen's
+/// end, as /screen draws them; `names` top to bottom in one column.
+fn spans(s: *Session, comptime n: usize, names: [n][]const u8) ![n][2]usize {
+ var out: [n][2]usize = undefined;
+ for (names, 0..) |name, i| out[i][0] = try tagRow(s, name);
+ const rows = std.mem.count(u8, try s.screen(), "\n") + 1;
+ for (0..n) |i| out[i][1] = (if (i + 1 < n) out[i + 1][0] else rows) - out[i][0];
+ return out;
+}
+
+test "placement: a look from a pane's text goes under its text when it has many blank rows, else halves the biggest pane" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ for ([_][]const u8{ "second.txt", "third.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n");
+ defer s.deinit();
+ s.detach();
+ try s.write("/ctl", "size 100 60\n");
+ const top = try s.focused();
+ // Most of the pane is blank: the look starts under its three lines
+ // (makenewwindow, util.c:482-486).
+ try s.write(s.at("/pane/{d}/look", .{top}), s.at("{s}/second.txt\n", .{at}));
+ const second = try s.focused();
+ const shown = s.at("{s}/second.txt", .{at});
+ try std.testing.expectEqual((try tagRow(&s, "/test.txt")) + 1 + 3, try tagRow(&s, shown));
+ // Both full of text: no blank space is big, so the biggest is halved.
+ const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
+ for ([_]u32{ top, second }) |n| try s.replace(s.at("/pane/{d}/body", .{n}), full);
+ const was = try spans(&s, 2, .{ "/test.txt", shown });
+ const big: usize = if (was[1][1] >= was[0][1]) 1 else 0;
+ try s.write(s.at("/pane/{d}/look", .{second}), s.at("{s}/third.txt\n", .{at}));
+ const third = try s.focused();
+ const ids = [_]u32{ top, second };
+ try std.testing.expect(std.mem.indexOf(u8, try s.columns(), s.at("{d},{d}", .{ ids[big], third })) != null);
+ const made = s.at("{s}/third.txt", .{at});
+ const now = if (big == 1) try spans(&s, 3, .{ "/test.txt", shown, made }) else try spans(&s, 3, .{ "/test.txt", made, shown });
+ try std.testing.expectEqual(was[big][0] + was[big][1] / 2, now[big + 1][0]);
+ try std.testing.expectEqual(was[big][0] + was[big][1], now[big + 1][0] + now[big + 1][1]);
+}
+
+test "placement: a look from the middle of a column splits only the pane it came from, short ones round it kept short, through a Newcol too" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ for ([_][]const u8{ "mid", "low", "made" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ s.detach();
+ try s.write("/ctl", "size 100 60\n");
+ const top = try s.focused();
+ try s.write(s.at("/pane/{d}/look", .{top}), s.at("{s}/mid\n", .{at}));
+ const mid = try s.focused();
+ try s.write(s.at("/pane/{d}/look", .{mid}), s.at("{s}/low\n", .{at}));
+ const low = try s.focused();
+ const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*)));
+ for ([_]u32{ top, mid, low }) |n| try s.replace(s.at("/pane/{d}/body", .{n}), full);
+ // Short names, so a narrowed column draws each tag on one row.
+ try s.write(s.at("/pane/{d}/name", .{mid}), "/mid\n");
+ try s.write(s.at("/pane/{d}/name", .{low}), "/low\n");
+ const names = [_][]const u8{ "/test.txt", "/mid", "/low", "/made" };
+ // The top and bottom panes dragged by their boxes to two and three
+ // rows, under a placement's minimum; the middle one full of text, so
+ // the one halved.
+ const rows = std.mem.count(u8, try s.screen(), "\n") + 1;
+ const r = try spans(&s, 3, names[0..3].*);
+ try s.write("/mousein", s.at("m 0 {d} 1\nm 0 {d} 1\nm 0 {d} 0\n", .{ r[1][0], r[0][0] + 2, r[0][0] + 2 }));
+ try s.write("/mousein", s.at("m 0 {d} 1\nm 0 {d} 1\nm 0 {d} 0\n", .{ r[2][0], rows - 3, rows - 3 }));
+ const was = try spans(&s, 3, names[0..3].*);
+ try std.testing.expectEqual(@as(usize, 2), was[0][1]);
+ try std.testing.expectEqual(@as(usize, 3), was[2][1]);
+ try s.write(s.at("/pane/{d}/look", .{mid}), s.at("{s}/made\n", .{at}));
+ const made = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{made}), "/made\n");
+ try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d},{d}", .{ try s.column(0), top, mid, made, low }), try s.columns());
+ const now = try spans(&s, 4, .{ names[0], names[1], names[3], names[2] });
+ try std.testing.expectEqual(was[0], now[0]);
+ try std.testing.expectEqual(was[2], now[3]);
+ // A new column narrows this one, and the short panes keep their rows.
+ try s.write(s.at("/pane/{d}/exec", .{made}), "Newcol\n");
+ try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, try s.columns(), ":"));
+ const narrowed = try spans(&s, 4, .{ names[0], names[1], names[3], names[2] });
+ try std.testing.expectEqual(was[0][1], narrowed[0][1]);
+ try std.testing.expectEqual(was[2][1], narrowed[3][1]);
+}