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
73
74
75
76
77
78
79
80
81
82
83
84
|
//! 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 replaces the selection it was made from, for an address, a range and text found" {
var s = try Session.initFile(std.testing.allocator, "alpha\nbravo\ncharlie\nneedle\n");
defer s.deinit();
const n = try s.focused();
const dot = s.at("/pane/{d}/dot", .{n});
const look = s.at("/pane/{d}/look", .{n});
try s.write(dot, "0 5");
try s.write(look, "/test.txt:3:2\n");
try expectEqual(.{ @as(u32, 13), @as(u32, 13) }, try s.range(dot));
try s.write(dot, "0 5");
try s.write(look, "/test.txt:2:2-4\n");
try s.expect(s.at("/pane/{d}/sel", .{n}), "rav");
try s.write(s.at("/pane/{d}/name", .{n}), "/tmp/look-selection-source.txt");
try s.write(dot, "0 5");
// A count typed before it is gone after it.
try s.keys("5");
try s.write(look, "needle\n");
try s.expect(s.at("/pane/{d}/sel", .{n}), "needle");
try s.keys("l");
try expectEqual(.{ @as(u32, 26), @as(u32, 26) }, try s.range(dot));
try expectEqual(n, try s.focused());
}
test "look-and-exec: a look into another pane leaves the source's dot and replaces the destination's selection" {
var s = try Session.initFile(std.testing.allocator, "source\nlines\n");
defer s.deinit();
const source = try s.focused();
const dest = try s.newPane();
try s.write(s.at("/pane/{d}/name", .{dest}), "/look-destination.txt");
try s.write(s.at("/pane/{d}/body", .{dest}), "alpha\nbravo\ncharlie\n");
const dest_dot = s.at("/pane/{d}/dot", .{dest});
for ([_]bool{ false, true }) |range| {
try s.write("/focus", s.at("{d}", .{source}));
try s.write(s.at("/pane/{d}/dot", .{source}), "0 6");
try s.write(dest_dot, "0 5");
try s.write(s.at("/pane/{d}/look", .{source}), if (range) "/look-destination.txt:2:2-4\n" else "/look-destination.txt:3:2\n");
try expectEqual(dest, try s.focused());
// The source keeps its dot, as acme's look leaves it.
try s.expect(s.at("/pane/{d}/sel", .{source}), "source");
if (range)
try s.expect(s.at("/pane/{d}/sel", .{dest}), "rav")
else
try expectEqual(.{ @as(u32, 13), @as(u32, 13) }, try s.range(dest_dot));
}
}
|