diff options
Diffstat (limited to 'test/panes.zig')
| -rw-r--r-- | test/panes.zig | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/test/panes.zig b/test/panes.zig index d1c8af02..28256495 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -2266,16 +2266,22 @@ const ImageTests = struct { 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" { + test "an image's dump keeps its path, its renderer choices and its tag's tail, and reopens from the file; a file gone waits as a placeholder saying so" { 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; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); const source = "P6\n1 1\n255\n\x0d\x4d\xe7"; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "restored-image.ppm", .data = source }); + var dir_buf: [4096]u8 = undefined; + const file = try std.fmt.allocPrint(gpa, "{s}/restored-image.ppm", .{dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]}); + defer gpa.free(file); const k = load(p); - const pane = try pardes.Kind.open(p, 0, k, "/missing/restored-image.ppm", source); + const pane = try pardes.Kind.open(p, 0, k, file, 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"); @@ -2294,16 +2300,21 @@ const ImageTests = struct { 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; + // No record: opened from its file, as a Look reads it. const slot = restored_pane.addon.?; - try std.testing.expectEqualSlices(u8, source, kept[0..slot.ops.?.dump.?(slot.st, &kept, kept.len)]); + try std.testing.expect(slot.record == null and slot.live); + try std.testing.expectEqual(std.hash.Wyhash.hash(0, source), slot.opened); - // 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.?); + // Its file gone, a restore waits saying so; back, a watch opens it. + try tmp.dir.deleteFile(std.testing.io, "restored-image.ppm"); + const gone = try dump.initFromDump(gpa, .{ .tty_only = true, .addons = &brought }, p.dump_out.?); + defer gone.deinit(); + const waiting = gone.panes[0].?.addon.?; + try std.testing.expect(!waiting.live); + try std.testing.expect(std.mem.endsWith(u8, waiting.refused.slice(), "restored-image.ppm is not here")); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "restored-image.ppm", .data = source }); + try std.testing.expect(pardes.Kind.fileChanged(gone, 0, "")); + try std.testing.expect(waiting.live and waiting.refused.len == 0); } }; @@ -3917,7 +3928,7 @@ const PdfAddon = struct { try std.testing.expect(r.stats.stopped >= 1); } - test "the tag a step lays out for a PDF's pane is of the frame its tick left, not the frame before it" { + test "a PDF's tag has the core's art words from its first step, in a view without graphics and with them" { if (!addons.has_pdf) return error.SkipZigTest; const R = pardes.replica; const gpa = std.testing.allocator; @@ -3932,19 +3943,16 @@ const PdfAddon = struct { const land: Land = .{ .a = a }; const id = try opened(a, land); const slot = a.core.panes[id].?.addon.?; - // A view without graphics: the page's text layer, no picture. - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") == null); - // A window's: its tick lays the pages out as pictures and asks - // for them; the step their answers land in ticks it again, and its - // tag says what that tick placed, as the next step's will (a - // replica's guess of its next input is the tag this step laid out). + // A view without graphics: the page's text layer, its pictures' + // words glyph art's (PA_PICTURES: the kind's, not the frame's). + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:on ") != null); + // A window's: the pages as pictures, the same words, its own. try land.step(.{ .frontend = .{ .windowed = true, .native_images = true } }); try jobs(a.core, land); - try std.testing.expect(slot.placed); - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:off ") != null); } - test "a PDF's pane in a window's view and a terminal's in turn: each one's step lays its tag out as its frame shows it" { + test "a PDF's pane in a window's view and a terminal's in turn: each is told its view, its tag its page and art words in both" { if (!addons.has_pdf) return error.SkipZigTest; const R = pardes.replica; const gpa = std.testing.allocator; @@ -3973,15 +3981,19 @@ const PdfAddon = struct { defer win.deinit(); _ = try a.take(try win.input(.{ .frontend = .{ .windowed = true, .native_images = true } })); try jobs(a.core, land); - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:on ") != null); + // Both views told (by id, the session's 1 and the window's), each + // with its own frontend's facts. + try std.testing.expect(slot.views[0] != 0 and slot.views[k] != 0 and slot.views[0] != slot.views[k]); for (0..2) |_| { - // The terminal's key: its view's tick, the page's text layer. + // The terminal's key, the strip laid out for its view, and the + // window's: the same tag whichever view's step laid it out (the + // session's first view's art words, a terminal's: glyph art). _ = try a.take(try tty.input(.{ .key = .{ .cp = 'j', .text = "j" } })); try jobs(a.core, land); - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") == null); - // The window's: the pages as pictures again, in its tag at once. + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "/16] petscii:on ") != null); _ = try a.take(try win.input(.{ .key = .{ .cp = 'j', .text = "j" } })); - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "/16] petscii:on ") != null); try jobs(a.core, land); } } @@ -4013,6 +4025,7 @@ const PdfAddon = struct { // again, on the page it can still be on, as height-fitted. try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "live.pdf", .data = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/outline.pdf", p.scratch.allocator(), .unlimited) }); try std.testing.expect(p.reloadWatchedFile(@intCast(id), &.{})); + p.update(.tick); var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); _ = try p.render(arena.allocator()); |
