diff options
Diffstat (limited to 'test/behaviour/look_and_exec.zig')
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 2ff4345b..ec26b74f 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -36,3 +36,49 @@ test "look-and-exec: a bare :N or :N:M look addresses the pane itself, from its 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)); + } +} |
