diff options
Diffstat (limited to 'test/behaviour/addons.zig')
| -rw-r--r-- | test/behaviour/addons.zig | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index b64a6974..3a53766a 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -37,7 +37,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com defer unload(&s, "fake"); // `<kind> <version> <abi> <panes open> <path> <blake3> <state>`. const listed = try s.read("/addons"); - try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 2.2 0 /")); + try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 3.0 0 /")); var fields = std.mem.tokenizeScalar(u8, listed[0..std.mem.indexOfScalar(u8, listed, '\n').?], ' '); for (0..5) |_| _ = fields.next(); try std.testing.expectEqual(@as(usize, 64), fields.next().?.len); @@ -51,7 +51,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com // A pane of it open, it stays; closed, it goes. try s.write("/ctl", "Fake\n"); const pane = try paneOf(&s, "fake"); - try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 2.2 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 3.0 1 /")); try std.testing.expect(try s.refused("/ctl", "Addon unload fake\n") != 0); try std.testing.expect(has(s.said, "1 fake pane is open")); try s.write(s.at("/pane/{d}/ctl", .{pane}), "Del\n"); @@ -65,10 +65,10 @@ test "addons: a library of another ABI, one with no pardes_addon, and one whose defer s.deinit(); for ([_][]const u8{ fake.abi, fake.no_export, fake.core_word }) |path| try load(&s, path); const listed = try s.read("/addons"); - try std.testing.expect(std.mem.startsWith(u8, listed, "fakeabi 1 3.0 0 /")); - try std.testing.expect(has(listed, " refused: wants abi 3, this pardes speaks 2\n")); + try std.testing.expect(std.mem.startsWith(u8, listed, "fakeabi 1 2.2 0 /")); + try std.testing.expect(has(listed, " refused: wants abi 2, this pardes speaks 3\n")); try std.testing.expect(has(listed, " refused: it has no pardes_addon\n")); - try std.testing.expect(has(listed, "\nfakeword 1 2.2 0 /")); + try std.testing.expect(has(listed, "\nfakeword 1 3.0 0 /")); try std.testing.expect(has(listed, " refused: word Save is the core's\n")); // A file that is no library at all: listed with what the loader said. var tmp = std.testing.tmpDir(.{}); @@ -115,12 +115,12 @@ test "addons: a pane of an addon's kind shows its cells and its picture, takes i try std.testing.expect(try s.focused() != pane); } -test "addons: the image addon opens the pictures a Look names, fitted, with the core's art words in its tag; refuses what it cannot read; and keeps a picture's bytes through a dump" { +test "addons: the image addon opens the pictures a Look names, fitted, with the core's art words in its tag; refuses what it cannot read; and a dump's pane reads its file again" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); try load(&s, Session.image_addon); const listed = try s.read("/addons"); - try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 2.2 0 /") and has(listed, " loaded\n")); + try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 3.0 0 /") and has(listed, " loaded\n")); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var buf: [4096]u8 = undefined; @@ -134,6 +134,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the .{ "red.jpeg", "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wgARCAAIABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAVAQEBAAAAAAAAAAAAAAAAAAAGCP/aAAwDAQACEAMQAAABkIC1V//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAQUCP//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEABj8CP//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8hP//aAAwDAQACAAMAAAAQA//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8QP//Z", 16, 8 }, .{ "pixel.ppm", "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7", 2, 1 }, }; + var red: []const u8 = ""; for (pictures) |pic| { const bytes = if (std.mem.endsWith(u8, pic[0], ".ppm")) pic[1] else blk: { const out = try s.arena.allocator().alloc(u8, try b64.calcSizeForSlice(pic[1])); @@ -141,6 +142,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the break :blk out; }; try tmp.dir.writeFile(std.testing.io, .{ .sub_path = pic[0], .data = bytes }); + if (red.len == 0) red = bytes; try s.write("/look", s.at("{s}/{s}\n", .{ dir, pic[0] })); try std.testing.expect(has(try s.read("/screen"), s.at("\"serial\":{d},\"rect\":", .{try s.focused()}))); try std.testing.expect(has(try s.read("/screen"), s.at("\"src\":[0,0,{d},{d}]", .{ pic[2], pic[3] }))); @@ -160,8 +162,8 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the try std.testing.expect(try s.refused("/look", s.at("{s}/bad.png\n", .{dir})) != 0); try std.testing.expect(has(s.said, "bad.png: not an image pardes can read")); try std.testing.expectEqual(panes, (try s.read("/index")).len); - // Its record is the file's bytes: restored without the addon it waits - // as a placeholder holding them, and shows them again when it comes. + // A dump keeps its path, not its bytes: restored without the addon it + // waits as a placeholder, and reads its file again when the addon comes. try s.write("/ctl", "Dump\n"); const label = try s.arena.allocator().dupe(u8, std.mem.sliceTo(try s.read("/dumps"), ' ')); var lines = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n'); @@ -172,6 +174,15 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the try load(&s, Session.image_addon); defer unload(&s, "image"); try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]")); + // Its file gone, a restore waits saying so; back, a Look of it opens it. + try tmp.dir.deleteFile(std.testing.io, "red.png"); + try s.write("/ctl", s.at("Restore {s}\n", .{label})); + const said = s.at("{s}/red.png is not here", .{dir}); + try std.testing.expect(has(try s.screen(), said[0..@min(said.len, 40)])); + try std.testing.expect(!has(try s.read("/screen"), "\"src\":[0,0,4,2]")); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "red.png", .data = red }); + try s.write("/look", s.at("{s}/red.png\n", .{dir})); + try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]")); } test "addons: a Plumb rule to a loaded kind opens that kind's pane, is refused naming one not loaded, and with its kind gone the look falls through to text" { |
