summaryrefslogtreecommitdiff
path: root/test/session.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/session.zig')
-rw-r--r--test/session.zig29
1 files changed, 22 insertions, 7 deletions
diff --git a/test/session.zig b/test/session.zig
index 5b608521..8b8ec17f 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -403,24 +403,39 @@ pub const Session = struct {
// pdf:
+ /// The pdf addon (addons/pdf/pdf.c), as the build makes it; a build
+ /// without it (-Dmupdf=false) has none.
+ pub const pdf_addon: ?[]const u8 = if (@import("session_options").has_pdf_addon) @import("session_options").pdf_addon else null;
+
+ /// The pdf addon loaded into the session, once: a test of a PDF in a
+ /// build without it skips.
+ pub fn loadPdf(s: *Session) !void {
+ const lib = pdf_addon orelse return error.SkipZigTest;
+ if (std.mem.indexOf(u8, try s.read("/addons"), "pdf ") != null) return;
+ const real = try std.Io.Dir.cwd().realPathFileAlloc(std.testing.io, lib, s.arena.allocator());
+ try s.write("/ctl", s.at("Addon load {s}\n", .{real}));
+ }
+
/// A Look of `path` at the root (one relative to the working directory
/// made absolute first); the serial of the pane with the keyboard after.
- /// A PDF in a build without them (-Dmupdf=false: no PdfTint in
- /// /commands) skips the test.
+ /// A PDF loads the pdf addon first.
pub fn lookFile(s: *Session, path: []const u8) !u32 {
- if (std.mem.endsWith(u8, path, ".pdf") and std.mem.indexOf(u8, try s.read("/commands"), "PdfTint") == null) return error.SkipZigTest;
+ if (std.mem.endsWith(u8, path, ".pdf")) try s.loadPdf();
var buf: [4096]u8 = undefined;
const abs = if (std.fs.path.isAbsolute(path)) path else s.at("{s}/{s}", .{ buf[0..try std.Io.Dir.cwd().realPath(std.testing.io, &buf)], path });
try s.write("/look", s.at("{s}\n", .{abs}));
return s.focused();
}
- /// The page a PDF pane shows and its pages, from its tag's `[page/pages]`.
+ /// The page a PDF pane shows and its pages, from its tag's `[page/pages]`
+ /// (the pdf addon's prefix, which starts it).
pub fn pdfPage(s: *Session, n: u32) !struct { u32, u32 } {
+ // A kind's prefix is its last frame's: one drawn first.
+ _ = try s.read("/screen");
const tag = try s.read(s.at("/pane/{d}/tag", .{n}));
- const lo = std.mem.indexOf(u8, tag, " [") orelse return error.NoPage;
- const close = std.mem.indexOfScalarPos(u8, tag, lo, ']') orelse return error.NoPage;
- var it = std.mem.splitScalar(u8, tag[lo + 2 .. close], '/');
+ if (!std.mem.startsWith(u8, tag, "[")) return error.NoPage;
+ const close = std.mem.indexOfScalar(u8, tag, ']') orelse return error.NoPage;
+ var it = std.mem.splitScalar(u8, tag[1..close], '/');
return .{ try std.fmt.parseInt(u32, it.next().?, 10), try std.fmt.parseInt(u32, it.next() orelse return error.NoPage, 10) };
}