summaryrefslogtreecommitdiff
path: root/test/behaviour/settings.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/settings.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/settings.zig')
-rw-r--r--test/behaviour/settings.zig43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig
new file mode 100644
index 00000000..5970e6b5
--- /dev/null
+++ b/test/behaviour/settings.zig
@@ -0,0 +1,43 @@
+//! docs/typ/reference.typ, Settings <settings>.
+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 root ctl's line for `word`.
+fn setting(s: *Session, word: []const u8) ![]const u8 {
+ var lines = std.mem.splitScalar(u8, try s.read("/ctl"), '\n');
+ while (lines.next()) |line| if (std.mem.startsWith(u8, line, word) and line.len > word.len and line[word.len] == ' ') return line;
+ return error.NoSuchSetting;
+}
+
+test "settings: Pager is pardes by default, off taken, anything else refused with its choices" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try std.testing.expectEqualStrings("Pager pardes", try setting(&s, "Pager"));
+ try s.write("/ctl", "Pager off\n");
+ try std.testing.expectEqualStrings("Pager off", try setting(&s, "Pager"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Pager less\n"));
+ try std.testing.expectEqualStrings("bad value in control message; takes pardes, off \"less\"", s.said);
+ try std.testing.expectEqualStrings("Pager off", try setting(&s, "Pager"));
+}
+
+test "settings: Shell refuses a path that is no executable, and bare it goes back to the default" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const default = try setting(&s, "Shell");
+ try std.testing.expect(try s.refused("/ctl", "Shell /nonexistent/zzsh\n") != 0);
+ try std.testing.expect(has(s.said, "Shell: shell \"/nonexistent/zzsh\" not found"));
+ try std.testing.expect(has(try s.read("/log"), "shell \"/nonexistent/zzsh\" not found"));
+ // Its words say a directory, which a mount reads as EISDIR too.
+ try std.testing.expectEqual(@as(u16, 21), try s.refused("/ctl", "Shell /etc\n"));
+ try std.testing.expect(has(try s.read("/log"), "Shell: not a shell: /etc is a directory"));
+ try std.testing.expectEqualStrings(default, try setting(&s, "Shell"));
+ try s.write("/ctl", "Shell /bin/sh\n");
+ try std.testing.expectEqualStrings("Shell /bin/sh", try setting(&s, "Shell"));
+ try s.write("/ctl", "Shell\n");
+ try std.testing.expect(has(try s.read("/log"), "Shell: the default again, "));
+ try std.testing.expectEqualStrings(default, try setting(&s, "Shell"));
+}