summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
committerGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
commita479792a1ab2b593642d7f648194bfa23ce01dba (patch)
tree96ddee7d879a9084daa07db43b0b7910b072a785 /test/panes.zig
parente179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff)
parent4c761893e5b3fdae422622cfa02104ab36633045 (diff)
downloadpardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz
pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig75
1 files changed, 14 insertions, 61 deletions
diff --git a/test/panes.zig b/test/panes.zig
index e2cd85dc..fc3f7804 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -587,6 +587,7 @@ const BodyHitTests = struct {
pane.scrollBy(10);
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
+ p.sync();
_ = try p.render(frame.allocator());
const layer = &p.surface.body_layers[0];
try std.testing.expect(layer.context_rows >= 4);
@@ -635,6 +636,7 @@ const LineNumberLookTests = struct {
pane.scrollBy(30);
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
+ p.sync();
_ = try p.render(frame.allocator());
const layer = &p.surface.body_layers[0];
try std.testing.expect(layer.context_rows >= 2);
@@ -693,6 +695,7 @@ const TreeContextTests = struct {
pane.scrollBy(10);
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
+ p.sync();
_ = try p.render(frame.allocator());
const layer = &p.surface.body_layers[0];
try std.testing.expectEqual(@as(u16, 4), layer.context_rows);
@@ -747,9 +750,11 @@ const TreeContextTests = struct {
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
pane.scrollBy(7);
+ p.sync();
_ = try p.render(frame.allocator());
try std.testing.expectEqual(@as(u16, 0), pane.context_rows);
try std.testing.expect(p.executeBuiltinLine(0, "TreeContext"));
+ p.sync();
_ = try p.render(frame.allocator());
try std.testing.expectEqual(@as(u16, 4), pane.context_rows);
for (0..4) |row| try std.testing.expectEqual(@as(i32, @intCast(row)), pane.wrapAt(@intCast(row)).line);
@@ -803,6 +808,7 @@ const TreeContextTests = struct {
pane.hscroll = 4;
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
+ p.sync();
const surface = try p.render(frame.allocator());
try std.testing.expectEqual(@as(u16, 3), pane.context_rows);
const rect = p.rects[0];
@@ -822,6 +828,7 @@ const TreeContextTests = struct {
// builtin above put up, so the body moved with it.
try std.testing.expectEqual(p.bodyTop(pane, p.rects[0]), cursor.y);
panes.File.setContent(p, &pane.file.?, try p.gpa.dupe(u8, std.mem.asBytes(&@as([18][28]u8, @splat("// no enclosing declaration\n".*)))));
+ p.sync();
_ = try p.render(frame.allocator());
try std.testing.expectEqual(@as(u16, 0), pane.context_rows);
try std.testing.expectEqual(pane.scroll(), pane.wrapAt(0).line);
@@ -840,6 +847,7 @@ const TreeContextTests = struct {
pane.scrollBy(2);
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
+ p.sync();
const surface = try p.render(frame.allocator());
try std.testing.expectEqual(@as(u16, 1), pane.context_rows);
try std.testing.expectEqual(@as(i32, 2), pane.wrapAt(1).line);
@@ -2289,7 +2297,7 @@ test "a prompt opens with one allocation" {
}
test "file history construction failures preserve existing panes" {
- const Case = enum { open, restore, output, tutor, replace };
+ const Case = enum { open, output, tutor, replace };
for (std.enums.values(Case)) |case| {
var succeeded = false;
for (0..32) |failure| {
@@ -2306,12 +2314,6 @@ test "file history construction failures preserve existing panes" {
failing.fail_index = failing.alloc_index + failure;
const result = switch (case) {
.open => panes.File.open(p, p.freeSlot().?, path, 0),
- .restore => panes.File.restore(p, 1, .{
- .kind = .file,
- .tag = "",
- .body = "",
- .file = .{ .path = "/restored.zig", .content = "restored\n" },
- }),
.output => panes.Output.open(p, p.freeSlot().?, "/", .{ .cmd = .Help }, "", incoming.?),
.tutor => p.openTutorView(1),
.replace => p.setTestFile("replacement\n"),
@@ -2397,39 +2399,6 @@ test "file history allocation precedes reading the served tree" {
}
}
-test "file history survives PDF fallback restoration and allocation failures" {
- const saved =
- \\.{
- \\ .screen = .{ .cols = 40, .rows = 12 },
- \\ .columns = .{.{ .panes = .{0} }},
- \\ .panes = .{.{
- \\ .kind = .image, .tag = "", .body = "",
- \\ .image = .{ .path = "/virtual/missing-history.pdf", .bytes_b64 = "cmF3" },
- \\ }},
- \\}
- ;
- var succeeded = false;
- for (0..256) |failure| {
- var failing = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = failure });
- if (pardes.dump.initFromDump(failing.allocator(), .{ .tty_only = true }, saved)) |p| {
- defer p.deinit();
- const pane = p.panes[0].?;
- try std.testing.expect(pane.file != null);
- try std.testing.expectEqualStrings("raw", pane.file.?.content);
- try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len);
- try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.redo_len);
- if (!failing.has_induced_failure) {
- succeeded = true;
- break;
- }
- } else |err| {
- try std.testing.expect(failing.has_induced_failure);
- try std.testing.expect(err == error.OutOfMemory or err == error.WriteFailed);
- }
- }
- try std.testing.expect(succeeded);
-}
-
test "Save rearms renamed file watches only after a successful write" {
const Host = struct {
const Result = enum { success, failure, edited, replaced, closed };
@@ -2661,6 +2630,9 @@ const FileTests = struct {
try std.testing.expectEqual(text.len, byteAtDisplay(text, 5));
try std.testing.expectEqual(@as(usize, 3), rawDisplayCol(text, 5));
try std.testing.expectEqual(@as(usize, 5), rawAtDisplay(text, 3));
+ // At the line's end and past it (virtual columns, one byte each).
+ try std.testing.expectEqual(text.len, rawAtDisplay(text, 5));
+ try std.testing.expectEqual(text.len + 2, rawAtDisplay(text, 7));
try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth("👩\u{200d}🚀"));
}
@@ -2684,7 +2656,6 @@ const OutputTests = struct {
const max_arg = panes.Output.max_arg;
const State = panes.Output.State;
const setArg = panes.Output.setArg;
- const fromWord = panes.Output.fromWord;
const fillResults = panes.Output.fillResults;
test "Locations align Unicode paths by display width and preserve source indentation" {
@@ -2868,7 +2839,7 @@ const OutputTests = struct {
if (w.line == 0 and w.pad > 0 and w.at < file.location_rows[0].location_end) break vr;
} else return error.MissingWrappedLocation;
const w = result.wrapAt(@intCast(wrapped));
- const shown = try panes.File.bodyText(frame.allocator(), result, file, true);
+ const shown = try panes.File.bodyText(frame.allocator(), result, file);
const shown_line = modal.lineSlice(shown, wrapped);
try std.testing.expect(std.mem.startsWith(u8, shown_line[panes.File.gutterWidth(result)..], "│ │ "));
const rect = p.rects[result_id];
@@ -3207,12 +3178,6 @@ const OutputTests = struct {
try std.testing.expect(!result.body.vsel.active and !result.body.msel.active);
}
- test "dump origins accept only builtins that actually own output panes" {
- try std.testing.expectEqual(Origin{ .cmd = .Help }, fromWord("Help").?);
- try std.testing.expect(fromWord("Kill") == null);
- try std.testing.expect(fromWord("Theme") == null);
- }
-
test "result refill identity retains the full bounded argument" {
const p = try Pardes.init(std.testing.allocator, .{
.tty_only = true,
@@ -3285,7 +3250,6 @@ const OutputTests = struct {
const ImageTests = struct {
const State = panes.Image.State;
- const restore = panes.Image.restore;
const toggleGlyphArt = panes.Image.toggleGlyphArt;
const togglePalette = panes.Image.togglePalette;
const toggleAscii = panes.Image.toggleAscii;
@@ -3304,18 +3268,6 @@ const ImageTests = struct {
);
}
- test "dump restore propagates malformed embedded image bytes" {
- const p = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- try std.testing.expect(p.panes[1] == null);
- try std.testing.expectError(error.InvalidCharacter, restore(p, 1, .{
- .kind = .image,
- .tag = "img /tmp/bad.ppm",
- .body = "",
- .image = .{ .path = "/tmp/bad.ppm", .bytes_b64 = "A..A" },
- }));
- try std.testing.expect(p.panes[1] == null);
- }
};
const PdfTests = struct {
@@ -4894,6 +4846,7 @@ test "Zig keywords keep every rendered byte colored across line-number widths" {
p.settings.colors = true;
p.settings.wrap = view.wrap;
p.presentation.enabled = false;
+ p.sync();
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const surface = try p.render(frame.allocator());