summaryrefslogtreecommitdiff
path: root/test/behaviour
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:28:55 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:30:20 -0300
commitccb668645e9afc3710b1a50903022367a800ff1b (patch)
treede07ade44f2261050534249f60b0d4e17a2fe134 /test/behaviour
parent3632bbeaa75f912281d0c9d636feb153d04f668e (diff)
downloadpardes-ccb668645e9afc3710b1a50903022367a800ff1b.tar.gz
pardes-ccb668645e9afc3710b1a50903022367a800ff1b.zip
test: four more of src/pardes.zig's tests through the 9P tree alone (test/behaviour/limits, settings, placement): a builtin that needs a pane refused in words once every one of the 64 slots is taken, Pet refused in a terminal's view from a pane and the root (a window's pets read back from /ctl), New and 9P's new taking the bottom half of a column's last pane, Placement pardes putting a pane right under the asking one and stepping back to acme bare (each read from /ctl); each checked to fail against a break (openHelp's failure unsaid, a GUI-only word run in a terminal's view, acmePlace's split at a quarter, pardes placement placing as acme)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour')
-rw-r--r--test/behaviour/limits.zig18
-rw-r--r--test/behaviour/placement.zig37
-rw-r--r--test/behaviour/settings.zig23
3 files changed, 78 insertions, 0 deletions
diff --git a/test/behaviour/limits.zig b/test/behaviour/limits.zig
new file mode 100644
index 00000000..08c864eb
--- /dev/null
+++ b/test/behaviour/limits.zig
@@ -0,0 +1,18 @@
+//! docs/typ/reference.typ, Limits <limits>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "limits: a builtin that needs a pane says so when every slot is taken" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.focused();
+ // Room on the screen for every pane, so the slots run out first.
+ s.detach();
+ try s.write("/ctl", "size 100 400\n");
+ var made: usize = 1;
+ while (s.newPane()) |_| made += 1 else |_| {}
+ try std.testing.expectEqual(@as(usize, 64), made);
+ _ = try s.refused(s.at("/pane/{d}/exec", .{n}), "Help\n");
+ try std.testing.expectEqualStrings("help: no space for a pane: 64 max", s.said);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "help: no space for a pane") != null);
+}
diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig
index 350e94f8..079b5a5e 100644
--- a/test/behaviour/placement.zig
+++ b/test/behaviour/placement.zig
@@ -22,3 +22,40 @@ test "placement: an empty active column takes the new pane whole, a look from an
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);
+}
diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig
new file mode 100644
index 00000000..59e6f7c3
--- /dev/null
+++ b/test/behaviour/settings.zig
@@ -0,0 +1,23 @@
+//! docs/typ/reference.typ, Settings <settings>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "settings: Pet is the window's: a terminal's view refuses it, from a pane and the root; a window takes only its pets" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ if (try s.refused("/ctl", "Pet cat\n") == 0) {
+ // A window's: dog is no pet of its, and off is.
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null);
+ _ = try s.refused("/ctl", "Pet dog\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null);
+ try s.write("/ctl", "Pet frog\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet frog\n") != null);
+ try s.write("/ctl", "Pet off\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet off\n") != null);
+ return;
+ }
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "Pet is GUI-only, invalid here"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Pet cat\n"));
+ try std.testing.expectEqualStrings("Pet is GUI-only, invalid here", s.said);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "Pet ") == null);
+}