summaryrefslogtreecommitdiff
path: root/test/behaviour/keys.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/keys.zig')
-rw-r--r--test/behaviour/keys.zig36
1 files changed, 25 insertions, 11 deletions
diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig
index 78503dec..e02b1fa5 100644
--- a/test/behaviour/keys.zig
+++ b/test/behaviour/keys.zig
@@ -9,23 +9,27 @@ const window = "\x17"; // Ctrl-w
test "keys: a prompt's entry and cancellation leave the tag, the body and its cursor as they were" {
var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
defer s.deinit();
+ // A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
+ try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
const n = try s.focused();
const tag = s.at("/pane/{d}/tag", .{n});
const dot = s.at("/pane/{d}/dot", .{n});
try s.replace(tag, " keep");
for ([_]struct { keys: []const u8, shown: []const u8 }{
- .{ .keys = "s", .shown = " /zq" },
- .{ .keys = "|", .shown = " |zq" },
- .{ .keys = alt ++ "|", .shown = " |-zq" },
- .{ .keys = "!", .shown = " !zq" },
- .{ .keys = alt ++ "!", .shown = " !+zq" },
+ .{ .keys = "s", .shown = " s zq" },
+ .{ .keys = "|", .shown = " | zq" },
+ .{ .keys = alt ++ "|", .shown = " A-| zq" },
+ .{ .keys = "!", .shown = " ! zq" },
+ .{ .keys = alt ++ "!", .shown = " A-! zq" },
}) |case| {
try s.write(dot, "6 6");
try s.keys(case.keys);
- // The answer is typed into the prompt's own line, never the tag.
+ // The answer is typed into the tag's head (walk UI), shown in place
+ // of the tag's own text, which it never touches.
try s.keys("zq");
_ = try s.where(case.shown);
- try std.testing.expectEqualStrings("/test.txt keep", try s.read(tag));
+ const head = try s.read(tag);
+ try std.testing.expect(std.mem.startsWith(u8, head, "/test.txt") and std.mem.startsWith(u8, head["/test.txt".len..], case.shown));
try s.keys("\x1b");
try std.testing.expectError(error.NotOnScreen, s.where(case.shown));
try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal "));
@@ -56,8 +60,8 @@ test "keys: a prompt opens whatever the tag already holds" {
try s.keys(key);
try s.keys("zq");
_ = try s.where("zq");
- try std.testing.expectEqualStrings(full, try s.read(tag));
try s.keys("\x1b");
+ try std.testing.expectEqualStrings(full, try s.read(tag));
}
}
@@ -108,6 +112,8 @@ test "keys: a count or a prefix a click or a change of pane cancels leaves nothi
errdefer std.debug.print("\nkeys={s} gesture={s}\n", .{ typed, @tagName(gesture) });
var s = try Session.initFile(std.testing.allocator, "abcdefghij\n");
defer s.deinit();
+ // A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
+ try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
const n = try s.focused();
try s.write("/ctl", "Newcol\n");
const other = try s.newPane();
@@ -353,6 +359,12 @@ test "keys: SPC j n from the pane a Look gave the keyboard walks back into the c
try std.testing.expect(std.mem.startsWith(u8, try s.read(sel), "Theme "));
}
+/// The screen as drawn, its notice row left out.
+fn panesShown(s: *Session) ![]const u8 {
+ const shown = try s.screen();
+ return shown[0 .. std.mem.lastIndexOfScalar(u8, shown, '\n') orelse shown.len];
+}
+
/// Screen row `row` as drawn.
fn screenRow(s: *Session, row: usize) ![]const u8 {
var rows = std.mem.splitScalar(u8, try s.screen(), '\n');
@@ -378,9 +390,9 @@ test "keys: a PDF in normal mode keeps : (its tag and back), SPC (a leader, canc
// The leader shows its key cell in the tag at once (walk UI) until a
// key the PDF takes, which takes the leader away.
try s.keys(" ");
- try std.testing.expect(std.mem.indexOf(u8, try s.screen(), " ␣ ") != null);
+ try std.testing.expect(std.mem.indexOf(u8, try panesShown(&s), " ␣ ") != null);
try s.keys("!");
- try std.testing.expect(std.mem.indexOf(u8, try s.screen(), " ␣ ") == null);
+ try std.testing.expect(std.mem.indexOf(u8, try panesShown(&s), " ␣ ") == null);
try s.keys("/");
try std.testing.expect(try s.cursor() != null);
try std.testing.expectEqual(n, try s.focused());
@@ -394,9 +406,11 @@ test "keys: zz and zc put the cursor's line in the middle row of an odd view, as
for (&lines, 0..) |*l, i| _ = try std.fmt.bufPrint(l, "l{d:0>2}\n", .{i});
var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&lines));
defer s.deinit();
+ s.resize(80, 25);
for ([_][]const u8{ "15jzz", "ztzc" }) |keys| {
try s.keys(keys);
- // 80x24 gives the pane 21 rows: l05 to l25, l15 the eleventh
+ // 80x25 gives the pane 21 rows (the notice row under it): l05 to
+ // l25, l15 the eleventh
const top = (try s.where("l05"))[1];
try std.testing.expectEqual(top + 10, (try s.where("l15"))[1]);
try std.testing.expectEqual(top + 20, (try s.where("l25"))[1]);