diff options
Diffstat (limited to 'test/behaviour/placement.zig')
| -rw-r--r-- | test/behaviour/placement.zig | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig new file mode 100644 index 00000000..079b5a5e --- /dev/null +++ b/test/behaviour/placement.zig @@ -0,0 +1,61 @@ +//! docs/typ/reference.typ, Placement <placement>. +const std = @import("std"); +const Session = @import("session").Session; + +test "placement: an empty active column takes the new pane whole, a look from another column's text too" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\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, "x\n"); + defer s.deinit(); + const first = try s.focused(); + // Its tag has the keyboard: it is the active column, and stays so + // when Esc gives the keyboard back. + try s.write("/ctl", "Newcol\n"); + try s.keys("\x1b"); + try std.testing.expectEqual(first, try s.focused()); + // A look from the first pane's text still lands in the active column, + // as acme's makenewwindow puts it in activecol first (util.c:456). + try s.write(s.at("/pane/{d}/look", .{first}), s.at("{s}/f.txt\n", .{at})); + const made = try s.focused(); + try std.testing.expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ try s.column(0), first, try s.column(1), made }), try s.columns()); +} + +/// The screen row the tag starting `name` is drawn on. +fn tagRow(s: *Session, name: []const u8) !usize { + return (try s.where(s.at("{s} Save", .{name})))[1]; +} + +test "placement: New and 9P's new take the bottom half of the column's last pane" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const first = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{first}), "New\n"); + const last = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{last}), "/last\n"); + const was = try tagRow(&s, "/last"); + const made = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{made}), "/made\n"); + try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d}", .{ try s.column(0), first, last, made }), try s.columns()); + // The last pane keeps its top and gives up its bottom half. + try std.testing.expectEqual(was, try tagRow(&s, "/last")); + const rows = std.mem.count(u8, try s.screen(), "\n") + 1; + try std.testing.expect(try tagRow(&s, "/made") >= was + (rows - was) / 2); +} + +test "placement: Placement pardes puts a new pane right under the asking one, and bare it steps back to acme" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "Placement pardes\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement pardes\n") != null); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + const below = try s.focused(); + // Directly under the asking pane, as New always put it. + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d}", .{ try s.column(0), top, try s.focused(), below }), try s.columns()); + try s.write("/ctl", "Placement\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement acme\n") != null); +} |
