From 8fe05231e6e683b09b89356d4dff0ddb487962e4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:22:33 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour.zig | 1 + test/behaviour/keys.zig | 135 ++++++++++ test/behaviour/look_and_exec.zig | 46 ++++ test/behaviour/tags.zig | 189 +++++++++++++ test/panes.zig | 557 --------------------------------------- 5 files changed, 371 insertions(+), 557 deletions(-) create mode 100644 test/behaviour/keys.zig diff --git a/test/behaviour.zig b/test/behaviour.zig index 17d753fb..f48c6da7 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -5,6 +5,7 @@ test { _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); + _ = @import("behaviour/keys.zig"); _ = @import("behaviour/look_and_exec.zig"); _ = @import("behaviour/mouse.zig"); _ = @import("behaviour/other_files.zig"); 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 . +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"); + } + } +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 2ff4345b..ec26b74f 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -36,3 +36,49 @@ test "look-and-exec: a bare :N or :N:M look addresses the pane itself, from its try s.write(s.at("/pane/{d}/event", .{n}), "ML0 0 0 2 :1\n"); try expectEqual(.{ @as(u32, 0), @as(u32, 6) }, try s.range(dot)); } + +test "look-and-exec: a look replaces the selection it was made from, for an address, a range and text found" { + var s = try Session.initFile(std.testing.allocator, "alpha\nbravo\ncharlie\nneedle\n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + const look = s.at("/pane/{d}/look", .{n}); + try s.write(dot, "0 5"); + try s.write(look, "/test.txt:3:2\n"); + try expectEqual(.{ @as(u32, 13), @as(u32, 13) }, try s.range(dot)); + try s.write(dot, "0 5"); + try s.write(look, "/test.txt:2:2-4\n"); + try s.expect(s.at("/pane/{d}/sel", .{n}), "rav"); + try s.write(s.at("/pane/{d}/name", .{n}), "/tmp/look-selection-source.txt"); + try s.write(dot, "0 5"); + // A count typed before it is gone after it. + try s.keys("5"); + try s.write(look, "needle\n"); + try s.expect(s.at("/pane/{d}/sel", .{n}), "needle"); + try s.keys("l"); + try expectEqual(.{ @as(u32, 26), @as(u32, 26) }, try s.range(dot)); + try expectEqual(n, try s.focused()); +} + +test "look-and-exec: a look into another pane leaves the source's dot and replaces the destination's selection" { + var s = try Session.initFile(std.testing.allocator, "source\nlines\n"); + defer s.deinit(); + const source = try s.focused(); + const dest = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{dest}), "/look-destination.txt"); + try s.write(s.at("/pane/{d}/body", .{dest}), "alpha\nbravo\ncharlie\n"); + const dest_dot = s.at("/pane/{d}/dot", .{dest}); + for ([_]bool{ false, true }) |range| { + try s.write("/focus", s.at("{d}", .{source})); + try s.write(s.at("/pane/{d}/dot", .{source}), "0 6"); + try s.write(dest_dot, "0 5"); + try s.write(s.at("/pane/{d}/look", .{source}), if (range) "/look-destination.txt:2:2-4\n" else "/look-destination.txt:3:2\n"); + try expectEqual(dest, try s.focused()); + // The source keeps its dot, as acme's look leaves it. + try s.expect(s.at("/pane/{d}/sel", .{source}), "source"); + if (range) + try s.expect(s.at("/pane/{d}/sel", .{dest}), "rav") + else + try expectEqual(.{ @as(u32, 13), @as(u32, 13) }, try s.range(dest_dot)); + } +} diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig index e9b33cb0..9a8430d7 100644 --- a/test/behaviour/tags.zig +++ b/test/behaviour/tags.zig @@ -191,3 +191,192 @@ test "tags: a tag's normal mode is the body's: motions stay in the tag and inser try std.testing.expectEqual(first, try s.focused()); } } + +test "tags: a tag with a newline in it is as tall as its lines, and each line is typed into and pointed at" { + for ([_]bool{ false, true }) |bottom| { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + if (bottom) try s.write("/ctl", "Tagbottom on\n"); + // Insert mode in a tag is a body's: Enter is a new line. + try s.keys(":A\nSecond"); + try std.testing.expectEqualStrings("/test.txt Save Tty Collapse Del\nSecond", try tag(&s, n)); + const x, const y = try s.where("/test.txt"); + try std.testing.expectEqual(.{ x, y + 1 }, try s.where("Second")); + // The caret is on the second line, after what was typed. + try std.testing.expectEqual(.{ x + 6, y + 1 }, try s.cursor()); + // The body starts under (or over) the whole tag. + const by = (try s.where("1 body"))[1]; + try std.testing.expect(if (bottom) by < y else by == y + 2); + // A click on the second line puts the tag's cursor on it. + try s.keys("\x1b:"); + try s.write("/mousein", s.at("m {d} {d} 1\nm {d} {d} 0\n", .{ x + 2, y + 1, x + 2, y + 1 })); + try std.testing.expectEqual(.{ x + 2, y + 1 }, try s.cursor()); + try s.keys("X"); + try std.testing.expectEqualStrings("/test.txt Save Tty Collapse Del\nSeXcond", try tag(&s, n)); + try s.expect(s.at("/pane/{d}/body", .{n}), "body\n"); + } +} + +test "tags: a tag with more lines than rows scrolls to keep its caret in view" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + var many: std.ArrayList(u8) = .empty; + defer many.deinit(std.testing.allocator); + for (1..21) |i| try many.print(std.testing.allocator, "\nL{d}", .{i}); + try s.write(s.at("/pane/{d}/tag", .{n}), many.items); + const x, const y = try s.where("/test.txt"); + // To the last line: the tag scrolls so it is the bottom row, caret on it. + try s.keys(":ge"); + const lx, const ly = try s.where("L20"); + try std.testing.expectEqual(.{ lx, ly }, try s.cursor()); + // What the pointer sees is what is shown: its first row is line 13. + try std.testing.expectEqual(.{ x, y }, try s.where("L13")); + try std.testing.expectError(error.NotOnScreen, s.where("L12")); + try s.write("/mousein", s.at("m {d} {d} 1\nm {d} {d} 0\n", .{ x + 1, y + 1, x + 1, y + 1 })); + try s.keys("X"); + _ = try s.where("LX14"); + // Back to the first line brings the prefix back into view. + try s.keys("\x1bgg"); + try std.testing.expectEqual(.{ x, y }, try s.where("/test.txt")); + try std.testing.expectEqual(y, (try s.cursor())[1]); + // A column tag is one row, as acme's: its lines are joined. + var layout = std.mem.tokenizeScalar(u8, try s.read("/layout"), ' '); + const col_tag = s.at("/col/{s}/tag", .{layout.next().?}); + try s.replace(col_tag, "New\nC1\nC2"); + try std.testing.expect(std.mem.indexOfScalar(u8, try s.read(col_tag), '\n') == null); + try std.testing.expectEqual(y, (try s.where("/test.txt"))[1]); +} + +test "tags: a long pane tag wraps onto rows, and a click on a wrapped row maps to the whole tag's address" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + s.detach(); + try s.write("/ctl", "size 50 12\n"); + const n = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{n}), "/an/especially/deep/project/path/with/a/long/component/filename.zig"); + try s.write(s.at("/pane/{d}/tag", .{n}), " SyntaxBold"); + const before = try tag(&s, n); + try s.keys(":A"); + try std.testing.expect((try s.cursor())[0] < 50); + // SyntaxBold is on a row of its own, below the path's. + try std.testing.expect((try s.where("SyntaxBold"))[1] > (try s.where("/an/"))[1]); + // Its last character, which a wrapped row's offset not mapped back misses. + try s.click("SyntaxBold", "SyntaxBol".len, 2); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "SyntaxBold on\n") != null); + try std.testing.expectEqualStrings(before, try tag(&s, n)); +} + +test "tags: a word the tag's wrapping breaks across rows is still one word to a click" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + s.detach(); + try s.write("/ctl", "size 50 12\n"); + const n = try s.focused(); + // Lengthen the path until the wrap splits the word after "Synt" (a + // rename resets the tag's text, so it is written again each time). + var pad: usize = 1; + while (pad < 80) : (pad += 1) { + try s.write(s.at("/pane/{d}/name", .{n}), s.at("/{s}/f.zig", .{(&@as([80]u8, @splat('a')))[0..pad]})); + try s.write(s.at("/pane/{d}/tag", .{n}), " SyntaxBold"); + var rows = std.mem.splitScalar(u8, try s.screen(), '\n'); + const split = while (rows.next()) |row| { + if (std.mem.endsWith(u8, std.mem.trimEnd(u8, row, " "), "Synt")) break true; + } else false; + if (split) break; + } else return error.NoSplit; + try s.click("Synt", 1, 2); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "SyntaxBold on\n") != null); +} + +/// A click on the tag's path, at its last character: a name drafted +/// there, its caret taken to its end. +fn clickPathEnd(s: *Session, path: []const u8) !void { + try s.click(path, path.len - 1, 1); + try s.keys("\u{F018}"); +} + +test "tags: a name drafted in the tag commits with Enter, cancels with two Escs, and changes neither body nor tag text" { + var s = try Session.initFile(std.testing.allocator, "original body\n"); + defer s.deinit(); + const n = try s.focused(); + const name = s.at("/pane/{d}/name", .{n}); + try s.write(s.at("/pane/{d}/tag", .{n}), " SyntaxBold"); + for ([_]bool{ false, true }) |commit| { + const path = std.mem.trimEnd(u8, try s.read(name), "\n"); + try clickPathEnd(&s, path); + try s.keys("\x15/new name.zig"); + try s.expect(name, s.at("{s}\n", .{path})); + _ = try s.where("/new name.zig Save Tty Collapse Del SyntaxBold"); + try s.expect(s.at("/pane/{d}/body", .{n}), "original body\n"); + // Esc keeps the draft pending; a second drops it. + try s.keys(if (commit) "\n" else "\x1b\x1b"); + try s.expect(name, if (commit) "/new name.zig\n" else "/test.txt\n"); + try std.testing.expectEqualStrings(s.at("{s} Save Tty Collapse Del SyntaxBold", .{if (commit) "/new name.zig" else "/test.txt"}), try tag(&s, n)); + // The keyboard is the body's again. + try std.testing.expect((try s.cursor())[1] != (try s.where("Save Tty"))[1]); + } + try std.testing.expectEqual(@as(usize, 0), s.saved); + // A name alone is no edit: the pane stays clean. + try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n"); +} + +test "tags: a drafted name's edits are by grapheme, and an empty one is not committed" { + var s = try Session.initFile(std.testing.allocator, "untouched\n"); + defer s.deinit(); + const n = try s.focused(); + try clickPathEnd(&s, "/test.txt"); + try s.keys("\x15/café界\x08"); + _ = try s.where("/café Save"); + try s.keys("\x08"); + _ = try s.where("/caf Save"); + try s.keys("\x15\n"); + try std.testing.expectError(error.NotOnScreen, s.where("/test.txt")); + try s.expect(s.at("/pane/{d}/name", .{n}), "/test.txt\n"); + try s.expect(s.at("/pane/{d}/body", .{n}), "untouched\n"); + // Esc keeps the draft pending; a second drops it. + try s.keys("\x1b"); + try std.testing.expectError(error.NotOnScreen, s.where("/test.txt")); + try s.keys("\x1b"); + _ = try s.where("/test.txt"); +} + +test "tags: leaving a pane or entering a header drops an uncommitted name" { + for ([_]bool{ false, true }) |header| { + var s = try Session.initFile(std.testing.allocator, "untouched\n"); + defer s.deinit(); + const n = try s.focused(); + try clickPathEnd(&s, "/test.txt"); + try s.keys("\x15/draft"); + _ = try s.where("/draft"); + if (header) try s.click("Newcol", 1, 1) else _ = try s.newPane(); + try std.testing.expectError(error.NotOnScreen, s.where("/draft")); + try s.expect(s.at("/pane/{d}/name", .{n}), "/test.txt\n"); + } +} + +test "tags: middle clicking Save commits the drafted name before saving" { + var s = try Session.initFile(std.testing.allocator, "untouched\n"); + defer s.deinit(); + const n = try s.focused(); + try clickPathEnd(&s, "/test.txt"); + try s.keys("\x15/renamed.txt"); + try s.click("Save Tty", 0, 2); + try s.expect(s.at("/pane/{d}/name", .{n}), "/renamed.txt\n"); + try std.testing.expectEqualStrings("/renamed.txt Save Tty Collapse Del", try tag(&s, n)); + try s.expect(s.at("/pane/{d}/body", .{n}), "untouched\n"); + try std.testing.expectEqual(@as(usize, 1), s.saved); +} + +test "tags: an oversized drafted name is refused at commit and the draft stays to correct" { + var s = try Session.initFile(std.testing.allocator, "untouched\n"); + defer s.deinit(); + const n = try s.focused(); + try clickPathEnd(&s, "/test.txt"); + const excess = s.at("\x15/{s}\n", .{&@as([4999]u8, @splat('x'))}); + try s.keys(excess); + try s.expect(s.at("/pane/{d}/name", .{n}), "/test.txt\n"); + try s.expect(s.at("/pane/{d}/body", .{n}), "untouched\n"); + _ = try s.where("/xxxx"); +} diff --git a/test/panes.zig b/test/panes.zig index e1be67b9..db816d41 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -182,120 +182,6 @@ fn tagY(p: *Pardes, r: anytype) u16 { return p.tagTop(paneAt(p, r), r); } -test "a tag with a newline in it is as tall as its lines, and each line is typed into and pointed at" { - for ([_]bool{ false, true }) |bottom| { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 14 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.presentation.enabled = false; - p.settings.tag_bottom = bottom; - p.update(.tick); - try std.testing.expectEqual(@as(u16, 1), pane.tag_rows); - const height = p.rects[0].h; - const body_rows = pane.rows; - // Insert mode in a tag is a body's: Enter is a new line. - p.update(.{ .key = .{ .cp = ':' } }); - p.update(.{ .key = .{ .cp = 'A' } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - p.update(.{ .key = .{ .cp = 'S', .text = "Second" } }); - try std.testing.expect(std.mem.endsWith(u8, pardes.tagline.curTail(pane), "\nSecond")); - try std.testing.expectEqual(@as(u16, 2), pane.tag_rows); - // The pane keeps its height; the body gives the tag its row. - try std.testing.expectEqual(height, p.rects[0].h); - try std.testing.expectEqual(body_rows - 1, pane.rows); - var frame = std.heap.ArenaAllocator.init(std.testing.allocator); - defer frame.deinit(); - const surface = try p.render(frame.allocator()); - const r = p.rects[0]; - const tag_y = p.tagTop(pane, r); - const x = r.x + pardes.TAG_TEXT_INSET; - try std.testing.expectEqualStrings("/", surface.at(x, tag_y).grapheme()); - for ("Second", 0..) |byte, i| try std.testing.expectEqual(byte, surface.at(x + @as(u16, @intCast(i)), tag_y + 1).text[0]); - try std.testing.expectEqual(pardes.FontRole.tagline, surface.at(x, tag_y + 1).style.font_role); - // the caret is on the second line, after what was typed - try std.testing.expectEqual(tag_y + 1, surface.cursor.?.y); - try std.testing.expectEqual(x + 6, surface.cursor.?.x); - // the body starts under (or over) the whole tag - const body_y = p.bodyTop(pane, r); - try std.testing.expectEqual(if (bottom) r.y else r.y + 2, body_y); - try std.testing.expectEqualStrings("b", surface.at(r.x + config.GUTTER + panes.File.gutterWidth(pane), body_y).grapheme()); - // one layer, a row to each line, for a pixel shell - var layers: usize = 0; - for (p.surface.tagLayers()) |*layer| { - if (layer.rows == 0 or layer.kind != .pane or layer.id != 0) continue; - try std.testing.expectEqual(tag_y, layer.viewport.y); - try std.testing.expectEqual(@as(u16, 2), layer.rows); - try std.testing.expectEqual(@as(u16, 2), layer.viewport.h); - layers += 1; - } - try std.testing.expectEqual(@as(usize, 1), layers); - // a click on the second line puts the tag's cursor on it - p.update(.{ .key = .{ .cp = Key.escape } }); - p.update(.{ .key = .{ .cp = ':' } }); - ClickCursorTests.click(p, .left, x + 2, tag_y + 1); - try std.testing.expect(pane.focus == .tag); - try std.testing.expectEqual(@as(i32, 1), pane.tag.cur_row); - try std.testing.expectEqual(@as(i32, 2), pane.tag.cur_col); - // and the pane's text, a row to a screen row, has both of its lines - const text = try pardes.edit.paneText(p, pane); - try std.testing.expect(std.mem.startsWith(u8, modal.lineSlice(text, 0), "/test.txt")); - try std.testing.expectEqualStrings("Second", modal.lineSlice(text, 1)); - try std.testing.expectEqualStrings("body\n", pane.file.?.content); - } -} - -test "a tag with more lines than rows scrolls to keep its caret in view" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 30 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.presentation.enabled = false; - var many: std.ArrayList(u8) = .empty; - defer many.deinit(std.testing.allocator); - for (1..21) |n| try many.print(std.testing.allocator, "\nL{d}", .{n}); - try pane.appendTag(many.items); - p.update(.tick); - try std.testing.expectEqual(@as(u16, pardes.MAX_TAG_ROWS), pane.tag_rows); - var frame = std.heap.ArenaAllocator.init(std.testing.allocator); - defer frame.deinit(); - const r = p.rects[0]; - const x = r.x + pardes.TAG_TEXT_INSET; - // To the last line: the tag scrolls so it is the bottom row, caret on it. - p.update(.{ .key = .{ .cp = ':' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'e' } }); - try std.testing.expectEqual(@as(i32, 20), pane.tag.cur_row); - const bottom = try p.render(frame.allocator()); - const tag_y = p.tagTop(pane, r); - const last_row = tag_y + pardes.MAX_TAG_ROWS - 1; - try std.testing.expectEqual(last_row, bottom.cursor.?.y); - try std.testing.expectEqualStrings("L", bottom.at(x, last_row).grapheme()); - try std.testing.expectEqualStrings("2", bottom.at(x + 1, last_row).grapheme()); - try std.testing.expectEqualStrings("0", bottom.at(x + 2, last_row).grapheme()); - // what the pointer sees is what is shown: its first row is line 13 - const text = try pardes.edit.paneText(p, pane); - try std.testing.expectEqualStrings("L13", modal.lineSlice(text, 0)); - ClickCursorTests.click(p, .left, x + 1, tag_y + 1); - try std.testing.expectEqual(@as(i32, 14), pane.tag.cur_row); - try std.testing.expectEqual(@as(i32, 1), pane.tag.cur_col); - // Back to the first line brings the prefix back into view. - p.update(.{ .key = .{ .cp = Key.escape } }); - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - const top = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(u16, 0), pane.tag_top); - try std.testing.expectEqual(tag_y, top.cursor.?.y); - try std.testing.expectEqualStrings("/", top.at(x, tag_y).grapheme()); - - // A column tag is one row, as acme's: its lines are joined. - many.clearRetainingCapacity(); - try many.appendSlice(std.testing.allocator, "New"); - for (1..21) |n| try many.print(std.testing.allocator, "\nC{d}", .{n}); - p.col_tags[0].own = try p.gpa.dupe(u8, many.items); - p.update(.tick); - try std.testing.expectEqual(pardes.COLBAR_H, p.columnBarHeight()); - try std.testing.expect(std.mem.indexOfScalar(u8, p.col_tags[0].own.?, '\n') == null); -} - const BodyHitTests = struct { fn mouse(layer: *const pardes.Layer, row: u16, col: u16, kind: pardes.Mouse.Kind) pardes.Mouse { const width: f32 = if (row < layer.context_rows) 8 else 10; @@ -1147,138 +1033,6 @@ fn redraft(pane: *Pane, name: []const u8) void { pane.input.cur_col = @intCast(name.len); } -/// Click the tagline at the end of the path: a name draft, caret there. -fn clickPathEnd(p: *Pardes, pane: *Pane) void { - const rect = p.rects[p.active]; - const y = tagY(p, rect); - const x = rect.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(pane.file.?.path) - 1)); - ClickCursorTests.click(p, .left, x, y); - std.debug.assert(pane.prompt == .name); - pane.input.cur_col = @intCast(pane.input.own.?.len); -} - -test "pane filename drafts commit and cancel without changing body or command tail" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 70, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("original body\n"); - const original = try p.gpa.dupe(u8, pane.file.?.path); - defer p.gpa.free(original); - try pane.appendTag(" SyntaxBold"); - const tail = try p.gpa.dupe(u8, pardes.tagline.curTail(pane)); - defer p.gpa.free(tail); - for ([_]bool{ false, true }) |commit| { - clickPathEnd(p, pane); - p.update(.{ .key = .{ .cp = 'u', .ctrl = true } }); - p.update(.{ .paste = "/new name.zig" }); - try std.testing.expectEqualStrings(original, pane.file.?.path); - try std.testing.expectEqualStrings("/new name.zig", pane.input.own.?); - try std.testing.expectEqualStrings(tail, pardes.tagline.curTail(pane)); - try std.testing.expectEqualStrings("original body\n", pane.file.?.content); - // Esc keeps the draft pending; a second drops it. - p.update(.{ .key = .{ .cp = if (commit) Key.enter else Key.escape } }); - if (!commit) p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.focus == .body); - try std.testing.expect(pane.prompt == .none); - try std.testing.expectEqualStrings(if (commit) "/new name.zig" else original, pane.file.?.path); - try std.testing.expectEqualStrings(tail, pardes.tagline.curTail(pane)); - while (p.nextEffect()) |effect| try std.testing.expect(std.meta.activeTag(effect) != .save_file); - } - // A name alone is no edit: the pane stays clean. - try std.testing.expect(pane.file.?.revision == pane.file.?.saved_revision); -} - -test "pane filename grapheme edits and invalid empty commits preserve the buffer" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("untouched\n"); - clickPathEnd(p, pane); - p.update(.{ .key = .{ .cp = 'u', .ctrl = true } }); - p.update(.{ .paste = "/café界" }); - p.update(.{ .key = .{ .cp = Key.backspace } }); - try std.testing.expectEqualStrings("/café", pane.input.own.?); - p.update(.{ .key = .{ .cp = Key.backspace } }); - try std.testing.expectEqualStrings("/caf", pane.input.own.?); - p.update(.{ .key = .{ .cp = 'u', .ctrl = true } }); - try std.testing.expectEqualStrings("", pane.input.own.?); - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expect(pane.prompt == .name); - try std.testing.expectEqualStrings("/test.txt", pane.file.?.path); - try std.testing.expectEqualStrings("untouched\n", pane.file.?.content); - // Esc keeps the draft pending; a second drops it. - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt == .name); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt == .none); -} - -test "leaving a pane or entering a header cancels an uncommitted filename" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("untouched\n"); - for ([_]bool{ false, true }) |header| { - p.active = 0; - pardes.tagline.exitHeader(p); - p.update(.tick); - clickPathEnd(p, pane); - p.update(.{ .paste = "/draft" }); - try std.testing.expect(pane.prompt == .name); - if (header) { - pardes.tagline.enterHeader(p, null); - p.update(.tick); - } else { - try std.testing.expect(p.executeBuiltinLine(0, "New")); - p.update(.tick); - } - try std.testing.expect(pane.prompt == .none); - try std.testing.expect(pane.focus == .body); - try std.testing.expectEqualStrings("/test.txt", pane.file.?.path); - } -} - -test "middle clicking Save commits the drafted filename before issuing a save" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 70, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("untouched\n"); - clickPathEnd(p, pane); - p.update(.{ .key = .{ .cp = 'u', .ctrl = true } }); - p.update(.{ .paste = "/renamed.txt" }); - var arena = std.heap.ArenaAllocator.init(p.gpa); - defer arena.deinit(); - _ = try p.render(arena.allocator()); - const text = try pardes.tagline.tagText(p, arena.allocator(), pane); - const save_at = std.mem.indexOf(u8, text, "Save").?; - const x: u16 = @intCast(p.rects[0].x + pardes.TAG_TEXT_INSET + save_at - pane.tag_scroll); - const y = p.rects[0].y; - while (p.nextEffect()) |_| {} - p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .press } }); - p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .release } }); - try std.testing.expectEqualStrings("/renamed.txt", pane.file.?.path); - try std.testing.expect(pane.prompt == .none); - try std.testing.expectEqualStrings("untouched\n", pane.file.?.content); - var saves: usize = 0; - while (p.nextEffect()) |effect| if (effect == .save_file) { - try std.testing.expectEqual(@as(u8, 0), effect.save_file.pane); - saves += 1; - }; - try std.testing.expectEqual(@as(usize, 1), saves); -} - -test "an oversized drafted name is refused at commit and the draft stays to correct" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("untouched\n"); - clickPathEnd(p, pane); - const excess = try p.gpa.alloc(u8, 5000); - defer p.gpa.free(excess); - @memset(excess, 'x'); - excess[0] = '/'; - p.update(.{ .paste = excess }); - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expect(pane.prompt == .name); - try std.testing.expectEqualStrings("/test.txt", pane.file.?.path); - try std.testing.expectEqualStrings("untouched\n", pane.file.?.content); -} - test "paste into pane commands and prompts never inserts into the body" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); @@ -1324,60 +1078,6 @@ test "a tag that exactly fills its row stays one row, its caret at the edge as a try std.testing.expectEqual(p.rects[0].x + p.rects[0].w - 1, surface.cursor.?.x); } -test "a long pane tag wraps onto rows, and a click on a wrapped row maps to the whole tag's address" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 50, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.gpa.free(pane.file.?.path); - pane.file.?.path = try p.gpa.dupe(u8, "/an/especially/deep/project/path/with/a/long/component/filename.zig"); - try pane.appendTag(" SyntaxBold"); - p.update(.{ .key = .{ .cp = ':' } }); - p.update(.{ .key = .{ .cp = 'A' } }); - var arena = std.heap.ArenaAllocator.init(p.gpa); - defer arena.deinit(); - const surface = try p.render(arena.allocator()); - try std.testing.expect(pane.tag_rows > 1); - try std.testing.expect(surface.cursor.?.x < p.rects[0].x + p.rects[0].w); - const text = try pardes.tagline.tagText(p, p.gpa, pane); - defer p.gpa.free(text); - const shown = try pardes.tagline.shownTag(p, arena.allocator(), pane); - const at = shown.fromReal(std.mem.indexOf(u8, text, "SyntaxBold").?); - const pos = modal.positionAt(shown.text, at); - const x: u16 = @intCast(p.rects[0].x + pardes.TAG_TEXT_INSET + panes.File.rawDisplayCol(modal.lineSlice(shown.text, pos.row), pos.col)); - const y = p.tagTop(pane, p.rects[0]) + @as(u16, @intCast(pos.row)); - const before = p.settings.syntax_bold; - p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .press } }); - p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .release } }); - try std.testing.expectEqual(!before, p.settings.syntax_bold); - try std.testing.expectEqualStrings(text, try pardes.tagline.tagText(p, p.scratch.allocator(), pane)); -} - -test "a word the tag's wrapping breaks across rows is still one word to a click" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 50, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - try pane.appendTag(" SyntaxBold"); - var arena = std.heap.ArenaAllocator.init(p.gpa); - defer arena.deinit(); - // Lengthen the path until the wrap splits the word after "Synt". - var pad: usize = 1; - const shown = while (pad < 80) : (pad += 1) { - p.gpa.free(pane.file.?.path); - const path = try std.fmt.allocPrint(arena.allocator(), "/{s}/f.zig", .{(&@as([80]u8, @splat('a')))[0..pad]}); - pane.file.?.path = try p.gpa.dupe(u8, path); - p.sync(); - const s = try pardes.tagline.shownTag(p, arena.allocator(), pane); - if (std.mem.indexOf(u8, s.text, "Synt\n") != null) break s; - } else return error.NoSplit; - const pos = modal.positionAt(shown.text, std.mem.indexOf(u8, shown.text, "Synt").?); - const x: u16 = @intCast(p.rects[0].x + pardes.TAG_TEXT_INSET + pos.col + 1); - const y = p.tagTop(pane, p.rects[0]) + @as(u16, @intCast(pos.row)); - const before = p.settings.syntax_bold; - p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .press } }); - p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .release } }); - try std.testing.expectEqual(!before, p.settings.syntax_bold); -} - test "terminal overlay recoloring never materializes unrelated history" { const testing = std.testing; const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 32, .rows = 8 }); @@ -1648,86 +1348,6 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv try std.testing.expectEqualStrings("kept edit", pane.ovl.?.text); } -test "a prompt's entry and cancellation leave the tag, the body and its cursor as they were" { - const Case = struct { key: ?Key = null, save: bool = false, marker: []const u8 }; - const cases = [_]Case{ - .{ .marker = config.search_marker }, - .{ .save = true, .marker = config.save_marker ++ "/dír space/" }, - .{ .key = .{ .cp = '|' }, .marker = config.pipe_marker }, - .{ .key = .{ .cp = '|', .alt = true }, .marker = config.pipe_marker_to }, - .{ .key = .{ .cp = '!' }, .marker = config.pipe_marker_insert }, - .{ .key = .{ .cp = '!', .alt = true }, .marker = config.pipe_marker_append }, - }; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("one\ntwo\n"); - try pane.setOwnedCwd("/dír space"); - const tail = " keep"; - for (cases) |case| { - try setTag(pane, tail); - pane.body.cur_row = 1; - pane.body.cur_col = 2; - pane.body.cur_pinned = true; - if (case.key) |key| { - p.update(.{ .key = key }); - } else if (case.save) { - p.startPrompt(pane, &pane.body, .save); - } else { - p.startPrompt(pane, &pane.body, .{ .search = config.search_marker }); - } - // The answer is typed into the prompt's own line, never the tag. - try std.testing.expect(pane.focus == .body); - try std.testing.expectEqual(.insert, pane.input.mode); - try std.testing.expectEqualStrings(case.marker, pane.promptText().?); - try std.testing.expectEqual(@as(i32, @intCast(case.marker.len)), pane.input.cur_col); - try std.testing.expectEqualStrings(tail, pane.tag.own.?); - try std.testing.expectEqualDeep(modal.Normal.State{}, pane.body.normal); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt == .none); - try std.testing.expect(pane.input.own == null); - try std.testing.expectEqual(.normal, pane.body.mode); - try std.testing.expectEqualStrings(tail, pane.tag.own.?); - try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); - try std.testing.expectEqual(@as(i32, 2), pane.body.cur_col); - try std.testing.expectEqualStrings("one\ntwo\n", pane.file.?.content); - } -} - -test "a prompt opens whatever the tag already holds" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("one\n"); - const full = try p.gpa.alloc(u8, pardes.memory.limits.max_tag_tail); - defer p.gpa.free(full); - @memset(full, 'x'); - try setTag(pane, full); - for (0..3) |case| { - switch (case) { - 0 => p.startPrompt(pane, &pane.body, .{ .search = config.search_marker }), - 1 => p.startPrompt(pane, &pane.body, .save), - else => p.update(.{ .key = .{ .cp = '|' } }), - } - try std.testing.expect(pane.prompt != .none); - try std.testing.expectEqualStrings(full, pane.tag.own.?); - p.update(.{ .key = .{ .cp = Key.escape } }); - } -} - -test "generated output refuses every pipe prompt before seeding the tag" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const content = try p.gpa.dupe(u8, "generated\n"); - const pane = try panes.Output.open(p, p.freeSlot().?, "/", .{ .cmd = .Help }, "", content); - p.active = 1; - for ([_]Key{ .{ .cp = '|' }, .{ .cp = '|', .alt = true }, .{ .cp = '!' }, .{ .cp = '!', .alt = true } }) |key| { - p.update(.{ .key = key }); - try std.testing.expect(pane.prompt == .none); - try std.testing.expect(pane.tag.own == null); - try std.testing.expect(pane.focus == .body); - try std.testing.expectEqualStrings("generated\n", pane.file.?.content); - } -} - test "a prompt owns the pipe behavior through cancellation and submission" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); @@ -1755,34 +1375,6 @@ test "a prompt owns the pipe behavior through cancellation and submission" { } } -test "prompt cancellation restores the selection before regex previews" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("one two one"); - const cases = [_]struct { key: u21, pattern: []const u8, secondary: u8 }{ - .{ .key = 's', .pattern = "one", .secondary = 1 }, - .{ .key = 'S', .pattern = " ", .secondary = 2 }, - }; - for (cases) |case| { - pane.body.cur_row = 0; - pane.body.cur_col = 10; - pane.body.cur_pinned = true; - pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; - pane.body.nsel = 0; - p.update(.{ .key = .{ .cp = case.key } }); - try std.testing.expect(pane.prompt == .search); - p.update(.{ .key = .{ .cp = case.pattern[0], .text = case.pattern } }); - try std.testing.expectEqual(case.secondary, pane.body.nsel); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); - try std.testing.expectEqual(@as(u16, 0), pane.nsel_snap); - try std.testing.expectEqual(@as(i32, 10), pane.body.cur_col); - try std.testing.expectEqual(@as(i32, 0), pane.body.vsel.col); - try std.testing.expect(pane.body.vsel.active and pane.body.vsel.explicit); - try std.testing.expectEqualStrings("one two one", pane.file.?.content); - } -} - test "a prompt that cannot be opened leaves the open one as it was" { const Request = @typeInfo(@TypeOf(Pardes.startPrompt)).@"fn".param_types[3].?; for ([_]Request{ .{ .search = config.search_marker }, .save, .{ .pipe = .replace }, .{ .pipe = .ignore }, .{ .pipe = .insert }, .{ .pipe = .append } }) |request| { @@ -4162,83 +3754,6 @@ test { _ = TerminalTests; } -test "an empty counted paste leaves no count for the next motion" { - for ([_]bool{ false, true }) |empty_register| { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("abcdefgh\n"); - if (empty_register) p.registers.put(p.gpa, '"', "", 0, 1, true); - for ("3p") |cp| p.update(.{ .key = .{ .cp = cp } }); - try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal); - p.update(.{ .key = .{ .cp = 'l' } }); - try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); - try std.testing.expectEqualStrings("abcdefgh\n", pane.file.?.content); - } -} - -test "cancelled normal gestures leave no count or subprefix after mouse and focus changes" { - const Gesture = enum { body, tag, focus, last }; - for ([_][]const u8{ "3", "3g", "mr(" }) |keys| { - for ([_]Gesture{ .body, .tag, .focus, .last }) |gesture| { - errdefer std.debug.print("\nkeys={s} gesture={s}\n", .{ keys, @tagName(gesture) }); - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 16 }); - defer p.deinit(); - const pane = try p.setTestFile("abcdefghij\n"); - p.settings.colors = false; - p.presentation.enabled = false; - try std.testing.expect(p.executeBuiltinLine(0, "New")); - const other = p.active; - try std.testing.expect(layout.splitColumn(p, other, other, false)); - p.active = 0; - p.update(.tick); - var frame = std.heap.ArenaAllocator.init(std.testing.allocator); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - for (keys) |cp| p.update(.{ .key = .{ .cp = cp } }); - try std.testing.expect(!std.meta.eql(modal.Normal.State{}, pane.body.normal)); - switch (gesture) { - .body, .tag => { - const rect = p.rects[0]; - const tag_y = tagY(p, rect); - const body_y = p.bodyTop(pane, rect); - const x = if (gesture == .tag) - rect.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(try pardes.tagline.tagPrefix(p, pane)))) + 3 - else - rect.x + config.GUTTER + @as(u16, @intCast(panes.File.gutterWidth(pane))) + 3; - const y = if (gesture == .tag) tag_y else body_y; - p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x, .row = y } }); - p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x, .row = y } }); - if (gesture == .tag) { - try std.testing.expect(pane.focus == .tag); - p.update(.{ .key = .{ .cp = Key.escape } }); - p.update(.{ .key = .{ .cp = ':' } }); - try std.testing.expect(pane.focus == .body); - } - }, - .focus, .last => { - p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - p.update(.{ .key = .{ .cp = 'l' } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqual(other, p.active); - if (gesture == .last) { - p.update(.{ .key = .{ .cp = Key.escape } }); - } else { - p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - p.update(.{ .key = .{ .cp = 'h' } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - } - try std.testing.expectEqual(@as(usize, 0), p.active); - }, - } - try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal); - const col = pane.body.cur_col; - p.update(.{ .key = .{ .cp = 'l' } }); - try std.testing.expectEqual(col + 1, pane.body.cur_col); - try std.testing.expectEqualStrings("abcdefghij\n", pane.file.?.content); - } - } -} - test "cancelled normal gestures leave no count or subprefix through raw tty mode" { for ([_][]const u8{ "3", "3g", "mr(" }) |keys| { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 12 }); @@ -4503,78 +4018,6 @@ const LookResetTests = struct { for (pane.sel) |selection| try std.testing.expectEqual(.none, selection.state); for (pane.pointer_selections) |selection| try std.testing.expect(selection == null); } - - fn selected(pane: *const Pane) []const u8 { - if (!pane.body.vsel.active or pane.body.cur_row != pane.body.vsel.row) return ""; - const line = modal.lineSlice(pane.file.?.content, @intCast(pane.body.cur_row)); - const lo: usize = @intCast(@min(pane.body.cur_col, pane.body.vsel.col)); - const hi: usize = @intCast(@max(pane.body.cur_col, pane.body.vsel.col)); - return line[lo..modal.nextGrapheme(line, hi)]; - } - - test "Look replaces old selection for same-pane addresses ranges and text fallback" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - const pane = try p.setTestFile("alpha\nbravo\ncharlie\nneedle\n"); - try seed(pane, "/test.txt:3:2"); - // This operand is released by Look's selection cleanup. - pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); - try cleared(pane); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); - try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); - try std.testing.expect(!pane.body.vsel.active); - - try seed(pane, "/test.txt:2:2-4"); - pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); - try cleared(pane); - try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); - try std.testing.expectEqualStrings("rav", selected(pane)); - - p.gpa.free(pane.file.?.path); - pane.file.?.path = try p.gpa.dupe(u8, "/tmp/look-selection-source.txt"); - try seed(pane, "needle"); - pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?); - try cleared(pane); - try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row); - try std.testing.expectEqualStrings("needle", selected(pane)); - } - - test "Look clears the source's click highlight, not its dot, and the destination's selections before focus" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); - defer p.deinit(); - const source = try p.setTestFile("source\nlines\n"); - const id = p.freeSlot().?; - const destination = try p.newDocPane(id); - destination.file = .{ - .path = try p.gpa.dupe(u8, "/look-destination.txt"), - .content = try p.gpa.dupe(u8, "alpha\nbravo\ncharlie\n"), - .history = try panes.File.History.create(p.gpa), - }; - layout.insert(p, 0, 1, id); - layout.compute(p); - for ([_]bool{ false, true }) |range| { - p.active = 0; - try seed(source, if (range) "/look-destination.txt:2:2-4" else "/look-destination.txt:3:2"); - try seed(destination, "previous destination"); - pardes.look.lookAt(p, 0, source.pointer_selections[0].?.raw_text.?); - try std.testing.expectEqual(id, p.active); - // The source keeps its dot (acme's look leaves it); the click's - // highlight goes. - for (source.sel) |selection| try std.testing.expectEqual(.none, selection.state); - for (source.pointer_selections) |selection| try std.testing.expect(selection == null); - try std.testing.expect(source.body.vsel.active); - try cleared(destination); - if (range) { - try std.testing.expectEqual(@as(i32, 1), destination.body.cur_row); - try std.testing.expectEqualStrings("rav", selected(destination)); - } else { - try std.testing.expectEqual(@as(i32, 2), destination.body.cur_row); - try std.testing.expectEqual(@as(i32, 1), destination.body.cur_col); - try std.testing.expect(!destination.body.vsel.active); - } - } - } }; test { -- cgit v1.3