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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
//! 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: pager answers its +Pager on the open that asked, whatever another client exec'd meanwhile, and refuses a directory it cannot page in" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
const asked = try s.hold("/pager", 2);
try std.testing.expectEqual(@as(u16, 0), try s.writeFid(asked, "/tmp\n"));
// Another client execs between the request and its read: a pane of its own.
const racer = try s.hold("/exec", 2);
try std.testing.expectEqual(@as(u16, 0), try s.writeFid(racer, "New\n"));
s.clunk(racer);
const paged = try s.readFid(asked);
s.clunk(asked);
// A fresh open reads the session's last answer, the racer's pane.
try std.testing.expect(!std.mem.eql(u8, paged, try s.read("/exec")));
try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, paged, "\n")}), "/tmp/+Pager\n");
// Refused, an open answers nothing, not the session's last answer.
const refused = try s.hold("/pager", 2);
try std.testing.expectEqual(@as(u16, 22), try s.writeFid(refused, "relative\n"));
try std.testing.expectEqualStrings("", try s.readFid(refused));
s.clunk(refused);
// Resolved: `/tmp/../tmp/.` is /tmp, a +Pager of its own beside the
// one made above, which keeps its page.
const resolved = try s.hold("/pager", 2);
try std.testing.expectEqual(@as(u16, 0), try s.writeFid(resolved, "/tmp/../tmp/.\n"));
const second = try s.readFid(resolved);
s.clunk(resolved);
try std.testing.expect(!std.mem.eql(u8, paged, second));
try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, second, "\n")}), "/tmp/+Pager\n");
try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, paged, "\n")}), "/tmp/+Pager\n");
// One that may not be written is refused, permission denied (Linux's /proc/1).
try std.testing.expectEqual(@as(u16, 1), try s.refused("/pager", "/proc/1\n"));
// One directory an open: one refused is not followed by another, as a
// mount sends two lines in two writes.
const twice = try s.hold("/pager", 2);
try std.testing.expectEqual(@as(u16, 22), try s.writeFid(twice, "relative\n"));
try std.testing.expectEqual(@as(u16, 22), try s.writeFid(twice, "/tmp\n"));
s.clunk(twice);
try std.testing.expectEqual(@as(u16, 22), try s.refused("/pager", "relative\n"));
try std.testing.expectEqualStrings("pager: invalid directory \"relative\": must be absolute", s.said);
try std.testing.expectEqual(@as(u16, 2), try s.refused("/pager", "/tmp/pardes-surely-missing-dir\n"));
try std.testing.expectEqual(@as(u16, 20), try s.refused("/pager", "/etc/passwd\n"));
}
|