diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 11:09:10 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 11:17:24 -0300 |
| commit | a5504e6e808c5b147e114d43b5c165bbe714f3c3 (patch) | |
| tree | 81d61c2d451a8715ca076088414be226dd49cb9a | |
| parent | fa3031d6ded24d4ba7ab5bab21e17387e48306aa (diff) | |
| download | pardes-a5504e6e808c5b147e114d43b5c165bbe714f3c3.tar.gz pardes-a5504e6e808c5b147e114d43b5c165bbe714f3c3.zip | |
test: test/output.zig's Mini, setting and command-output LookNext tests through the 9P tree alone: in a new test/behaviour/builtins.zig (docs/typ/builtins.typ) Mini mapping a file of the pane's directory over pardes's own of that name, one pane for it, a snapshot refreshed only by the next Mini, and Save on it writing nothing (the old test trimmed to the watch it never asks for, an effect); in test/behaviour/settings.zig every on/off setting the root ctl reads flipping when its word is written bare, and Theme and Shell taking a value (the old test trimmed to a window's fonts, transitions and passes in DumpConfig's report); in test/behaviour/keys.zig SPC j n in a command output (+Themes) selecting its whole row, Tab running it, and from a pane a Look took the keyboard to walking on in it, and SPC j n and SPC j p walking on and back from the place a Look's +Search listing chose (the old test trimmed to its fillResults answers); each checked to fail against a break (Mini making a new pane each time, a setting's bare word not flipping it, a command output's grain a word, the walk's owner forgotten)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | test/behaviour.zig | 1 | ||||
| -rw-r--r-- | test/behaviour/builtins.zig | 35 | ||||
| -rw-r--r-- | test/behaviour/keys.zig | 49 | ||||
| -rw-r--r-- | test/behaviour/settings.zig | 23 | ||||
| -rw-r--r-- | test/output.zig | 70 |
5 files changed, 117 insertions, 61 deletions
diff --git a/test/behaviour.zig b/test/behaviour.zig index d9b15183..2e2ca864 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -4,6 +4,7 @@ //! so a test sees the session as a 9P client does. test { _ = @import("behaviour/addresses.zig"); + _ = @import("behaviour/builtins.zig"); _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); _ = @import("behaviour/event.zig"); diff --git a/test/behaviour/builtins.zig b/test/behaviour/builtins.zig new file mode 100644 index 00000000..6f029072 --- /dev/null +++ b/test/behaviour/builtins.zig @@ -0,0 +1,35 @@ +//! docs/typ/builtins.typ, the builtins' glossary. +const std = @import("std"); +const Session = @import("session").Session; + +test "builtins: Mini maps a file of the pane's directory over pardes's own source of that name, in one pane, refreshed only when asked again" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "x\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/look", s.at("{s}/a.txt\n", .{at})); + const a = try s.focused(); + // The directory's one-line build.zig, one braille row, not pardes's. + try s.write(s.at("/pane/{d}/exec", .{a}), "Mini build.zig\n"); + const mini = try s.focused(); + try std.testing.expect(mini != a); + const body = s.at("/pane/{d}/body", .{mini}); + try s.expect(body, "⠁\n"); + const index = try s.read("/index"); + try s.write(s.at("/pane/{d}/exec", .{mini}), "Mini build.zig\n"); + try std.testing.expectEqual(mini, try s.focused()); + try s.expect("/index", index); + // A snapshot: the file grown on disk shows only at the next Mini. + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "xx\n" }); + try s.expect(body, "⠁\n"); + try s.write(s.at("/pane/{d}/exec", .{mini}), "Mini build.zig\n"); + try s.expect(body, "⠉\n"); + try s.expect("/index", index); + // Save asks for a path; nothing is written for it. + try s.write(s.at("/pane/{d}/exec", .{mini}), "Save\n"); + try std.testing.expectEqual(@as(usize, 0), s.saved); +} diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig index 41a2821a..e659b369 100644 --- a/test/behaviour/keys.zig +++ b/test/behaviour/keys.zig @@ -225,3 +225,52 @@ test "keys: SPC j n and SPC j p walk Themes' rows, whole, never its section head try s.keys("\t"); try std.testing.expectEqualStrings(names.items[brk - 1]["Theme ".len..], try setting(&s, "Theme")); } + +test "keys: SPC j n in a command output selects its whole row, Tab runs it, and from where a Look took the keyboard it walks on there" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + for ([_][]const u8{ "a.txt", "b.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/look", s.at("{s}/a.txt\n", .{at})); + const a = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{a}), "Themes\n"); + try s.keys(" jn"); + const themes = try s.focused(); + try std.testing.expect(themes != a); + const sel = s.at("/pane/{d}/sel", .{themes}); + try s.expect(sel, "Theme orchard"); + try s.keys(" jn\t"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nTheme dusk\n") != null); + try s.write(s.at("/pane/{d}/exec", .{a}), "Look b.txt\n"); + try std.testing.expect(try s.focused() != themes); + try s.keys(" jn"); + try std.testing.expectEqual(themes, try s.focused()); + try std.testing.expect(std.mem.startsWith(u8, try s.read(sel), "Theme ")); +} + +test "keys: SPC j n and SPC j p walk on from the place a Look's +Search listing chose, its keyboard left in the file" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "look-owner.txt", .data = "alpha target\nbeta target\ngamma target\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "LookWord list\n"); // the +Search listing is what is walked + try s.write("/look", s.at("{s}/look-owner.txt\n", .{at})); + const file = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{file}), "Look target\n"); + try std.testing.expectEqual(file, try s.focused()); + // The Look took the first; the walk goes on from it, and back. + try s.keys(" jn"); + const results = try s.focused(); + try std.testing.expect(results != file); + const sel = s.at("/pane/{d}/sel", .{results}); + try s.expect(sel, "look-owner.txt:2:6-11"); + try s.keys(" jp"); + try std.testing.expectEqual(results, try s.focused()); + try s.expect(sel, "look-owner.txt:1:7-12"); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig index ff24704a..027fd1c9 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -101,3 +101,26 @@ test "settings: Config without a configuration directory says so and opens nothi try s.expect("/index", index); try expectHas(try s.read("/log"), "Config: no startup file here: no configuration directory"); } + +test "settings: every on/off setting the root ctl reads flips when its word is written bare, and Theme and Shell take a value" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + var lines = std.mem.tokenizeScalar(u8, try s.read("/ctl"), '\n'); + var flipped: usize = 0; + while (lines.next()) |line| { + const space = std.mem.indexOfScalar(u8, line, ' ') orelse continue; + const word, const was = .{ line[0..space], line[space + 1 ..] }; + const on = std.mem.eql(u8, was, "on"); + if (!on and !std.mem.eql(u8, was, "off")) continue; + try s.write("/ctl", s.at("{s}\n", .{word})); + try std.testing.expectEqualStrings(s.at("{s} {s}", .{ word, if (on) "off" else "on" }), try setting(&s, word)); + flipped += 1; + } + try std.testing.expect(flipped > 20); + for ([_][]const u8{ "Colors off", "Wrap off", "Tagbottom on", "Debug on" }) |want| + try std.testing.expectEqualStrings(want, try setting(&s, want[0..std.mem.indexOfScalar(u8, want, ' ').?])); + try s.write("/ctl", "Theme acme\n"); + try s.write("/ctl", "Shell /bin/sh\n"); + try std.testing.expectEqualStrings("Theme acme", try setting(&s, "Theme")); + try std.testing.expectEqualStrings("Shell /bin/sh", try setting(&s, "Shell")); +} diff --git a/test/output.zig b/test/output.zig index 3cfece45..876cd8fc 100644 --- a/test/output.zig +++ b/test/output.zig @@ -389,7 +389,9 @@ test "result stepping reaches an unterminated last row" { try std.testing.expectEqual(@as(i32, 1), result.body.cur_row); } -test "Mini uses OS source precedence and refreshes one independent snapshot" { +// What it shows and when it refreshes is test/behaviour/builtins.zig's; +// the watch it never asks for is an effect, unseen through 9P. +test "Mini asks for no watch on its pane" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "x\n" }); @@ -401,27 +403,11 @@ test "Mini uses OS source precedence and refreshes one independent snapshot" { try std.testing.expect(p.executeBuiltinLine(0, "Mini build.zig")); const id = p.active; try std.testing.expect(id != 0); - const mini = p.panes[id].?; - try std.testing.expect(mini.terminal == null); - try std.testing.expectEqualStrings("⠁\n", mini.file.?.content); - try std.testing.expect(std.mem.startsWith(u8, mini.file.?.mini.?.source, dir)); - const next = p.freeSlot(); - const body = mini.file.?.content.ptr; - try std.testing.expect(p.executeBuiltinLine(id, "Mini build.zig")); - try std.testing.expectEqual(id, p.active); - try std.testing.expectEqual(body, mini.file.?.content.ptr); - try std.testing.expectEqual(next, p.freeSlot()); - try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "xx\n" }); - try std.testing.expectEqualStrings("⠁\n", mini.file.?.content); try std.testing.expect(p.executeBuiltinLine(id, "Mini build.zig")); - try std.testing.expectEqual(id, p.active); - try std.testing.expectEqualStrings("⠉\n", mini.file.?.content); while (p.nextEffect()) |effect| switch (effect) { .watch => |watch| try std.testing.expect(watch.pane != id), else => {}, }; - try std.testing.expect(p.executeBuiltinLine(id, "Save")); - try std.testing.expect(mini.prompt == .save); } test "Mini dump preserves its exact virtual snapshot and body writes detach colors" { @@ -617,7 +603,7 @@ test "EffectCode lists readable virtual sources used by this backend" { try std.testing.expectEqualStrings(pardes.filesystem.sourceBytes(backend_source["/virtual/".len..]).?, source.content); } -test "every enabled setting builtin mutates the State Config reports" { +test "a window's setting builtins (TaglineSize, Font, transitions, scene passes) reach the report DumpConfig writes" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); p.locations_config.layout = .@"inline"; @@ -653,14 +639,8 @@ test "every enabled setting builtin mutates the State Config reports" { try std.testing.expect(p.executeBuiltinLine(p.active, "DumpConfig")); const report = p.panes[p.active].?.file.?.content; - for ([_][]const u8{ - "Colors off\n", - "Wrap off\n", - "Tagbottom on\n", - "Debug on\n", - "Theme acme\n", - "Shell fish\n", - }) |line| try std.testing.expect(std.mem.indexOf(u8, report, line) != null); + // The toggles, Theme and Shell are test/behaviour/settings.zig's, through + // the root ctl; what is left is a window's (fonts, transitions, passes). const transition = if (!builtins.viewCapabilities(p).panel_transitions) "PanelSlide unsupported\n" else if (p.settings.panel_transition == .off) @@ -821,7 +801,7 @@ test "LookNext/LookPrev selects one output location per row and opens nothing" { try std.testing.expectEqual(panes.Output.Grain.word, panes.Output.grain(p.panes[p.active].?.file.?.output)); } -test "LookNext/LookPrev resumes the result output whose Look moved focus away" { +test "LookNext/LookPrev keeps the result output a Look chose through a no-match answer, and a stale serial once it is deleted" { if (platform == .web) return; var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); @@ -844,12 +824,8 @@ test "LookNext/LookPrev resumes the result output whose Look moved focus away" { try std.testing.expect(results.look_at != null); try std.testing.expectEqual(results.serial, p.look_walk_owner orelse return error.MissingLookOwner); - lookKey(p, 'n'); - try std.testing.expectEqual(rid, p.active); - try std.testing.expectEqual(first + 1, results.body.cur_row); - lookKey(p, 'N'); - try std.testing.expectEqual(first, results.body.cur_row); - + // The walk on and back from it is test/behaviour/keys.zig's; what is + // left needs answers put in by fillResults. // A later no-match answer has no position to resume and therefore cannot // steal the provenance established by the Look above. const owner = results.serial; @@ -924,34 +900,6 @@ test "LookPrev exactly reverses LookNext across output panes and the ring seam" try std.testing.expect(saw_first and saw_second); } -test "LookNext/LookPrev selects command outputs by whole row" { - if (platform == .web) return; - var cwd_buf: [4096]u8 = undefined; - var path_buf: [4096]u8 = undefined; - const paths = try projectPaths(&cwd_buf, &path_buf); - const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 40, .file = paths.boot }); - defer p.deinit(); - p.update(.{ .resize = .{ .cols = 100, .rows = 40 } }); - - try std.testing.expect(p.executeBuiltinLine(p.active, "Themes")); - const tid = p.panes[p.active].?.search_pane orelse return error.MissingThemeList; - const themes = p.panes[tid].?; - try std.testing.expect(panes.Output.fileTraits(themes.file.?.output).commands); - lookKey(p, 'n'); - const row0 = std.mem.trimEnd(u8, modal.lineSlice(themes.file.?.content, 1), " \t\r"); - try std.testing.expectEqualStrings(row0, selectedOutputText(themes) orelse ""); - const theme_before = p.settings.theme; - lookKey(p, 'n'); - p.update(.{ .key = .{ .cp = Key.tab } }); - try std.testing.expect(p.settings.theme != theme_before); - - try std.testing.expect(p.executeBuiltinLine(0, "Look build.zig")); - p.update(.tick); - try std.testing.expect(p.active != 0); - lookKey(p, 'n'); - try std.testing.expectEqual(@as(usize, 0), p.active); -} - test "identical result refresh keeps warm content caches without allocation" { var allocator: std.testing.FailingAllocator = .init(std.testing.allocator, .{}); const p = try Pardes.init(allocator.allocator(), .{ .tty_only = true, .cols = 80, .rows = 24 }); |
