From 63e62131aaedb91a8fa995b8e00ced808e053519 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:01:04 -0300 Subject: test: five of test/panes.zig's mouse tests through the 9P tree alone (test/behaviour/mouse.zig, guide.typ's The mouse): a double-click's word, bracketed, quoted and line selections (read from sel) and in a tag (yanked and pasted into the body), a B1 chord's cut and paste one undo step (one Undo gives back the text before the cut), a click past a line's or the file's end and on a tab's or a wide glyph's second cell (dot, then the Z insert types), a B1 sweep over several lines a stream in a body and a tag (a B1-B2 cut of it); Session.where, the screen cell text is first drawn at; each checked to fail against a break (double-click selecting nothing, chord_hold no longer folding the chord's undo steps, the click clamp a column short of the line's end, every grapheme one cell wide to a click, a sweep's start at the lesser of its two columns) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour.zig | 1 + 1 file changed, 1 insertion(+) (limited to 'test/behaviour.zig') diff --git a/test/behaviour.zig b/test/behaviour.zig index 32138f94..46fa8402 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -6,6 +6,7 @@ test { _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); _ = @import("behaviour/look_and_exec.zig"); + _ = @import("behaviour/mouse.zig"); _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/root_ctl.zig"); -- cgit v1.3 From 5322d373c78ecee48b934886c95f3b8c4471a11f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:04:29 -0300 Subject: test: five of test/pdf.zig's tests through the 9P tree alone: a PDF's body a line for each line of its page's text (panes), PdfTint stepped in its ctl and never in its tag, refused at another pane (panes), PdfSections on a PDF with no outline opening nothing (panes, a PDF written by the test), /recent keeping a PDF open then closed (other_files), the pages a PDF shown as text turns for j/k, Ctrl-d/u/f/b, ge, gg, 3gg, 2G and the editing keys consumed (keys, a new file); the parts with no surface stay as two small tests (tint colours of a theme with none, `:`/SPC/`/` on a PDF); each checked to fail against a break (the page text's newline a blank, toggleTint not stepping, the no-outline check dropped, a PDF given no Recent place, a counted text-mode j taking half its count) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour.zig | 1 + test/behaviour/keys.zig | 27 +++++++ test/behaviour/other_files.zig | 10 +++ test/behaviour/panes.zig | 69 ++++++++++++++++ test/pdf.zig | 173 +---------------------------------------- 5 files changed, 109 insertions(+), 171 deletions(-) create mode 100644 test/behaviour/keys.zig (limited to 'test/behaviour.zig') diff --git a/test/behaviour.zig b/test/behaviour.zig index 32138f94..3e377ed7 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/other_files.zig"); _ = @import("behaviour/panes.zig"); diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig new file mode 100644 index 00000000..3d6fdf31 --- /dev/null +++ b/test/behaviour/keys.zig @@ -0,0 +1,27 @@ +//! docs/typ/guide.typ, Keys . +const std = @import("std"); +const Session = @import("session").Session; + +test "keys: a PDF shown as text turns pages for the moving keys, counted, and the editing keys do nothing" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const pages = (try s.pdfPage(n))[1]; + try std.testing.expect(pages > 3); + // j k, Ctrl-d Ctrl-u, Ctrl-f Ctrl-b: a page each, counted. + for ([_][]const u8{ "2j", "2k", "2\x04", "2\x15", "2\x06", "2\x02" }, 0..) |keys, i| { + try s.keys(keys); + try std.testing.expectEqual(@as(u32, if (i % 2 == 0) 3 else 1), (try s.pdfPage(n))[0]); + } + for ([_]struct { []const u8, u32 }{ .{ "ge", pages }, .{ "gg", 1 }, .{ "3gg", 3 }, .{ "2G", 2 } }) |step| { + try s.keys(step[0]); + try std.testing.expectEqual(step[1], (try s.pdfPage(n))[0]); + } + // Consumed, with their count: the page stays, no selection begins, and + // the next j is one page. + try s.keys("4dv|"); + try std.testing.expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal ")); + try s.keys("j"); + try std.testing.expectEqual(@as(u32, 3), (try s.pdfPage(n))[0]); +} diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index c0f9c08f..e778ad77 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -28,3 +28,13 @@ test "other-files: kbdin's Kalt rune is Alt on the key after it alone, and an Al try s.keys("i\u{F015}zy\x1b"); try s.expect(s.at("/pane/{d}/body", .{try s.focused()}), "yx\n"); } + +test "other-files: /recent keeps a PDF as it keeps a file: open, then closed" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("open {s}\n", .{name})) != null); + try s.write(s.at("/pane/{d}/ctl", .{n}), "Del\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("closed {s}\n", .{name})) != null); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 01820a07..8a906c2b 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -49,3 +49,72 @@ test "panes: Putall saves every pane with unsaved edits to a file, one each, and try s.write("/ctl", "Putall\n"); try std.testing.expectEqual(@as(usize, 1), s.saved); } + +/// `name` in `dir`: a one-page PDF with no outline and no text. +fn plainPdf(dir: std.Io.Dir, name: []const u8) !void { + const objects = [_][]const u8{ + "<< /Type /Catalog /Pages 2 0 R >>", + "<< /Type /Pages /Count 1 /Kids [3 0 R] >>", + "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 300] /Resources << >> >>", + }; + var buf: [1024]u8 = undefined; + var w: std.Io.Writer = .fixed(&buf); + var at: [objects.len]usize = undefined; + try w.writeAll("%PDF-1.4\n"); + for (objects, 0..) |object, i| { + at[i] = w.end; + try w.print("{d} 0 obj\n{s}\nendobj\n", .{ i + 1, object }); + } + const xref = w.end; + try w.print("xref\n0 {d}\n0000000000 65535 f \n", .{objects.len + 1}); + for (at) |off| try w.print("{d:0>10} 00000 n \n", .{off}); + try w.print("trailer\n<< /Size {d} /Root 1 0 R >>\nstartxref\n{d}\n%%EOF\n", .{ objects.len + 1, xref }); + try dir.writeFile(std.testing.io, .{ .sub_path = name, .data = w.buffered() }); +} + +test "panes: a PDF's body is the text of the page shown, each line of it a line, never a heading run into the text under it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const body = s.at("/pane/{d}/body", .{n}); + try std.testing.expect(std.mem.startsWith(u8, try s.read(body), "Pardes: A Text Environment\nArchitecture and implementation of the rewrite\n")); + try s.write(s.at("/pane/{d}/look", .{n}), ":2\n"); + try std.testing.expect(!std.mem.startsWith(u8, try s.read(body), "Pardes: A Text Environment\n")); +} + +test "panes: PdfTint steps a PDF's tint, read in its ctl and never in its tag, and only a PDF pane takes it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const text = try s.focused(); + const n = try s.lookFile("docs/design.pdf"); + const ctl = s.at("/pane/{d}/ctl", .{n}); + const tag = try s.read(s.at("/pane/{d}/tag", .{n})); + try std.testing.expect(std.mem.endsWith(u8, tag, " PdfSections PdfTint PdfFit Collapse Del")); + for ([_][]const u8{ "full", "disabled", "filtered" }) |want| { + try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), "fit:width ") != null); + try s.write(ctl, "PdfTint\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), s.at(" tint:{s} ", .{want})) != null); + try s.expect(s.at("/pane/{d}/tag", .{n}), tag); + // Another pane's PdfTint is refused and leaves the PDF's alone. + try std.testing.expectEqual(@as(u16, 5), try s.refused(s.at("/pane/{d}/ctl", .{text}), "PdfTint\n")); + try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), s.at(" tint:{s} ", .{want})) != null); + } +} + +test "panes: PdfSections on a PDF with no outline says so and opens nothing" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try plainPdf(tmp.dir, "plain.pdf"); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile(s.at("{s}/plain.pdf", .{dir})); + try std.testing.expectEqual(@as(u32, 1), (try s.pdfPage(n))[1]); + const index = try s.read("/index"); + for (0..2) |_| { + _ = try s.refused(s.at("/pane/{d}/exec", .{n}), "PdfSections\n"); + try s.expect("/index", index); + } + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "PdfSections: this PDF has no outline") != null); +} diff --git a/test/pdf.zig b/test/pdf.zig index 4d387a4c..a068fc40 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -278,19 +278,6 @@ test "PDF feature gates keep argv and builtin behavior coherent" { } } -test "a PDF's body puts each line of its text on a line of its own, never a heading run into the text under it" { - if (!pdf_enabled or platform == .web) return; - var tmp = std.testing.tmpDir(.{}); - defer tmp.cleanup(); - const p = try PdfLinkTests.init(tmp); - defer p.deinit(); - const text = p.panes[0].?.pdf.?.ensureText(p.pdf_gpa); - // The page's three text runs, each its own line. - try std.testing.expect(std.mem.indexOf(u8, text, "target.txt\n") != null); - try std.testing.expect(std.mem.indexOf(u8, text, "https://example.com/same\n") != null); - try std.testing.expect(std.mem.indexOf(u8, text, "label\n") != null); -} - test "PdfSections Look follows the exact owning PDF, not an equal path" { if (!pdf_enabled or platform == .web) return; const gpa = std.testing.allocator; @@ -340,49 +327,6 @@ test "PdfSections Look follows the exact owning PDF, not an equal path" { try std.testing.expectEqual(first_output_id, p.active); } -test "PdfSections on a PDF with no outline says so and opens nothing" { - if (!pdf_enabled or platform == .web) return; - const gpa = std.testing.allocator; - var tmp = std.testing.tmpDir(.{}); - defer tmp.cleanup(); - const fixture = try pdf_impl.makeNoOutlineTestPdf(gpa); - defer gpa.free(fixture); - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "plain.pdf", .data = fixture }); - var path_buf: [256]u8 = undefined; - const path = try std.fmt.bufPrint(&path_buf, ".zig-cache/tmp/{s}/plain.pdf", .{tmp.sub_path}); - const p = try Pardes.init(gpa, .{ .file = path }); - defer p.deinit(); - const pane = p.panes[0].?; - for (0..2) |_| { - panes.Pdf.openSections(p, 0); - try std.testing.expect(pane.search_pane == null); - try std.testing.expectEqualStrings("PdfSections: this PDF has no outline", pane.msg[0..pane.msg_len]); - } -} - -test "Recent keeps a PDF as it keeps a file: open, then closed at its page" { - if (!pdf_enabled or platform == .web) return; - const gpa = std.testing.allocator; - var tmp = std.testing.tmpDir(.{}); - defer tmp.cleanup(); - const fixture = try pdf_impl.makeNoOutlineTestPdf(gpa); - defer gpa.free(fixture); - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "plain.pdf", .data = fixture }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; - var path_buf: [4200]u8 = undefined; - const path = try std.fmt.bufPrint(&path_buf, "{s}/plain.pdf", .{dir}); - const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 28 }); - defer p.deinit(); - pardes.look.lookAt(p, p.active, path); - p.update(.{ .resize = .{ .cols = 80, .rows = 28 } }); // an update's end announces it - var out: std.Io.Writer.Allocating = .init(gpa); - defer out.deinit(); - try panes.Output.recentText(p, &out.writer, true); - var want: [4300]u8 = undefined; - try std.testing.expect(std.mem.indexOf(u8, out.written(), try std.fmt.bufPrint(&want, "{s}:1:1 open\n", .{path})) != null); -} - test "SDL PDF raster policy is materially denser than Kitty" { try std.testing.expect( pardes.sdl_pdf_raster_policy.dpi >= pardes.kitty_pdf_raster_policy.dpi * 2, @@ -1202,7 +1146,7 @@ fn copySourceRect( return out; } -test "PDF normal adapter consumes unsupported actions and navigates page fallback" { +test "PDF normal mode keeps `:`, SPC and `/` on their shared paths" { if (!pdf_enabled or platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ @@ -1212,61 +1156,8 @@ test "PDF normal adapter consumes unsupported actions and navigates page fallbac }); defer p.deinit(); const pane = p.panes[0].?; - const pv = &pane.pdf.?; - try std.testing.expect(pv.page_count > 3); p.native_images = false; - // Every vertical vocabulary falls back to counted page changes when the - // shell cannot place native pixels. - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'j' } }); - try std.testing.expectEqual(@as(usize, 2), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'k' } }); - try std.testing.expectEqual(@as(usize, 0), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'd', .ctrl = true } }); - try std.testing.expectEqual(@as(usize, 2), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'u', .ctrl = true } }); - try std.testing.expectEqual(@as(usize, 0), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'f', .ctrl = true } }); - try std.testing.expectEqual(@as(usize, 2), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); - try std.testing.expectEqual(@as(usize, 0), pv.page); - - // Prefix actions and the counted text goto-line action map to pages. - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'e' } }); - try std.testing.expectEqual(pv.page_count - 1, pv.page); - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - try std.testing.expectEqual(@as(usize, 0), pv.page); - p.update(.{ .key = .{ .cp = '3' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - try std.testing.expectEqual(@as(usize, 2), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'G' } }); - try std.testing.expectEqual(@as(usize, 1), pv.page); - - // Editing/selection actions are consumed no-ops: parser state clears, - // placeholder cells never acquire a range, and PDF state stays intact. - const page_before_noop = pv.page; - const revision_before_noop = pv.next_raster_revision; - p.update(.{ .key = .{ .cp = '4' } }); - p.update(.{ .key = .{ .cp = 'd' } }); - p.update(.{ .key = .{ .cp = 'v' } }); - p.update(.{ .key = .{ .cp = '|' } }); - try std.testing.expectEqual(page_before_noop, pv.page); - try std.testing.expectEqual(revision_before_noop, pv.next_raster_revision); - try std.testing.expectEqual(@as(u32, 0), pane.body.normal.count); - try std.testing.expectEqual(.none, pane.body.normal.prefix); - try std.testing.expect(!pane.body.vsel.active and !pane.body.msel.active and pane.body.nsel == 0); - try std.testing.expect(pane.focus == .body); - // Cross-pane BODY-NORMAL actions keep their established shared paths. p.update(.{ .key = .{ .cp = ':' } }); try std.testing.expect(pane.focus == .tag); @@ -1420,7 +1311,7 @@ test "PDF continuous strip renders every intersecting short page" { } } -test "PdfTint cycles pane-local state without adding tag clutter" { +test "PDF tint resolves a theme's null page colors to its chrome" { if (!pdf_enabled or platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ @@ -1429,66 +1320,6 @@ test "PdfTint cycles pane-local state without adding tag clutter" { .rows = 24, }); defer p.deinit(); - const pane = p.panes[0].?; - const pv = &pane.pdf.?; - const tint_builtin = std.meta.stringToEnum(Builtin, "PdfTint") orelse - return error.MissingPdfTintBuiltin; - - try std.testing.expectEqual(PdfTintMode.filtered, pv.tint); - const initial_tag = try pardes.tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expect(std.mem.startsWith(u8, initial_tag, pv.path)); - try std.testing.expect(std.mem.endsWith(u8, initial_tag, " PdfSections PdfTint PdfFit Collapse Del")); - try std.testing.expect(std.mem.indexOf(u8, initial_tag, "filtered") == null); - - try std.testing.expect(pardes.test_api.runBuiltin( - p, - @tagName(tint_builtin), - 0, - "", - null, - )); - try std.testing.expectEqual(PdfTintMode.full, pv.tint); - const full_tag = try pardes.tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expectEqualStrings(initial_tag, full_tag); - try std.testing.expect(std.mem.indexOf(u8, full_tag, "full") == null); - - // Running the same pane-scoped word in a terminal cannot mutate the PDF - // next to it. A FILE boot is one pane now, so that terminal is asked for - // here rather than inherited from init. - _ = try p.newShell(1, ""); - _ = layout.splitColumn(p, 0, 1, false); - p.sync(); // rects for the new column, exactly as the two-pane boot did - try std.testing.expect(!hasPdf(p.panes[1].?)); - try std.testing.expect(pardes.test_api.runBuiltin( - p, - @tagName(tint_builtin), - 1, - "", - null, - )); - try std.testing.expectEqual(PdfTintMode.full, pv.tint); - - try std.testing.expect(pardes.test_api.runBuiltin( - p, - @tagName(tint_builtin), - 0, - "", - null, - )); - try std.testing.expectEqual(PdfTintMode.disabled, pv.tint); - const disabled_tag = try pardes.tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expectEqualStrings(initial_tag, disabled_tag); - try std.testing.expect(std.mem.indexOf(u8, disabled_tag, "disabled") == null); - try std.testing.expect(pardes.test_api.runBuiltin( - p, - @tagName(tint_builtin), - 0, - "", - null, - )); - try std.testing.expectEqual(PdfTintMode.filtered, pv.tint); - try std.testing.expectEqual(PdfFitMode.width, pv.fit); - // `dark` intentionally leaves page bg/fg null. PDF tint resolves those // deterministically to its chrome colors rather than host defaults. const dark_index = for (themes, 0..) |th, i| { -- cgit v1.3 From 6ff5fc7447cc411dc24cb1d841130f15a410e354 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:08:35 -0300 Subject: test: three of test/output.zig's tests through the 9P tree alone: DumpConfig's report in its one +DumpConfig pane, a second refreshing it in place (settings, a new file: /index, /focus and its body, Theme acme seen there), Config with no configuration directory refused, said in the log and opening nothing (settings), a Mini that cannot read its file leaving the panes, the last snapshot and the keyboard as they were (panes); the startup path line stays, a process flag with no 9P surface; each checked to fail against a break (openRead never reusing an output pane, Config taking a made-up path when there is no directory, a failed Mini giving the keyboard back to its caller) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour.zig | 1 + test/behaviour/panes.zig | 16 ++++++++++++ test/behaviour/settings.zig | 38 ++++++++++++++++++++++++++++ test/output.zig | 60 ++------------------------------------------- 4 files changed, 57 insertions(+), 58 deletions(-) create mode 100644 test/behaviour/settings.zig (limited to 'test/behaviour.zig') diff --git a/test/behaviour.zig b/test/behaviour.zig index 3e377ed7..2a37693e 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -10,4 +10,5 @@ test { _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/root_ctl.zig"); + _ = @import("behaviour/settings.zig"); } diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 8a906c2b..90c283b7 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -118,3 +118,19 @@ test "panes: PdfSections on a PDF with no outline says so and opens nothing" { } try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "PdfSections: this PDF has no outline") != null); } + +test "panes: a Mini that cannot read its file leaves the panes, the last Mini's snapshot and the keyboard as they were" { + var s = try Session.initFile(std.testing.allocator, "abc\n"); + defer s.deinit(); + const text = try s.focused(); + const exec = s.at("/pane/{d}/exec", .{text}); + try s.write(exec, s.at("Mini /virtual/pane/{d}/body\n", .{text})); + const mini = try s.focused(); + try std.testing.expect(mini != text); + const body = try s.read(s.at("/pane/{d}/body", .{mini})); + const index = try s.read("/index"); + try std.testing.expectEqual(@as(u16, 2), try s.refused(exec, "Mini /virtual/does-not-exist\n")); + try std.testing.expectEqual(mini, try s.focused()); + try s.expect("/index", index); + try s.expect(s.at("/pane/{d}/body", .{mini}), body); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig new file mode 100644 index 00000000..57751ab1 --- /dev/null +++ b/test/behaviour/settings.zig @@ -0,0 +1,38 @@ +//! docs/typ/reference.typ, Settings . +const std = @import("std"); +const Session = @import("session").Session; + +fn has(text: []const u8, part: []const u8) !void { + if (std.mem.indexOf(u8, text, part) == null) { + std.debug.print("not in it: {s}\n", .{part}); + return error.TestExpectedText; + } +} + +test "settings: DumpConfig reports the settings in its one +DumpConfig pane, a second refreshing it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const text = try s.focused(); + const exec = s.at("/pane/{d}/exec", .{text}); + try s.write(exec, "DumpConfig\n"); + const out = try s.focused(); + try std.testing.expect(out != text); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("{d} text 0 /+DumpConfig ", .{out})) != null); + const report = try s.read(s.at("/pane/{d}/body", .{out})); + for ([_][]const u8{ "Theme orchard\n", "Last shell spawned: (none)\n", "Shell change pending: on\n", "\nShell ", "LocationsConfig ", "no per-user config path" }) |line| try has(report, line); + try s.write("/ctl", "Theme acme\n"); + try s.write("/focus", s.at("{d}", .{text})); + try s.write(exec, "DumpConfig\n"); + try std.testing.expectEqual(out, try s.focused()); + try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/index"), "/+DumpConfig ")); + try has(try s.read(s.at("/pane/{d}/body", .{out})), "Theme acme\n"); +} + +test "settings: Config without a configuration directory says so and opens nothing" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const index = try s.read("/index"); + try std.testing.expectEqual(@as(u16, 5), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Config\n")); + try s.expect("/index", index); + try has(try s.read("/log"), "Config: no startup file here: no configuration directory"); +} diff --git a/test/output.zig b/test/output.zig index 2b8bf1f5..4d5945cd 100644 --- a/test/output.zig +++ b/test/output.zig @@ -495,60 +495,12 @@ test "Mini syntax colors survive toggles themes and rendering without source acc } } -test "Mini failures leave its existing snapshot and focus unchanged" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const source = try p.setTestFile("abc\n"); - var path_buf: [128]u8 = undefined; - const path = try std.fmt.bufPrint(&path_buf, "/virtual/pane/{d}/body", .{source.serial}); - try panes.mini.open(p, 0, path); - const id = p.active; - const mini = p.panes[id].?; - const body = mini.file.?.content.ptr; - const next = p.freeSlot(); - try std.testing.expectError(error.FileNotFound, panes.mini.open(p, 0, "/virtual/does-not-exist")); - try std.testing.expectEqual(id, p.active); - try std.testing.expectEqual(body, mini.file.?.content.ptr); - try std.testing.expectEqual(next, p.freeSlot()); -} - -test "DumpConfig prints the startup path and refreshes its one output" { +test "DumpConfig prints the startup path" { const path = "/home/pardes-test/.config/pardes/init"; const p = try Pardes.init(std.testing.allocator, .{ .startup_config_path = path }); defer p.deinit(); - - try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig")); - const opened = p.active; - const out = p.panes[opened].?.file.?; - for ([_][]const u8{ - "Startup config: " ++ path ++ "\n", - "Theme orchard\n", - "Last shell spawned: (none)\n", - "Shell change pending: on\n", - "LocationsConfig ", - }) |line| try std.testing.expect(std.mem.indexOf(u8, out.content, line) != null); - var default_line: [256]u8 = undefined; - try std.testing.expect(std.mem.indexOf(u8, out.content, try std.fmt.bufPrint(&default_line, "Shell {s}\n", .{config.defaultShell()})) != null); - try std.testing.expectEqualStrings(config.dump_config_buffer, std.fs.path.basename(out.path)); - try std.testing.expectEqual(panes.Output.Origin{ .cmd = .DumpConfig }, out.output.?.from); - - try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig")); - try std.testing.expectEqual(opened, p.active); - var buffers: usize = 0; - for (p.panes) |slot| { - const f = (slot orelse continue).file orelse continue; - const origin = (f.output orelse continue).from; - buffers += @intFromBool(std.meta.eql(origin, panes.Output.Origin{ .cmd = .DumpConfig })); - } - try std.testing.expectEqual(@as(usize, 1), buffers); -} - -test "DumpConfig reports the absence of a per-user config path" { - const p = try Pardes.init(std.testing.allocator, .{}); - defer p.deinit(); try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig")); - const report = p.panes[p.active].?.file.?.content; - try std.testing.expect(std.mem.indexOf(u8, report, "no per-user config path") != null); + try std.testing.expect(std.mem.indexOf(u8, p.panes[p.active].?.file.?.content, "Startup config: " ++ path ++ "\n") != null); } /// The file Config names, in a fresh temporary directory: `pardes/init` @@ -621,14 +573,6 @@ test "Config with no startup file opens a pane of its name, and Save makes its d try std.testing.expectEqual(std.Io.File.Kind.directory, made.kind); } -test "Config without a configuration directory says so and opens nothing" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const before = p.freeSlot(); - try std.testing.expect(p.executeBuiltinLine(p.active, "Config")); - try std.testing.expectEqual(before, p.freeSlot()); -} - test "EffectCode lists readable virtual sources used by this backend" { if (comptime !builtins.EffectCode.enabled) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); -- cgit v1.3 From 4d4d9fcba44798340184f865d119e49c63709b70 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:09:37 -0300 Subject: test: test/panes.zig's eight tag-navigation tests through the 9P tree alone (test/behaviour/tags.zig, guide.typ's Tags): s and S in a tag selecting its own text (a c changing both S's) while / searches the body (its +Search lists the match), ms and md read back from the tag file, the path the keyboard reaches, yanks (pasted into the body) and cannot edit, a name drafted by typing into it, a tag remembering its cursor across panes and a prompt, starting on Save and moved by a click, Tab and Enter from a tag giving the body the keyboard back (a Save counted, the next keys typed into the body), the cursor after a rename and a shorter tag, window keys from a tag, a tag's normal and insert modes; Session.cursor (the screen's cursor cell, read from /screen) and Session.replace (a write truncating first, a shell's >); each checked to fail against a break (a tag's s prompt answering for the body, ms closing a character early, a tag edit into the path taken, enterTag always landing on Save, a truncated tag's cursor left at 0, the execute key leaving the tag the keyboard, a tag the keyboard left keeping it) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour.zig | 1 + test/behaviour/tags.zig | 193 ++++++++++++++++++++++++++++++++++ test/panes.zig | 274 ------------------------------------------------ test/session.zig | 18 ++++ 4 files changed, 212 insertions(+), 274 deletions(-) create mode 100644 test/behaviour/tags.zig (limited to 'test/behaviour.zig') diff --git a/test/behaviour.zig b/test/behaviour.zig index 46fa8402..17d753fb 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -10,4 +10,5 @@ test { _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/root_ctl.zig"); + _ = @import("behaviour/tags.zig"); } diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig new file mode 100644 index 00000000..e9b33cb0 --- /dev/null +++ b/test/behaviour/tags.zig @@ -0,0 +1,193 @@ +//! docs/typ/guide.typ, Tags . +const std = @import("std"); +const Session = @import("session").Session; + +const home = "\u{F00D}"; +const right = "\u{F012}"; +const window = "\x17"; // Ctrl-w + +/// The pane's tag file. +fn tag(s: *Session, n: u32) ![]const u8 { + return s.read(s.at("/pane/{d}/tag", .{n})); +} + +/// The column of the screen's cursor in the tag drawn starting with +/// `path`, which must be on its row. +fn tagCol(s: *Session, path: []const u8) !usize { + const x, const y = try s.where(path); + const cx, const cy = try s.cursor(); + try std.testing.expectEqual(y, cy); + return cx - x; +} + +test "tags: s and S in a tag answer for the tag's own text; / still searches the body" { + var s = try Session.initFile(std.testing.allocator, "Some body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.replace(s.at("/pane/{d}/tag", .{n}), " Save Del Snarf"); + // The tag's line, its S's selected, then changed: both are the tag's. + try s.keys(":xsS\ncZ\x1b"); + try std.testing.expectEqualStrings("/test.txt Zave Del Znarf", try tag(&s, n)); + try s.expect(s.at("/pane/{d}/body", .{n}), "Some body\n"); + // `/` from the tag is the body's search, as acme's Look from a tag is. + // Its places list the body's match. + try s.keys(",/body\n"); + _ = try s.where("test.txt:1:6-9"); +} + +test "tags: ms and md edit a tag's own text, and the text the edit made is read back whole" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.keys(":miwms("); + try std.testing.expectEqualStrings("/test.txt (Save) Tty Collapse Del", try tag(&s, n)); + try s.keys("md("); + try std.testing.expectEqualStrings("/test.txt Save Tty Collapse Del", try tag(&s, n)); +} + +test "tags: the keyboard reaches a tag's path, which it can select and yank but not edit" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + const before = try tag(&s, n); + // `0` is the line's start, as in acme, where the name is ordinary text. + try s.keys(":0"); + try std.testing.expectEqual(@as(usize, 0), try tagCol(&s, "/test.txt")); + // An edit that reaches into it is refused, the cursor with it. + try s.keys("Eyd"); + try std.testing.expectEqualStrings(before, try tag(&s, n)); + try std.testing.expectEqual(@as(usize, "/test.tx".len), try tagCol(&s, "/test.txt")); + // Typed into, the path drafts a name there, as a click on it does. + try s.keys(";0ix"); + _ = try s.where("x/test.txt"); + // Esc keeps the draft pending; a second drops it. + try s.keys("\x1b\x1b"); + try s.expect(s.at("/pane/{d}/name", .{n}), "/test.txt\n"); + // After the path, the text is the tag's own to edit. + try s.keys(":A!\x1b"); + try std.testing.expectEqualStrings("/test.txt Save Tty Collapse Del!", try tag(&s, n)); + // What it yanked was the path. + try s.keys(":P"); + try s.expect(s.at("/pane/{d}/body", .{n}), "/test.txtbody\n"); +} + +test "tags: a tag remembers its cursor, starts on Save, and a click moves it" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const first = try s.focused(); + try s.write("/ctl", "Newcol\n"); + const second = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{second}), "/second.txt"); + const focus = s.at("{d}", .{first}); + const other = s.at("{d}", .{second}); + try s.write("/focus", focus); + // Nothing to remember yet: `:` lands on Save. + try s.keys(":"); + try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt")); + // Home is the line's start, the path's: the keyboard reaches it. + try s.keys(home ++ right ++ right ++ right); + try std.testing.expectEqual(@as(usize, 3), try tagCol(&s, "/test.txt")); + // `:` in the tag's normal mode is the way back to the body. + try s.keys(":"); + try std.testing.expect((try s.cursor())[1] != (try s.where("/test.txt"))[1]); + try s.write("/focus", other); + try s.keys(":" ++ home ++ right ++ right ++ right ++ right ++ right ++ ":"); + try s.write("/focus", focus); + try s.keys(":"); + try std.testing.expectEqual(@as(usize, 3), try tagCol(&s, "/test.txt")); + try s.keys(":"); + try s.write("/focus", other); + try s.keys(":"); + try std.testing.expectEqual(@as(usize, 5), try tagCol(&s, "/second.txt")); + try s.keys(":"); + // A click in the tag puts its cursor there, the pane's keyboard with it. + try s.click("Save Tty", 6, 1); + try std.testing.expectEqual(first, try s.focused()); + try std.testing.expectEqual(@as(usize, "/test.txt Save T".len), try tagCol(&s, "/test.txt")); + // A prompt opened and left from the body leaves it there. + try s.keys("\x1b:/\x1b:"); + try std.testing.expectEqual(@as(usize, "/test.txt Save T".len), try tagCol(&s, "/test.txt")); + try s.keys(":"); + try s.expect(s.at("/pane/{d}/body", .{first}), "body\n"); +} + +test "tags: executing a word from the tag runs it and gives the keyboard back to the body" { + for ([_][]const u8{ "\t", "\n" }) |chord| { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.keys("ix\x1b"); + // `:` lands on Save; the execute key runs it, the look key looks + // it up. Either way the tag lets go of the keyboard first. + try s.keys(":"); + try s.keys(chord); + try std.testing.expectEqual(@as(usize, if (chord[0] == '\t') 1 else 0), s.saved); + try s.keys("iQ\x1b"); + try s.expect(s.at("/pane/{d}/body", .{n}), "xQbody\n"); + // ...and the tag still knows where it was. + try s.keys(":"); + try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt")); + } +} + +test "tags: a renamed path moves the tag's cursor with the text after it and a shorter tag pulls it back" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.keys("::"); // on Save, and back + try s.write(s.at("/pane/{d}/name", .{n}), "/界.zig"); + try s.keys(":"); + try std.testing.expectEqual(@as(usize, "/界.zig ".len - 1), try tagCol(&s, "/界")); + try s.keys(":"); + try s.replace(s.at("/pane/{d}/tag", .{n}), "é"); + try s.keys(":"); + // `/界.zig é`: the cursor is pulled back onto the last character. + try std.testing.expectEqual(@as(usize, "/界.zig ".len - 1), try tagCol(&s, "/界")); + try s.expect(s.at("/pane/{d}/body", .{n}), "body\n"); +} + +test "tags: window keys move between panes from a tag and each tag keeps its cursor" { + for ([_]bool{ false, true }) |bottom| { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + if (bottom) try s.write("/ctl", "Tagbottom on\n"); + const first = try s.focused(); + const second = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{second}), "/second.txt"); + try s.write("/focus", s.at("{d}", .{first})); + try s.keys(":" ++ home ++ "ll" ++ window ++ "j\n"); + try std.testing.expectEqual(second, try s.focused()); + try s.keys(":" ++ home ++ "llll" ++ window ++ "k\n"); + try std.testing.expectEqual(first, try s.focused()); + try s.keys(":"); + try std.testing.expectEqual(@as(usize, 2), try tagCol(&s, "/test.txt")); + try s.keys(window ++ "j\n:"); + try std.testing.expectEqual(@as(usize, 4), try tagCol(&s, "/second.txt")); + } +} + +test "tags: a tag's normal mode is the body's: motions stay in the tag and insert types into it" { + for ([_]bool{ false, true }) |bottom| { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + if (bottom) try s.write("/ctl", "Tagbottom on\n"); + const first = try s.focused(); + try s.write("/ctl", "Newcol\n"); + const right_pane = try s.newPane(); + try s.write("/focus", s.at("{d}", .{first})); + try s.keys(":" ++ home ++ "l"); + try std.testing.expectEqual(@as(usize, 1), try tagCol(&s, "/test.txt")); + try s.keys("hkj"); + try std.testing.expectEqual(@as(usize, 0), try tagCol(&s, "/test.txt")); + try std.testing.expectEqual(first, try s.focused()); + try s.keys(window ++ "l\n"); + try std.testing.expectEqual(right_pane, try s.focused()); + try s.keys(window ++ "h\n"); + try std.testing.expectEqual(first, try s.focused()); + try s.keys(":i\u{F018}hjklHJKL:"); + try std.testing.expectEqualStrings("/test.txt Save Tty Collapse DelhjklHJKL:", try tag(&s, first)); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{first})), " mode:normal ")); + try s.expect(s.at("/pane/{d}/body", .{first}), "body\n"); + try std.testing.expectEqual(first, try s.focused()); + } +} diff --git a/test/panes.zig b/test/panes.zig index 6970cbb5..e1be67b9 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -296,279 +296,6 @@ test "a tag with more lines than rows scrolls to keep its caret in view" { try std.testing.expect(std.mem.indexOfScalar(u8, p.col_tags[0].own.?, '\n') == null); } -const TagNavigationTests = struct { - fn key(p: *Pardes, cp: u21) void { - p.update(.{ .key = .{ .cp = cp } }); - } - - test "s, S and | in a tag answer for the tag's own text; / still searches the body" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const pane = try p.setTestFile("Some body\n"); - try setTag(pane, " Save Del Snarf"); - key(p, ':'); - key(p, 'x'); // the tag's line - key(p, 's'); - try std.testing.expect(pane.prompt == .search and pane.prompt_for == .tag and pane.focus == .tag); - p.update(.{ .key = .{ .cp = 'S', .text = "S" } }); - key(p, Key.enter); - try std.testing.expect(pane.focus == .tag and pane.prompt == .none); - var ranges: [panes.Text.max_selections]modal.Selection = undefined; - const text = try pardes.edit.flatSurface(p, &pane.tag); - const got = pane.tag.ranges(text, 0, &ranges); - try std.testing.expectEqual(@as(usize, 2), got.n); - for (ranges[0..got.n]) |range| try std.testing.expectEqualStrings("S", text[@min(range.anchor, range.head)..@max(range.anchor, range.head)]); - // the body's selection is its own - try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); - // `/` from the tag is the body's search, as acme's Look from a tag is - key(p, ','); - key(p, '/'); - try std.testing.expect(pane.prompt == .search and pane.prompt_for == .body and pane.focus == .body); - key(p, Key.escape); - try std.testing.expect(pane.prompt == .none and pane.focus == .body); - } - - test "ms and md edit a tag's own text, and the text the edit made is read back whole" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.update(.tick); - key(p, ':'); // the tag, on `Save` the first time - for ("miwms(") |cp| key(p, cp); - try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), "(Save)") != null); - for ("md(") |cp| key(p, cp); - try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), " Save ") != null); - try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), "(") == null); - } - - test "the keyboard reaches a tag's path, which it can select and yank but not edit" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.update(.tick); - key(p, ':'); - // `0` is the line's start, as in acme, where the name is ordinary text - key(p, '0'); - try std.testing.expectEqual(@as(i32, 0), pane.tag.cur_col); - key(p, 'E'); - key(p, 'y'); - try std.testing.expectEqualStrings("/test.txt", p.registers.text(p.gpa, '"').?); - // an edit that reaches into it is refused, the cursor with it - const before = try std.testing.allocator.dupe(u8, try pardes.edit.flatSurface(p, &pane.tag)); - defer std.testing.allocator.free(before); - const cursor = pane.tag.cur_col; - key(p, 'd'); - try std.testing.expectEqualStrings(before, try pardes.edit.flatSurface(p, &pane.tag)); - try std.testing.expectEqual(cursor, pane.tag.cur_col); - try std.testing.expect(pane.tag.vsel.active); - // typed into, the path drafts a name there, as a click on it does - key(p, ';'); - key(p, '0'); - key(p, 'i'); - p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); - try std.testing.expect(pane.prompt == .name); - try std.testing.expectEqualStrings("x/test.txt", pane.input.own.?); - // Esc keeps the draft pending; a second drops it. - key(p, Key.escape); - key(p, Key.escape); - try std.testing.expect(pane.prompt == .none); - try std.testing.expectEqualStrings("/test.txt", pane.file.?.path); - // after the path, the text is the tag's own to edit - key(p, ':'); - key(p, 'A'); - p.update(.{ .key = .{ .cp = '!', .text = "!" } }); - try std.testing.expect(std.mem.endsWith(u8, pardes.tagline.curTail(pane), "!")); - try std.testing.expectEqualStrings("body\n", pane.file.?.content); - } - - fn window(p: *Pardes, letter: u21) void { - p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); - key(p, letter); - key(p, Key.enter); - } - - test "a tag remembers its cursor, starts on Save, and a click moves it" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const first = try p.setTestFile("body\n"); - p.presentation.enabled = false; - try std.testing.expect(p.executeBuiltinLine(0, "New")); - const second_id = p.active; - const second = p.panes[second_id].?; - try std.testing.expect(layout.splitColumn(p, second_id, second_id, false)); - p.update(.tick); - p.active = 0; - // Nothing to remember yet: `:` lands on Save, in normal mode. - key(p, ':'); - try std.testing.expect(first.focus == .tag and first.tag.mode == .normal); - const shown = try pardes.edit.flatSurface(p, &first.tag); - try std.testing.expectEqualStrings("Save", shown[@intCast(first.tag.cur_col)..][0..4]); - // Home is the line's start, the path's: the keyboard reaches it. - key(p, Key.home); - for (0..3) |_| key(p, Key.right); - try std.testing.expectEqual(@as(i32, 3), first.tag.cur_col); - // `:` in the tag's normal mode is the way back to the body. - key(p, ':'); - try std.testing.expect(first.focus == .body); - p.active = second_id; - key(p, ':'); - key(p, Key.home); - for (0..5) |_| key(p, Key.right); - key(p, ':'); - p.active = 0; - key(p, ':'); - try std.testing.expectEqual(@as(i32, 3), first.tag.cur_col); - key(p, ':'); - p.active = second_id; - key(p, ':'); - try std.testing.expectEqual(@as(i32, 5), second.tag.cur_col); - key(p, ':'); - var frame = std.heap.ArenaAllocator.init(p.gpa); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - const rect = p.rects[0]; - const y = tagY(p, rect); - const prefix: u16 = @intCast(panes.File.displayWidth(try pardes.tagline.tagPrefix(p, first))); - ClickCursorTests.click(p, .left, rect.x + pardes.TAG_TEXT_INSET + prefix + 6, y); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expect(first.focus == .tag and first.tag.mode == .insert); - try std.testing.expectEqual(@as(i32, prefix + 6), first.tag.cur_col); - key(p, Key.escape); - key(p, ':'); - p.startPrompt(first, &first.body, .{ .search = config.search_marker }); - key(p, Key.escape); - key(p, ':'); - try std.testing.expectEqual(@as(i32, prefix + 6), first.tag.cur_col); - key(p, ':'); - try std.testing.expectEqualStrings("body\n", first.file.?.content); - } - - test "executing a word from the tag runs it and gives the keyboard back to the body" { - for ([_]u21{ Key.tab, Key.enter }) |chord| { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - const pane = try p.setTestFile("body\n"); - p.update(.{ .key = .{ .cp = 'i' } }); - p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); - p.update(.{ .key = .{ .cp = Key.escape } }); - while (p.nextEffect()) |_| {} - // `:` lands on Save; the execute key runs it, the look key looks - // it up. Either way the tag lets go of the keyboard first. - key(p, ':'); - try std.testing.expect(pane.focus == .tag); - key(p, chord); - try std.testing.expect(pane.focus == .body); - try std.testing.expectEqual(.normal, pane.body.mode); - var saved = false; - while (p.nextEffect()) |effect| { - if (effect == .save_file) saved = true; - } - try std.testing.expectEqual(chord == Key.tab, saved); - // ...and the tag still knows where it was. - key(p, ':'); - try std.testing.expectEqualStrings("Save", (try pardes.edit.flatSurface(p, &pane.tag))[@intCast(pane.tag.cur_col)..][0..4]); - } - } - - test "a renamed path moves the tag's cursor with the text after it and a shorter tag pulls it back" { - 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"); - key(p, ':'); // on Save - key(p, ':'); - p.gpa.free(pane.file.?.path); - pane.file.?.path = try p.gpa.dupe(u8, "/界.zig"); - p.update(.tick); - key(p, ':'); - const shown = try pardes.edit.flatSurface(p, &pane.tag); - try std.testing.expectEqualStrings("Save", shown[@intCast(pane.tag.cur_col)..][0..4]); - key(p, ':'); - try setTag(pane, "é"); - p.update(.tick); - key(p, ':'); - // `/界.zig é`: the cursor is pulled back onto the last character - try std.testing.expectEqual(@as(i32, "/界.zig ".len), pane.tag.cur_col); - try std.testing.expectEqualStrings("body\n", pane.file.?.content); - } - - test "window keys move between panes from a tag and each tag keeps its cursor" { - for ([_]bool{ false, true }) |bottom| { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - const first = try p.setTestFile("body\n"); - p.presentation.enabled = false; - p.settings.tag_bottom = bottom; - try std.testing.expect(p.executeBuiltinLine(0, "New")); - const second_id = p.active; - const second = p.panes[second_id].?; - p.update(.tick); - p.active = 0; - key(p, ':'); - key(p, Key.home); - key(p, 'l'); - key(p, 'l'); - window(p, 'j'); - try std.testing.expectEqual(second_id, p.active); - try std.testing.expect(first.focus == .body and second.focus == .body); - key(p, ':'); - key(p, Key.home); - for (0..4) |_| key(p, 'l'); - window(p, 'k'); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expect(second.focus == .body); - key(p, ':'); - try std.testing.expectEqual(@as(i32, 2), first.tag.cur_col); - window(p, 'j'); - key(p, ':'); - try std.testing.expectEqual(@as(i32, 4), second.tag.cur_col); - } - } - - test "a tag's normal mode is the body's: motions stay in the tag and insert types into it" { - for ([_]bool{ false, true }) |bottom| { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - p.presentation.enabled = false; - p.settings.tag_bottom = bottom; - try std.testing.expect(p.executeBuiltinLine(0, "New")); - const right = p.active; - try std.testing.expect(layout.splitColumn(p, right, right, false)); - p.update(.tick); - p.active = 0; - key(p, ':'); - const pane = p.panes[0].?; - key(p, Key.home); - key(p, 'l'); - try std.testing.expectEqual(@as(i32, 1), pane.tag.cur_col); - key(p, 'h'); - key(p, 'k'); - key(p, 'j'); - try std.testing.expectEqual(@as(i32, 0), pane.tag.cur_col); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expect(pane.focus == .tag and !p.header_focus); - window(p, 'l'); - try std.testing.expectEqual(right, p.active); - try std.testing.expect(pane.focus == .body and p.panes[right].?.focus == .body); - window(p, 'h'); - try std.testing.expectEqual(@as(usize, 0), p.active); - key(p, ':'); - key(p, 'i'); - key(p, Key.end); - const before = pardes.tagline.curTail(pane).len; - try std.testing.expect(pane.focus == .tag and pane.tag.mode == .insert and pane.body.mode == .normal); - for ("hjklHJKL:") |letter| { - const text = [_]u8{letter}; - p.update(.{ .key = .{ .cp = letter, .text = &text } }); - try std.testing.expect(pane.focus == .tag and pane.tag.mode == .insert); - } - try std.testing.expectEqualStrings("hjklHJKL:", pardes.tagline.curTail(pane)[before..]); - try std.testing.expectEqualStrings("body\n", pane.file.?.content); - try std.testing.expectEqual(@as(usize, 0), p.active); - } - } -}; - 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; @@ -4414,7 +4141,6 @@ const TerminalTests = struct { }; test { - _ = TagNavigationTests; _ = TagLayerTests; _ = TagNameTintTests; _ = TreeContextTests; diff --git a/test/session.zig b/test/session.zig index b55987eb..f3d96918 100644 --- a/test/session.zig +++ b/test/session.zig @@ -188,6 +188,24 @@ pub const Session = struct { pub fn where(s: *Session, text: []const u8) !struct { usize, usize } { return s.find(text); } + + /// The cell the screen's cursor is drawn on, its column and row. + pub fn cursor(s: *Session) !struct { usize, usize } { + const json = try std.json.parseFromSliceLeaky(std.json.Value, s.arena.allocator(), try s.read("/screen"), .{}); + const c = json.object.get("cursor").?; + if (c != .object) return error.NoCursor; + return .{ @intCast(c.object.get("x").?.integer), @intCast(c.object.get("y").?.integer) }; + } + + /// `data` written to `path` truncated first, as a shell's `>` does. + pub fn replace(s: *Session, path: []const u8, data: []const u8) !void { + const node, const h = try s.open(path, 1); + defer _ = s.serve(.{ .tag = 0, .op = .release, .node = node, .handle = h, .opened = true }); + const t = s.serve(.{ .tag = 0, .op = .setattr, .node = node, .handle = h, .truncate = true }); + if (t.status != .ok) return refusal(path, t); + const w = s.serve(.{ .tag = 0, .op = .write, .node = node, .handle = h, .data = data }); + if (w.status != .ok) return refusal(path, w); + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { -- cgit v1.3 From 5cc02232d522d5cd5a453caedd1e592ca20471ea Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:09:53 -0300 Subject: test: eleven more of src/pardes.zig's tests through the 9P tree alone (test/behaviour/columns_and_tags, modes, tags, panes): a click past a column tag's text typing after it, a newline there a space and a long tag scrolled to its caret, Enter and Tab in a tag running the word under the cursor, Esc alternating two panes of a kind, Esc out of a column or the workspace tag, Shift-Esc out of every mode, a name typed into the tag's path pending past Esc, an unsaved file's tag its name alone, a question ended in the log when its pane closes, focus on a closed pane to the one taking its place; Session's cursor (/screen's); each checked to fail against a break (flatten keeping newlines, the header drawn unscrolled, Enter in a header a Look, Esc in normal mode not running Last, Esc in a header not leaving it, Shift-Esc leaving insert on, the first Esc on a drafted name dropping it, a dirty tag marked ' *', del_side left out of noteRetire's answer, removeColumn's focus to any pane) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 231 ------------------------------------ test/behaviour.zig | 2 + test/behaviour/columns_and_tags.zig | 39 ++++++ test/behaviour/modes.zig | 65 ++++++++++ test/behaviour/panes.zig | 63 ++++++++++ test/behaviour/tags.zig | 19 +++ test/session.zig | 10 ++ 7 files changed, 198 insertions(+), 231 deletions(-) create mode 100644 test/behaviour/modes.zig create mode 100644 test/behaviour/tags.zig (limited to 'test/behaviour.zig') diff --git a/src/pardes.zig b/src/pardes.zig index ea8b52df..3d29dfcd 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1462,21 +1462,6 @@ test "dragging a column's only pane to another leaves that column in place, empt try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); } -test "an unsaved file's tag is its name alone: the grip, not a mark, says it is unsaved" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - const pane = try p.setTestFile("before\n"); - const clean = try tagline.tagText(p, p.scratch.allocator(), pane); - panes.File.setContent(p, &pane.file.?, try gpa.dupe(u8, "after\n")); - const dirty = try tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expectEqualStrings(clean, dirty); - try std.testing.expect(std.mem.indexOf(u8, dirty, " *") == null); - // The dirty file and index's flag still say it. - try std.testing.expect(ctlfs.pane.dirtyOf(pane)); -} - test "unknown Exec from a document runs as a command pane in its directory, typed into no terminal" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{}); @@ -3180,33 +3165,6 @@ fn pardes_ctlfs_ctlText(p: *Pardes, pane: *Pane) []const u8 { return th.rd(p, ctlfs.Node.of(pane.serial, .ctl), 0, 4096).bytes; } -test "a name typed into the tag's path survives Esc, pending, and the next Enter renames; a second Esc drops it" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("x\n"); - for ([_]bool{ true, false }) |enter| { - tagline.enterTag(p, pane); - pane.tag.mode = .insert; - pane.tag.cur_row = 0; - pane.tag.cur_col = 1; - p.update(.{ .key = .{ .cp = 'z', .text = "z" } }); - try std.testing.expect(pane.prompt == .name); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt == .name); - // A stray key changes nothing while it waits. - p.update(.{ .key = .{ .cp = 'q', .text = "q" } }); - if (enter) { - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqualStrings("/ztest.txt", pane.file.?.path); - } else { - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt != .name); - try std.testing.expectEqualStrings("/ztest.txt", pane.file.?.path); - } - } -} - test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 }); @@ -3389,43 +3347,6 @@ test "column tag first-cell execution keeps New local to the clicked column" { try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content); } -test "header clicks beyond text append and long UTF-8 tags reveal their caret" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "New"); - p.acknowledgePanelPresentation(&.{}); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .key = .{ .cp = 'x', .text = " extended" } }); - try std.testing.expectEqualStrings("New extended", tagline.columnTag(p, 0)); - p.update(.{ .paste = " 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界" }); - const frame = try p.render(p.scratch.allocator()); - try std.testing.expect(p.header_scroll > 0); - try std.testing.expect(frame.cursor != null); - try std.testing.expectEqual(TOPBAR_H, frame.cursor.?.y); - try std.testing.expect(frame.cursor.?.x < p.screen_w); - p.update(.{ .key = .{ .cp = Key.home } }); - _ = try p.render(p.scratch.allocator()); - try std.testing.expectEqual(@as(usize, 0), p.header_scroll); -} - -test "a newline typed into a column tag is a space: the tag stays one row" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "New"); - p.acknowledgePanelPresentation(&.{}); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - p.update(.{ .key = .{ .cp = 'S', .text = "Snarf" } }); - _ = try p.render(p.scratch.allocator()); - try std.testing.expectEqualStrings("New Snarf", tagline.columnTag(p, 0)); - try std.testing.expectEqual(COLBAR_H, p.columnBarHeight()); - try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.rects[0].y); -} - test "tiny screens keep pane space before adding a column tag" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 8, .rows = 2, .tty_only = true }); defer p.deinit(); @@ -3456,18 +3377,6 @@ test "a screen too short for the column row releases a column tag's focus withou try std.testing.expectEqualStrings("unchanged body\n", pane.file.?.content); } -test "a header's execute key runs the word under its cursor and lets go of the keyboard first" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - tagline.enterHeader(p, null); - p.global_tag.cur_col = @intCast(std.mem.indexOf(u8, config.topbar_str, "Dump").?); - p.update(.{ .key = .{ .cp = Key.tab } }); - try std.testing.expect(!p.header_focus); - try std.testing.expect(p.dump_out != null); - try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); -} - test "s in a header selects in the header's own text" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); defer p.deinit(); @@ -3487,20 +3396,6 @@ test "s in a header selects in the header's own text" { try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); } -test "Enter in a header runs the word under its cursor, as the execute key does" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - tagline.enterHeader(p, null); - p.global_tag.cur_col = @intCast(std.mem.indexOf(u8, config.topbar_str, "Newcol").?); - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - // and the workspace tag lets go of the keyboard: the new, empty - // column's tag has it - try std.testing.expect(p.header_focus and p.header_column.? == 1); -} - test "window keys walk from a pane up through the column and workspace tags and back" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true }); defer p.deinit(); @@ -8272,31 +8167,6 @@ pub const Pardes = struct { } }; -test "Esc alternates between two panes of the SAME kind" { - if (platform == .web) return; - const gpa = std.testing.allocator; - var cwdbuf: [4096]u8 = undefined; - const cwd = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwdbuf, cwdbuf.len) orelse return))); - var pathbuf: [4096]u8 = undefined; - const boot = try std.fmt.bufPrint(&pathbuf, "{s}/mise.toml", .{cwd}); - - const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 40, .file = boot }); - defer p.deinit(); - p.update(.{ .resize = .{ .cols = 80, .rows = 40 } }); - const a = p.active; - exec.runBuiltin(p, .Look, a, "", "build.zig"); - p.sync(); - const b = p.active; - try std.testing.expect(b != a); - try std.testing.expect(!p.panes[a].?.isTerminal() and !p.panes[b].?.isTerminal()); - - for (0..6) |_| { - const was = p.active; - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expectEqual(if (was == a) b else a, p.active); - } -} - test "a boot file that will not open boots an errors pane rather than failing the launch" { if (platform == .web) return; const gpa = std.testing.allocator; @@ -8676,49 +8546,6 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" { try std.testing.expect(p.panes[low] == null); } -test "focus on a closed pane goes to the pane that takes its place, not the one focused before" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); - defer p.deinit(); - const shell = p.active; - p.newColumn(shell); - p.newScratchIn(shell, p.activeColumn().?); - const right = p.active; - p.sync(); - p.newScratchBelow(shell); - const low = p.active; - p.sync(); - // The dogfood case: `right` was focused just before `low`, but `shell` - // grows into `low`'s rows, so `shell` gets the focus. - try std.testing.expect(p.executeBuiltinLine(low, "Del")); - p.sync(); - try std.testing.expect(p.panes[low] == null); - try std.testing.expectEqual(shell, p.active); - - // Closing a pane that has no focus leaves the focus where it is. - p.newScratchBelow(shell); - const other = p.active; - p.sync(); - p.active = right; - p.sync(); - try std.testing.expect(p.executeBuiltinLine(other, "Del")); - try std.testing.expectEqual(right, p.active); - - // Delcol: the column that takes the width holds, level with the closed - // pane, the pane that takes its place; `right` was focused just before. - p.newScratchBelow(right); - const right_low = p.active; - p.newScratchBelow(shell); - const left_low = p.active; - p.active = right; - p.sync(); - p.active = left_low; - p.sync(); - try p.removeColumn(layout.findPane(p, left_low).?.col); - p.sync(); - try std.testing.expectEqual(right_low, p.active); -} - test "the bare tty startup opens a text pane under the shell, unfocused" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .boot = .tty }); @@ -8892,43 +8719,6 @@ test "with ProgramEsc raw tty Escape only leaves at a shell prompt" { try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); } -test "Shift-Esc backs out to the previous pane in every mode, never into raw" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); - defer p.deinit(); - p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc - const shell = p.active; - const sp = p.panes[shell].?; - // A terminal in normal mode: out, still normal, never raw. - if (sp.body.mode == .tty) p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); - try std.testing.expectEqual(Text.Mode.normal, sp.body.mode); - p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(Text.Mode.normal, sp.body.mode); - // A text pane in insert mode: out of insert, and out of the pane. - const doc = p.panes[0].?; - p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); - try std.testing.expectEqual(Text.Mode.insert, doc.body.mode); - p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); - try std.testing.expectEqual(Text.Mode.normal, doc.body.mode); - try std.testing.expect(p.active != 0); -} - -test "Esc in a column or the workspace tag gives the keyboard back to a pane, as Shift-Esc does" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); - defer p.deinit(); - p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a pane to go back to - for ([_]?usize{ 0, null }) |column| { - tagline.enterHeader(p, column); - try std.testing.expect(tagline.focusedHeader(p) != null); - const was = p.active; - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(tagline.focusedHeader(p) == null); - try std.testing.expect(p.active != was); - } -} - test "window mode moves an outline and focuses it on Enter, Esc or a label" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 }); defer p.deinit(); @@ -9870,27 +9660,6 @@ test "core animation keeps wall time at 60, 120 and 144 Hz and across a stall" { try std.testing.expectEqual(@as(?u64, null), p.nextWake()); } -test "a pane closed while its question stands ends the question in the log" { - const th = @import("ninep/testing.zig"); - const p = try th.withFile(std.testing.allocator, "x\n"); - defer p.deinit(); - p.settings.placement = .pardes; - p.newScratchBelow(0); - const closing = p.active; - p.newScratchBelow(closing); - p.sync(); - p.active = closing; // a middle pane: Del from a key asks which side - const serial = p.panes[closing].?.serial; - p.update(.{ .key = .{ .cp = ' ' } }); - p.update(.{ .key = .{ .cp = 'd' } }); - try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[closing].?.prompt); - // A bare answer says what this question takes. - try std.testing.expectEqualStrings("answer takes k j or -", th.wr(p, ctlfs.Node.of(serial, .ctl), "answer\n").reply.ename); - try p.removePane(closing, null); - var want: [64]u8 = undefined; - try std.testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "answer {d} -\ndel {d}", .{ serial, serial }))); -} - test "a Save the host could not do logs no save record" { const th = @import("ninep/testing.zig"); const p = try th.withFile(std.testing.allocator, "x\n"); diff --git a/test/behaviour.zig b/test/behaviour.zig index 32138f94..902ef520 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -6,7 +6,9 @@ test { _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); _ = @import("behaviour/look_and_exec.zig"); + _ = @import("behaviour/modes.zig"); _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/root_ctl.zig"); + _ = @import("behaviour/tags.zig"); } diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig index 80f9c710..5b78a6c8 100644 --- a/test/behaviour/columns_and_tags.zig +++ b/test/behaviour/columns_and_tags.zig @@ -149,3 +149,42 @@ test "columns-and-tags: New is a column tag's word, in no pane's tag nor the wor } try expectEqualStrings("New Tty Find Grep Joincol Delcol", try s.read(s.at("/col/{d}/tag", .{try s.column(0)}))); } + +test "columns-and-tags: a click past a column tag's text types after it, a newline typed there a space, and a long tag scrolls to its caret" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const tag = s.at("/col/{d}/tag", .{try s.column(0)}); + // Its row, then the pane's tag: the column's stays one row. + const rows = " New Tty Find Grep Joincol Delcol"; + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " ") != null); + try s.click("Delcol", 20, 1); + try s.keys("\nSnarf"); + try expectEqualStrings("New Tty Find Grep Joincol Delcol Snarf", try s.read(tag)); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " Snarf ") != null); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "\n /test.txt Save") != null); + // Wider than the screen: the tag scrolls to keep its caret drawn. + try s.keys(" 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界"); + const col, const row = (try s.cursor()).?; + try std.testing.expectEqual(@as(usize, 1), row); + try std.testing.expect(col < 80); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows) == null); + try s.keys("\u{F00D}"); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows) != null); +} + +test "columns-and-tags: Enter in a tag in normal mode runs the word under its cursor, and Tab does too, letting go of the keyboard first" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const first = try s.focused(); + try s.click("Newcol", 1, 1); + try s.keys("\x1b\n"); + try expectEqualStrings(s.at("{d}:{d} {d}:", .{ try s.column(0), first, try s.column(1) }), try s.columns()); + // The workspace tag lets go of the keyboard: the new, empty column's + // tag has it. + try s.expect("/focus", ""); + try s.keys("iMine\x1b"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/col/{d}/tag", .{try s.column(1)})), "Mine") != null); + try s.click("Tutor", 1, 1); + try s.keys("\x1b\t"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/name", .{try s.focused()})), "/+Tutor\n")); +} diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig new file mode 100644 index 00000000..cdcf1be6 --- /dev/null +++ b/test/behaviour/modes.zig @@ -0,0 +1,65 @@ +//! docs/typ/guide.typ, Modes . +const std = @import("std"); +const Session = @import("session").Session; +const expectEqual = std.testing.expectEqual; + +fn mode(s: *Session, pane: u32) ![]const u8 { + const ctl = try s.read(s.at("/pane/{d}/ctl", .{pane})); + const at = std.mem.lastIndexOf(u8, ctl, " mode:").? + " mode:".len; + return std.mem.trimEnd(u8, ctl[at..], " "); +} + +test "modes: Esc in normal mode alternates between two panes of the same kind" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "a\n"); + defer s.deinit(); + const a = try s.focused(); + try s.write("/look", s.at("{s}/b.txt\n", .{at})); + const b = try s.focused(); + try std.testing.expect(a != b); + for (0..6) |_| { + const was = try s.focused(); + try s.keys("\x1b"); + try expectEqual(if (was == a) b else a, try s.focused()); + } +} + +test "modes: Esc in a column or the workspace tag gives the keyboard back to a pane, as Shift-Esc does" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + _ = try s.newPane(); + for ([_][]const u8{ "New Tty", "Newcol" }) |tag| { + const was = try s.focused(); + // A click types into the tag; Esc is normal mode there, the next + // one is out of it. + try s.click(tag, 0, 1); + try s.keys("\x1b"); + try s.expect("/focus", ""); + try s.keys("\x1b"); + try std.testing.expect(was != try s.focused()); + } +} + +test "modes: Shift-Esc backs out to the previous pane in every mode, never into raw" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const doc = try s.focused(); + try s.keys("\u{F015}n"); // a shell under the doc + const shell = try s.focused(); + if (std.mem.eql(u8, try mode(&s, shell), "tty")) try s.keys("\x02"); + try std.testing.expectEqualStrings("normal", try mode(&s, shell)); + // A terminal in normal mode: out, still normal, never raw. + try s.keys("\u{F016}\x1b"); + try expectEqual(doc, try s.focused()); + try std.testing.expectEqualStrings("normal", try mode(&s, shell)); + // A text pane in insert mode: out of insert, and out of the pane. + try s.keys("i"); + try std.testing.expectEqualStrings("insert", try mode(&s, doc)); + try s.keys("\u{F016}\x1b"); + try std.testing.expectEqualStrings("normal", try mode(&s, doc)); + try std.testing.expect(doc != try s.focused()); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 01820a07..d0773bfb 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -49,3 +49,66 @@ test "panes: Putall saves every pane with unsaved edits to a file, one each, and try s.write("/ctl", "Putall\n"); try std.testing.expectEqual(@as(usize, 1), s.saved); } + +test "panes: an unsaved file's tag is its name alone, its dirty file says it is unsaved" { + var s = try Session.initFile(std.testing.allocator, "before\n"); + defer s.deinit(); + const n = try s.focused(); + const tag = s.at("/pane/{d}/tag", .{n}); + const clean = try s.read(tag); + try s.write(s.at("/pane/{d}/body", .{n}), "after\n"); + try std.testing.expectEqualStrings(clean, try s.read(tag)); + try std.testing.expect(std.mem.indexOf(u8, clean, " *") == null); + try s.expect(s.at("/pane/{d}/dirty", .{n}), "1\n"); +} + +test "panes: a pane closed while its question stands ends the question in the log" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "Placement pardes\n"); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + const closing = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{closing}), "New\n"); + // A middle pane: Del from a key asks which side. + try s.write("/focus", s.at("{d}\n", .{closing})); + try s.keys(" d"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("ask {d} del k j\n", .{closing})) != null); + // A bare answer says what this question takes. + const ctl = s.at("/pane/{d}/ctl", .{closing}); + _ = try s.refused(ctl, "answer\n"); + try std.testing.expectEqualStrings("answer takes k j or -", s.said); + try s.write(ctl, "Del\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("answer {d} -\ndel {d}", .{ closing, closing })) != null); +} + +test "panes: focus on a closed pane goes to the pane that takes its place, not the one focused before" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const left = try s.focused(); + try s.write("/ctl", "Newcol\n"); + try s.write(s.at("/col/{d}/ctl", .{try s.column(1)}), "New\n"); + const right = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const low = try s.focused(); + // `right` was focused just before `low`, but `left` grows into `low`'s + // rows, so `left` gets the focus. + try s.write(s.at("/pane/{d}/ctl", .{low}), "Del\n"); + try std.testing.expectEqual(left, try s.focused()); + // Closing a pane that has no focus leaves the focus where it is. + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const other = try s.focused(); + try s.write("/focus", s.at("{d}\n", .{right})); + try s.write(s.at("/pane/{d}/ctl", .{other}), "Del\n"); + try std.testing.expectEqual(right, try s.focused()); + // Delcol: the column that takes the width holds, level with the closed + // pane, the pane that takes its place; `right` was focused just before. + try s.write(s.at("/pane/{d}/exec", .{right}), "New\n"); + const right_low = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const left_low = try s.focused(); + try s.write("/focus", s.at("{d}\n", .{right})); + try s.write("/focus", s.at("{d}\n", .{left_low})); + try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Delcol\n"); + try std.testing.expectEqual(right_low, try s.focused()); +} diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig new file mode 100644 index 00000000..ab109b78 --- /dev/null +++ b/test/behaviour/tags.zig @@ -0,0 +1,19 @@ +//! docs/typ/guide.typ, Tags . +const std = @import("std"); +const Session = @import("session").Session; + +test "tags: a name typed into the tag's path survives Esc, pending, and the next Enter renames; a second Esc drops it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + const name = s.at("/pane/{d}/name", .{n}); + // A click on the path types into it; a stray key while it waits + // changes nothing. + try s.click("/test.txt", 1, 1); + try s.keys("z\x1bq\n"); + try s.expect(name, "/ztest.txt\n"); + try s.click("/ztest.txt", 1, 1); + try s.keys("z\x1bq\x1b"); + try s.expect(name, "/ztest.txt\n"); + try std.testing.expect(std.mem.startsWith(u8, try s.read(s.at("/pane/{d}/tag", .{n})), "/ztest.txt ")); +} diff --git a/test/session.zig b/test/session.zig index c4ed0db2..f67f3b25 100644 --- a/test/session.zig +++ b/test/session.zig @@ -210,6 +210,16 @@ pub const Session = struct { const col = cols.next() orelse return error.NoColumn; return std.fmt.parseInt(u32, col[0..std.mem.indexOfScalar(u8, col, ':').?], 10); } + + /// Where /screen draws the cursor, column and row; null when it draws none. + pub fn cursor(s: *Session) !?struct { usize, usize } { + const json = try std.json.parseFromSliceLeaky(std.json.Value, s.arena.allocator(), try s.read("/screen"), .{}); + const c = switch (json.object.get("cursor").?) { + .object => |o| o, + else => return null, + }; + return .{ @intCast(c.get("x").?.integer), @intCast(c.get("y").?.integer) }; + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { -- cgit v1.3 From 3632bbeaa75f912281d0c9d636feb153d04f668e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:22:47 -0300 Subject: test: five more of src/pardes.zig's tests through the 9P tree alone (test/behaviour/placement, panes, terminals, modes): an empty active column taking a look from another column's text whole, Collapse folding a pane to its tag (no text drawn, no cursor, its tag still typed into) and restoring it, a pane its whole text fits in never scrolled for a margin, Togglettymode and Ctrl-B sharing the mode's transitions from the body or the tag and a text pane refusing it, Esc back into a file keeping its view where a look's :N centres; Session's where (the first place /screen draws a text); each checked to fail against a break (acmeColumn ignoring the active column, toggleCollapse never unfolding, the scroll margin clamped at the last line alone, toggleTty leaving the tag the keyboard, Last landing centred) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 147 ------------------------------------------- test/behaviour.zig | 2 + test/behaviour/modes.zig | 39 ++++++++++++ test/behaviour/panes.zig | 49 +++++++++++++++ test/behaviour/placement.zig | 24 +++++++ test/behaviour/terminals.zig | 46 ++++++++++++++ test/session.zig | 5 ++ 7 files changed, 165 insertions(+), 147 deletions(-) create mode 100644 test/behaviour/placement.zig create mode 100644 test/behaviour/terminals.zig (limited to 'test/behaviour.zig') diff --git a/src/pardes.zig b/src/pardes.zig index 3d29dfcd..3d6b6e28 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -710,34 +710,6 @@ test "pane-tag Exec prefers Tty and argument builtins before shell fallback" { try std.testing.expectEqualStrings("DefinitelyNotABuiltin\r", sent[0..sent_len]); } -test "Collapse builtin keeps content and restores the pane from its default tag" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 24, .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("keep this text\n"); - p.sync(); - const height = p.rects[0].h; - const revision = pane.file.?.revision; - for ([_][]const u8{ tagline.pane_tail, tagline.file_pane_tail, tagline.pdf_pane_tail, tagline.terminal_pane_tail }) |tail| - try std.testing.expect(std.mem.endsWith(u8, tail, " Collapse Del")); - - try std.testing.expect(p.executeBuiltinLine(0, "Collapse")); - p.sync(); - try std.testing.expect(pane.collapsed); - try std.testing.expectEqual(@as(u16, BOX_H), p.rects[0].h); - try std.testing.expectEqual(@as(f32, @floatFromInt(height)), pane.vweight); - try std.testing.expectEqual(revision, pane.file.?.revision); - try std.testing.expectEqualStrings("keep this text\n", pane.file.?.content); - try std.testing.expect((try p.render(p.scratch.allocator())).cursor == null); - tagline.enterTag(p, pane); - const tag_cursor = (try p.render(p.scratch.allocator())).cursor orelse return error.MissingTagCursor; - try std.testing.expectEqual(p.rects[0].y, tag_cursor.y); - pane.focus = .body; - try std.testing.expect(p.executeBuiltinLine(0, "Collapse")); - p.sync(); - try std.testing.expect(!pane.collapsed); - try std.testing.expectEqual(height, p.rects[0].h); -} - test "LocationsConfig command reports partial updates and survives restore" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); @@ -851,42 +823,6 @@ test "TreeContext command and custom tag survive a workspace round trip" { try std.testing.expectEqualStrings(" Save Keep Del", tagline.curTail(saved)); } -test "Togglettymode builtin and keyboard chord share mode transitions including edited tags" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20, .tty_only = true }); - defer p.deinit(); - const pane = p.panes[0].?; - try std.testing.expect(std.mem.indexOf(u8, tagline.curTail(pane), " Mode ") != null); - try pane.appendTag(" Togglettymode"); - try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); - try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode")); - try std.testing.expectEqual(Text.Mode.normal, pane.body.mode); - p.update(.{ .key = .{ .cp = p.tty_toggle, .ctrl = true } }); - try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); - // The tag has its own mode: the body keeps tty while the tag is typed into. - tagline.enterTag(p, pane); - try std.testing.expect(pane.focus == .tag); - try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); - try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode")); - try std.testing.expectEqual(Text.Mode.normal, pane.body.mode); - try std.testing.expect(pane.focus == .body); - tagline.enterTag(p, pane); - p.update(.{ .key = .{ .cp = p.tty_toggle, .ctrl = true } }); - try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); - try std.testing.expect(pane.focus == .body); - - p.acknowledgePanelPresentation(&.{}); - const tag = try tagline.tagText(p, p.scratch.allocator(), pane); - const x = p.rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(std.mem.indexOf(u8, tag, "Togglettymode").?)); - const y = p.rects[0].y; - p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = x, .row = y } }); - p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = x, .row = y } }); - try std.testing.expectEqual(Text.Mode.normal, pane.body.mode); - const file = try p.setTestFile("unchanged\n"); - try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode")); - try std.testing.expectEqual(Text.Mode.normal, file.body.mode); - try std.testing.expectEqualStrings("unchanged\n", file.file.?.content); -} - test "Filter is ordered after Del and toggles only its terminal or +Pager pane" { const testing = std.testing; const del = std.meta.stringToEnum(Builtin, "Del") orelse return error.MissingDelBuiltin; @@ -1259,24 +1195,6 @@ test "first document keeps its originating shell and only opens a column when it } } -test "acme placement: an empty active column takes the new pane whole" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 32 }); - defer p.deinit(); - try std.testing.expectEqual(config.Runtime.Placement.acme, p.settings.placement); - p.newColumn(0); // its tag has the keyboard: it is the active column - tagline.exitHeader(p); - p.sync(); - // A Look from the shell's text still lands in the active column, as - // acme's makenewwindow puts it in activecol first (util.c:456). - _ = try p.openTutorView(1); - exec.placeNew(p, 0, 0, 1, .doc); - try std.testing.expectEqualSlices(usize, &.{1}, p.col_panes[1][0..p.col_n[1]]); - try std.testing.expectEqual(@as(usize, 1), p.active); - try std.testing.expectEqual(@as(?usize, 1), p.activeColumn()); - // Never a new column. - try std.testing.expectEqual(@as(usize, 2), p.ncol); -} - test "acme placement: under a pane's text when it has many blank rows, else halving the biggest" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 }); defer p.deinit(); @@ -1419,24 +1337,6 @@ test "BootShell keep leaves the untouched boot shell a dragged document joins; r } } -test "a pane its whole text fits in never scrolls to keep a margin" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 30 }); - defer p.deinit(); - const pane = try p.setTestFile("one\ntwo\nthree\n"); - // A second pane under it, as acme's placement puts one: right under the - // three lines, which leaves the file exactly three body rows. - const below = p.freeSlot().?; - _ = try p.openTutorView(below); - exec.placeNew(p, 0, 0, below, .doc); - p.active = 0; - p.sync(); - try std.testing.expectEqual(@as(u16, 3), p.rects[0].h - pane.tag_rows); - for ("jj") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); - p.sync(); - try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); - try std.testing.expectEqual(@as(i32, 0), pane.scroll()); -} - test "dragging a column's only pane to another leaves that column in place, empty" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 32 }); defer p.deinit(); @@ -8615,53 +8515,6 @@ test "tty output follows only from the bottom" { try std.testing.expect(panes.terminal.scrollbar(sp).offset > live); } -test "Esc back into a file leaves its view where it was" { - if (platform == .web) return; - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "src/memory.zig" }); - defer p.deinit(); - // Rows are lines: the centring below counts lines, and a wrapped line - // above the cursor would push it out of the view it centres. - p.settings.wrap = false; - p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); - p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc - const shell = p.active; - p.update(.{ .key = .{ .cp = Key.escape } }); // back onto the doc - p.sync(); - const doc = p.active; - try std.testing.expect(doc != shell); - const dp = p.panes[doc].?; - try std.testing.expect(dp.file != null); - - // Ride the cursor down until the view has scrolled: it now sits in the - // bottom band, which is exactly where a recenter is visible. - for (0..20) |_| p.update(.{ .key = .{ .cp = 'j' } }); - p.sync(); - const view = dp.file.?.scroll; - const row = dp.body.cur_row; - try std.testing.expect(view > 0); - - p.update(.{ .key = .{ .cp = Key.escape } }); // out to the shell - p.sync(); - try std.testing.expectEqual(shell, p.active); - p.update(.{ .key = .{ .cp = Key.escape } }); // ...and back - p.sync(); - try std.testing.expectEqual(doc, p.active); - - // Nothing moved. The old landing recentred the line under the cursor, so - // coming back repainted the whole screen to show what was already on it. - try std.testing.expectEqual(view, dp.file.?.scroll); - try std.testing.expectEqual(row, dp.body.cur_row); - // ...and the cursor is still on screen, which is all `.nearest` promises. - try std.testing.expect(dp.body.cur_row >= @as(i32, @intCast(view))); - try std.testing.expect(dp.body.cur_row < @as(i32, @intCast(view)) + @as(i32, dp.rows)); - - // The other arm still centres: a look target, a `:NN`, a search hit. - look.focusPaneLine(p, doc, .{ .line = @intCast(row + 1), .col = 1 }, .center); - try std.testing.expect(dp.file.?.scroll != view); - try std.testing.expectEqual(@as(usize, @intCast(row)) -| @as(usize, dp.rows) / 2, dp.file.?.scroll); -} - test "raw tty Esc backs out and Shift-Esc is the program's Esc" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); diff --git a/test/behaviour.zig b/test/behaviour.zig index 902ef520..bec74d89 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -9,6 +9,8 @@ test { _ = @import("behaviour/modes.zig"); _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); + _ = @import("behaviour/placement.zig"); _ = @import("behaviour/root_ctl.zig"); _ = @import("behaviour/tags.zig"); + _ = @import("behaviour/terminals.zig"); } diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig index cdcf1be6..dde3ffb6 100644 --- a/test/behaviour/modes.zig +++ b/test/behaviour/modes.zig @@ -63,3 +63,42 @@ test "modes: Shift-Esc backs out to the previous pane in every mode, never into try std.testing.expectEqualStrings("normal", try mode(&s, doc)); try std.testing.expect(doc != try s.focused()); } + +/// The first line number drawn under the tag that starts with `tag`. +fn topLine(s: *Session, tag: []const u8) !usize { + const row = (try s.where(tag))[1]; + var rows = std.mem.splitScalar(u8, try s.screen(), '\n'); + for (0..row + 1) |_| _ = rows.next(); + var words = std.mem.tokenizeScalar(u8, rows.next().?, ' '); + return std.fmt.parseInt(usize, words.next().?, 10); +} + +test "modes: Esc back into a file leaves its view where it was, and a look centres its line" { + var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*)))); + defer s.deinit(); + const doc = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{doc}); + try s.keys("\u{F015}n"); // a shell under the doc + const shell = try s.focused(); + try s.keys("\x1b"); + try expectEqual(doc, try s.focused()); + // Ride the cursor down until the view has scrolled. + try s.keys(&@as([20]u8, @splat('j'))); + const top = try topLine(&s, "/test.txt"); + const at = try s.range(dot); + try std.testing.expect(top > 1); + try s.keys("\x1b"); + try expectEqual(shell, try s.focused()); + try s.keys("\x1b"); + try expectEqual(doc, try s.focused()); + // Nothing moved: the old landing recentred the line under the cursor. + try expectEqual(top, try topLine(&s, "/test.txt")); + try expectEqual(at, try s.range(dot)); + // The other arm still centres: a look's `:NN`. + const line = 60; + try s.write(s.at("/pane/{d}/look", .{doc}), s.at(":{d}\n", .{line})); + const rows = (try s.where("Tty Save Mode"))[1] - (try s.where("/test.txt"))[1] - 1; + // Drawn mid-pane, a row either way. + const drawn_at = line - try topLine(&s, "/test.txt"); + try std.testing.expect(drawn_at + 1 >= rows / 2 and drawn_at <= rows / 2 + 1); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index d0773bfb..149c8da1 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -112,3 +112,52 @@ test "panes: focus on a closed pane goes to the pane that takes its place, not t try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Delcol\n"); try std.testing.expectEqual(right_low, try s.focused()); } + +test "panes: Collapse keeps the text and folds the pane to its tag, and again restores it" { + var s = try Session.initFile(std.testing.allocator, "keep this text\n"); + defer s.deinit(); + var t = try Session.initTerm(std.testing.allocator); + defer t.deinit(); + const n = try s.focused(); + for ([_][]const u8{ + try s.read(s.at("/pane/{d}/tag", .{n})), + try s.read(s.at("/pane/{d}/tag", .{try s.newPane()})), + try t.read(t.at("/pane/{d}/tag", .{try t.focused()})), + }) |tag| try std.testing.expect(std.mem.endsWith(u8, tag, " Collapse Del")); + try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Del\n"); + const ctl = s.at("/pane/{d}/ctl", .{n}); + try s.write(ctl, "Collapse\n"); + // Folded to its tag: no text drawn, no cursor in it, the text kept. + try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), " collapsed ") != null); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "keep this text") == null); + try std.testing.expectEqual(null, try s.cursor()); + try s.expect(s.at("/pane/{d}/body", .{n}), "keep this text\n"); + try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n"); + // Its tag still takes the keyboard, the cursor on the tag's row. + try s.keys(":"); + try std.testing.expectEqual((try s.where("/test.txt"))[1], (try s.cursor()).?[1]); + try s.write(ctl, "Collapse\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), " collapsed ") == null); + try std.testing.expectEqual((try s.where("/test.txt"))[1] + 1, (try s.where("1 keep this text"))[1]); +} + +test "panes: a pane its whole text fits in never scrolls to keep a margin" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n"); + defer s.deinit(); + const n = try s.focused(); + // A second pane under it, as acme's placement puts one: right under the + // three lines, which leaves the file exactly three body rows. + try s.write(s.at("/pane/{d}/look", .{n}), s.at("{s}/f.txt\n", .{at})); + try s.write("/focus", s.at("{d}\n", .{n})); + try s.keys("jj"); + const top = (try s.where("/test.txt"))[1]; + try std.testing.expectEqual(top + 4, (try s.where(at[0..@min(at.len, 20)]))[1]); + // On the last line, and line 1 still the first drawn. + try std.testing.expectEqual(.{ @as(u32, 8), @as(u32, 8) }, try s.range(s.at("/pane/{d}/dot", .{n}))); + try std.testing.expectEqual(top + 1, (try s.where("1 one"))[1]); +} diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig new file mode 100644 index 00000000..350e94f8 --- /dev/null +++ b/test/behaviour/placement.zig @@ -0,0 +1,24 @@ +//! docs/typ/reference.typ, Placement . +const std = @import("std"); +const Session = @import("session").Session; + +test "placement: an empty active column takes the new pane whole, a look from another column's text too" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const first = try s.focused(); + // Its tag has the keyboard: it is the active column, and stays so + // when Esc gives the keyboard back. + try s.write("/ctl", "Newcol\n"); + try s.keys("\x1b"); + try std.testing.expectEqual(first, try s.focused()); + // A look from the first pane's text still lands in the active column, + // as acme's makenewwindow puts it in activecol first (util.c:456). + try s.write(s.at("/pane/{d}/look", .{first}), s.at("{s}/f.txt\n", .{at})); + const made = try s.focused(); + try std.testing.expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ try s.column(0), first, try s.column(1), made }), try s.columns()); +} diff --git a/test/behaviour/terminals.zig b/test/behaviour/terminals.zig new file mode 100644 index 00000000..f6bbdfa0 --- /dev/null +++ b/test/behaviour/terminals.zig @@ -0,0 +1,46 @@ +//! docs/typ/guide.typ, Terminals . +const std = @import("std"); +const Session = @import("session").Session; + +fn mode(s: *Session, pane: u32) ![]const u8 { + const ctl = try s.read(s.at("/pane/{d}/ctl", .{pane})); + const at = std.mem.lastIndexOf(u8, ctl, " mode:").? + " mode:".len; + return std.mem.trimEnd(u8, ctl[at..], " "); +} + +test "terminals: Togglettymode and Ctrl-B share the mode's transitions, from the body or its tag, and a text pane refuses it" { + var s = try Session.initTerm(std.testing.allocator); + defer s.deinit(); + const n = try s.focused(); + const ctl = s.at("/pane/{d}/ctl", .{n}); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/tag", .{n})), " Mode ") != null); + try s.write(s.at("/pane/{d}/tag", .{n}), " Togglettymode"); + try std.testing.expectEqualStrings("tty", try mode(&s, n)); + try s.write(ctl, "Togglettymode\n"); + try std.testing.expectEqualStrings("normal", try mode(&s, n)); + try s.keys("\x02"); + try std.testing.expectEqualStrings("tty", try mode(&s, n)); + // The tag has its own mode: the body keeps tty while the tag is typed + // into, and either way of toggling gives the body the keyboard back. + const tag_row = (try s.where("Togglettymode"))[1]; + try s.click("Togglettymode", 0, 1); + try std.testing.expectEqualStrings("tty", try mode(&s, n)); + try std.testing.expectEqual(tag_row, (try s.cursor()).?[1]); + try s.write(ctl, "Togglettymode\n"); + try std.testing.expectEqualStrings("normal", try mode(&s, n)); + try std.testing.expect((try s.cursor()).?[1] > tag_row); + try s.click("Togglettymode", 0, 1); + try s.keys("\x02"); + try std.testing.expectEqualStrings("tty", try mode(&s, n)); + try std.testing.expect((try s.cursor()).?[1] > tag_row); + // A middle click on the word in the tag. + try s.click("Togglettymode", 0, 2); + try std.testing.expectEqualStrings("normal", try mode(&s, n)); + // A text pane refuses it, normal, its text as it was. + const file = try s.newPane(); + try s.write(s.at("/pane/{d}/body", .{file}), "unchanged\n"); + _ = try s.refused(s.at("/pane/{d}/ctl", .{file}), "Togglettymode\n"); + try std.testing.expectEqualStrings("Togglettymode: only a terminal pane takes it", s.said); + try std.testing.expectEqualStrings("normal", try mode(&s, file)); + try s.expect(s.at("/pane/{d}/body", .{file}), "unchanged\n"); +} diff --git a/test/session.zig b/test/session.zig index f67f3b25..6d214874 100644 --- a/test/session.zig +++ b/test/session.zig @@ -220,6 +220,11 @@ pub const Session = struct { }; return .{ @intCast(c.get("x").?.integer), @intCast(c.get("y").?.integer) }; } + + /// Where `text` is first drawn on /screen, column and row. + pub fn where(s: *Session, text: []const u8) !struct { usize, usize } { + return s.find(text); + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { -- cgit v1.3 From ccb668645e9afc3710b1a50903022367a800ff1b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:28:55 -0300 Subject: test: four more of src/pardes.zig's tests through the 9P tree alone (test/behaviour/limits, settings, placement): a builtin that needs a pane refused in words once every one of the 64 slots is taken, Pet refused in a terminal's view from a pane and the root (a window's pets read back from /ctl), New and 9P's new taking the bottom half of a column's last pane, Placement pardes putting a pane right under the asking one and stepping back to acme bare (each read from /ctl); each checked to fail against a break (openHelp's failure unsaid, a GUI-only word run in a terminal's view, acmePlace's split at a quarter, pardes placement placing as acme) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 64 -------------------------------------------- test/behaviour.zig | 2 ++ test/behaviour/limits.zig | 18 +++++++++++++ test/behaviour/placement.zig | 37 +++++++++++++++++++++++++ test/behaviour/settings.zig | 23 ++++++++++++++++ 5 files changed, 80 insertions(+), 64 deletions(-) create mode 100644 test/behaviour/limits.zig create mode 100644 test/behaviour/settings.zig (limited to 'test/behaviour.zig') diff --git a/src/pardes.zig b/src/pardes.zig index 3d6b6e28..b47119c4 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1268,38 +1268,6 @@ test "acme placement: a pane made from the middle of a column moves only the one try std.testing.expectEqual(was_bottom.h, p.rects[bottom].h); } -test "acme placement: New and 9P's new take the bottom half of the last pane" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); - defer p.deinit(); - p.newScratchBelow(p.active); - const last = p.active; - p.sync(); - const was = p.rects[last]; - p.newScratchFor(last, .fs); - const made = p.active; - p.sync(); - try std.testing.expectEqual(layout.findPane(p, last).?.idx + 1, layout.findPane(p, made).?.idx); - try std.testing.expectEqual(was.y + was.h, p.rects[made].y + p.rects[made].h); - try std.testing.expect(p.rects[made].y > was.y + BOX_H); -} - -test "Placement pardes brings back the old rules, and says so in DumpConfig" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); - defer p.deinit(); - try std.testing.expect(p.executeBuiltinLine(p.active, "Placement pardes")); - try std.testing.expectEqual(config.Runtime.Placement.pardes, p.settings.placement); - const top = p.active; - p.sync(); - const was = p.rects[top]; - p.newScratchBelow(top); - p.sync(); - // Directly under the asking pane, as New always put it. - try std.testing.expectEqual(@as(usize, 1), layout.findPane(p, p.active).?.idx); - try std.testing.expectEqual(was.y + was.h, p.rects[p.active].y + p.rects[p.active].h); - try std.testing.expect(p.executeBuiltinLine(p.active, "Placement")); - try std.testing.expectEqual(config.Runtime.Placement.acme, p.settings.placement); -} - test "an empty column shows its theme's empty_col under its tag: acme's white, else the border" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 20 }); defer p.deinit(); @@ -2618,18 +2586,6 @@ test "a host with no methods at all is a complete in-process pardes" { try std.testing.expect(p.quit); } -test "a builtin that needs a pane reports capacity failure when every slot is full" { - const p = try Pardes.init(std.testing.allocator, .{ .shells = 3, .cols = 100, .rows = 30 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - for (0..MAX_PANES) |id| if (p.panes[id] == null) { - _ = try p.newDocPane(id); - }; - const help = std.meta.stringToEnum(Builtin, "Help") orelse return error.MissingHelpBuiltin; - exec.runBuiltin(p, help, 0, "", null); - try std.testing.expect(std.mem.indexOf(u8, p.panes[0].?.msg[0..p.panes[0].?.msg_len], "help: no space for a pane") != null); -} - test "Font keeps requested and acknowledged faces as separate plain state" { if (comptime !font_picker) return; // there is no Font builtin on tty or web const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); @@ -2718,26 +2674,6 @@ test "Font size suffix reaches native request and invalid input leaves it intact try std.testing.expectEqual(@as(u16, 1850), p.settings.font.effective_size_hundredths); } -test "Pet command is SDL-only optional and validates its argument" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); - defer p.deinit(); - try std.testing.expectEqual(.off, p.settings.pet); - if (comptime platform != .gui) { - // A terminal's view has the word and takes it not. - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet cat")); - try std.testing.expectEqual(.off, p.settings.pet); - return; - } - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet cat")); - try std.testing.expectEqual(.cat, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet dog")); - try std.testing.expectEqual(.cat, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet frog")); - try std.testing.expectEqual(.frog, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet off")); - try std.testing.expectEqual(.off, p.settings.pet); -} - test "startup config overrides restored styling before initFromDump returns" { const source = try Pardes.init(std.testing.allocator, .{ .startup_config = "Theme dark\n" }); defer source.deinit(); diff --git a/test/behaviour.zig b/test/behaviour.zig index bec74d89..3049f648 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -5,12 +5,14 @@ test { _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); + _ = @import("behaviour/limits.zig"); _ = @import("behaviour/look_and_exec.zig"); _ = @import("behaviour/modes.zig"); _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/placement.zig"); _ = @import("behaviour/root_ctl.zig"); + _ = @import("behaviour/settings.zig"); _ = @import("behaviour/tags.zig"); _ = @import("behaviour/terminals.zig"); } diff --git a/test/behaviour/limits.zig b/test/behaviour/limits.zig new file mode 100644 index 00000000..08c864eb --- /dev/null +++ b/test/behaviour/limits.zig @@ -0,0 +1,18 @@ +//! docs/typ/reference.typ, Limits . +const std = @import("std"); +const Session = @import("session").Session; + +test "limits: a builtin that needs a pane says so when every slot is taken" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + // Room on the screen for every pane, so the slots run out first. + s.detach(); + try s.write("/ctl", "size 100 400\n"); + var made: usize = 1; + while (s.newPane()) |_| made += 1 else |_| {} + try std.testing.expectEqual(@as(usize, 64), made); + _ = try s.refused(s.at("/pane/{d}/exec", .{n}), "Help\n"); + try std.testing.expectEqualStrings("help: no space for a pane: 64 max", s.said); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "help: no space for a pane") != null); +} diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig index 350e94f8..079b5a5e 100644 --- a/test/behaviour/placement.zig +++ b/test/behaviour/placement.zig @@ -22,3 +22,40 @@ test "placement: an empty active column takes the new pane whole, a look from an const made = try s.focused(); try std.testing.expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ try s.column(0), first, try s.column(1), made }), try s.columns()); } + +/// The screen row the tag starting `name` is drawn on. +fn tagRow(s: *Session, name: []const u8) !usize { + return (try s.where(s.at("{s} Save", .{name})))[1]; +} + +test "placement: New and 9P's new take the bottom half of the column's last pane" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const first = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{first}), "New\n"); + const last = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{last}), "/last\n"); + const was = try tagRow(&s, "/last"); + const made = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{made}), "/made\n"); + try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d}", .{ try s.column(0), first, last, made }), try s.columns()); + // The last pane keeps its top and gives up its bottom half. + try std.testing.expectEqual(was, try tagRow(&s, "/last")); + const rows = std.mem.count(u8, try s.screen(), "\n") + 1; + try std.testing.expect(try tagRow(&s, "/made") >= was + (rows - was) / 2); +} + +test "placement: Placement pardes puts a new pane right under the asking one, and bare it steps back to acme" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "Placement pardes\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement pardes\n") != null); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + const below = try s.focused(); + // Directly under the asking pane, as New always put it. + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d}", .{ try s.column(0), top, try s.focused(), below }), try s.columns()); + try s.write("/ctl", "Placement\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement acme\n") != null); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig new file mode 100644 index 00000000..59e6f7c3 --- /dev/null +++ b/test/behaviour/settings.zig @@ -0,0 +1,23 @@ +//! docs/typ/reference.typ, Settings . +const std = @import("std"); +const Session = @import("session").Session; + +test "settings: Pet is the window's: a terminal's view refuses it, from a pane and the root; a window takes only its pets" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + if (try s.refused("/ctl", "Pet cat\n") == 0) { + // A window's: dog is no pet of its, and off is. + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null); + _ = try s.refused("/ctl", "Pet dog\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null); + try s.write("/ctl", "Pet frog\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet frog\n") != null); + try s.write("/ctl", "Pet off\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet off\n") != null); + return; + } + try std.testing.expect(std.mem.startsWith(u8, s.said, "Pet is GUI-only, invalid here")); + try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Pet cat\n")); + try std.testing.expectEqualStrings("Pet is GUI-only, invalid here", s.said); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "Pet ") == null); +} -- cgit v1.3 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 (limited to 'test/behaviour.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