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/panes.zig | 557 --------------------------------------------------------- 1 file changed, 557 deletions(-) (limited to 'test/panes.zig') 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