summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig86
1 files changed, 86 insertions, 0 deletions
diff --git a/test/panes.zig b/test/panes.zig
index a19af1a6..7592742c 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -3780,6 +3780,9 @@ const PdfAddon = struct {
var why: pardes.Kind.Buf(160) = .{};
const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why);
try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } });
+ // A frontend with pictures (a terminal without them is shown the
+ // page's text layer).
+ try land.step(.{ .frontend = .{ .windowed = false, .native_images = true } });
try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null);
var buf: [4096]u8 = undefined;
const real = try std.Io.Dir.cwd().realPathFile(std.testing.io, "docs/design.pdf", &buf);
@@ -3866,6 +3869,89 @@ const PdfAddon = struct {
var fields: [256]u8 = undefined;
try std.testing.expect(std.mem.indexOf(u8, pardes.Kind.ctlRead(p.panes[id].?, &fields), "fit:height") != null);
}
+
+ /// A core showing `path` as the addon's pane with pictures, its first
+ /// pages landed: its id.
+ fn landed(p: *Pardes, path: []const u8, arena: *std.heap.ArenaAllocator, now: *u64) !usize {
+ p.view().frontend.native_images = true;
+ pardes.Addon.perform(p, .load, 0, pdf_lib);
+ var buf: [4096]u8 = undefined;
+ const real = try std.Io.Dir.cwd().realPathFile(std.testing.io, path, &buf);
+ var line: [4200]u8 = undefined;
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, try std.fmt.bufPrint(&line, "Look {s}", .{buf[0..real]})));
+ const Self = struct {
+ core: *Pardes,
+ fn step(l: @This(), ev: pardes.Event) !void {
+ l.core.update(ev);
+ }
+ };
+ for (0..4) |_| {
+ now.* += std.time.ns_per_ms;
+ p.advance(now.*);
+ p.update(.tick);
+ try jobs(p, Self{ .core = p });
+ _ = try p.render(arena.allocator());
+ }
+ return p.view().active;
+ }
+
+ test "a PDF's pointer is a hand over a link once the pointer rests there, and the arrow off it" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .tty_only = true });
+ defer p.deinit();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var now: u64 = std.time.ns_per_s;
+ const id = try landed(p, "test/pdf-fixtures/links.pdf", &arena, &now);
+ const r = p.view().rects[id];
+ const pane = p.panes[id].?;
+ // Rested on each cell in turn until one is a link's.
+ const found = scan: {
+ var row: u16 = r.y + pane.tag_rows;
+ while (row < r.y + r.h) : (row += 1) {
+ var col: u16 = r.x + 2;
+ while (col < r.x + r.w) : (col += 3) {
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = col, .row = row } });
+ now += 40 * std.time.ns_per_ms;
+ p.advance(now);
+ p.update(.tick);
+ _ = try p.render(arena.allocator());
+ _ = try p.render(arena.allocator());
+ if (p.surface.pointer_shape == .link) break :scan true;
+ }
+ }
+ break :scan false;
+ };
+ try std.testing.expect(found);
+ // Off the pane's body (its tag): the arrow again.
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = r.x + 2, .row = r.y } });
+ _ = try p.render(arena.allocator());
+ _ = try p.render(arena.allocator());
+ try std.testing.expect(p.surface.pointer_shape != .link);
+ }
+
+ test "a touchpad's fraction of a turn moves a PDF's strip by that fraction of a notch's" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .tty_only = true });
+ defer p.deinit();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var now: u64 = std.time.ns_per_s;
+ const id = try landed(p, "docs/design.pdf", &arena, &now);
+ const r = p.view().rects[id];
+ const slot = p.panes[id].?.addon.?;
+ var at: [3]f32 = undefined;
+ for (&at, [_]f32{ 0, 1, 0.25 }) |*a, turn| {
+ if (turn > 0) p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = r.x + 4, .row = r.y + r.h - 2, .amount = turn } });
+ _ = try p.render(arena.allocator());
+ a.* = slot.thumb_at;
+ }
+ const notch = at[1] - at[0];
+ try std.testing.expect(notch > 0);
+ try std.testing.expectApproxEqRel(notch / 4, at[2] - at[1], 0.05);
+ }
};
test {