summaryrefslogtreecommitdiff
path: root/test/behaviour/root_ctl.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 10:40:00 -0300
committerGabriel Schneider <[email protected]>2026-11-04 10:40:53 -0300
commitb798f2c1cf5dd4f98c8c1f81c8642b005890f6ee (patch)
tree202677c160f685012317f867192fc011f8ffa703 /test/behaviour/root_ctl.zig
parent7bbcd971a761def328fb9eeb881301bf45fb4783 (diff)
downloadpardes-b798f2c1cf5dd4f98c8c1f81c8642b005890f6ee.tar.gz
pardes-b798f2c1cf5dd4f98c8c1f81c8642b005890f6ee.zip
test: ten more of src/ninep/ctl.zig's tests through the 9P tree alone, in test/behaviour/panes.zig: get reloading from disk and asking once over unsaved text, Get and Get file (asking once, loading a file by a name from the pane's directory), Undo after Get file or Edit e putting the old name, text and clean state back with Putall saving nothing, a failed Get file leaving no name, text or undo step changed, Zerox's twins (one text, undo and dirty state, a cursor each, Del of one asking nothing, a rename logged for each), the small refusals (one name an open, EISDIR, EACCES and ENOTDIR in words, /dev/zero not a regular file, twins saved once by Putall, a 2-byte scratch loaded over unasked) and Get of a file not there saying so unasked; in root_ctl.zig a bad Tab width and a bad Incl directory refused, changing nothing (bare Incl's list the same); the Zerox test kept for its Save performed, and the init-file half of the Get test, each trimmed; each checked to fail against a break (get's Modified words, Get not asking about unsaved edits, an undo of a load not putting the name back, Del asking about a twin, a twin's rename not logged, Putall saving each twin, Get's not-there check after the ask, Tab taking 17, a failed Get file pushing an undo step)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/root_ctl.zig')
-rw-r--r--test/behaviour/root_ctl.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig
index c00c3cfe..3e546237 100644
--- a/test/behaviour/root_ctl.zig
+++ b/test/behaviour/root_ctl.zig
@@ -92,3 +92,34 @@ test "root-ctl: Kill with a name and nothing running says so and does not fail,
try s.write("/ctl", "Kill zzz\n");
try std.testing.expect(has(try s.read("/log"), "Kill: nothing running"));
}
+
+test "root-ctl: a bad Tab width and a bad Incl directory are refused invalid, changing nothing" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const before = try s.read("/ctl");
+ // Bare, Incl lists its directories.
+ try s.write("/ctl", "Incl\n");
+ const listed = try lastIncl(&s);
+ for ([_][]const u8{ "Tab 0\n", "Tab 17\n", "Tab x\n" }) |line| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", line));
+ // Run from a pane, as a tag click runs it: said invalid too.
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), line));
+ try std.testing.expect(has(s.said, "invalid tab width"));
+ }
+ try s.expect("/ctl", before);
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Incl rel/dir\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Incl - /usr/include\n"));
+ try std.testing.expectEqual(@as(u16, 2), try s.refused("/ctl", "Incl /tmp/pardes-surely-no-such-dir\n"));
+ // The same list again: none taken.
+ try s.write("/ctl", "Incl\n");
+ try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, try s.read("/log"), listed));
+ // Bare Tab on the root ctl says the width, as from a pane.
+ try s.write("/ctl", "Tab\n");
+}
+
+/// The log's one `msg - Incl:` record, whole.
+fn lastIncl(s: *Session) ![]const u8 {
+ const log = try s.read("/log");
+ const at = std.mem.indexOf(u8, log, "\nmsg - Incl:") orelse return error.NoIncl;
+ return log[at .. std.mem.indexOfScalarPos(u8, log, at + 1, '\n').? + 1];
+}