summaryrefslogtreecommitdiff
path: root/test/behaviour/other_files.zig
blob: e778ad77a6c0f4c292a1b7b9db0c238470e0bb99 (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, Other files <other-files>.
const std = @import("std");
const Session = @import("session").Session;

test "other-files: kbdin types at the pane with the keyboard and mousein clicks, each done before its write is answered" {
    var s = try Session.initFile(std.testing.allocator, "x\n");
    defer s.deinit();
    const body = try std.fmt.allocPrint(s.arena.allocator(), "/pane/{d}/body", .{try s.focused()});
    try s.keys("ihello \x1b");
    try s.expect(body, "hello x\n");
    // Plan 9's Khome rune, then text before it.
    try s.keys("A!\x1b\u{F00D}i>\x1b");
    try s.expect(body, ">hello x!\n");
    // A left click on the second l, then text there.
    try s.click(">hello", 4, 1);
    try s.keys("i#\x1b");
    try s.expect(body, ">hel#lo x!\n");
    // Refused, in words, as rio and devmouse refuse.
    try std.testing.expectEqual(@as(u16, 22), try s.refused("/mousein", "m 1 2\n"));
    try std.testing.expectEqual(@as(u16, 22), try s.refused("/mousein", "x 1 2 0\n"));
    try std.testing.expectEqual(@as(u16, 22), try s.refused("/kbdin", "\xff"));
    try std.testing.expectError(error.Refused, s.read("/kbdin"));
}

test "other-files: kbdin's Kalt rune is Alt on the key after it alone, and an Alt key types nothing" {
    var s = try Session.initFile(std.testing.allocator, "x\n");
    defer s.deinit();
    try s.keys("i\u{F015}zy\x1b");
    try s.expect(s.at("/pane/{d}/body", .{try s.focused()}), "yx\n");
}

test "other-files: /recent keeps a PDF as it keeps a file: open, then closed" {
    var s = try Session.initFile(std.testing.allocator, "x\n");
    defer s.deinit();
    const n = try s.lookFile("docs/design.pdf");
    const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n");
    try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("open {s}\n", .{name})) != null);
    try s.write(s.at("/pane/{d}/ctl", .{n}), "Del\n");
    try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("closed {s}\n", .{name})) != null);
}