summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:22:54 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:23:24 -0300
commit5e778c87a33688c0079c916023d9c337dc944a69 (patch)
tree315a6defd3ed7db0e3404042f5e92a91524cba56 /test
parentd20a480e5d556b522aedfc7ec67fa423f37c8d1d (diff)
downloadpardes-5e778c87a33688c0079c916023d9c337dc944a69.tar.gz
pardes-5e778c87a33688c0079c916023d9c337dc944a69.zip
test: six of src/ninep/pane.zig's tests through the 9P tree alone, in new test/behaviour/{tree,addresses,flags}.zig and rules.zig: /index's rows (kind, dirty, name, column; stat 0, mode 0444, read at an offset), a terminal listed as term under its directory and refused a rename, body read at offsets and appended to (its stat its length, its qid version moving with each edit, a tag's 0), data and xdata from addr (data moving it), sel and dot (a truncated dot emptied at its clunk, a write to sel selected, one open's writes running on), the dirty, mark and scroll flags; each checked to fail against a break: kind text written txt, term written terminal, body's version always 0, a data read leaving addr where it was, a truncated dot never emptied, mark always reading 1
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/addresses.zig65
-rw-r--r--test/behaviour/flags.zig42
-rw-r--r--test/behaviour/rules.zig20
-rw-r--r--test/behaviour/tree.zig44
5 files changed, 174 insertions, 0 deletions
diff --git a/test/behaviour.zig b/test/behaviour.zig
index 49245d82..a272d0f6 100644
--- a/test/behaviour.zig
+++ b/test/behaviour.zig
@@ -3,9 +3,11 @@
//! 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/addresses.zig");
_ = @import("behaviour/columns_and_tags.zig");
_ = @import("behaviour/edit.zig");
_ = @import("behaviour/event.zig");
+ _ = @import("behaviour/flags.zig");
_ = @import("behaviour/log.zig");
_ = @import("behaviour/look_and_exec.zig");
_ = @import("behaviour/mounts.zig");
@@ -14,4 +16,5 @@ test {
_ = @import("behaviour/root_ctl.zig");
_ = @import("behaviour/rules.zig");
_ = @import("behaviour/settings.zig");
+ _ = @import("behaviour/tree.zig");
}
diff --git a/test/behaviour/addresses.zig b/test/behaviour/addresses.zig
new file mode 100644
index 00000000..a1474c3d
--- /dev/null
+++ b/test/behaviour/addresses.zig
@@ -0,0 +1,65 @@
+//! docs/typ/reference.typ, Addresses and data <addresses>.
+const std = @import("std");
+const Session = @import("session").Session;
+const expectEqual = std.testing.expectEqual;
+
+test "addresses: data and xdata read from addr, data moving it, and a write goes through it" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const addr = s.at("/pane/{d}/addr", .{n});
+ const data = s.at("/pane/{d}/data", .{n});
+ try s.write(addr, "#0");
+ try std.testing.expectEqualStrings("one", try s.readAt(data, 0, 3));
+ try expectEqual(.{ @as(u32, 3), @as(u32, 3) }, try s.range(addr));
+ try s.write(addr, "1");
+ try s.expect(s.at("/pane/{d}/xdata", .{n}), "one\n");
+ try s.write(addr, "1");
+ try s.expect(data, "one\ntwo\n");
+ try s.write(addr, "1");
+ try s.write(data, "ONE\n");
+ try s.expect(s.at("/pane/{d}/body", .{n}), "ONE\ntwo\n");
+ try expectEqual(@as(u32, 4), (try s.range(addr))[0]);
+}
+
+test "addresses: sel reads the selection, and a write to sel replaces it and is selected" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const addr = s.at("/pane/{d}/addr", .{n});
+ const dot = s.at("/pane/{d}/dot", .{n});
+ const sel = s.at("/pane/{d}/sel", .{n});
+ const body = s.at("/pane/{d}/body", .{n});
+ // Copying addr onto dot is the whole of acme's `dot=addr`, and back again
+ // of `addr=dot`; each range file reads exactly what the other takes.
+ try s.write(addr, "#0,#3");
+ try s.write(dot, " 0 3 ");
+ try s.expect(dot, " 0 3 ");
+ try expectEqual(@as(u64, 24), (try s.stat(dot)).size);
+ try s.expect(sel, "one");
+ try expectEqual(@as(u64, 3), (try s.stat(sel)).size);
+ try s.write(addr, "#0");
+ try s.write(addr, " 0 3 ");
+ try expectEqual(.{ @as(u32, 0), @as(u32, 3) }, try s.range(addr));
+ // A truncation empties dot once its open goes, nothing written after
+ // it; an address expression addresses it.
+ const h = try s.hold(dot, 1);
+ try s.truncate(h);
+ try s.expect(sel, "one");
+ s.clunk(h);
+ try s.expect(sel, "");
+ try s.write(dot, "#0,#3");
+ try s.write(sel, "ONE");
+ try s.expect(body, "ONE\ntwo\n");
+ // What was written is selected, as acme's wrsel leaves it.
+ try s.expect(sel, "ONE");
+ // A write of another open replaces it; one open's writes run on.
+ try s.write(sel, "!");
+ try s.expect(body, "!\ntwo\n");
+ const w = try s.hold(sel, 1);
+ try expectEqual(@as(u16, 0), try s.writeFid(w, "a"));
+ try expectEqual(@as(u16, 0), try s.writeFid(w, "b"));
+ s.clunk(w);
+ try s.expect(body, "ab\ntwo\n");
+ try s.expect(sel, "ab");
+}
diff --git a/test/behaviour/flags.zig b/test/behaviour/flags.zig
new file mode 100644
index 00000000..656d219f
--- /dev/null
+++ b/test/behaviour/flags.zig
@@ -0,0 +1,42 @@
+//! docs/typ/reference.typ, Flags and undo <flags>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "flags: dirty, mark and scroll read and write the state acme kept behind ctl verbs, 1 or 0" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dirty = s.at("/pane/{d}/dirty", .{n});
+ const mark = s.at("/pane/{d}/mark", .{n});
+ const scroll = s.at("/pane/{d}/scroll", .{n});
+ for ([_][]const u8{ dirty, mark, scroll }) |flag| {
+ try std.testing.expectEqual(@as(u64, 2), (try s.stat(flag)).size);
+ for ([_][]const u8{ "", "yes", "2", "0 1", "true" }) |bad| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(flag, bad));
+ try std.testing.expectEqualStrings("bad flag: takes 1 or 0", s.said);
+ }
+ }
+ try s.expect(dirty, "0\n");
+ try s.expect(mark, "1\n");
+ try s.expect(scroll, "1\n");
+ // dirty as /index shows it.
+ try s.write(dirty, "1\n");
+ try s.expect(dirty, "1\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("{d} text 1 ", .{n})) != null);
+ try s.write(dirty, "0");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("{d} text 0 ", .{n})) != null);
+ try s.write(mark, "0");
+ try s.write(scroll, "0");
+ try s.expect(mark, "0\n");
+ try s.expect(scroll, "0\n");
+ try s.write(mark, "1");
+ try s.write(scroll, "1");
+ try s.expect(mark, "1\n");
+ try s.expect(scroll, "1\n");
+ // A terminal has no file, so its dirty flag is readable but not writable.
+ var t = try Session.initTerm(std.testing.allocator);
+ defer t.deinit();
+ const term_dirty = t.at("/pane/{d}/dirty", .{try t.focused()});
+ try t.expect(term_dirty, "0\n");
+ try std.testing.expectEqual(@as(u16, 22), try t.refused(term_dirty, "1"));
+}
diff --git a/test/behaviour/rules.zig b/test/behaviour/rules.zig
index a29db6f0..4b853a40 100644
--- a/test/behaviour/rules.zig
+++ b/test/behaviour/rules.zig
@@ -17,3 +17,23 @@ test "rules: a control character in a write to any ctl refuses the whole write,
try std.testing.expect(std.mem.indexOf(u8, s.said, "\"bogus\"") != null);
try std.testing.expect(std.mem.indexOfScalar(u8, s.said, '\t') == null);
}
+
+test "rules: body reads at any offset and writes append; a stat says its length, and its version moves with each edit" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const body = s.at("/pane/{d}/body", .{try s.focused()});
+ try std.testing.expectEqualStrings("two\n", try s.readAt(body, 4, 100));
+ try std.testing.expectEqualStrings("wo", try s.readAt(body, 5, 2));
+ try std.testing.expectEqualStrings("", try s.readAt(body, 999, 2));
+ try s.write(body, "three\n");
+ try s.expect(body, "one\ntwo\nthree\n");
+ // A rune cut at the write's end is not taken.
+ try s.write(body, "a\xC3");
+ try s.expect(body, "one\ntwo\nthree\na");
+ const st = try s.stat(body);
+ try std.testing.expectEqual(@as(u64, "one\ntwo\nthree\na".len), st.size);
+ try std.testing.expectEqual(@as(u16, 0o666), st.mode);
+ try s.write(body, "more\n");
+ try std.testing.expect((try s.stat(body)).version != st.version);
+ try std.testing.expectEqual(@as(u32, 0), (try s.stat(s.at("/pane/{d}/tag", .{try s.focused()}))).version);
+}
diff --git a/test/behaviour/tree.zig b/test/behaviour/tree.zig
new file mode 100644
index 00000000..7f9b37a4
--- /dev/null
+++ b/test/behaviour/tree.zig
@@ -0,0 +1,44 @@
+//! docs/typ/reference.typ, The tree <tree>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+/// The first column's serial, /layout's first word.
+fn firstColumn(s: *Session) ![]const u8 {
+ return std.mem.sliceTo(try s.read("/layout"), ' ');
+}
+
+test "tree: index lists serial kind dirty name column, and stats 0, a view generated by each read" {
+ var s = try Session.initFile(std.testing.allocator, "hello\nthere\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const col = try firstColumn(&s);
+ const clean = s.at("{d} text 0 /test.txt {s}\n", .{ n, col });
+ const index = try s.read("/index");
+ const at = std.mem.indexOf(u8, index, clean) orelse return error.NotListed;
+ const st = try s.stat("/index");
+ try std.testing.expectEqual(@as(u64, 0), st.size);
+ try std.testing.expectEqual(@as(u16, 0o444), st.mode);
+ try s.write(s.at("/pane/{d}/body", .{n}), "more\n");
+ try std.testing.expect(has(try s.read("/index"), s.at("{d} text 1 /test.txt {s}\n", .{ n, col })));
+ // Read from an offset, as any file.
+ const kind = at + std.mem.indexOfScalar(u8, clean, ' ').? + 1;
+ try std.testing.expectEqualStrings("text", try s.readAt("/index", kind, 4));
+ const made = try s.newPane();
+ const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{made})), "\n");
+ try std.testing.expect(std.mem.endsWith(u8, try s.read("/index"), s.at("\n{d} text 0 {s} {s}\n", .{ made, name, col })));
+}
+
+test "tree: a terminal is listed as term with its directory as name, which a write to name cannot change" {
+ var s = try Session.initTerm(std.testing.allocator);
+ defer s.deinit();
+ const n = try s.focused();
+ const dir = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n");
+ try std.testing.expect(std.mem.startsWith(u8, dir, "/"));
+ try std.testing.expect(has(try s.read("/index"), s.at("{d} term 0 {s} {s}\n", .{ n, dir, try firstColumn(&s) })));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/name", .{n}), "/elsewhere\n"));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "invalid rename: a terminal is named"));
+}