summaryrefslogtreecommitdiff
path: root/test/behaviour/limits.zig
blob: d84d4490b92ff65db350426f7ce043bdd7e408a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! 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);
}

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}), "");
}