From 49ed5492dec8275ace22e37003f4de548b2d2fc5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 11:19:29 -0300 Subject: test: test/pdf.zig's PDF normal-mode keys through the 9P tree alone, in test/behaviour/keys.zig: in a PDF, : giving its tag the keyboard in normal mode and : again the body back, SPC a leader (its keys shown at the row's end) that a key it has not cancels, and / a search prompt that Esc closes, the PDF keeping the keyboard; each checked to fail against a break (a PDF's : doing nothing, its / doing nothing, its SPC not starting the leader) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/keys.zig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/behaviour/keys.zig') diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig index e659b369..b6fe1e83 100644 --- a/test/behaviour/keys.zig +++ b/test/behaviour/keys.zig @@ -274,3 +274,35 @@ test "keys: SPC j n and SPC j p walk on from the place a Look's +Search listing try std.testing.expectEqual(results, try s.focused()); try s.expect(sel, "look-owner.txt:1:7-12"); } + +/// Screen row `row` as drawn. +fn screenRow(s: *Session, row: usize) ![]const u8 { + var rows = std.mem.splitScalar(u8, try s.screen(), '\n'); + for (0..row) |_| _ = rows.next(); + return rows.next().?; +} + +test "keys: a PDF in normal mode keeps : (its tag and back), SPC (a leader, cancelled by a key it has not) and / (a search prompt, Esc closing it)" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const body = (try s.cursor()).?; + const tag = (try s.where("docs/design.pdf [1/"))[1]; + try s.keys(":"); + const on_tag = (try s.cursor()).?[1]; + try std.testing.expect(on_tag == tag or on_tag == tag + 1); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal ")); + try s.keys(":"); + try std.testing.expectEqual(body, (try s.cursor()).?); + // The leader shows its keys at the row's end until one it has not. + try s.keys(" "); + try std.testing.expect(std.mem.endsWith(u8, std.mem.trimEnd(u8, try screenRow(&s, body[1]), " "), " SPC")); + try s.keys("!"); + try std.testing.expect(!std.mem.endsWith(u8, std.mem.trimEnd(u8, try screenRow(&s, body[1]), " "), " SPC")); + try s.keys("/"); + try std.testing.expect(!std.meta.eql(body, (try s.cursor()).?)); + try std.testing.expectEqual(n, try s.focused()); + try s.keys("\x1b"); + try std.testing.expectEqual(body, (try s.cursor()).?); + try std.testing.expectEqual(n, try s.focused()); +} -- cgit v1.3