summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig56
1 files changed, 48 insertions, 8 deletions
diff --git a/test/panes.zig b/test/panes.zig
index e0c383fd..28a884ab 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -8,7 +8,6 @@ const Key = pardes.Key;
const config = pardes.config;
const modal = pardes.modal;
const dump = pardes.dump;
-const image = pardes.image;
const syntax = pardes.syntax;
const filesystem = pardes.filesystem;
@@ -2246,24 +2245,65 @@ const OutputTests = struct {
}
};
+/// The image addon (addons/image/image.c), loaded as `Addon load` loads it.
const ImageTests = struct {
+ fn load(p: *Pardes) u8 {
+ pardes.Addon.perform(p, .load, 0, @import("test_addons").image);
+ return p.kinds.byName("image").?;
+ }
+
test "pane-local renderer choices are visible in the image tag" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
- pardes.image.start(std.testing.io, std.testing.allocator);
- defer pardes.image.stop();
// A picture shown (its decode landed, a frame drawn): the core's
// art words after the kind's `img`, then its path.
const id = p.freeSlot().?;
- const pane = try pardes.Kind.open(p, id, pardes.Kind.image, "/tmp/picture.ppm", "P6\n1 1\n255\n\x01\x02\x03");
+ const pane = try pardes.Kind.open(p, id, load(p), "/tmp/picture.ppm", "P6\n1 1\n255\n\x01\x02\x03");
while (p.nextEffect()) |e| p.perform(e);
pardes.exec.placeNew(p, 0, 0, id, .doc);
_ = try p.render(p.scratch.allocator());
pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false };
- try std.testing.expectEqualStrings(
- config.tag_image ++ " petscii:on palette:terminal ascii:off /tmp/picture.ppm",
- try pardes.tagline.tagPrefix(p, pane),
- );
+ try std.testing.expectEqualStrings("img petscii:on palette:terminal ascii:off /tmp/picture.ppm", try pardes.tagline.tagPrefix(p, pane));
+ }
+
+ test "an image's dump keeps its file's bytes, its renderer choices and its tag's tail" {
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true });
+ defer p.deinit();
+ try pardes.panes.deinitPane(p, p.panes[0].?);
+ p.panes[0] = null;
+
+ const source = "P6\n1 1\n255\n\x0d\x4d\xe7";
+ const k = load(p);
+ const pane = try pardes.Kind.open(p, 0, k, "/missing/restored-image.ppm", source);
+ pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false };
+ if (pane.tag.own) |own| p.gpa.free(own);
+ pane.tag.own = try p.gpa.dupe(u8, " Keep Del");
+ try dump.dumpState(p);
+
+ // Restored where its addon is (a Restore's kinds are the process's).
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ const e = &p.kinds.kinds[k];
+ const brought = [_]pardes.Kind.Loaded{pardes.Kind.loadedOf(p.kinds.ops[k].?, e.path.slice(), e.hash, &words)};
+ const restored = try dump.initFromDump(gpa, .{ .tty_only = true, .addons = &brought }, p.dump_out.?);
+ defer restored.deinit();
+ const restored_pane = restored.panes[0].?;
+ const art = restored_pane.addon.?.art;
+ try std.testing.expect(art.glyph);
+ try std.testing.expectEqual(pardes.Placement.Art.Palette.terminal, art.palette);
+ try std.testing.expect(!art.ascii);
+ try std.testing.expect(restored_pane.tag.own != null);
+ try std.testing.expectEqualStrings(" Keep Del", pardes.tagline.curTail(restored_pane));
+ var kept: [64]u8 = undefined;
+ const slot = restored_pane.addon.?;
+ try std.testing.expectEqualSlices(u8, source, kept[0..slot.ops.?.dump.?(slot.st, &kept, kept.len)]);
+
+ // And dumped again, its bytes still there.
+ try dump.dumpState(restored);
+ const again = try dump.load(gpa, .{ .tty_only = true }, restored.dump_out.?, null);
+ defer again.deinit();
+ // Loaded as a replica loads it: a placeholder holding the record.
+ try std.testing.expectEqualSlices(u8, source, again.panes[0].?.addon.?.record.?);
}
};