diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-03 17:00:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-03 17:04:18 -0300 |
| commit | 37408da299e21b8807ccd10545482a709bac88c7 (patch) | |
| tree | ff29465e50538df66a712d9aeabf156c9185a1b1 | |
| parent | d1273bbd99daf9b1855d82bf315db8ede20abde5 (diff) | |
| download | pardes-37408da299e21b8807ccd10545482a709bac88c7.tar.gz pardes-37408da299e21b8807ccd10545482a709bac88c7.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | src/pardes.zig | 184 | ||||
| -rw-r--r-- | test/behaviour/columns_and_tags.zig | 118 | ||||
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 8 | ||||
| -rw-r--r-- | test/session.zig | 28 |
4 files changed, 154 insertions, 184 deletions
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 <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} { |
