diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 10:45:49 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 10:48:35 -0300 |
| commit | a0ec419725ebb4094d811f5206eb0d95bbc5add0 (patch) | |
| tree | fddf0fd9e4bd3e6861348133bbb71c315ad4206c /test/behaviour/modes.zig | |
| parent | 52bfa3f2aa8f8158d4d7ca720d81ea0c654f94bf (diff) | |
| download | pardes-a0ec419725ebb4094d811f5206eb0d95bbc5add0.tar.gz pardes-a0ec419725ebb4094d811f5206eb0d95bbc5add0.zip | |
test: src/pardes.zig's three window-mode tests through the 9P tree alone, in test/behaviour/modes.zig (guide.typ's Modes): Ctrl-w outlining the pane with the keyboard (its tag in the outline's colour, each box its letter), h j k l moving only the outline, Enter, Esc (after SPC w), : (its tag the keyboard's) and a letter giving a pane the keyboard, other keys changing nothing; d deleting the outlined pane (between two it waits for k or j, Esc taking it back; the rows and the outline going to the pane that took them, one neighbour closing at once), c collapsing and restoring it (the ctl read's collapsed), the mode staying on until Enter; window keys walking from the top pane up to its column's tag (normal mode, w moving its caret), across columns and back to the caret it had, up to the workspace tag, down again, and : back to the body; each checked to fail against a break (h j k l moving the keyboard too, a letter choosing nothing, the outline's tint not painted, the outline dropped after d, c not collapsing, k past a column's top pane doing nothing)
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.zig | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig index dde3ffb6..f29a4b56 100644 --- a/test/behaviour/modes.zig +++ b/test/behaviour/modes.zig @@ -102,3 +102,160 @@ test "modes: Esc back into a file leaves its view where it was, and a look centr const drawn_at = line - try topLine(&s, "/test.txt"); try std.testing.expect(drawn_at + 1 >= rows / 2 and drawn_at <= rows / 2 + 1); } + +/// Three panes named /a.txt (left column), /b.txt over /c.txt (right), +/// the keyboard on /a.txt; their serials. +fn threePanes(s: *Session) ![3]u32 { + const a = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{a}), "/a.txt\n"); + try s.write("/ctl", "Newcol\n"); + try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n"); + const b = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{b}), "New\n"); + const c = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{b}), "/b.txt\n"); + try s.write(s.at("/pane/{d}/name", .{c}), "/c.txt\n"); + try s.write("/focus", s.at("{d}\n", .{a})); + return .{ a, b, c }; +} + +/// The panes whose tag (`name Save`) is drawn in `lit`, the outline's colour. +fn outlined(s: *Session, lit: []const u8, names: []const []const u8) ![]const u8 { + var found: []const u8 = ""; + for (names) |name| { + const x, const y = try s.where(s.at("{s} Save", .{name})); + if (std.mem.eql(u8, lit, try s.bg(x, y))) found = s.at("{s}{s}", .{ found, name }); + } + return found; +} + +test "modes: Ctrl-w outlines a pane, h j k l move the outline, and Enter, Esc, : or a pane's letter gives it the keyboard" { + var s = try Session.initFile(std.testing.allocator, "left\n"); + defer s.deinit(); + const a, const b, const c = try threePanes(&s); + const names = &[_][]const u8{ "/a.txt", "/b.txt", "/c.txt" }; + try s.keys("\x17"); + const x, const y = try s.where("/a.txt Save"); + const lit = try s.bg(x, y); + try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names)); + // Each pane's box shows its letter: the left column's is a. + try std.testing.expectEqualStrings("a /a.txt", (try s.screen())[y * 81 ..][0.."a /a.txt".len]); + try s.keys("l"); + try std.testing.expectEqualStrings("/b.txt", try outlined(&s, lit, names)); + try s.keys("j"); + try std.testing.expectEqualStrings("/c.txt", try outlined(&s, lit, names)); + try expectEqual(a, try s.focused()); + try s.keys("\n"); + try expectEqual(c, try s.focused()); + try std.testing.expectEqualStrings("", try outlined(&s, lit, names)); + // SPC w enters it too, and Esc leaves it on the outlined pane. + try s.keys(" wh\x1b"); + try expectEqual(a, try s.focused()); + // Other keys change nothing. + try s.keys("\x17!"); + try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names)); + try s.keys("\x1b"); + // `:` gives the outlined pane's tag the keyboard. + try s.keys("\x17l:"); + try expectEqual(b, try s.focused()); + try expectEqual((try s.where("/b.txt Save"))[1], (try s.cursor()).?[1]); + try s.keys("\x1b"); + // A letter goes straight there. + try s.keys("\x17a"); + try expectEqual(a, try s.focused()); + try std.testing.expectEqualStrings("", try outlined(&s, lit, names)); +} + +fn listed(s: *Session, n: u32) !bool { + var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n'); + while (rows.next()) |row| if (std.mem.startsWith(u8, row, s.at("{d} ", .{n}))) return true; + return false; +} + +test "modes: in window mode d deletes the outlined pane, asking k or j between two, c collapses it, and the mode stays on" { + var s = try Session.initFile(std.testing.allocator, "top\n"); + defer s.deinit(); + // The neighbours below are what is under test: each New right under its asker. + try s.write("/ctl", "Placement pardes\n"); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + const mid = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{mid}), "New\n"); + const low = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{mid}), "/mid\n"); + try s.write(s.at("/pane/{d}/name", .{low}), "/low\n"); + const names = &[_][]const u8{ "/test.txt", "/mid", "/low" }; + const row_top = (try s.where("/test.txt Save"))[1]; + const row_mid = (try s.where("/mid Save"))[1]; + const row_low = (try s.where("/low Save"))[1]; + // From the bottom pane, the outline up to the middle one. + const mx, const my = try s.where("/mid Save"); + const plain = try s.bg(mx, my); + try s.keys("\x17k"); + const lit = try s.bg(mx, my); + try std.testing.expect(!std.mem.eql(u8, plain, lit)); + try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names)); + // c folds it to its tag and back, the mode staying. + try s.keys("c"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") != null); + try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names)); + try s.keys("c"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") == null); + try expectEqual(row_low, (try s.where("/low Save"))[1]); + // d between two panes asks, as SPC d does; Esc takes it back, the + // outline where it was. + try s.keys("d\x1b"); + try std.testing.expect(try listed(&s, mid)); + try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names)); + // j: the pane below takes the rows, and the outline goes with them. + try s.keys("dj"); + try std.testing.expect(!try listed(&s, mid)); + try expectEqual(row_top, (try s.where("/test.txt Save"))[1]); + try expectEqual(row_mid, (try s.where("/low Save"))[1]); + try std.testing.expectEqualStrings("/low", try outlined(&s, lit, &.{ "/test.txt", "/low" })); + // With one neighbour nothing is asked: d closes it, the outline on the + // pane that grew. + try s.keys("d"); + try std.testing.expect(!try listed(&s, low)); + try std.testing.expectEqualStrings("/test.txt", try outlined(&s, lit, &.{"/test.txt"})); + // Enter leaves the mode on it. + try s.keys("\n"); + try expectEqual(top, try s.focused()); + try std.testing.expectEqualStrings("", try outlined(&s, lit, &.{"/test.txt"})); +} + +test "modes: window keys walk from a pane up through its column's tag and the workspace's, across, and back down" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const a = try s.focused(); + try s.write("/ctl", "Newcol\n"); + try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n"); + try s.write("/focus", s.at("{d}\n", .{a})); + const right = 40; // two columns on 80 cells: the right one's first + // Up from the top pane: its column's tag, in normal mode (w moves). + try s.keys("\x17k"); + try s.expect("/focus", ""); + const x0, const y0 = (try s.cursor()).?; + try expectEqual(@as(usize, 1), y0); + try std.testing.expect(x0 < right); + try s.keys("w"); + const remembered = (try s.cursor()).?; + try std.testing.expect(remembered[0] > x0); + // Across to the right column's tag, and back to where the caret was. + try s.keys("\x17l"); + try std.testing.expect((try s.cursor()).?[0] >= right); + try s.keys("\x17h"); + try expectEqual(remembered, (try s.cursor()).?); + // Up again: the workspace tag; down, the column's, then the pane. + try s.keys("\x17k"); + try expectEqual(@as(usize, 0), (try s.cursor()).?[1]); + try s.keys("\x17j"); + try expectEqual(@as(usize, 1), (try s.cursor()).?[1]); + try s.keys("\x17j"); + try expectEqual(a, try s.focused()); + // `:` in a column's tag is the way back to the body. + try s.keys("\x17k:"); + try expectEqual(a, try s.focused()); + try expectEqual((try s.where("body"))[1], (try s.cursor()).?[1]); + try s.expect(s.at("/pane/{d}/body", .{a}), "body\n"); +} |
