//! docs/typ/reference.typ, 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); } test "limits: a ctl line over 1 MiB is refused once, EINVAL, and its tail is not run as a line of its own" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); const n = try s.focused(); const ctl = try s.hold(s.at("/pane/{d}/ctl", .{n}), 1); const chunk: [4096]u8 = @splat('z'); var refused: usize = 0; for (0..270) |_| { const errno = try s.writeFid(ctl, &chunk); if (errno != 0) { refused += 1; try std.testing.expectEqual(@as(u16, 22), errno); } } try std.testing.expectEqual(@as(u16, 0), try s.writeFid(ctl, "zzz\nEdit ,d\n")); s.clunk(ctl); try std.testing.expectEqual(@as(usize, 1), refused); try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "unknown control message") == null); // What came after the long line's newline ran. try s.expect(s.at("/pane/{d}/body", .{n}), ""); } test "limits: a ctl line with no newline is held whatever its write's size, and runs at the close, its failure in the log" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); const ctl = try s.hold(s.at("/pane/{d}/ctl", .{try s.focused()}), 1); const line = "bogus" ++ @as([20000]u8, @splat('x')); try std.testing.expectEqual(@as(u16, 0), try s.writeFid(ctl, line)); try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "ctl: unknown control message") == null); s.clunk(ctl); try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "ctl: unknown control message") != null); }