summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/ctl.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index a4979f7d..e963da3f 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2034,6 +2034,32 @@ test "DumpConfig's whole report writes back to the root ctl, line by line, with
}
}
+test "a ThemeFile that fails to load changes nothing: the root ctl still names the one loaded, or none" {
+ if (comptime !pardes.hosted) return;
+ const gpa = testing.allocator;
+ const p = try withFile(gpa, "x\n");
+ defer p.deinit();
+ const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ // None loaded: a failed one leaves Theme as it was.
+ _ = wr(p, root_ctl, "ThemeFile /tmp/pardes-no-such-theme.zon\n");
+ pardes.colors.failThemeFile(p, p.theme_file_generation, error.FileNotFound);
+ try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "ThemeFile") == null);
+ try testing.expectEqualStrings("", p.theme_file_path.get());
+ // One loaded, then another that fails: still the first, on every read.
+ const good = "/tmp/pardes-good-theme.zon";
+ _ = wr(p, root_ctl, "ThemeFile " ++ good ++ "\n");
+ var custom = pardes.themes[0];
+ custom.name = "good";
+ var encoded: std.Io.Writer.Allocating = .init(gpa);
+ defer encoded.deinit();
+ try std.zon.stringify.serialize(custom, .{}, &encoded.writer);
+ try testing.expect(pardes.colors.loadThemeFile(p, p.theme_file_generation, encoded.written(), false));
+ _ = wr(p, root_ctl, "ThemeFile /tmp/pardes-bad-theme.zon\n");
+ try testing.expect(!pardes.colors.loadThemeFile(p, p.theme_file_generation, ".{ .name = ", false));
+ try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "ThemeFile " ++ good ++ "\n") != null);
+ try testing.expectEqualStrings(good, p.theme_file_path.get());
+}
+
test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path, which writes back" {
if (comptime !pardes.hosted) return;
const gpa = testing.allocator;