summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 16:38:06 -0300
committerGabriel Schneider <[email protected]>2026-11-03 16:39:22 -0300
commita0320c49c1288e8e74f18983f18988a024952bb8 (patch)
tree5134488431aad3a2555198cc96ba9955e2cdad91 /test
parentd197289c331365081295cb44f27ee2893294cffa (diff)
downloadpardes-a0320c49c1288e8e74f18983f18988a024952bb8.tar.gz
pardes-a0320c49c1288e8e74f18983f18988a024952bb8.zip
test: four more of src/ninep/ctl.zig's tests through the 9P tree alone (test/behaviour/look_and_exec, columns_and_tags, root_ctl): a look's leading blanks and exec's trim, a bare :N look from a pane's look, the root's and an event write-back (dot read from the dot file), a look after Newcol (the column read from /layout), size of a detached session (the screen read from /screen); Session's range and detach; each checked to fail against a break (a look's blanks trimmed, size taking a screen too small for its panes)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test')
-rw-r--r--test/behaviour.zig3
-rw-r--r--test/behaviour/columns_and_tags.zig33
-rw-r--r--test/behaviour/look_and_exec.zig38
-rw-r--r--test/behaviour/root_ctl.zig31
-rw-r--r--test/session.zig11
5 files changed, 116 insertions, 0 deletions
diff --git a/test/behaviour.zig b/test/behaviour.zig
index 31da19a1..32138f94 100644
--- a/test/behaviour.zig
+++ b/test/behaviour.zig
@@ -3,7 +3,10 @@
//! named by the label first. This module imports test/session.zig alone,
//! so a test sees the session as a 9P client does.
test {
+ _ = @import("behaviour/columns_and_tags.zig");
_ = @import("behaviour/edit.zig");
+ _ = @import("behaviour/look_and_exec.zig");
_ = @import("behaviour/other_files.zig");
_ = @import("behaviour/panes.zig");
+ _ = @import("behaviour/root_ctl.zig");
}
diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig
new file mode 100644
index 00000000..25ba4c64
--- /dev/null
+++ b/test/behaviour/columns_and_tags.zig
@@ -0,0 +1,33 @@
+//! docs/typ/reference.typ, Columns and tags <columns-and-tags>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+/// /layout's line for the last column.
+fn lastColumn(s: *Session) ![]const u8 {
+ var lines = std.mem.splitScalar(u8, try s.read("/layout"), '\n');
+ var last: []const u8 = "";
+ while (lines.next()) |line| {
+ if (std.mem.startsWith(u8, line, "active") or line.len == 0) continue;
+ last = line;
+ }
+ return last;
+}
+
+test "columns-and-tags: a look after Newcol fills the empty column the keyboard is on" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "file\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();
+ // Newcol makes an empty column and gives its tag the keyboard; no pane
+ // has it, so focus reads empty.
+ try s.write("/ctl", "Newcol\n");
+ try std.testing.expect(std.mem.indexOf(u8, try lastColumn(&s), " empty") != null);
+ try s.expect("/focus", "");
+ try s.write("/look", s.at("{s}/f.txt\n", .{at}));
+ const col = try lastColumn(&s);
+ 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()})));
+}
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig
new file mode 100644
index 00000000..2ff4345b
--- /dev/null
+++ b/test/behaviour/look_and_exec.zig
@@ -0,0 +1,38 @@
+//! docs/typ/reference.typ, look and exec <look-and-exec>.
+const std = @import("std");
+const Session = @import("session").Session;
+const expectEqual = std.testing.expectEqual;
+
+test "look-and-exec: a 9P look keeps its leading blanks, a blank-only look included, and exec still trims" {
+ var s = try Session.initFile(std.testing.allocator, "a indented\nb\n indented\n \n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ try s.write(dot, "0 0");
+ // The indented line, not the `indented` after `a `.
+ try s.write(s.at("/pane/{d}/look", .{n}), " indented\n");
+ try expectEqual(.{ @as(u32, 13), @as(u32, 25) }, try s.range(dot));
+ // Blanks alone are text to find too.
+ try s.write(dot, "26 26");
+ try s.write(s.at("/pane/{d}/look", .{n}), " \n");
+ try expectEqual(.{ @as(u32, 26), @as(u32, 30) }, try s.range(dot));
+ // exec's line is still trimmed: ` Msg hi` runs Msg.
+ try s.write(s.at("/pane/{d}/exec", .{n}), " Msg blanks trimmed\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "blanks trimmed") != null);
+}
+
+test "look-and-exec: a bare :N or :N:M look addresses the pane itself, from its look, the root's and event write-back" {
+ var s = try Session.initFile(std.testing.allocator, "alpha\nbeta\ngamma\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ try s.write(s.at("/pane/{d}/look", .{n}), ":2\n");
+ try expectEqual(.{ @as(u32, 6), @as(u32, 11) }, try s.range(dot));
+ try s.write("/look", ":3\n");
+ try expectEqual(.{ @as(u32, 11), @as(u32, 17) }, try s.range(dot));
+ try s.write(s.at("/pane/{d}/look", .{n}), ":3:2\n");
+ try expectEqual(@as(u32, 12), (try s.range(dot))[0]);
+ // Written back by an event reader, the same.
+ 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));
+}
diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig
new file mode 100644
index 00000000..bdf912da
--- /dev/null
+++ b/test/behaviour/root_ctl.zig
@@ -0,0 +1,31 @@
+//! docs/typ/reference.typ, The root ctl <root-ctl>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+/// The screen's size, as /screen draws it.
+fn size(s: *Session) !struct { usize, usize } {
+ const screen = try s.screen();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0 .. std.mem.indexOfScalar(u8, screen, '\n') orelse screen.len]);
+ return .{ cols, std.mem.count(u8, screen, "\n") + 1 };
+}
+
+test "root-ctl: size sets the screen of a session no frontend is attached to, and only of one" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size 120 40\n")); // a frontend's
+ s.detach();
+ try s.write("/ctl", "size 120 40\n");
+ try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size 120\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size\n"));
+ _ = try s.refused("/ctl", "size 5 2\n");
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "at least 20x6, at most 4096x4096") != null);
+ // The bad value quoted, never the word size.
+ try std.testing.expect(std.mem.endsWith(u8, s.said, "\"5 2\""));
+ // Too small for the panes it has, each its tag and two rows: refused,
+ // the size as it was.
+ for (0..4) |_| _ = try s.newPane();
+ _ = try s.refused("/ctl", "size 80 8\n");
+ try std.testing.expect(std.mem.indexOf(u8, s.said, "too small for the panes") != null);
+ try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s));
+}
diff --git a/test/session.zig b/test/session.zig
index 28557322..8b3c5c41 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -120,6 +120,17 @@ pub const Session = struct {
return out.items;
}
+ /// A range file (`dot`, `addr`, `limit`) as its two offsets.
+ pub fn range(s: *Session, path: []const u8) !struct { u32, u32 } {
+ var it = std.mem.tokenizeScalar(u8, try s.read(path), ' ');
+ return .{ try std.fmt.parseInt(u32, it.next() orelse return error.NoRange, 10), try std.fmt.parseInt(u32, it.next() orelse return error.NoRange, 10) };
+ }
+
+ /// No frontend attached, as a detached session's daemon says.
+ pub fn detach(s: *Session) void {
+ pardesOf(s).unattended = true;
+ }
+
/// The serial of the pane with the keyboard.
pub fn focused(s: *Session) !u32 {
return std.fmt.parseInt(u32, std.mem.trim(u8, try s.read("/focus"), "\n"), 10);