summaryrefslogtreecommitdiff
path: root/test/behaviour/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 16:59:08 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:13:25 -0300
commit023793be1112bc35b50551580d273f4cf611b3da (patch)
tree4167a4e0435d545dbdb8e09e4f6578491b1dd1e2 /test/behaviour/panes.zig
parentd1273bbd99daf9b1855d82bf315db8ede20abde5 (diff)
downloadpardes-023793be1112bc35b50551580d273f4cf611b3da.tar.gz
pardes-023793be1112bc35b50551580d273f4cf611b3da.zip
test: sixteen of src/ninep/ctl.zig's tests through the 9P tree alone, in new test/behaviour/{log,mounts,rules,settings}.zig and appended to edit, columns_and_tags, look_and_exec, panes and root_ctl: the log's msg and err records (a root ctl's message the session's, the same failure counted, a root exec's err its pane's), Mount's refusals (and nothing mounted, read from Unmount), Pager and Shell read back from the root ctl, a control character in any ctl and in any tag, a bad command inside an Edit block, a look's :addr and file:addr, the root look's file:/re/ from the dot, exec's readback, focus (a column tag's keyboard taken by Newcol), the pane ctl's and the root ctl's words; each checked to fail against a break: the (xN) count one short, msg - written as msg 0, a root exec's err left as -, a missing socket's words changed, Pager defaulting off, a bare Shell not clearing, tree.zig's ctl check skipped, DEL taken in a tag, an Edit block's bad command naming }, a look's address evaluated from 0 not the dot, no results recorded, focus leaving the header the keyboard, "not a pane control message", every setting value taken
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/panes.zig')
-rw-r--r--test/behaviour/panes.zig66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig
index 01820a07..d48ff812 100644
--- a/test/behaviour/panes.zig
+++ b/test/behaviour/panes.zig
@@ -49,3 +49,69 @@ test "panes: Putall saves every pane with unsaved edits to a file, one each, and
try s.write("/ctl", "Putall\n");
try std.testing.expectEqual(@as(usize, 1), s.saved);
}
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+test "panes: focus reads the pane with the keyboard, and a serial written to it moves the keyboard there, and only that" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const first = try s.focused();
+ const second = try s.newPane();
+ try s.expect("/focus", s.at("{d}\n", .{second}));
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{first})), " notcurrent "));
+ // A column's tag has the keyboard: no pane does, and a write takes it back.
+ try s.write("/ctl", "Newcol\n");
+ try s.expect("/focus", "");
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{second})), " notcurrent "));
+ try s.write("/focus", s.at("{d}\n", .{first}));
+ try s.expect("/focus", s.at("{d}\n", .{first}));
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{first})), " current "));
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{second})), " notcurrent "));
+ try std.testing.expectEqual(@as(u16, 2), try s.refused("/focus", "99999\n"));
+ try std.testing.expectEqualStrings("no such pane", s.said);
+ for ([_][]const u8{ "", "two", "-1", "1 2" }) |bad| try std.testing.expectEqual(@as(u16, 22), try s.refused("/focus", bad));
+ try s.expect("/focus", s.at("{d}\n", .{first}));
+ // Focus gives the keyboard only: a folded pane stays folded.
+ try s.write(s.at("/pane/{d}/ctl", .{second}), "Collapse\n");
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{second})), " collapsed "));
+ try s.write("/focus", s.at("{d}", .{second}));
+ try s.expect("/focus", s.at("{d}\n", .{second}));
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{second})), " collapsed "));
+}
+
+test "panes: the pane ctl takes acme's verbs and the pane's builtins, and refuses the rest in Plan 9's words" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ // A builtin is its own capitalised word: `GET` and `DEL` are none.
+ for ([_][]const u8{ "lock x", "bogus", "DEL", "GET", "get x", "look /tmp", "exec Del" }) |bad| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, s.at("{s}\n", .{bad})));
+ try std.testing.expectEqualStrings(s.at("unknown control message \"{s}\"", .{std.mem.sliceTo(bad, ' ')}), s.said);
+ }
+ _ = try s.refused(ctl, "Newcol\n");
+ try std.testing.expectEqualStrings("not a window control message \"Newcol\": write it to /ctl", s.said);
+ _ = try s.refused(ctl, "Verbose off\n");
+ try std.testing.expectEqualStrings("not a window control message \"Verbose\": write it to /ctl", s.said);
+ _ = try s.refused(ctl, "Collapse now\n");
+ try std.testing.expectEqualStrings("wrong #args in control message \"Collapse\"", s.said);
+ // Checked whole first: a bad line anywhere and nothing ran.
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "Msg first\nbogus\n"));
+ // A pane's builtin runs at that pane.
+ try s.write(ctl, "Msg from ctl\n");
+ try std.testing.expect(has(try s.read("/log"), s.at("msg {d} from ctl\n", .{n})));
+ // One that means nothing bare is refused before anything runs.
+ _ = try s.refused(ctl, "Find\n");
+ try std.testing.expectEqualStrings("wrong #args in control message \"Find\"", s.said);
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "Msg first\nMsg\n"));
+ try std.testing.expect(!has(try s.read("/log"), "first"));
+ // Save with no name on a scratch would ask for one: refused, not asked.
+ const other = try s.newPane();
+ _ = try s.refused(s.at("/pane/{d}/ctl", .{other}), "Save\n");
+ try std.testing.expectEqualStrings("control message needs its argument \"Save\"", s.said);
+ // A line after the one that closed the pane has nowhere to run.
+ try std.testing.expectEqual(@as(u16, 2), try s.refused(s.at("/pane/{d}/ctl", .{other}), "Del\nMsg after\n"));
+ try std.testing.expectError(error.Refused, s.read(s.at("/pane/{d}/ctl", .{other})));
+}