summaryrefslogtreecommitdiff
path: root/test/behaviour/modes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:22:47 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:24:11 -0300
commit3632bbeaa75f912281d0c9d636feb153d04f668e (patch)
treedd3e91c78036b3c168c71b030047f42a9b55aa31 /test/behaviour/modes.zig
parent5cc02232d522d5cd5a453caedd1e592ca20471ea (diff)
downloadpardes-3632bbeaa75f912281d0c9d636feb153d04f668e.tar.gz
pardes-3632bbeaa75f912281d0c9d636feb153d04f668e.zip
test: five more of src/pardes.zig's tests through the 9P tree alone (test/behaviour/placement, panes, terminals, modes): an empty active column taking a look from another column's text whole, Collapse folding a pane to its tag (no text drawn, no cursor, its tag still typed into) and restoring it, a pane its whole text fits in never scrolled for a margin, Togglettymode and Ctrl-B sharing the mode's transitions from the body or the tag and a text pane refusing it, Esc back into a file keeping its view where a look's :N centres; Session's where (the first place /screen draws a text); each checked to fail against a break (acmeColumn ignoring the active column, toggleCollapse never unfolding, the scroll margin clamped at the last line alone, toggleTty leaving the tag the keyboard, Last landing centred)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/modes.zig')
-rw-r--r--test/behaviour/modes.zig39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig
index cdcf1be6..dde3ffb6 100644
--- a/test/behaviour/modes.zig
+++ b/test/behaviour/modes.zig
@@ -63,3 +63,42 @@ test "modes: Shift-Esc backs out to the previous pane in every mode, never into
try std.testing.expectEqualStrings("normal", try mode(&s, doc));
try std.testing.expect(doc != try s.focused());
}
+
+/// The first line number drawn under the tag that starts with `tag`.
+fn topLine(s: *Session, tag: []const u8) !usize {
+ const row = (try s.where(tag))[1];
+ var rows = std.mem.splitScalar(u8, try s.screen(), '\n');
+ for (0..row + 1) |_| _ = rows.next();
+ var words = std.mem.tokenizeScalar(u8, rows.next().?, ' ');
+ return std.fmt.parseInt(usize, words.next().?, 10);
+}
+
+test "modes: Esc back into a file leaves its view where it was, and a look centres its line" {
+ var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))));
+ defer s.deinit();
+ const doc = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{doc});
+ try s.keys("\u{F015}n"); // a shell under the doc
+ const shell = try s.focused();
+ try s.keys("\x1b");
+ try expectEqual(doc, try s.focused());
+ // Ride the cursor down until the view has scrolled.
+ try s.keys(&@as([20]u8, @splat('j')));
+ const top = try topLine(&s, "/test.txt");
+ const at = try s.range(dot);
+ try std.testing.expect(top > 1);
+ try s.keys("\x1b");
+ try expectEqual(shell, try s.focused());
+ try s.keys("\x1b");
+ try expectEqual(doc, try s.focused());
+ // Nothing moved: the old landing recentred the line under the cursor.
+ try expectEqual(top, try topLine(&s, "/test.txt"));
+ try expectEqual(at, try s.range(dot));
+ // The other arm still centres: a look's `:NN`.
+ const line = 60;
+ try s.write(s.at("/pane/{d}/look", .{doc}), s.at(":{d}\n", .{line}));
+ const rows = (try s.where("Tty Save Mode"))[1] - (try s.where("/test.txt"))[1] - 1;
+ // Drawn mid-pane, a row either way.
+ const drawn_at = line - try topLine(&s, "/test.txt");
+ try std.testing.expect(drawn_at + 1 >= rows / 2 and drawn_at <= rows / 2 + 1);
+}