From fa3031d6ded24d4ba7ab5bab21e17387e48306aa Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 11:05:00 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/placement.zig | 88 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'test/behaviour/placement.zig') 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]); +} -- cgit v1.3