diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/pdf.zig | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/pdf.zig b/test/pdf.zig index fbd580b3..fe084cc1 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -407,6 +407,51 @@ test "Recent keeps a PDF as it keeps a file: open, then closed at its page" { try std.testing.expect(std.mem.indexOf(u8, out.written(), try std.fmt.bufPrint(&want, "{s}:1:1 open\n", .{path})) != null); } +test "`:N` on a PDF turns to page N, from the pane and from the root's look, and `@pN:N` logs no err" { + if (!pdf_enabled or platform == .web) return; + const gpa = std.testing.allocator; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const fixture = try pdf_impl.makeOutlineTestPdf(gpa); + defer gpa.free(fixture); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "outline.pdf", .data = fixture }); + var path_buf: [256]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, ".zig-cache/tmp/{s}/outline.pdf", .{tmp.sub_path}); + const p = try Pardes.init(gpa, .{ .file = path, .cols = 80, .rows = 28 }); + defer p.deinit(); + const doc = p.panes[0].?; + const pages = doc.pdf.?.page_count; + try std.testing.expect(pages >= 2); + const failures = p.fs.failures; + pardes.look.lookAt(p, 0, ":2"); + try std.testing.expect(!p.look_missed); + try std.testing.expectEqual(@as(usize, 1), doc.pdf.?.page); + var line: [64]u8 = undefined; + pardes.look.lookAt(p, 0, try std.fmt.bufPrint(&line, "@p{d}:1", .{doc.serial})); + try std.testing.expect(!p.look_missed); + try std.testing.expectEqual(@as(usize, 0), doc.pdf.?.page); + try std.testing.expectEqual(failures, p.fs.failures); + // Over 9P too: the root's look at `@pN:2` answers ok and logs no err. + const ctlfs = pardes.ctlfs; + const written = p.serveFs(.{ .tag = 1, .op = .write, .node = @intFromEnum(ctlfs.TopFile.look), .data = try std.fmt.bufPrint(&line, "@p{d}:2\n", .{doc.serial}) }); + try std.testing.expectEqual(ctlfs.Status.ok, written.status); + try std.testing.expectEqual(@as(usize, 1), doc.pdf.?.page); + const log = @intFromEnum(ctlfs.TopFile.log); + const h = p.serveFs(.{ .tag = 2, .op = .open, .node = log }).handle; + const record = p.fsPayload(p.serveFs(.{ .tag = 3, .op = .read, .node = log, .handle = h, .size = 1 << 16 })); + try std.testing.expect(std.mem.indexOf(u8, record, "\nerr ") == null); + _ = p.serveFs(.{ .tag = 4, .op = .release, .node = log, .handle = h }); + while (p.nextEffect()) |_| {} + // A byte offset or a pattern is no PDF address: refused with words. + pardes.look.lookAt(p, 0, ":#3"); + try std.testing.expect(p.look_missed); + try std.testing.expect(std.mem.indexOf(u8, doc.msg[0..doc.msg_len], "its address is a page, :N") != null); + p.look_missed = false; + pardes.look.lookAt(p, 0, try std.fmt.bufPrint(&line, ":{d}", .{pages + 1})); + try std.testing.expect(p.look_missed); + try std.testing.expectEqual(@as(usize, 1), doc.pdf.?.page); // where the 9P look left it +} + test "a look at a PDF's page past its last is a miss, never the last page" { if (!pdf_enabled or platform == .web) return; const gpa = std.testing.allocator; |
