summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:00:43 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:01:13 -0300
commit53c2a95eff9c67871d6004baa3e7d3c3b2a195fd (patch)
treeb2bc1fec3ab6b33eab1a29613c7d3cb5be6da1a2 /test
parentd1273bbd99daf9b1855d82bf315db8ede20abde5 (diff)
downloadpardes-53c2a95eff9c67871d6004baa3e7d3c3b2a195fd.tar.gz
pardes-53c2a95eff9c67871d6004baa3e7d3c3b2a195fd.zip
test: three of test/pdf.zig's look tests through the 9P tree alone (test/behaviour/look_and_exec): `:N` on a PDF from its look, the root's and `@pN:N` (the page read from its tag's [P/N]), its misses in the log (no page 0, no search hit, no text to address, one past the last); a page past the last a miss, open or not, opening nothing (/index); a +PdfSections row's page checked against the outline; Session's lookFile and pdfPage; each checked to fail against a break (a PDF look turning to page 1 always, an open PDF's past-last page check dropped, Pdf.openPane taking .last for .refuse, the sections row's page check dropped)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test')
-rw-r--r--test/behaviour/look_and_exec.zig94
-rw-r--r--test/pdf.zig132
-rw-r--r--test/session.zig20
3 files changed, 114 insertions, 132 deletions
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig
index 2ff4345b..a6f28960 100644
--- a/test/behaviour/look_and_exec.zig
+++ b/test/behaviour/look_and_exec.zig
@@ -36,3 +36,97 @@ test "look-and-exec: a bare :N or :N:M look addresses the pane itself, from its
try s.write(s.at("/pane/{d}/event", .{n}), "ML0 0 0 2 :1\n");
try expectEqual(.{ @as(u32, 0), @as(u32, 6) }, try s.range(dot));
}
+
+/// The log's `err` records, counted.
+fn errs(s: *Session) !usize {
+ return std.mem.count(u8, try s.read("/log"), "\nerr ");
+}
+
+/// The serial of the pane /index names with `suffix`.
+fn paneNamed(s: *Session, suffix: []const u8) !u32 {
+ var lines = std.mem.splitScalar(u8, try s.read("/index"), '\n');
+ while (lines.next()) |line| {
+ // serial kind dirty name column
+ const name = line[0 .. std.mem.lastIndexOfScalar(u8, line, ' ') orelse continue];
+ if (std.mem.endsWith(u8, name, suffix)) return std.fmt.parseInt(u32, line[0..std.mem.indexOfScalar(u8, line, ' ').?], 10);
+ }
+ return error.NoSuchPane;
+}
+
+test "look-and-exec: `:N` on a PDF turns to page N, from the pane and from the root's look, and `@pN:N` logs no err" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.lookFile("docs/design.pdf");
+ const look = s.at("/pane/{d}/look", .{n});
+ const pages = (try s.pdfPage(n))[1];
+ try std.testing.expect(pages >= 3);
+ try s.write(look, ":2\n");
+ try expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]);
+ try s.write(look, s.at("@p{d}:1\n", .{n}));
+ try expectEqual(@as(u32, 1), (try s.pdfPage(n))[0]);
+ try s.write("/look", s.at("@p{d}:2\n", .{n}));
+ try expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]);
+ try expectEqual(@as(usize, 0), try errs(&s));
+ // `:N:H` is hit H of its search on page N, as a search row's
+ // `file.pdf:N:H` is: with no search there is no hit 3, a miss that turns
+ // no page.
+ try s.write(look, ":1\n");
+ _ = try s.refused(look, ":2:3\n");
+ try expectEqual(@as(u32, 1), (try s.pdfPage(n))[0]);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "has no search hit 3 on page 2") != null);
+ try s.write(look, ":2\n");
+ _ = try s.refused(look, ":0\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "has no page 0") != null);
+ // A byte offset or a pattern is no PDF address: refused with words.
+ _ = try s.refused(look, ":#3\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "its address is a page, :N") != null);
+ const before = try errs(&s);
+ _ = try s.refused(look, s.at(":{d}\n", .{pages + 1}));
+ try expectEqual(before + 1, try errs(&s));
+ try expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]);
+}
+
+test "look-and-exec: a look at a PDF's page past its last is a miss, never the last page, and opens nothing" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ try std.Io.Dir.cwd().copyFile("docs/design.pdf", tmp.dir, "other.pdf", std.testing.io, .{});
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.lookFile("docs/design.pdf");
+ const look = s.at("/pane/{d}/look", .{n});
+ const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n");
+ // Open: it stays on its page.
+ try s.write(look, ":2\n");
+ _ = try s.refused(look, s.at("{s}:999\n", .{name}));
+ try expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "has no page 999") != null);
+ // Not open: nothing opens.
+ const index = try s.read("/index");
+ _ = try s.refused(look, s.at("{s}/other.pdf:999\n", .{dir}));
+ try s.expect("/index", index);
+}
+
+test "look-and-exec: a +PdfSections row's first number is the page: a section not there, or on another page, is a miss said" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.lookFile("docs/design.pdf");
+ try s.write(s.at("/pane/{d}/exec", .{n}), "PdfSections\n");
+ const out = try paneNamed(&s, "/+PdfSections");
+ const body = try s.read(s.at("/pane/{d}/body", .{out}));
+ const row = body[0..std.mem.indexOfScalar(u8, body, '\n').?];
+ const place = row[0..std.mem.indexOfScalar(u8, row, ' ').?]; // design.pdf:P:S
+ var fields = std.mem.splitScalar(u8, place, ':');
+ _ = fields.next();
+ const page = try std.fmt.parseInt(u32, fields.next().?, 10);
+ const look = s.at("/pane/{d}/look", .{out});
+ // As listed: found, no miss.
+ try s.write(look, s.at("{s}\n", .{place}));
+ try expectEqual(@as(usize, 0), try errs(&s));
+ // The section on another page than the row says, and one not there.
+ _ = try s.refused(look, s.at("design.pdf:{d}:1\n", .{page + 1}));
+ try expectEqual(@as(usize, 1), try errs(&s));
+ _ = try s.refused(look, "design.pdf:1:999\n");
+ try expectEqual(@as(usize, 2), try errs(&s));
+}
diff --git a/test/pdf.zig b/test/pdf.zig
index fca0c240..4d387a4c 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -278,43 +278,6 @@ test "PDF feature gates keep argv and builtin behavior coherent" {
}
}
-test "a +PdfSections row's first number is the page: a section not there, or on another page, is a miss said" {
- 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();
- panes.Pdf.openSections(p, 0);
- const out_id = p.panes[0].?.search_pane orelse return error.MissingPdfSectionsOutput;
- const out = p.panes[out_id].?;
- const row = std.mem.sliceTo(out.file.?.content, '\n');
- const place = row[0 .. std.mem.indexOfScalar(u8, row, ' ') orelse row.len]; // outline.pdf:P:1
- var fields = std.mem.splitScalar(u8, place, ':');
- _ = fields.next();
- const page = try std.fmt.parseInt(usize, fields.next().?, 10);
- var line: [128]u8 = undefined;
- // As listed: found, no miss.
- p.look_missed = false;
- pardes.look.lookAt(p, out_id, place);
- try std.testing.expect(!p.look_missed);
- // The section on another page than the row says, and one not there.
- for ([_][]const u8{ try std.fmt.bufPrint(&line, "outline.pdf:{d}:1", .{page + 1}), "outline.pdf:1:999" }) |bad| {
- var copy: [128]u8 = undefined;
- @memcpy(copy[0..bad.len], bad);
- p.look_missed = false;
- const failures = p.fs.failures;
- pardes.look.lookAt(p, out_id, copy[0..bad.len]);
- try std.testing.expect(p.look_missed);
- try std.testing.expect(p.fs.failures != failures);
- }
-}
-
test "a PDF's body puts each line of its text on a line of its own, never a heading run into the text under it" {
if (!pdf_enabled or platform == .web) return;
var tmp = std.testing.tmpDir(.{});
@@ -420,101 +383,6 @@ 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 = @backingInt(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 = @backingInt(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()) |_| {}
- // `:N:H` on the pane is hit H of its search on page N, as `file.pdf:N:H`
- // (a search row) is: with no search there is no hit 3, a miss that
- // turns no page.
- p.look_missed = false;
- pardes.look.lookAt(p, 0, ":1");
- pardes.look.lookAt(p, 0, ":2:3");
- try std.testing.expect(p.look_missed);
- try std.testing.expect(std.mem.indexOf(u8, doc.msg[0..doc.msg_len], "has no search hit 3 on page 2") != null);
- try std.testing.expectEqual(@as(usize, 0), doc.pdf.?.page);
- pardes.look.lookAt(p, 0, ":2");
- // Page 0 is no page: the has-no-page miss.
- p.look_missed = false;
- pardes.look.lookAt(p, 0, ":0");
- try std.testing.expect(p.look_missed);
- try std.testing.expect(std.mem.indexOf(u8, doc.msg[0..doc.msg_len], "has no page 0") != null);
- p.look_missed = false;
- // 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;
- 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" {
try std.testing.expect(
pardes.sdl_pdf_raster_policy.dpi >= pardes.kitty_pdf_raster_policy.dpi * 2,
diff --git a/test/session.zig b/test/session.zig
index 8b3c5c41..f11a4c7f 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -182,6 +182,26 @@ pub const Session = struct {
fn pardesOf(s: *Session) *Pardes {
return @ptrCast(@alignCast(s.core));
}
+
+ // pdf:
+
+ /// 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.
+ pub fn lookFile(s: *Session, path: []const u8) !u32 {
+ 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]`.
+ pub fn pdfPage(s: *Session, n: u32) !struct { u32, u32 } {
+ 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], '/');
+ return .{ try std.fmt.parseInt(u32, it.next().?, 10), try std.fmt.parseInt(u32, it.next() orelse return error.NoPage, 10) };
+ }
};
fn refusal(path: []const u8, r: Reply) error{Refused} {