From 6ff5fc7447cc411dc24cb1d841130f15a410e354 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:08:35 -0300 Subject: test: three of test/output.zig's tests through the 9P tree alone: DumpConfig's report in its one +DumpConfig pane, a second refreshing it in place (settings, a new file: /index, /focus and its body, Theme acme seen there), Config with no configuration directory refused, said in the log and opening nothing (settings), a Mini that cannot read its file leaving the panes, the last snapshot and the keyboard as they were (panes); the startup path line stays, a process flag with no 9P surface; each checked to fail against a break (openRead never reusing an output pane, Config taking a made-up path when there is no directory, a failed Mini giving the keyboard back to its caller) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/settings.zig | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/behaviour/settings.zig (limited to 'test/behaviour/settings.zig') diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig new file mode 100644 index 00000000..57751ab1 --- /dev/null +++ b/test/behaviour/settings.zig @@ -0,0 +1,38 @@ +//! docs/typ/reference.typ, Settings . +const std = @import("std"); +const Session = @import("session").Session; + +fn has(text: []const u8, part: []const u8) !void { + if (std.mem.indexOf(u8, text, part) == null) { + std.debug.print("not in it: {s}\n", .{part}); + return error.TestExpectedText; + } +} + +test "settings: DumpConfig reports the settings in its one +DumpConfig pane, a second refreshing it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const text = try s.focused(); + const exec = s.at("/pane/{d}/exec", .{text}); + try s.write(exec, "DumpConfig\n"); + const out = try s.focused(); + try std.testing.expect(out != text); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("{d} text 0 /+DumpConfig ", .{out})) != null); + const report = try s.read(s.at("/pane/{d}/body", .{out})); + for ([_][]const u8{ "Theme orchard\n", "Last shell spawned: (none)\n", "Shell change pending: on\n", "\nShell ", "LocationsConfig ", "no per-user config path" }) |line| try has(report, line); + try s.write("/ctl", "Theme acme\n"); + try s.write("/focus", s.at("{d}", .{text})); + try s.write(exec, "DumpConfig\n"); + try std.testing.expectEqual(out, try s.focused()); + try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/index"), "/+DumpConfig ")); + try has(try s.read(s.at("/pane/{d}/body", .{out})), "Theme acme\n"); +} + +test "settings: Config without a configuration directory says so and opens nothing" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const index = try s.read("/index"); + try std.testing.expectEqual(@as(u16, 5), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Config\n")); + try s.expect("/index", index); + try has(try s.read("/log"), "Config: no startup file here: no configuration directory"); +} -- cgit v1.3 From ccb668645e9afc3710b1a50903022367a800ff1b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:28:55 -0300 Subject: test: four more of src/pardes.zig's tests through the 9P tree alone (test/behaviour/limits, settings, placement): a builtin that needs a pane refused in words once every one of the 64 slots is taken, Pet refused in a terminal's view from a pane and the root (a window's pets read back from /ctl), New and 9P's new taking the bottom half of a column's last pane, Placement pardes putting a pane right under the asking one and stepping back to acme bare (each read from /ctl); each checked to fail against a break (openHelp's failure unsaid, a GUI-only word run in a terminal's view, acmePlace's split at a quarter, pardes placement placing as acme) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pardes.zig | 64 -------------------------------------------- test/behaviour.zig | 2 ++ test/behaviour/limits.zig | 18 +++++++++++++ test/behaviour/placement.zig | 37 +++++++++++++++++++++++++ test/behaviour/settings.zig | 23 ++++++++++++++++ 5 files changed, 80 insertions(+), 64 deletions(-) create mode 100644 test/behaviour/limits.zig create mode 100644 test/behaviour/settings.zig (limited to 'test/behaviour/settings.zig') diff --git a/src/pardes.zig b/src/pardes.zig index 3d6b6e28..b47119c4 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1268,38 +1268,6 @@ test "acme placement: a pane made from the middle of a column moves only the one try std.testing.expectEqual(was_bottom.h, p.rects[bottom].h); } -test "acme placement: New and 9P's new take the bottom half of the last pane" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); - defer p.deinit(); - p.newScratchBelow(p.active); - const last = p.active; - p.sync(); - const was = p.rects[last]; - p.newScratchFor(last, .fs); - const made = p.active; - p.sync(); - try std.testing.expectEqual(layout.findPane(p, last).?.idx + 1, layout.findPane(p, made).?.idx); - try std.testing.expectEqual(was.y + was.h, p.rects[made].y + p.rects[made].h); - try std.testing.expect(p.rects[made].y > was.y + BOX_H); -} - -test "Placement pardes brings back the old rules, and says so in DumpConfig" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); - defer p.deinit(); - try std.testing.expect(p.executeBuiltinLine(p.active, "Placement pardes")); - try std.testing.expectEqual(config.Runtime.Placement.pardes, p.settings.placement); - const top = p.active; - p.sync(); - const was = p.rects[top]; - p.newScratchBelow(top); - p.sync(); - // Directly under the asking pane, as New always put it. - try std.testing.expectEqual(@as(usize, 1), layout.findPane(p, p.active).?.idx); - try std.testing.expectEqual(was.y + was.h, p.rects[p.active].y + p.rects[p.active].h); - try std.testing.expect(p.executeBuiltinLine(p.active, "Placement")); - try std.testing.expectEqual(config.Runtime.Placement.acme, p.settings.placement); -} - test "an empty column shows its theme's empty_col under its tag: acme's white, else the border" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 20 }); defer p.deinit(); @@ -2618,18 +2586,6 @@ test "a host with no methods at all is a complete in-process pardes" { try std.testing.expect(p.quit); } -test "a builtin that needs a pane reports capacity failure when every slot is full" { - const p = try Pardes.init(std.testing.allocator, .{ .shells = 3, .cols = 100, .rows = 30 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - for (0..MAX_PANES) |id| if (p.panes[id] == null) { - _ = try p.newDocPane(id); - }; - const help = std.meta.stringToEnum(Builtin, "Help") orelse return error.MissingHelpBuiltin; - exec.runBuiltin(p, help, 0, "", null); - try std.testing.expect(std.mem.indexOf(u8, p.panes[0].?.msg[0..p.panes[0].?.msg_len], "help: no space for a pane") != null); -} - test "Font keeps requested and acknowledged faces as separate plain state" { if (comptime !font_picker) return; // there is no Font builtin on tty or web const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); @@ -2718,26 +2674,6 @@ test "Font size suffix reaches native request and invalid input leaves it intact try std.testing.expectEqual(@as(u16, 1850), p.settings.font.effective_size_hundredths); } -test "Pet command is SDL-only optional and validates its argument" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); - defer p.deinit(); - try std.testing.expectEqual(.off, p.settings.pet); - if (comptime platform != .gui) { - // A terminal's view has the word and takes it not. - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet cat")); - try std.testing.expectEqual(.off, p.settings.pet); - return; - } - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet cat")); - try std.testing.expectEqual(.cat, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet dog")); - try std.testing.expectEqual(.cat, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet frog")); - try std.testing.expectEqual(.frog, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet off")); - try std.testing.expectEqual(.off, p.settings.pet); -} - test "startup config overrides restored styling before initFromDump returns" { const source = try Pardes.init(std.testing.allocator, .{ .startup_config = "Theme dark\n" }); defer source.deinit(); diff --git a/test/behaviour.zig b/test/behaviour.zig index bec74d89..3049f648 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -5,12 +5,14 @@ test { _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); + _ = @import("behaviour/limits.zig"); _ = @import("behaviour/look_and_exec.zig"); _ = @import("behaviour/modes.zig"); _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/placement.zig"); _ = @import("behaviour/root_ctl.zig"); + _ = @import("behaviour/settings.zig"); _ = @import("behaviour/tags.zig"); _ = @import("behaviour/terminals.zig"); } diff --git a/test/behaviour/limits.zig b/test/behaviour/limits.zig new file mode 100644 index 00000000..08c864eb --- /dev/null +++ b/test/behaviour/limits.zig @@ -0,0 +1,18 @@ +//! docs/typ/reference.typ, Limits . +const std = @import("std"); +const Session = @import("session").Session; + +test "limits: a builtin that needs a pane says so when every slot is taken" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + // Room on the screen for every pane, so the slots run out first. + s.detach(); + try s.write("/ctl", "size 100 400\n"); + var made: usize = 1; + while (s.newPane()) |_| made += 1 else |_| {} + try std.testing.expectEqual(@as(usize, 64), made); + _ = try s.refused(s.at("/pane/{d}/exec", .{n}), "Help\n"); + try std.testing.expectEqualStrings("help: no space for a pane: 64 max", s.said); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "help: no space for a pane") != null); +} diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig index 350e94f8..079b5a5e 100644 --- a/test/behaviour/placement.zig +++ b/test/behaviour/placement.zig @@ -22,3 +22,40 @@ test "placement: an empty active column takes the new pane whole, a look from an const made = try s.focused(); try std.testing.expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ try s.column(0), first, try s.column(1), made }), try s.columns()); } + +/// The screen row the tag starting `name` is drawn on. +fn tagRow(s: *Session, name: []const u8) !usize { + return (try s.where(s.at("{s} Save", .{name})))[1]; +} + +test "placement: New and 9P's new take the bottom half of the column's last pane" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const first = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{first}), "New\n"); + const last = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{last}), "/last\n"); + const was = try tagRow(&s, "/last"); + const made = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{made}), "/made\n"); + try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d}", .{ try s.column(0), first, last, made }), try s.columns()); + // The last pane keeps its top and gives up its bottom half. + try std.testing.expectEqual(was, try tagRow(&s, "/last")); + const rows = std.mem.count(u8, try s.screen(), "\n") + 1; + try std.testing.expect(try tagRow(&s, "/made") >= was + (rows - was) / 2); +} + +test "placement: Placement pardes puts a new pane right under the asking one, and bare it steps back to acme" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "Placement pardes\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement pardes\n") != null); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + const below = try s.focused(); + // Directly under the asking pane, as New always put it. + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + try std.testing.expectEqualStrings(s.at("{d}:{d},{d},{d}", .{ try s.column(0), top, try s.focused(), below }), try s.columns()); + try s.write("/ctl", "Placement\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement acme\n") != null); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig new file mode 100644 index 00000000..59e6f7c3 --- /dev/null +++ b/test/behaviour/settings.zig @@ -0,0 +1,23 @@ +//! docs/typ/reference.typ, Settings . +const std = @import("std"); +const Session = @import("session").Session; + +test "settings: Pet is the window's: a terminal's view refuses it, from a pane and the root; a window takes only its pets" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + if (try s.refused("/ctl", "Pet cat\n") == 0) { + // A window's: dog is no pet of its, and off is. + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null); + _ = try s.refused("/ctl", "Pet dog\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null); + try s.write("/ctl", "Pet frog\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet frog\n") != null); + try s.write("/ctl", "Pet off\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet off\n") != null); + return; + } + try std.testing.expect(std.mem.startsWith(u8, s.said, "Pet is GUI-only, invalid here")); + try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Pet cat\n")); + try std.testing.expectEqualStrings("Pet is GUI-only, invalid here", s.said); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "Pet ") == null); +} -- cgit v1.3 From f9e538742f149598e26d893732ba249fed6b5e14 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:38:40 -0300 Subject: test: review of the core migration's tests: the Pet test takes its branch from the build's platform (pardes_config, imported into the behaviour module, its options alone), not from whether Pet was taken, so a terminal's view taking Pet now fails it; New's absence checked in a file pane's tag and a scratch's made by New, not only in 9P's +New twice; the emptied column's tag shown to have the keyboard (typed into); the pane's tag drawn on the row under a one-row column tag; each checked to fail against a break (Pet without in_window, New in the file pane's tag, an emptied column's focus given to the workspace tag) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- build.zig | 3 +++ test/behaviour/columns_and_tags.zig | 17 ++++++++++++++--- test/behaviour/settings.zig | 6 +++++- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'test/behaviour/settings.zig') diff --git a/build.zig b/build.zig index 8a9451eb..c90485b6 100644 --- a/build.zig +++ b/build.zig @@ -1880,6 +1880,9 @@ pub fn build(b: *std.Build) void { .link_libc = true, }); behaviour_module.addImport("session", session_module); + // The build's options alone (platform), never the core: a test of a + // window's word knows which build it runs in. + behaviour_module.addImport("pardes_config", core_module.import_table.get("pardes_config").?); const behaviour_tests = b.addTest(.{ .root_module = behaviour_module, .filters = test_filters }); if (test_nonce) |nonce| behaviour_tests.root_module.addImport("test_rebuild_nonce", nonce); test_build.dependOn(&behaviour_tests.step); diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig index 5b78a6c8..a67fa110 100644 --- a/test/behaviour/columns_and_tags.zig +++ b/test/behaviour/columns_and_tags.zig @@ -102,6 +102,9 @@ test "columns-and-tags: closing a column's last pane leaves it empty, its tag wi // Down from it goes nowhere: nothing is below. try s.write(s.at("/pane/{d}/exec", .{first}), "Down\n"); try s.expect("/focus", ""); + // The tag with the keyboard is the emptied column's: what is typed lands there. + try s.keys("iMine\x1b"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/col/{d}/tag", .{col})), "Mine") != null); 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()); @@ -137,11 +140,18 @@ test "columns-and-tags: New is a column tag's word, in no pane's tag nor the wor defer s.deinit(); var t = try Session.initTerm(std.testing.allocator); defer t.deinit(); - const scratch = try s.newPane(); + // The file pane's, read before 9P's new takes the keyboard; a scratch + // made by New, and 9P's new (a +New file pane). + const file = try s.read(s.at("/pane/{d}/tag", .{try s.focused()})); + const made = try s.newPane(); + try s.write(s.at("/col/{d}/exec", .{try s.column(0)}), "New\n"); + const scratch = try s.focused(); + try std.testing.expect(made != scratch); for ([_][]const u8{ try s.read("/tag"), + file, + try s.read(s.at("/pane/{d}/tag", .{made})), 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, ' '); @@ -161,7 +171,8 @@ test "columns-and-tags: a click past a column tag's text types after it, a newli try s.keys("\nSnarf"); try expectEqualStrings("New Tty Find Grep Joincol Delcol Snarf", try s.read(tag)); try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " Snarf ") != null); - try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "\n /test.txt Save") != null); + // The pane's tag on the row right under it: the column's is one row. + try std.testing.expectEqual((try s.where(rows))[1] + 1, (try s.where("/test.txt Save"))[1]); // Wider than the screen: the tag scrolls to keep its caret drawn. try s.keys(" 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界"); const col, const row = (try s.cursor()).?; diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig index 59e6f7c3..e62539e4 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -5,7 +5,10 @@ const Session = @import("session").Session; test "settings: Pet is the window's: a terminal's view refuses it, from a pane and the root; a window takes only its pets" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); - if (try s.refused("/ctl", "Pet cat\n") == 0) { + // Which build, from its options, not from the answer: a terminal's view + // taking Pet must fail here, not pass as a window. + if (comptime @import("pardes_config").platform == .gui) { + try s.write("/ctl", "Pet cat\n"); // A window's: dog is no pet of its, and off is. try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null); _ = try s.refused("/ctl", "Pet dog\n"); @@ -16,6 +19,7 @@ test "settings: Pet is the window's: a terminal's view refuses it, from a pane a try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet off\n") != null); return; } + try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Pet cat\n")); try std.testing.expect(std.mem.startsWith(u8, s.said, "Pet is GUI-only, invalid here")); try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Pet cat\n")); try std.testing.expectEqualStrings("Pet is GUI-only, invalid here", s.said); -- cgit v1.3