From 53c2a95eff9c67871d6004baa3e7d3c3b2a195fd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:00:43 -0300 Subject: test: three of test/pdf.zig's look tests through the 9P tree alone (test/behaviour/look_and_exec): `:N` on a PDF from its look, the root's and `@pN:N` (the page read from its tag's [P/N]), its misses in the log (no page 0, no search hit, no text to address, one past the last); a page past the last a miss, open or not, opening nothing (/index); a +PdfSections row's page checked against the outline; Session's lookFile and pdfPage; each checked to fail against a break (a PDF look turning to page 1 always, an open PDF's past-last page check dropped, Pdf.openPane taking .last for .refuse, the sections row's page check dropped) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/look_and_exec.zig | 94 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'test/behaviour/look_and_exec.zig') diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 2ff4345b..a6f28960 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -36,3 +36,97 @@ 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)); } + +/// The log's `err` records, counted. +fn errs(s: *Session) !usize { + return std.mem.count(u8, try s.read("/log"), "\nerr "); +} + +/// The serial of the pane /index names with `suffix`. +fn paneNamed(s: *Session, suffix: []const u8) !u32 { + var lines = std.mem.splitScalar(u8, try s.read("/index"), '\n'); + while (lines.next()) |line| { + // serial kind dirty name column + const name = line[0 .. std.mem.lastIndexOfScalar(u8, line, ' ') orelse continue]; + if (std.mem.endsWith(u8, name, suffix)) return std.fmt.parseInt(u32, line[0..std.mem.indexOfScalar(u8, line, ' ').?], 10); + } + return error.NoSuchPane; +} + +test "look-and-exec: `:N` on a PDF turns to page N, from the pane and from the root's look, and `@pN:N` logs no err" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const look = s.at("/pane/{d}/look", .{n}); + const pages = (try s.pdfPage(n))[1]; + try std.testing.expect(pages >= 3); + try s.write(look, ":2\n"); + try expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]); + try s.write(look, s.at("@p{d}:1\n", .{n})); + try expectEqual(@as(u32, 1), (try s.pdfPage(n))[0]); + try s.write("/look", s.at("@p{d}:2\n", .{n})); + try expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]); + try expectEqual(@as(usize, 0), try errs(&s)); + // `:N:H` is hit H of its search on page N, as a search row's + // `file.pdf:N:H` is: with no search there is no hit 3, a miss that turns + // no page. + try s.write(look, ":1\n"); + _ = try s.refused(look, ":2:3\n"); + try expectEqual(@as(u32, 1), (try s.pdfPage(n))[0]); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "has no search hit 3 on page 2") != null); + try s.write(look, ":2\n"); + _ = try s.refused(look, ":0\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "has no page 0") != null); + // A byte offset or a pattern is no PDF address: refused with words. + _ = try s.refused(look, ":#3\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "its address is a page, :N") != null); + const before = try errs(&s); + _ = try s.refused(look, s.at(":{d}\n", .{pages + 1})); + try expectEqual(before + 1, try errs(&s)); + try expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]); +} + +test "look-and-exec: a look at a PDF's page past its last is a miss, never the last page, and opens nothing" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + try std.Io.Dir.cwd().copyFile("docs/design.pdf", tmp.dir, "other.pdf", std.testing.io, .{}); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const look = s.at("/pane/{d}/look", .{n}); + const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n"); + // Open: it stays on its page. + try s.write(look, ":2\n"); + _ = try s.refused(look, s.at("{s}:999\n", .{name})); + try expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "has no page 999") != null); + // Not open: nothing opens. + const index = try s.read("/index"); + _ = try s.refused(look, s.at("{s}/other.pdf:999\n", .{dir})); + try s.expect("/index", index); +} + +test "look-and-exec: a +PdfSections row's first number is the page: a section not there, or on another page, is a miss said" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + try s.write(s.at("/pane/{d}/exec", .{n}), "PdfSections\n"); + const out = try paneNamed(&s, "/+PdfSections"); + const body = try s.read(s.at("/pane/{d}/body", .{out})); + const row = body[0..std.mem.indexOfScalar(u8, body, '\n').?]; + const place = row[0..std.mem.indexOfScalar(u8, row, ' ').?]; // design.pdf:P:S + var fields = std.mem.splitScalar(u8, place, ':'); + _ = fields.next(); + const page = try std.fmt.parseInt(u32, fields.next().?, 10); + const look = s.at("/pane/{d}/look", .{out}); + // As listed: found, no miss. + try s.write(look, s.at("{s}\n", .{place})); + try expectEqual(@as(usize, 0), try errs(&s)); + // The section on another page than the row says, and one not there. + _ = try s.refused(look, s.at("design.pdf:{d}:1\n", .{page + 1})); + try expectEqual(@as(usize, 1), try errs(&s)); + _ = try s.refused(look, "design.pdf:1:999\n"); + try expectEqual(@as(usize, 2), try errs(&s)); +} -- cgit v1.3 From 37408da299e21b8807ccd10545482a709bac88c7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:00:11 -0300 Subject: test: eight of src/pardes.zig's tests through the 9P tree alone (test/behaviour/columns_and_tags, look_and_exec): Joincol folding a column into its right neighbour and refused with none, Newcol's empty column with its tag focused filled by the next Tty, a column's exec acting on that column and a pane's Delcol on its own, a column's last pane closed leaving it empty and Delcol taking it, a column's tag following it through Newcol and Joincol, Delcol on the last column leaving the window typed into, New in no pane's tag nor the workspace's, a look that finds nothing in the log; Session's columns and column (/layout as column:panes); each checked to fail against a break (joinCol inert, joinCol keeping the left tag, acmeColumn ignoring the active column, a scratch ignoring exec_column, no enterHeader for an emptied column, removeColumn refusing the last, New in a file pane's tail, missed logging nothing) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 184 ------------------------------------ test/behaviour/columns_and_tags.zig | 118 +++++++++++++++++++++++ test/behaviour/look_and_exec.zig | 8 ++ test/session.zig | 28 ++++++ 4 files changed, 154 insertions(+), 184 deletions(-) (limited to 'test/behaviour/look_and_exec.zig') diff --git a/src/pardes.zig b/src/pardes.zig index ff64cb9f..ea8b52df 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -978,29 +978,6 @@ test "compact tag commands stay beside their own prefix across layout changes" { try std.testing.expectEqualStrings(above_tag, try tagline.tagText(p, p.scratch.allocator(), above)); } -test "Joincol folds the active column into its right neighbor, keeping its panes" { - 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 right = p.freeSlot().?; - _ = try p.newShell(right, ""); - try std.testing.expect(layout.splitColumn(p, 0, right, false)); - while (p.nextEffect()) |_| {} - try std.testing.expectEqual(@as(usize, 2), p.ncol); - - p.active = 0; // the left column is current - layout.joinCol(p, 0); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - const lf = layout.findPane(p, 0) orelse return error.LostLeftPane; - const rf = layout.findPane(p, right) orelse return error.LostRightPane; - try std.testing.expectEqual(lf.col, rf.col); - - layout.joinCol(p, 0); // no right neighbor left: inert - try std.testing.expectEqual(@as(usize, 1), p.ncol); -} - test "Tty spawns a raw shell in the caller's directory" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -1485,16 +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 "pane defaults keep creation of scratch panes in column tags" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - for ([_][]const u8{ tagline.pane_tail, tagline.file_pane_tail, tagline.pdf_pane_tail, tagline.terminal_pane_tail, config.topbar_str }) |tag| { - var words = std.mem.tokenizeScalar(u8, tag, ' '); - while (words.next()) |word| try std.testing.expect(!std.mem.eql(u8, word, "New")); - } - try std.testing.expectEqualStrings("New Tty Find Grep Joincol Delcol", tagline.columnTag(p, 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 }); @@ -3345,21 +3312,6 @@ test "editable workspace and column tags are typed into and persist" { try std.testing.expectEqualStrings("", tagline.columnTag(empty, 0)); } -test "column tags follow their column through split and close" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("left\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "Left Find"); - _ = exec.execute(p, 0, "Newcol"); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqualStrings("Left Find", tagline.columnTag(p, 0)); - p.col_tags[1].own = try p.gpa.dupe(u8, "Right Grep"); - p.active = p.col_panes[0][0]; - layout.joinCol(p, 0); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - try std.testing.expectEqualStrings("Right Grep", tagline.columnTag(p, 0)); -} - test "column tags render edit hover and scroll from the column edge" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true }); defer p.deinit(); @@ -8609,62 +8561,6 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro try std.testing.expect(pane.prompt == .none and pane.input.own == null); } -test "Newcol makes an empty column, and the next pane made from its tag fills it" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); - defer p.deinit(); - const first = p.active; - const panes_before = p.col_n[0]; - try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); - try std.testing.expectEqual(panes_before, p.col_n[0]); - // The keyboard is on the new column's tag; no pane has it. - try std.testing.expect(p.header_focus and p.header_column.? == 1); - try std.testing.expectEqual(first, p.active); - p.sync(); - try std.testing.expect(p.executeBuiltinLine(first, "Tty")); - const shell = p.active; - try std.testing.expect(shell != first); - try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); - try std.testing.expectEqual(shell, p.col_panes[1][0]); - try std.testing.expect(!p.header_focus); - - // The next Tty splits as it always has: nothing is empty any more. - p.sync(); - try std.testing.expect(p.executeBuiltinLine(shell, "Tty")); - try std.testing.expectEqual(@as(usize, 2), p.col_n[1]); -} - -test "a column tag's command acts on that column" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); - defer p.deinit(); - const first = p.active; - try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); - try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); - try std.testing.expectEqual(@as(usize, 3), p.ncol); - p.sync(); - // New from the middle column's tag lands in it, not below `first`. - p.exec_column = 1; - try std.testing.expect(p.executeBuiltinLine(first, "New")); - p.exec_column = null; - try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); - try std.testing.expectEqual(p.active, p.col_panes[1][0]); - // Delcol from the empty right column's tag closes that one. - p.exec_column = 2; - try std.testing.expect(p.executeBuiltinLine(first, "Delcol")); - p.exec_column = null; - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); - // A pane's own Delcol closes its column whatever tag has the keyboard. - try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); - try std.testing.expect(p.header_focus); - try std.testing.expect(p.executeBuiltinLine(p.col_panes[1][0], "Delcol")); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); -} - test "Del from a key asks which neighbour takes the rows; nothing else asks" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 }); @@ -8780,17 +8676,6 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" { try std.testing.expect(p.panes[low] == null); } -test "a Look that finds nothing says so" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - p.newScratchBelow(p.active); - const id = p.active; - p.sync(); - look.lookAt(p, id, "/no/such/zzqq"); - try std.testing.expectEqualStrings("Look: no match for \"/no/such/zzqq\"", p.panes[id].?.msg[0..p.panes[id].?.msg_len]); -} - 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 }); @@ -8834,47 +8719,6 @@ test "focus on a closed pane goes to the pane that takes its place, not the one try std.testing.expectEqual(right_low, p.active); } -test "closing the last pane in a column leaves the column empty, its tag focused" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 24 }); - defer p.deinit(); - const shell = p.active; - p.newColumn(shell); - p.newScratchIn(shell, p.activeColumn().?); - const lone = p.active; - try std.testing.expect(lone != shell); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - const at = layout.findPane(p, lone).?; - try std.testing.expectEqual(@as(usize, 1), p.col_n[at.col]); - p.sync(); - - try p.removePane(lone, null); - p.sync(); - - // The column outlives the pane, as acme's does: still two columns, the - // emptied one with no pane and the keyboard on its tag. - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 0), p.col_n[at.col]); - try std.testing.expect(p.panes[lone] == null); - try std.testing.expect(p.header_focus and p.header_column.? == at.col); - try std.testing.expectEqual(shell, p.active); - try std.testing.expect(!p.quit); - - // Down from it goes nowhere: nothing is below. - try std.testing.expect(p.executeBuiltinLine(shell, "Down")); - try std.testing.expect(p.header_focus and p.header_column.? == at.col); - - // ...and Delcol is what actually takes the column away. - try p.removeColumn(at.col); - p.sync(); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - try std.testing.expectEqual(shell, p.active); - - // The session's last pane closing ends it. - try p.removePane(shell, null); - try std.testing.expect(p.quit); -} - 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 }); @@ -10070,31 +9914,3 @@ test "a Save the host could not do logs no save record" { p.perform(.{ .save_file = .{ .pane = 0 } }); try std.testing.expect(th.logHas(p, "\nsave ")); } - -test "Delcol on the last column leaves the window, drawn and typed into, and Newcol starts it again" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - while (p.ncol > 0) { - p.exec_column = 0; - _ = p.executeBuiltinLine(p.active, "Delcol"); - p.exec_column = null; - p.sync(); - } - try std.testing.expect(!p.quit); - try std.testing.expect(p.anyPane() == null); - // Drawn, and keys go to the workspace tag. - _ = try p.render(p.frame_arena.allocator()); - p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - p.sync(); - _ = try p.render(p.frame_arena.allocator()); - try std.testing.expect(!p.quit); - _ = p.executeBuiltinLine(p.active, "Newcol"); - p.sync(); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - _ = p.executeBuiltinLine(p.active, "New"); - p.sync(); - try std.testing.expect(p.anyPane() != null); - _ = try p.render(p.frame_arena.allocator()); -} diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig index 25ba4c64..80f9c710 100644 --- a/test/behaviour/columns_and_tags.zig +++ b/test/behaviour/columns_and_tags.zig @@ -1,6 +1,7 @@ //! docs/typ/reference.typ, Columns and tags . const std = @import("std"); const Session = @import("session").Session; +const expectEqualStrings = std.testing.expectEqualStrings; /// /layout's line for the last column. fn lastColumn(s: *Session) ![]const u8 { @@ -31,3 +32,120 @@ test "columns-and-tags: a look after Newcol fills the empty column the keyboard try std.testing.expect(std.mem.indexOf(u8, col, " full ") != null); try std.testing.expect(std.mem.endsWith(u8, col, s.at(" {d}", .{try s.focused()}))); } + +test "columns-and-tags: Joincol folds a column into its right neighbour, keeping its panes, and with none it is inert" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const left = try s.focused(); + const left_col = try s.column(0); + try s.write("/ctl", "Newcol\n"); + const right_col = try s.column(1); + try s.write(s.at("/col/{d}/ctl", .{right_col}), "New\n"); + const right = try s.focused(); + try s.write(s.at("/col/{d}/ctl", .{left_col}), "Joincol\n"); + try expectEqualStrings(s.at("{d}:{d},{d}", .{ right_col, right, left }), try s.columns()); + _ = try s.refused(s.at("/col/{d}/ctl", .{right_col}), "Joincol\n"); + try expectEqualStrings("Joincol: no column to the right", s.said); + try expectEqualStrings(s.at("{d}:{d},{d}", .{ right_col, right, left }), try s.columns()); +} + +test "columns-and-tags: Newcol makes an empty column with the keyboard on its tag, and the next pane made fills it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const first = try s.focused(); + try s.write("/ctl", "Newcol\n"); + const left, const col = .{ try s.column(0), try s.column(1) }; + try expectEqualStrings(s.at("{d}:{d} {d}:", .{ left, first, col }), try s.columns()); + try s.expect("/focus", ""); + try s.write(s.at("/pane/{d}/exec", .{first}), "Tty\n"); + const shell = try s.focused(); + try expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ left, first, col, shell }), try s.columns()); + // The next Tty splits as it always has: nothing is empty any more. + try s.write(s.at("/pane/{d}/exec", .{shell}), "Tty\n"); + try expectEqualStrings(s.at("{d}:{d} {d}:{d},{d}", .{ left, first, col, shell, try s.focused() }), try s.columns()); +} + +test "columns-and-tags: a column's exec acts on that column, and a pane's Delcol on its own" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const first = try s.focused(); + try s.write("/ctl", "Newcol\n"); + try s.write("/ctl", "Newcol\n"); + const left, const middle = .{ try s.column(0), try s.column(1) }; + // New from the middle column's tag lands in it, not below the pane + // with the keyboard. + try s.write(s.at("/col/{d}/exec", .{middle}), "New\n"); + const made = try s.focused(); + try expectEqualStrings(s.at("{d}:{d} {d}:{d} {d}:", .{ left, first, middle, made, try s.column(2) }), try s.columns()); + // Delcol from the empty right column's tag closes that one. + try s.write(s.at("/col/{d}/exec", .{try s.column(2)}), "Delcol\n"); + try expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ left, first, middle, made }), try s.columns()); + // A pane's own Delcol closes its column whatever tag has the keyboard. + try s.write("/ctl", "Newcol\n"); + try s.expect("/focus", ""); + const right = try s.column(2); + try s.write(s.at("/pane/{d}/exec", .{made}), "Delcol\n"); + try expectEqualStrings(s.at("{d}:{d} {d}:", .{ left, first, right }), try s.columns()); +} + +test "columns-and-tags: closing a column's last pane leaves it empty, its tag with the keyboard; Delcol takes it away" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const first = try s.focused(); + try s.write("/ctl", "Newcol\n"); + const left, const col = .{ try s.column(0), try s.column(1) }; + try s.write(s.at("/col/{d}/ctl", .{col}), "New\n"); + try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Del\n"); + // The column outlives the pane, as acme's does. + try expectEqualStrings(s.at("{d}:{d} {d}:", .{ left, first, col }), try s.columns()); + try s.expect("/focus", ""); + // Down from it goes nowhere: nothing is below. + try s.write(s.at("/pane/{d}/exec", .{first}), "Down\n"); + try s.expect("/focus", ""); + try s.write(s.at("/col/{d}/ctl", .{col}), "Delcol\n"); + try expectEqualStrings(s.at("{d}:{d}", .{ left, first }), try s.columns()); + try std.testing.expectEqual(first, try s.focused()); +} + +test "columns-and-tags: a column's tag follows its column through Newcol and Joincol" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write(s.at("/col/{d}/tag", .{try s.column(0)}), " Left"); + try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Newcol\n"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/col/{d}/tag", .{try s.column(0)})), " Left")); + try s.write(s.at("/col/{d}/tag", .{try s.column(1)}), " Right"); + try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Joincol\n"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/col/{d}/tag", .{try s.column(0)})), " Right")); +} + +test "columns-and-tags: Delcol on the last column leaves the window, drawn and typed into, and Newcol starts it again" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Delcol\n"); + try expectEqualStrings("", try s.columns()); + try s.expect("/index", ""); + // Drawn, and keys go to the workspace tag. + try s.keys("x\n"); + try std.testing.expect(std.mem.startsWith(u8, try s.screen(), " Newcol ")); + try s.write("/ctl", "Newcol\n"); + try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "New\n"); + try expectEqualStrings(s.at("{d}:{d}", .{ try s.column(0), try s.focused() }), try s.columns()); +} + +test "columns-and-tags: New is a column tag's word, in no pane's tag nor the workspace's" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + var t = try Session.initTerm(std.testing.allocator); + defer t.deinit(); + const scratch = try s.newPane(); + for ([_][]const u8{ + try s.read("/tag"), + try s.read(s.at("/pane/{d}/tag", .{scratch})), + try s.read(s.at("/pane/{d}/tag", .{try s.focused()})), + try t.read(t.at("/pane/{d}/tag", .{try t.focused()})), + }) |tag| { + var words = std.mem.tokenizeScalar(u8, tag, ' '); + while (words.next()) |word| try std.testing.expect(!std.mem.eql(u8, word, "New")); + } + try expectEqualStrings("New Tty Find Grep Joincol Delcol", try s.read(s.at("/col/{d}/tag", .{try s.column(0)}))); +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 2ff4345b..5b8d7e1a 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -36,3 +36,11 @@ 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 that finds nothing says so" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.newPane(); + try s.write(s.at("/pane/{d}/look", .{n}), "/no/such/zzqq\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("err {d} look: no match for \"/no/such/zzqq\"\n", .{n})) != null); +} diff --git a/test/session.zig b/test/session.zig index 8b3c5c41..c4ed0db2 100644 --- a/test/session.zig +++ b/test/session.zig @@ -182,6 +182,34 @@ pub const Session = struct { fn pardesOf(s: *Session) *Pardes { return @ptrCast(@alignCast(s.core)); } + + // core: + + /// /layout as its columns, left to right, `column:pane,pane` each and + /// a blank between (`1:2,5 3:`, column 3 empty). + pub fn columns(s: *Session) ![]const u8 { + const a = s.arena.allocator(); + var out: std.ArrayList(u8) = .empty; + var lines = std.mem.tokenizeScalar(u8, try s.read("/layout"), '\n'); + while (lines.next()) |line| { + if (std.mem.startsWith(u8, line, "active ")) continue; + var words = std.mem.tokenizeScalar(u8, line, ' '); + if (out.items.len > 0) try out.append(a, ' '); + try out.print(a, "{s}:", .{words.next().?}); + for (0..5) |_| _ = words.next(); // index x width current empty|full + var sep: []const u8 = ""; + while (words.next()) |pane| : (sep = ",") try out.print(a, "{s}{s}", .{ sep, pane }); + } + return out.items; + } + + /// The serial of the `i`th column from the left. + pub fn column(s: *Session, i: usize) !u32 { + var cols = std.mem.tokenizeScalar(u8, try s.columns(), ' '); + for (0..i) |_| _ = cols.next(); + const col = cols.next() orelse return error.NoColumn; + return std.fmt.parseInt(u32, col[0..std.mem.indexOfScalar(u8, col, ':').?], 10); + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { -- cgit v1.3 From e5b9badb0942f5269190dffdc745169a7aba0391 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:27:00 -0300 Subject: test: the pdf area's behavioural tests skip in a build without PDFs (-Dmupdf=false), as the old ones did: Session.lookFile of a .pdf skips the test when /commands has no PdfTint (seven failed there before, now eight skip); and a look at a page past the last of a PDF that is not open checks its miss in the log (other.pdf has no page 999), not /index alone; checked to fail against a break (Pdf.openPane's NoSuchPage answered with no miss), which passed the test before Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/look_and_exec.zig | 1 + test/session.zig | 3 +++ 2 files changed, 4 insertions(+) (limited to 'test/behaviour/look_and_exec.zig') diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index a6f28960..83ade2fc 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -106,6 +106,7 @@ test "look-and-exec: a look at a PDF's page past its last is a miss, never the l const index = try s.read("/index"); _ = try s.refused(look, s.at("{s}/other.pdf:999\n", .{dir})); try s.expect("/index", index); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "other.pdf has no page 999") != null); } test "look-and-exec: a +PdfSections row's first number is the page: a section not there, or on another page, is a miss said" { diff --git a/test/session.zig b/test/session.zig index f11a4c7f..4ac41d66 100644 --- a/test/session.zig +++ b/test/session.zig @@ -187,7 +187,10 @@ pub const Session = struct { /// A Look of `path` at the root (one relative to the working directory /// made absolute first); the serial of the pane with the keyboard after. + /// A PDF in a build without them (-Dmupdf=false: no PdfTint in + /// /commands) skips the test. pub fn lookFile(s: *Session, path: []const u8) !u32 { + if (std.mem.endsWith(u8, path, ".pdf") and std.mem.indexOf(u8, try s.read("/commands"), "PdfTint") == null) return error.SkipZigTest; var buf: [4096]u8 = undefined; const abs = if (std.fs.path.isAbsolute(path)) path else s.at("{s}/{s}", .{ buf[0..try std.Io.Dir.cwd().realPath(std.testing.io, &buf)], path }); try s.write("/look", s.at("{s}\n", .{abs})); -- 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/look_and_exec.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 From 00629bd791b8e41204366a795b6f36a289a45a68 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:45:10 -0300 Subject: test: two checks the panes migration dropped though the 9P tree shows them, from a review: a look leaves select mode and the extra cursors behind (mode:normal on the pane's ctl after Cv and a look, a Z typed once), as the old test's cleared() asked of select and nsel; a click past a line's end and on a wide glyph's second cell draws the caret where it lands, and insert mode draws it there too (Session.cursor from /screen), as the old tests compared the render's cursor; each checked to fail against a break (clearNavigationSelection keeping select, keeping nsel; the insert-mode body caret drawn a cell right) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/look_and_exec.zig | 11 +++++++++++ test/behaviour/mouse.zig | 16 +++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'test/behaviour/look_and_exec.zig') diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index ec26b74f..3c76988e 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -43,9 +43,20 @@ test "look-and-exec: a look replaces the selection it was made from, for an addr const n = try s.focused(); const dot = s.at("/pane/{d}/dot", .{n}); const look = s.at("/pane/{d}/look", .{n}); + const ctl = s.at("/pane/{d}/ctl", .{n}); + const body = s.at("/pane/{d}/body", .{n}); try s.write(dot, "0 5"); + // A second cursor on the line below, and select mode. + try s.keys("Cv"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:select ")); try s.write(look, "/test.txt:3:2\n"); try expectEqual(.{ @as(u32, 13), @as(u32, 13) }, try s.range(dot)); + // Both are gone with it: normal mode, and what is typed goes in once. + try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:normal ")); + try s.keys("iZ\x1b"); + try s.expect(body, "alpha\nbravo\ncZharlie\nneedle\n"); + try s.write(ctl, "Undo\n"); + try s.expect(body, "alpha\nbravo\ncharlie\nneedle\n"); 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"); diff --git a/test/behaviour/mouse.zig b/test/behaviour/mouse.zig index 27185409..13c9b631 100644 --- a/test/behaviour/mouse.zig +++ b/test/behaviour/mouse.zig @@ -54,11 +54,11 @@ test "mouse: everything a B1 chord does while B1 is down is one undo step" { test "mouse: a click past a line's or the file's end puts the caret where insertion types" { for ([_]bool{ false, true }) |already_insert| { for ([_]bool{ false, true }) |bottom_tag| { - for ([_]struct { text: []const u8, click_row: usize, dot: u32, result: []const u8 }{ - .{ .text = "abc\nxy", .click_row = 0, .dot = 3, .result = "abcZ\nxy" }, - .{ .text = "abc\nxy", .click_row = 5, .dot = 6, .result = "abc\nxyZ" }, - .{ .text = "abc\n", .click_row = 5, .dot = 4, .result = "abc\nZ" }, - .{ .text = "", .click_row = 5, .dot = 0, .result = "Z" }, + for ([_]struct { text: []const u8, click_row: usize, dot: u32, col: usize, row: usize, result: []const u8 }{ + .{ .text = "abc\nxy", .click_row = 0, .dot = 3, .col = 3, .row = 0, .result = "abcZ\nxy" }, + .{ .text = "abc\nxy", .click_row = 5, .dot = 6, .col = 2, .row = 1, .result = "abc\nxyZ" }, + .{ .text = "abc\n", .click_row = 5, .dot = 4, .col = 0, .row = 1, .result = "abc\nZ" }, + .{ .text = "", .click_row = 5, .dot = 0, .col = 0, .row = 0, .result = "Z" }, }) |case| { var s = try Session.initFile(std.testing.allocator, case.text); defer s.deinit(); @@ -69,8 +69,11 @@ test "mouse: a click past a line's or the file's end puts the caret where insert const x, const y = try s.where("1 "); try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + 2 + 15, y + case.click_row, x + 2 + 15, y + case.click_row }); try std.testing.expectEqual(.{ case.dot, case.dot }, try s.range(s.at("/pane/{d}/dot", .{n}))); + // The caret is drawn where it is, and insertion draws it there too. + try std.testing.expectEqual(.{ x + 2 + case.col, y + case.row }, try s.cursor()); if (!already_insert) try s.keys("i"); try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:insert ")); + try std.testing.expectEqual(.{ x + 2 + case.col, y + case.row }, try s.cursor()); try s.keys("Z"); try s.expect(s.at("/pane/{d}/body", .{n}), case.result); } @@ -95,7 +98,10 @@ test "mouse: a click on a tab's or a wrapped wide glyph's cells puts the caret o try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + 1, y, x + 1, y }); const at: u32 = @intCast(try std.unicode.utf8CountCodepoints(source[0..std.mem.indexOf(u8, source, "界").?])); try std.testing.expectEqual(.{ at, at }, try s.range(s.at("/pane/{d}/dot", .{n}))); + // Drawn on the glyph's first cell, in insert mode too. + try std.testing.expectEqual(.{ x, y }, try s.cursor()); if (!already_insert) try s.keys("i"); + try std.testing.expectEqual(.{ x, y }, try s.cursor()); try s.keys("Z"); const byte = std.mem.indexOf(u8, source, "界").?; try s.expect(s.at("/pane/{d}/body", .{n}), s.at("{s}Z{s}", .{ source[0..byte], source[byte..] })); -- cgit v1.3