summaryrefslogtreecommitdiff
path: root/test/behaviour/root_ctl.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/root_ctl.zig')
-rw-r--r--test/behaviour/root_ctl.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig
new file mode 100644
index 00000000..bdf912da
--- /dev/null
+++ b/test/behaviour/root_ctl.zig
@@ -0,0 +1,31 @@
+//! docs/typ/reference.typ, The root ctl <root-ctl>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+/// The screen's size, as /screen draws it.
+fn size(s: *Session) !struct { usize, usize } {
+ const screen = try s.screen();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0 .. std.mem.indexOfScalar(u8, screen, '\n') orelse screen.len]);
+ return .{ cols, std.mem.count(u8, screen, "\n") + 1 };
+}
+
+test "root-ctl: size sets the screen of a session no frontend is attached to, and only of one" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size 120 40\n")); // a frontend's
+ s.detach();
+ try s.write("/ctl", "size 120 40\n");
+ try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size 120\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size\n"));
+ _ = try s.refused("/ctl", "size 5 2\n");
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "at least 20x6, at most 4096x4096") != null);
+ // The bad value quoted, never the word size.
+ try std.testing.expect(std.mem.endsWith(u8, s.said, "\"5 2\""));
+ // Too small for the panes it has, each its tag and two rows: refused,
+ // the size as it was.
+ for (0..4) |_| _ = try s.newPane();
+ _ = try s.refused("/ctl", "size 80 8\n");
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "too small for the panes") != null);
+ try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s));
+}