summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 10:45:36 -0300
committerGabriel Schneider <[email protected]>2026-11-04 10:48:22 -0300
commitff0b8a382de7a1994a6912dc71ba28a8ecdaf474 (patch)
treefd93e430e7e95a0e91e587290fd076cbce1fcdb3 /test/panes.zig
parentfb9b3a3304e0bdbeffc68e56dfe2ad6511a6a64e (diff)
downloadpardes-ff0b8a382de7a1994a6912dc71ba28a8ecdaf474.tar.gz
pardes-ff0b8a382de7a1994a6912dc71ba28a8ecdaf474.zip
test: syntax colours and Save's prompt through the 9P tree alone, Session.styles added (each cell's style as /screen draws it, as JSON text): in test/behaviour/settings.zig Colors off drawing a source plain and on again colouring its fn and if, the layout as it was, an edit made while off included, and SyntaxBold keywords coloured and bold in every row a detached session's size grows a pane into; in panes.zig a rename colouring a source in its new name's language, its text unchanged; in keys.zig Save's prompt on a scratch made by New from a file's pane starting from its directory, one slash after it (/dír space/, and / alone); each checked to fail against a break (the Colors toggle not marking syntax dirty, the painted stretch four rows from the scroll, a rename not marking syntax dirty, the prompt's slash always added, the prompt from the session's directory); test/panes.zig's Colors and growing tests and pane.zig's cached-syntax rename test deleted, and the Save prompt test trimmed to an owned directory ending in a slash or empty (a shell's, T2)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig101
1 files changed, 4 insertions, 97 deletions
diff --git a/test/panes.zig b/test/panes.zig
index db816d41..c996ca00 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -1397,11 +1397,13 @@ test "a prompt that cannot be opened leaves the open one as it was" {
}
}
-test "Save's prompt starts from the pane's directory" {
+// A file's directory is test/behaviour/keys.zig's; an owned directory (a
+// shell's) ending in a slash, or none, only a real shell gives.
+test "Save's prompt starts from an owned directory ending in a slash, or none" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
const pane = try p.setTestFile("one\n");
- for ([_][]const u8{ "/dír space", "/dír space/", "" }) |dir| {
+ for ([_][]const u8{ "/dír space/", "" }) |dir| {
try pane.setOwnedCwd(dir);
const slash = if (dir.len == 0 or dir[dir.len - 1] != '/') "/" else "";
p.startPrompt(pane, &pane.body, .save);
@@ -3772,101 +3774,6 @@ test "cancelled normal gestures leave no count or subprefix through raw tty mode
}
}
-test "Colors restores syntax after rendering disabled files and disabled edits" {
- if (!syntax.enabled) return error.SkipZigTest;
- const gpa = std.testing.allocator;
- for ([_]bool{ false, true }) |edit_while_disabled| {
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("pub fn first() void { if (true) {} }\n");
- const file = &pane.file.?;
- gpa.free(file.path);
- file.path = try gpa.dupe(u8, "/colors.zig");
- p.settings.colors = edit_while_disabled;
- p.presentation.enabled = false;
- var frame = std.heap.ArenaAllocator.init(gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- if (edit_while_disabled) {
- try std.testing.expect(file.highlights.len > 0);
- p.update(.{ .command = "Colors" });
- panes.File.setContent(p, file, try gpa.dupe(u8, "pub fn edited() void { if (false) {} }\n"));
- _ = frame.reset(.retain_capacity);
- _ = try p.render(frame.allocator());
- }
- try std.testing.expect(!p.settings.colors);
- try std.testing.expectEqual(@as(usize, 0), file.highlights.len);
- try std.testing.expect(!file.syntax_dirty);
- const rect = p.rects[0];
- const cols = pane.cols;
- const rows = pane.rows;
- p.update(.{ .command = "Colors" });
- try std.testing.expectEqual(rect, p.rects[0]);
- try std.testing.expectEqual(cols, pane.cols);
- try std.testing.expectEqual(rows, pane.rows);
- _ = frame.reset(.retain_capacity);
- const surface = try p.render(frame.allocator());
- try std.testing.expect(p.settings.colors);
- try std.testing.expect(file.highlights.len > 0);
- try std.testing.expect(!file.syntax_dirty);
- var seen: usize = 0;
- for (surface.cells[0 .. surface.cells.len - 1], 0..) |*first, i| {
- const second = &surface.cells[i + 1];
- if (!(std.mem.eql(u8, first.grapheme(), "f") and std.mem.eql(u8, second.grapheme(), "n")) and
- !(std.mem.eql(u8, first.grapheme(), "i") and std.mem.eql(u8, second.grapheme(), "f"))) continue;
- seen += 1;
- for ([_]*pardes.Cell{ first, second }) |cell| {
- try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, cell.style.fg);
- try std.testing.expect(!cell.style.bold);
- }
- }
- try std.testing.expectEqual(@as(usize, 2), seen);
- }
-}
-
-test "growing a file pane colors every newly visible Zig keyword" {
- if (!syntax.enabled) return error.SkipZigTest;
- const gpa = std.testing.allocator;
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 8 });
- defer p.deinit();
- const pane = try p.setTestFile(std.mem.asBytes(&@as([100][33]u8, @splat("pub fn f() void { if (true) {} }\n".*))));
- const file = &pane.file.?;
- gpa.free(file.path);
- file.path = try gpa.dupe(u8, "/resize.zig");
- p.update(.{ .command = "SyntaxBold" });
- try std.testing.expect(p.settings.syntax_bold);
- p.settings.colors = true;
- p.presentation.enabled = false;
- var frame = std.heap.ArenaAllocator.init(gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const initial_end = file.highlight_start + file.highlights.len;
- for ([_]u16{ 50, 12, 70 }) |rows| {
- p.update(.{ .resize = .{ .cols = 80, .rows = rows } });
- _ = frame.reset(.retain_capacity);
- const surface = try p.render(frame.allocator());
- const rect = p.rects[0];
- const body_y = bodyY(p, rect);
- var seen: usize = 0;
- for (body_y..body_y + bodyH(p, rect)) |y| {
- for (rect.x + config.GUTTER..rect.x + rect.w - 1) |x| {
- const first = surface.at(@intCast(x), @intCast(y));
- const second = surface.at(@intCast(x + 1), @intCast(y));
- if (!(std.mem.eql(u8, first.grapheme(), "f") and std.mem.eql(u8, second.grapheme(), "n")) and
- !(std.mem.eql(u8, first.grapheme(), "i") and std.mem.eql(u8, second.grapheme(), "f"))) continue;
- seen += 1;
- for ([_]*pardes.Cell{ first, second }) |cell| {
- try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, cell.style.fg);
- try std.testing.expect(cell.style.bold);
- }
- }
- }
- try std.testing.expect(seen >= 2 * (rows - 4));
- try std.testing.expect(file.highlight_start + file.highlights.len > initial_end);
- try std.testing.expect(!file.syntax_dirty);
- }
-}
-
test "Zig keywords keep every rendered byte colored across line-number widths" {
if (!syntax.enabled) return error.SkipZigTest;
const gpa = std.testing.allocator;