summaryrefslogtreecommitdiff
path: root/test/behaviour/flags.zig
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/behaviour/flags.zig
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/behaviour/flags.zig')
-rw-r--r--test/behaviour/flags.zig42
1 files changed, 42 insertions, 0 deletions
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"));
+}