diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-03 17:22:33 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-03 17:31:56 -0300 |
| commit | 8fe05231e6e683b09b89356d4dff0ddb487962e4 (patch) | |
| tree | 6c5b34dca32f89488001ba0ef21588d34dc6b7d1 /test/behaviour/keys.zig | |
| parent | 4d4d9fcba44798340184f865d119e49c63709b70 (diff) | |
| download | pardes-8fe05231e6e683b09b89356d4dff0ddb487962e4.tar.gz pardes-8fe05231e6e683b09b89356d4dff0ddb487962e4.zip | |
test: twenty-one more of test/panes.zig's tests through the 9P tree alone: in test/behaviour/tags.zig a tag with a newline as tall as its lines, a tag with more lines than rows scrolling to its caret (a column tag one row), a click on a wrapped tag row and on a word the wrap breaks (SyntaxBold toggled, read from /ctl), and a name drafted in the tag (committed by Enter, dropped by two Escs or by leaving the pane or entering a header, edited by grapheme, an empty one and an oversized one not committed, a middle-clicked Save committing it first); in test/behaviour/keys.zig (guide.typ's Keys) a prompt's entry and cancellation (s, the four pipes, Save on a scratch) leaving tag, body and dot, a prompt opening over a full tag, generated output refusing the pipe prompts, a cancelled s or S restoring the selection, a counted paste of nothing and a count or prefix a click or a change of pane cancels (the next l moving one); in look_and_exec.zig a look replacing its pane's selection (address, range, text, a count typed before it gone) and one into another pane leaving the source's dot; each checked to fail against a break (tag rows always one, the tag not scrolled to its caret, wrapTag recording no soft breaks, Enter not committing a name, Save not committing it first, nameBuffer taking names over 4096 bytes, leaving a pane keeping its draft, backspace by byte, Esc not closing a prompt, startPrompt refusing a full tag, a pipe prompt on generated output, Esc not restoring an s preview's selection, an empty paste keeping its count, a click keeping the count, clearNavigationSelection keeping the count, a look dropping every pane's dot); the old tests' internal checks with no surface (a pixel shell's tag layer, prompt_for, the input's mode) are not carried over
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/keys.zig')
| -rw-r--r-- | test/behaviour/keys.zig | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig new file mode 100644 index 00000000..81087297 --- /dev/null +++ b/test/behaviour/keys.zig @@ -0,0 +1,135 @@ +//! docs/typ/guide.typ, Keys <keys>. +const std = @import("std"); +const Session = @import("session").Session; + +const alt = "\u{F015}"; +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(); + 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" }, + }) |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. + try s.keys("zq"); + _ = try s.where(case.shown); + try std.testing.expectEqualStrings("/test.txt keep", try s.read(tag)); + 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 ")); + try std.testing.expectEqualStrings("/test.txt keep", try s.read(tag)); + try std.testing.expectEqual(.{ 6, 6 }, try s.range(dot)); + try s.expect(s.at("/pane/{d}/body", .{n}), "one\ntwo\n"); + } + // Save on a scratch asks for a path, starting from its directory. + const scratch = try s.newPane(); + const scratch_tag = try s.read(s.at("/pane/{d}/tag", .{scratch})); + try s.keys(":\tzq"); + _ = try s.where("/zq"); + try s.expect(s.at("/pane/{d}/tag", .{scratch}), scratch_tag); + try s.keys("\x1b"); + try std.testing.expectError(error.NotOnScreen, s.where("/zq")); + try s.expect(s.at("/pane/{d}/tag", .{scratch}), scratch_tag); + try std.testing.expectEqual(@as(usize, 0), s.saved); +} + +test "keys: a prompt opens whatever the tag already holds" { + var s = try Session.initFile(std.testing.allocator, "one\n"); + defer s.deinit(); + const n = try s.focused(); + const tag = s.at("/pane/{d}/tag", .{n}); + try s.replace(tag, &@as([4096]u8, @splat('x'))); + const full = try s.read(tag); + for ([_][]const u8{ "s", "|" }) |key| { + 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"); + } +} + +test "keys: generated output refuses every pipe prompt before seeding the tag" { + var s = try Session.initFile(std.testing.allocator, "one\n"); + defer s.deinit(); + try s.write("/ctl", "Help\n"); + const n = try s.focused(); + const tag = try s.read(s.at("/pane/{d}/tag", .{n})); + const body = try s.read(s.at("/pane/{d}/body", .{n})); + for ([_][]const u8{ "|", alt ++ "|", "!", alt ++ "!" }) |key| { + try s.keys(key); + try std.testing.expectError(error.NotOnScreen, s.where(" |")); + try std.testing.expectError(error.NotOnScreen, s.where(" !")); + try s.expect(s.at("/pane/{d}/tag", .{n}), tag); + try s.expect(s.at("/pane/{d}/body", .{n}), body); + } +} + +test "keys: a cancelled prompt restores the selection its regex previews changed" { + var s = try Session.initFile(std.testing.allocator, "one two one"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + for ([_][]const u8{ "sone", "S " }) |typed| { + try s.write(dot, "0 11"); + try s.keys(typed); + try s.keys("\x1b"); + try std.testing.expectEqual(.{ 0, 11 }, try s.range(dot)); + try s.expect(s.at("/pane/{d}/sel", .{n}), "one two one"); + try s.expect(s.at("/pane/{d}/body", .{n}), "one two one"); + } +} + +test "keys: a counted paste of nothing leaves no count for the next motion" { + var s = try Session.initFile(std.testing.allocator, "abcdefgh\n"); + defer s.deinit(); + const n = try s.focused(); + try s.keys("3pl"); + try std.testing.expectEqual(.{ 1, 1 }, try s.range(s.at("/pane/{d}/dot", .{n}))); + try s.expect(s.at("/pane/{d}/body", .{n}), "abcdefgh\n"); +} + +test "keys: a count or a prefix a click or a change of pane cancels leaves nothing for the next motion" { + const Gesture = enum { body, tag, focus, last }; + for ([_][]const u8{ "3", "3g", "mr(" }) |typed| { + for ([_]Gesture{ .body, .tag, .focus, .last }) |gesture| { + 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(); + const n = try s.focused(); + try s.write("/ctl", "Newcol\n"); + const other = try s.newPane(); + try s.write("/focus", s.at("{d}", .{n})); + try s.keys(typed); + switch (gesture) { + .body => try s.click("abcdefghij", 3, 1), + .tag => { + try s.click("/test.txt Save", "/test.txt ".len + 3, 1); + try s.keys("\x1b:"); + }, + .focus, .last => { + try s.keys(window ++ "l\n"); + try std.testing.expectEqual(other, try s.focused()); + try s.keys(if (gesture == .last) "\x1b" else window ++ "h\n"); + try std.testing.expectEqual(n, try s.focused()); + }, + } + const dot = s.at("/pane/{d}/dot", .{n}); + const at = (try s.range(dot))[0]; + try s.keys("l"); + try std.testing.expectEqual(at + 1, (try s.range(dot))[0]); + try s.expect(s.at("/pane/{d}/body", .{n}), "abcdefghij\n"); + } + } +} |
