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
|
//! docs/typ/reference.typ, look and exec <look-and-exec>.
const std = @import("std");
const Session = @import("session").Session;
const expectEqual = std.testing.expectEqual;
test "look-and-exec: a 9P look keeps its leading blanks, a blank-only look included, and exec still trims" {
var s = try Session.initFile(std.testing.allocator, "a indented\nb\n indented\n \n");
defer s.deinit();
const n = try s.focused();
const dot = s.at("/pane/{d}/dot", .{n});
try s.write(dot, "0 0");
// The indented line, not the `indented` after `a `.
try s.write(s.at("/pane/{d}/look", .{n}), " indented\n");
try expectEqual(.{ @as(u32, 13), @as(u32, 25) }, try s.range(dot));
// Blanks alone are text to find too.
try s.write(dot, "26 26");
try s.write(s.at("/pane/{d}/look", .{n}), " \n");
try expectEqual(.{ @as(u32, 26), @as(u32, 30) }, try s.range(dot));
// exec's line is still trimmed: ` Msg hi` runs Msg.
try s.write(s.at("/pane/{d}/exec", .{n}), " Msg blanks trimmed\n");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "blanks trimmed") != null);
}
test "look-and-exec: a bare :N or :N:M look addresses the pane itself, from its look, the root's and event write-back" {
var s = try Session.initFile(std.testing.allocator, "alpha\nbeta\ngamma\n");
defer s.deinit();
const n = try s.focused();
const dot = s.at("/pane/{d}/dot", .{n});
try s.write(s.at("/pane/{d}/look", .{n}), ":2\n");
try expectEqual(.{ @as(u32, 6), @as(u32, 11) }, try s.range(dot));
try s.write("/look", ":3\n");
try expectEqual(.{ @as(u32, 11), @as(u32, 17) }, try s.range(dot));
try s.write(s.at("/pane/{d}/look", .{n}), ":3:2\n");
try expectEqual(@as(u32, 12), (try s.range(dot))[0]);
// Written back by an event reader, the same.
try s.write(s.at("/pane/{d}/event", .{n}), "ML0 0 0 2 :1\n");
try expectEqual(.{ @as(u32, 0), @as(u32, 6) }, try s.range(dot));
}
test "look-and-exec: a look that finds nothing says so" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
const n = try s.newPane();
try s.write(s.at("/pane/{d}/look", .{n}), "/no/such/zzqq\n");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("err {d} look: no match for \"/no/such/zzqq\"\n", .{n})) != null);
}
|