summaryrefslogtreecommitdiff
path: root/test/behaviour/settings.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/settings.zig')
-rw-r--r--test/behaviour/settings.zig62
1 files changed, 61 insertions, 1 deletions
diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig
index 5970e6b5..ff24704a 100644
--- a/test/behaviour/settings.zig
+++ b/test/behaviour/settings.zig
@@ -1,4 +1,5 @@
-//! docs/typ/reference.typ, Settings <settings>.
+
+
const std = @import("std");
const Session = @import("session").Session;
@@ -41,3 +42,62 @@ test "settings: Shell refuses a path that is no executable, and bare it goes bac
try std.testing.expect(has(try s.read("/log"), "Shell: the default again, "));
try std.testing.expectEqualStrings(default, try setting(&s, "Shell"));
}
+
+test "settings: Pet is the window's: a terminal's view refuses it, from a pane and the root; a window takes only its pets" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ // Which build, from its options, not from the answer: a terminal's view
+ // taking Pet must fail here, not pass as a window.
+ if (comptime @import("pardes_config").platform == .gui) {
+ try s.write("/ctl", "Pet cat\n");
+ // A window's: dog is no pet of its, and off is.
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null);
+ _ = try s.refused("/ctl", "Pet dog\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet cat\n") != null);
+ try s.write("/ctl", "Pet frog\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet frog\n") != null);
+ try s.write("/ctl", "Pet off\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPet off\n") != null);
+ return;
+ }
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Pet cat\n"));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "Pet is GUI-only, invalid here"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Pet cat\n"));
+ try std.testing.expectEqualStrings("Pet is GUI-only, invalid here", s.said);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "Pet ") == null);
+}
+
+fn expectHas(text: []const u8, part: []const u8) !void {
+ if (std.mem.indexOf(u8, text, part) == null) {
+ std.debug.print("not in it: {s}\n", .{part});
+ return error.TestExpectedText;
+ }
+}
+
+test "settings: DumpConfig reports the settings in its one +DumpConfig pane, a second refreshing it" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const text = try s.focused();
+ const exec = s.at("/pane/{d}/exec", .{text});
+ try s.write(exec, "DumpConfig\n");
+ const out = try s.focused();
+ try std.testing.expect(out != text);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("{d} text 0 /+DumpConfig ", .{out})) != null);
+ const report = try s.read(s.at("/pane/{d}/body", .{out}));
+ for ([_][]const u8{ "Theme orchard\n", "Last shell spawned: (none)\n", "Shell change pending: on\n", "\nShell ", "LocationsConfig ", "no per-user config path" }) |line| try expectHas(report, line);
+ try s.write("/ctl", "Theme acme\n");
+ try s.write("/focus", s.at("{d}", .{text}));
+ try s.write(exec, "DumpConfig\n");
+ try std.testing.expectEqual(out, try s.focused());
+ try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/index"), "/+DumpConfig "));
+ try expectHas(try s.read(s.at("/pane/{d}/body", .{out})), "Theme acme\n");
+}
+
+test "settings: Config without a configuration directory says so and opens nothing" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const index = try s.read("/index");
+ try std.testing.expectEqual(@as(u16, 5), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Config\n"));
+ try s.expect("/index", index);
+ try expectHas(try s.read("/log"), "Config: no startup file here: no configuration directory");
+}