From 53c2a95eff9c67871d6004baa3e7d3c3b2a195fd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:00:43 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/pdf.zig | 132 ----------------------------------------------------------- 1 file changed, 132 deletions(-) (limited to 'test/pdf.zig') 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, -- cgit v1.3 From 5322d373c78ecee48b934886c95f3b8c4471a11f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 17:04:29 -0300 Subject: test: five of test/pdf.zig's tests through the 9P tree alone: a PDF's body a line for each line of its page's text (panes), PdfTint stepped in its ctl and never in its tag, refused at another pane (panes), PdfSections on a PDF with no outline opening nothing (panes, a PDF written by the test), /recent keeping a PDF open then closed (other_files), the pages a PDF shown as text turns for j/k, Ctrl-d/u/f/b, ge, gg, 3gg, 2G and the editing keys consumed (keys, a new file); the parts with no surface stay as two small tests (tint colours of a theme with none, `:`/SPC/`/` on a PDF); each checked to fail against a break (the page text's newline a blank, toggleTint not stepping, the no-outline check dropped, a PDF given no Recent place, a counted text-mode j taking half its count) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour.zig | 1 + test/behaviour/keys.zig | 27 +++++++ test/behaviour/other_files.zig | 10 +++ test/behaviour/panes.zig | 69 ++++++++++++++++ test/pdf.zig | 173 +---------------------------------------- 5 files changed, 109 insertions(+), 171 deletions(-) create mode 100644 test/behaviour/keys.zig (limited to 'test/pdf.zig') diff --git a/test/behaviour.zig b/test/behaviour.zig index 32138f94..3e377ed7 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -5,6 +5,7 @@ test { _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); + _ = @import("behaviour/keys.zig"); _ = @import("behaviour/look_and_exec.zig"); _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig new file mode 100644 index 00000000..3d6fdf31 --- /dev/null +++ b/test/behaviour/keys.zig @@ -0,0 +1,27 @@ +//! docs/typ/guide.typ, Keys . +const std = @import("std"); +const Session = @import("session").Session; + +test "keys: a PDF shown as text turns pages for the moving keys, counted, and the editing keys do nothing" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const pages = (try s.pdfPage(n))[1]; + try std.testing.expect(pages > 3); + // j k, Ctrl-d Ctrl-u, Ctrl-f Ctrl-b: a page each, counted. + for ([_][]const u8{ "2j", "2k", "2\x04", "2\x15", "2\x06", "2\x02" }, 0..) |keys, i| { + try s.keys(keys); + try std.testing.expectEqual(@as(u32, if (i % 2 == 0) 3 else 1), (try s.pdfPage(n))[0]); + } + for ([_]struct { []const u8, u32 }{ .{ "ge", pages }, .{ "gg", 1 }, .{ "3gg", 3 }, .{ "2G", 2 } }) |step| { + try s.keys(step[0]); + try std.testing.expectEqual(step[1], (try s.pdfPage(n))[0]); + } + // Consumed, with their count: the page stays, no selection begins, and + // the next j is one page. + try s.keys("4dv|"); + try std.testing.expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal ")); + try s.keys("j"); + try std.testing.expectEqual(@as(u32, 3), (try s.pdfPage(n))[0]); +} diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index c0f9c08f..e778ad77 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -28,3 +28,13 @@ test "other-files: kbdin's Kalt rune is Alt on the key after it alone, and an Al try s.keys("i\u{F015}zy\x1b"); try s.expect(s.at("/pane/{d}/body", .{try s.focused()}), "yx\n"); } + +test "other-files: /recent keeps a PDF as it keeps a file: open, then closed" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("open {s}\n", .{name})) != null); + try s.write(s.at("/pane/{d}/ctl", .{n}), "Del\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("closed {s}\n", .{name})) != null); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 01820a07..8a906c2b 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -49,3 +49,72 @@ test "panes: Putall saves every pane with unsaved edits to a file, one each, and try s.write("/ctl", "Putall\n"); try std.testing.expectEqual(@as(usize, 1), s.saved); } + +/// `name` in `dir`: a one-page PDF with no outline and no text. +fn plainPdf(dir: std.Io.Dir, name: []const u8) !void { + const objects = [_][]const u8{ + "<< /Type /Catalog /Pages 2 0 R >>", + "<< /Type /Pages /Count 1 /Kids [3 0 R] >>", + "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 300] /Resources << >> >>", + }; + var buf: [1024]u8 = undefined; + var w: std.Io.Writer = .fixed(&buf); + var at: [objects.len]usize = undefined; + try w.writeAll("%PDF-1.4\n"); + for (objects, 0..) |object, i| { + at[i] = w.end; + try w.print("{d} 0 obj\n{s}\nendobj\n", .{ i + 1, object }); + } + const xref = w.end; + try w.print("xref\n0 {d}\n0000000000 65535 f \n", .{objects.len + 1}); + for (at) |off| try w.print("{d:0>10} 00000 n \n", .{off}); + try w.print("trailer\n<< /Size {d} /Root 1 0 R >>\nstartxref\n{d}\n%%EOF\n", .{ objects.len + 1, xref }); + try dir.writeFile(std.testing.io, .{ .sub_path = name, .data = w.buffered() }); +} + +test "panes: a PDF's body is the text of the page shown, each line of it a line, never a heading run into the text under it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile("docs/design.pdf"); + const body = s.at("/pane/{d}/body", .{n}); + try std.testing.expect(std.mem.startsWith(u8, try s.read(body), "Pardes: A Text Environment\nArchitecture and implementation of the rewrite\n")); + try s.write(s.at("/pane/{d}/look", .{n}), ":2\n"); + try std.testing.expect(!std.mem.startsWith(u8, try s.read(body), "Pardes: A Text Environment\n")); +} + +test "panes: PdfTint steps a PDF's tint, read in its ctl and never in its tag, and only a PDF pane takes it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const text = try s.focused(); + const n = try s.lookFile("docs/design.pdf"); + const ctl = s.at("/pane/{d}/ctl", .{n}); + const tag = try s.read(s.at("/pane/{d}/tag", .{n})); + try std.testing.expect(std.mem.endsWith(u8, tag, " PdfSections PdfTint PdfFit Collapse Del")); + for ([_][]const u8{ "full", "disabled", "filtered" }) |want| { + try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), "fit:width ") != null); + try s.write(ctl, "PdfTint\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), s.at(" tint:{s} ", .{want})) != null); + try s.expect(s.at("/pane/{d}/tag", .{n}), tag); + // Another pane's PdfTint is refused and leaves the PDF's alone. + try std.testing.expectEqual(@as(u16, 5), try s.refused(s.at("/pane/{d}/ctl", .{text}), "PdfTint\n")); + try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), s.at(" tint:{s} ", .{want})) != null); + } +} + +test "panes: PdfSections on a PDF with no outline says so and opens nothing" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try plainPdf(tmp.dir, "plain.pdf"); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.lookFile(s.at("{s}/plain.pdf", .{dir})); + try std.testing.expectEqual(@as(u32, 1), (try s.pdfPage(n))[1]); + const index = try s.read("/index"); + for (0..2) |_| { + _ = try s.refused(s.at("/pane/{d}/exec", .{n}), "PdfSections\n"); + try s.expect("/index", index); + } + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "PdfSections: this PDF has no outline") != null); +} diff --git a/test/pdf.zig b/test/pdf.zig index 4d387a4c..a068fc40 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -278,19 +278,6 @@ test "PDF feature gates keep argv and builtin behavior coherent" { } } -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(.{}); - defer tmp.cleanup(); - const p = try PdfLinkTests.init(tmp); - defer p.deinit(); - const text = p.panes[0].?.pdf.?.ensureText(p.pdf_gpa); - // The page's three text runs, each its own line. - try std.testing.expect(std.mem.indexOf(u8, text, "target.txt\n") != null); - try std.testing.expect(std.mem.indexOf(u8, text, "https://example.com/same\n") != null); - try std.testing.expect(std.mem.indexOf(u8, text, "label\n") != null); -} - test "PdfSections Look follows the exact owning PDF, not an equal path" { if (!pdf_enabled or platform == .web) return; const gpa = std.testing.allocator; @@ -340,49 +327,6 @@ test "PdfSections Look follows the exact owning PDF, not an equal path" { try std.testing.expectEqual(first_output_id, p.active); } -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(.{}); - 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 path_buf: [256]u8 = undefined; - 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(); - const pane = p.panes[0].?; - 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 "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, @@ -1202,7 +1146,7 @@ fn copySourceRect( return out; } -test "PDF normal adapter consumes unsupported actions and navigates page fallback" { +test "PDF normal mode keeps `:`, SPC and `/` on their shared paths" { if (!pdf_enabled or platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ @@ -1212,61 +1156,8 @@ test "PDF normal adapter consumes unsupported actions and navigates page fallbac }); defer p.deinit(); const pane = p.panes[0].?; - const pv = &pane.pdf.?; - try std.testing.expect(pv.page_count > 3); p.native_images = false; - // Every vertical vocabulary falls back to counted page changes when the - // shell cannot place native pixels. - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'j' } }); - try std.testing.expectEqual(@as(usize, 2), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'k' } }); - try std.testing.expectEqual(@as(usize, 0), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'd', .ctrl = true } }); - try std.testing.expectEqual(@as(usize, 2), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'u', .ctrl = true } }); - try std.testing.expectEqual(@as(usize, 0), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'f', .ctrl = true } }); - try std.testing.expectEqual(@as(usize, 2), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); - try std.testing.expectEqual(@as(usize, 0), pv.page); - - // Prefix actions and the counted text goto-line action map to pages. - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'e' } }); - try std.testing.expectEqual(pv.page_count - 1, pv.page); - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - try std.testing.expectEqual(@as(usize, 0), pv.page); - p.update(.{ .key = .{ .cp = '3' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - try std.testing.expectEqual(@as(usize, 2), pv.page); - p.update(.{ .key = .{ .cp = '2' } }); - p.update(.{ .key = .{ .cp = 'G' } }); - try std.testing.expectEqual(@as(usize, 1), pv.page); - - // Editing/selection actions are consumed no-ops: parser state clears, - // placeholder cells never acquire a range, and PDF state stays intact. - const page_before_noop = pv.page; - const revision_before_noop = pv.next_raster_revision; - p.update(.{ .key = .{ .cp = '4' } }); - p.update(.{ .key = .{ .cp = 'd' } }); - p.update(.{ .key = .{ .cp = 'v' } }); - p.update(.{ .key = .{ .cp = '|' } }); - try std.testing.expectEqual(page_before_noop, pv.page); - try std.testing.expectEqual(revision_before_noop, pv.next_raster_revision); - try std.testing.expectEqual(@as(u32, 0), pane.body.normal.count); - try std.testing.expectEqual(.none, pane.body.normal.prefix); - try std.testing.expect(!pane.body.vsel.active and !pane.body.msel.active and pane.body.nsel == 0); - try std.testing.expect(pane.focus == .body); - // Cross-pane BODY-NORMAL actions keep their established shared paths. p.update(.{ .key = .{ .cp = ':' } }); try std.testing.expect(pane.focus == .tag); @@ -1420,7 +1311,7 @@ test "PDF continuous strip renders every intersecting short page" { } } -test "PdfTint cycles pane-local state without adding tag clutter" { +test "PDF tint resolves a theme's null page colors to its chrome" { if (!pdf_enabled or platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ @@ -1429,66 +1320,6 @@ test "PdfTint cycles pane-local state without adding tag clutter" { .rows = 24, }); defer p.deinit(); - const pane = p.panes[0].?; - const pv = &pane.pdf.?; - const tint_builtin = std.meta.stringToEnum(Builtin, "PdfTint") orelse - return error.MissingPdfTintBuiltin; - - try std.testing.expectEqual(PdfTintMode.filtered, pv.tint); - const initial_tag = try pardes.tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expect(std.mem.startsWith(u8, initial_tag, pv.path)); - try std.testing.expect(std.mem.endsWith(u8, initial_tag, " PdfSections PdfTint PdfFit Collapse Del")); - try std.testing.expect(std.mem.indexOf(u8, initial_tag, "filtered") == null); - - try std.testing.expect(pardes.test_api.runBuiltin( - p, - @tagName(tint_builtin), - 0, - "", - null, - )); - try std.testing.expectEqual(PdfTintMode.full, pv.tint); - const full_tag = try pardes.tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expectEqualStrings(initial_tag, full_tag); - try std.testing.expect(std.mem.indexOf(u8, full_tag, "full") == null); - - // Running the same pane-scoped word in a terminal cannot mutate the PDF - // next to it. A FILE boot is one pane now, so that terminal is asked for - // here rather than inherited from init. - _ = try p.newShell(1, ""); - _ = layout.splitColumn(p, 0, 1, false); - p.sync(); // rects for the new column, exactly as the two-pane boot did - try std.testing.expect(!hasPdf(p.panes[1].?)); - try std.testing.expect(pardes.test_api.runBuiltin( - p, - @tagName(tint_builtin), - 1, - "", - null, - )); - try std.testing.expectEqual(PdfTintMode.full, pv.tint); - - try std.testing.expect(pardes.test_api.runBuiltin( - p, - @tagName(tint_builtin), - 0, - "", - null, - )); - try std.testing.expectEqual(PdfTintMode.disabled, pv.tint); - const disabled_tag = try pardes.tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expectEqualStrings(initial_tag, disabled_tag); - try std.testing.expect(std.mem.indexOf(u8, disabled_tag, "disabled") == null); - try std.testing.expect(pardes.test_api.runBuiltin( - p, - @tagName(tint_builtin), - 0, - "", - null, - )); - try std.testing.expectEqual(PdfTintMode.filtered, pv.tint); - try std.testing.expectEqual(PdfFitMode.width, pv.fit); - // `dark` intentionally leaves page bg/fg null. PDF tint resolves those // deterministically to its chrome colors rather than host defaults. const dark_index = for (themes, 0..) |th, i| { -- cgit v1.3