summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig177
1 files changed, 9 insertions, 168 deletions
diff --git a/test/panes.zig b/test/panes.zig
index 3b842c59..6b2af760 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -790,75 +790,8 @@ const JumpSelectionTests = struct {
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col1, .row = row1 } });
}
- fn exercise(prefix: []const u8, wrap: bool, reverse: bool, first_col: u16, last_col: u16, expected: ?[]const u8) !void {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 34, .rows = 10 });
- defer p.deinit();
- p.settings.wrap = wrap;
- const text = try std.fmt.allocPrint(p.gpa, "{s}{s}", .{ prefix, std.mem.asBytes(&@as([80][27]u8, @splat("unrelated destination text\n".*))) });
- defer p.gpa.free(text);
- const pane = try p.setTestFile(text);
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- if (wrap) try std.testing.expectEqual(pane.wrap_line[0], pane.wrap_line[1]);
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = p.bodyTop(pane, rect);
- if (reverse)
- drag(p, x + last_col, y + 1, x + first_col, y)
- else
- drag(p, x + first_col, y, x + last_col, y + 1);
-
- const selected = try p.gpa.dupe(u8, pardes.exec.heldSelection(p, 0) orelse return error.MissingMouseSelection);
- defer p.gpa.free(selected);
- if (expected) |want| try std.testing.expectEqualStrings(want, selected);
- try std.testing.expect(std.mem.indexOfScalar(u8, selected, '\n') != null);
- if (wrap) try std.testing.expect(std.mem.indexOf(u8, selected, "界") != null);
-
- // Seed two actual locations after the drag, so both history directions
- // must scroll and discard the previous selection.
- p.njumps = 2;
- p.jcur = 1;
- p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 60, .col = 1 };
- p.jumps[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 };
- p.update(.{ .key = .{ .cp = 'o', .ctrl = true } });
- _ = frame.reset(.retain_capacity);
- _ = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 0), p.jcur);
- try std.testing.expect(pane.file.?.scroll > 20);
- try LookResetTests.cleared(pane);
- try std.testing.expect(!pane.body.vsel.active);
- try std.testing.expect(pardes.exec.heldSelection(p, 0) == null);
- try std.testing.expectEqual(@as(i32, 59), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col);
-
- // A selection created after Back must also disappear on Forward.
- // Back announces itself, so the body sits under a notice band now.
- const y2 = p.bodyTop(pane, p.rects[0]);
- drag(p, x + 1, y2, x + 3, y2 + 1);
- try std.testing.expect(pardes.exec.heldSelection(p, 0) != null);
- p.update(.{ .key = .{ .cp = 'i', .ctrl = true } });
- _ = frame.reset(.retain_capacity);
- _ = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 1), p.jcur);
- try std.testing.expectEqual(@as(usize, 0), pane.file.?.scroll);
- try LookResetTests.cleared(pane);
- try std.testing.expect(!pane.body.vsel.active);
- try std.testing.expect(pardes.exec.heldSelection(p, 0) == null);
- try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col);
- }
-
- test "jump selection clears copied sweeps in both history directions" {
- for ([_]bool{ false, true }) |reverse|
- try exercise("alpha\nbravo\n", false, reverse, 1, 3, "lpha\nbrav");
- }
-
- test "jump selection clears wrapped Unicode and tab rectangles" {
- for ([_]bool{ false, true }) |reverse|
- try exercise("界\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n", true, reverse, 0, 8, null);
- }
-
+ // One pane's Back and Forward are test/behaviour/keys.zig's; this
+ // one seeds held selections in two panes, which only internals reach.
test "jump selection clears source and destination state across panes" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
defer p.deinit();
@@ -949,7 +882,9 @@ const TagNameTintTests = struct {
return visible_name;
}
- test "tag filename tint excludes directories dirty marker and output commands" {
+ // A file pane's is test/behaviour/tags.zig's; a search pane's needs
+ // results put in through fillResults.
+ test "tag filename tint of a search pane excludes its directory and command" {
for ([_]bool{ false, true }) |bottom| {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 24 });
defer p.deinit();
@@ -961,7 +896,6 @@ const TagNameTintTests = struct {
configure(p);
defer p.custom_theme = null;
p.settings.tag_bottom = bottom;
- try std.testing.expect((try check(p, 0, pane.file.?.path)) > 0);
try panes.Output.fillResults(p, 0, "/project", .search, "tint", try p.gpa.dupe(u8, "no matches\n"), null);
const id = pane.search_pane.?;
p.update(.tick);
@@ -1399,11 +1333,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);
@@ -3774,101 +3710,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;