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
|
//! docs/typ/reference.typ, Panes <panes>.
const std = @import("std");
const Session = @import("session").Session;
test "panes: a collapsed pane's ctl says so" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
const first = try s.focused();
_ = try s.newPane();
try s.write(s.at("/pane/{d}/ctl", .{first}), "Collapse\n");
try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{first})), " collapsed ") != null);
}
test "panes: a pane's ctl read ends with its mode, as its tag's box shows it" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
const ctl = s.at("/pane/{d}/ctl", .{try s.focused()});
try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:normal "));
try s.keys("i");
try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:insert "));
try s.keys("\x1bv");
try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:select "));
}
test "panes: the ctl word name refuses a leading blank, as the name file does" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
const ctl = s.at("/pane/{d}/ctl", .{try s.focused()});
try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "name /tmp/lead.txt\n"));
try std.testing.expectEqualStrings("bad character in file name: a blank at its start", s.said);
try s.write(ctl, "name /tmp/ok.txt\n");
try s.expect(s.at("/pane/{d}/name", .{try s.focused()}), "/tmp/ok.txt\n");
}
test "panes: Putall saves every pane with unsaved edits to a file, one each, and leaves the rest" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "clean.txt", .data = "clean\n" });
var dir_buf: [4096]u8 = undefined;
const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
const first = try s.focused();
try s.write(s.at("/pane/{d}/name", .{first}), "/tmp/pardes-putall-a.txt\n");
try s.write(s.at("/pane/{d}/body", .{first}), "edited\n");
// A file opened from disk, unedited.
try s.write(s.at("/pane/{d}/look", .{first}), s.at("{s}/clean.txt\n", .{dir}));
try std.testing.expectEqual(@as(usize, 0), s.saved);
try s.write("/ctl", "Putall\n");
try std.testing.expectEqual(@as(usize, 1), s.saved);
}
|