summaryrefslogtreecommitdiff
path: root/test/behaviour
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:04:29 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:05:58 -0300
commit5322d373c78ecee48b934886c95f3b8c4471a11f (patch)
tree9833d5871cc1cf838d13243943f43a5657cb5d6c /test/behaviour
parent53c2a95eff9c67871d6004baa3e7d3c3b2a195fd (diff)
downloadpardes-5322d373c78ecee48b934886c95f3b8c4471a11f.tar.gz
pardes-5322d373c78ecee48b934886c95f3b8c4471a11f.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour')
-rw-r--r--test/behaviour/keys.zig27
-rw-r--r--test/behaviour/other_files.zig10
-rw-r--r--test/behaviour/panes.zig69
3 files changed, 106 insertions, 0 deletions
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 <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);
+}