diff options
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/addons.zig | 33 | ||||
| -rw-r--r-- | test/behaviour/addons_pdf.zig | 24 |
2 files changed, 57 insertions, 0 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index 3a53766a..9b96a3d6 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -331,3 +331,36 @@ test "addons: a Look at a file whose extension an addon claims opens a pane of i const help = try s.read(s.at("/pane/{d}/body", .{try s.focused()})); try std.testing.expect(has(help, "SPC z f Fake a fake pane, counting (addon fake)\n")); } + +test "addons: an image pane whose file changes on disk shows the new picture, under a new key: a window keeps a texture by its key" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + s.graphics(); + try load(&s, Session.image_addon); + defer unload(&s, "image"); + 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 tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" }); + try s.write("/look", s.at("{s}/pic.ppm\n", .{dir})); + const n = try s.focused(); + const key = "\"key\":\""; + const before = try s.arena.allocator().dupe(u8, try s.read("/screen")); + try std.testing.expect(has(before, s.at("\"serial\":{d},", .{n})) and has(before, "\"src\":[0,0,2,1]")); + const old_key = before[std.mem.indexOf(u8, before, key).? + key.len ..][0..16]; + // The same size, other pixels: only its key tells a window it changed. + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic.ppm", .data = "P6\n2 1\n255\n\xe7\x4d\x0d\xe7\x4d\x0d" }); + try std.testing.expect(try s.filesChanged()); + const after = try s.read("/screen"); + try std.testing.expect(has(after, "\"src\":[0,0,2,1]")); + try std.testing.expect(!has(after, old_key)); + // Another size: the picture as it is now. + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic.ppm", .data = "P6\n3 1\n255\n\xe7\x4d\x0d\xe7\x4d\x0d\xe7\x4d\x0d" }); + try std.testing.expect(try s.filesChanged()); + try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,3,1]")); + // A second Look of it finds its pane, the new picture in it. + try s.write("/look", s.at("{s}/pic.ppm\n", .{dir})); + try std.testing.expectEqual(n, try s.focused()); + try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,3,1]")); +} diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig index 48b75806..6cdeebf1 100644 --- a/test/behaviour/addons_pdf.zig +++ b/test/behaviour/addons_pdf.zig @@ -232,3 +232,27 @@ test "addons: a PDF's body is its page's text layer, read from any offset and ne _ = try s.refused("/look", s.at("{s}/cut.pdf\n", .{dir})); try std.testing.expect(has(s.said, "cut.pdf") and has(s.said, "not a PDF pardes can read")); } + +test "addons: a PDF whose file changes on disk shows its new pages, under new keys: a window keeps a texture by its key" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + s.graphics(); + 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)]; + const a = s.arena.allocator(); + const links = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/links.pdf", a, .unlimited); + const outline = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/outline.pdf", a, .unlimited); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "doc.pdf", .data = links }); + const n = try s.lookFile(s.at("{s}/doc.pdf", .{dir})); + const first = try shown(&s, n); + try std.testing.expect(first.len >= 1); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "doc.pdf", .data = outline }); + try std.testing.expect(try s.filesChanged()); + // Its pages laid out at the step after (the host's next). + try s.keys("0"); + const now = try shown(&s, n); + try std.testing.expect(now.len >= 1); + for (now) |pic| for (first) |old| try std.testing.expect(!std.mem.eql(u8, pic.key, old.key)); +} |
