diff options
Diffstat (limited to 'test/pdf.zig')
| -rw-r--r-- | test/pdf.zig | 73 |
1 files changed, 64 insertions, 9 deletions
diff --git a/test/pdf.zig b/test/pdf.zig index 48869de1..fbd580b3 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -343,7 +343,7 @@ test "PdfSections Look follows the exact owning PDF, not an equal path" { try std.testing.expectEqual(first_revision, first_output.file.?.revision); const duplicate_id = p.freeSlot() orelse return error.NoDuplicatePdfSlot; - const duplicate = try panes.Pdf.openPane(p, duplicate_id, path, 0); + const duplicate = try panes.Pdf.openPane(p, duplicate_id, path, 0, .last); pardes.exec.placeNew(p, 0, 0, duplicate_id, .doc); layout.compute(p); panes.Pdf.openSections(p, duplicate_id); @@ -364,7 +364,7 @@ test "PdfSections Look follows the exact owning PDF, not an equal path" { try std.testing.expectEqual(first_output_id, p.active); } -test "PdfSections caches an empty outline output" { +test "PdfSections on a PDF with no outline says so and opens nothing" { if (!pdf_enabled or platform == .web) return; const gpa = std.testing.allocator; var tmp = std.testing.tmpDir(.{}); @@ -376,14 +376,69 @@ test "PdfSections caches an empty outline output" { const path = try std.fmt.bufPrint(&path_buf, ".zig-cache/tmp/{s}/plain.pdf", .{tmp.sub_path}); const p = try Pardes.init(gpa, .{ .file = path }); defer p.deinit(); - panes.Pdf.openSections(p, 0); const pane = p.panes[0].?; - const output_id = pane.search_pane orelse return error.MissingEmptyPdfSections; - try std.testing.expectEqual(@as(usize, 0), p.panes[output_id].?.file.?.content.len); - const serial = p.panes[output_id].?.serial; - panes.Pdf.openSections(p, 0); - try std.testing.expectEqual(output_id, pane.search_pane.?); - try std.testing.expectEqual(serial, p.panes[output_id].?.serial); + for (0..2) |_| { + panes.Pdf.openSections(p, 0); + try std.testing.expect(pane.search_pane == null); + try std.testing.expectEqualStrings("PdfSections: this PDF has no outline", pane.msg[0..pane.msg_len]); + } +} + +test "Recent keeps a PDF as it keeps a file: open, then closed at its page" { + 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.makeNoOutlineTestPdf(gpa); + defer gpa.free(fixture); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "plain.pdf", .data = fixture }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/plain.pdf", .{dir}); + const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 28 }); + defer p.deinit(); + pardes.look.lookAt(p, p.active, path); + p.update(.{ .resize = .{ .cols = 80, .rows = 28 } }); // an update's end announces it + var out: std.Io.Writer.Allocating = .init(gpa); + defer out.deinit(); + try panes.Output.recentText(p, &out.writer, true); + var want: [4300]u8 = undefined; + try std.testing.expect(std.mem.indexOf(u8, out.written(), try std.fmt.bufPrint(&want, "{s}:1:1 open\n", .{path})) != null); +} + +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; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const fixture = try pdf_impl.makeNoOutlineTestPdf(gpa); + defer gpa.free(fixture); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "plain.pdf", .data = fixture }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "other.pdf", .data = fixture }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/plain.pdf", .{dir}); + const p = try Pardes.init(gpa, .{ .file = path, .cols = 80, .rows = 28 }); + defer p.deinit(); + const doc = p.panes[0].?; + try std.testing.expect(doc.hasPdf()); + var line: [4300]u8 = undefined; + // Open: it stays on its page. + const page = doc.pdf.?.page; + pardes.look.lookAt(p, 0, try std.fmt.bufPrint(&line, "{s}:999", .{path})); + try std.testing.expect(p.look_missed); + try std.testing.expectEqual(page, doc.pdf.?.page); + // Not open: nothing opens. + p.look_missed = false; + var before: usize = 0; + for (p.panes) |slot| before += @intFromBool(slot != null); + pardes.look.lookAt(p, 0, try std.fmt.bufPrint(&line, "{s}/other.pdf:999", .{dir})); + try std.testing.expect(p.look_missed); + var after: usize = 0; + for (p.panes) |slot| after += @intFromBool(slot != null); + try std.testing.expectEqual(before, after); } test "SDL PDF raster policy is materially denser than Kitty" { |
