summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-08 12:03:46 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:15 -0300
commit1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2 (patch)
tree973976c63f560201638d453b4b8b277d9cb40040 /test/panes.zig
parent13d5613b77c62c425c3a124a34c0c2528cc6251f (diff)
downloadpardes-1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2.tar.gz
pardes-1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2.zip
Add a readable static Callstack pane and align tagline text
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig151
1 files changed, 146 insertions, 5 deletions
diff --git a/test/panes.zig b/test/panes.zig
index 41061bea..86e52838 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -121,10 +121,12 @@ const TagLayerTests = struct {
try std.testing.expectEqual(second, p.drag.move.id);
p.update(.{ .mouse = mouse(layer, grip_edge - 0.1, .release) });
try std.testing.expectEqualStrings(" ", p.surface.at(layer.viewport.x - 1, layer.viewport.y).grapheme());
- p.update(.{ .mouse = mouse(layer, edge - 0.1, .press) });
- try std.testing.expect(p.drag != .move);
- try std.testing.expect(p.panes[second].?.focus == .body);
- p.update(.{ .mouse = mouse(layer, edge - 0.1, .release) });
+ if (pardes.TAG_GAP > 0) {
+ p.update(.{ .mouse = mouse(layer, edge - 0.1, .press) });
+ try std.testing.expect(p.drag != .move);
+ try std.testing.expect(p.panes[second].?.focus == .body);
+ p.update(.{ .mouse = mouse(layer, edge - 0.1, .release) });
+ }
p.update(.{ .mouse = mouse(layer, edge + 0.1, .press) });
p.update(.{ .mouse = mouse(layer, edge + 0.1, .release) });
try std.testing.expectEqual(second, p.active);
@@ -164,7 +166,6 @@ const TagLayerTests = struct {
}
};
-
// Rows relative to where the pane's body and tag are, whatever height its
// tag has (a tag wraps onto more rows when it is long).
fn paneAt(p: *Pardes, r: anytype) *pardes.Pane {
@@ -2735,6 +2736,146 @@ const OutputTests = struct {
}
}
+ test "stacked Callstack aligns source below locations and keeps exact emphasis and navigation" {
+ if (!syntax.enabled) return error.SkipZigTest;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 30 });
+ defer p.deinit();
+ const source = " pub fn caller(\n value: u32,\n ) void {\n work(value);\n }\n";
+ const pane = try TreeContextTests.setZigFile(p, source);
+ try std.testing.expectEqual(config.Runtime.CallstackLayout.stacked, p.settings.callstack_layout);
+ const input = try std.fmt.allocPrint(p.gpa, "╰──╮ {s}:1:12-17 caller\n@callstack-match ╰─ {s}:4:9-12 work(value);\n", .{ pane.file.?.path, pane.file.?.path });
+ try fillResults(p, 0, "/", .{ .query = .callstack }, "", input, null);
+ const result_id = pane.search_pane.?;
+ const result = p.panes[result_id].?;
+ const file = &result.file.?;
+ try std.testing.expectEqual(@as(usize, 6), file.location_rows.len);
+ try std.testing.expectEqualStrings(" │ pub fn caller(", modal.lineSlice(file.content, 1));
+ try std.testing.expectEqualStrings(" │ value: u32,", modal.lineSlice(file.content, 2));
+ try std.testing.expectEqualStrings(" │ ) void {", modal.lineSlice(file.content, 3));
+ try std.testing.expectEqualStrings(" work(value);", modal.lineSlice(file.content, 5));
+ const site = file.location_rows[5];
+ try std.testing.expectEqual(@as(usize, 8), site.source_column);
+ try std.testing.expect(site.colors.len > 0);
+ const text = modal.lineSlice(file.content, 5);
+ const decoration = panes.Output.decorateRow(file.output, text, site);
+ try std.testing.expectEqualStrings("work", text[decoration.mark_start..decoration.mark_end]);
+ for (file.location_rows, 0..) |row, i| {
+ try std.testing.expectEqual(i == 0 or i == 4, panes.Output.isResultRow(file, i));
+ if (i != 5) try std.testing.expect(!row.mark_occurrence);
+ }
+ p.active = result_id;
+ result.body.cur_row = 4;
+ result.body.cur_col = " └─ ".len;
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row);
+ try pardes.dump.dumpState(p);
+ const restored = try pardes.dump.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?);
+ defer restored.deinit();
+ try std.testing.expectEqual(config.Runtime.CallstackLayout.stacked, restored.settings.callstack_layout);
+ const after = restored.panes[result_id].?.file.?;
+ try std.testing.expectEqualStrings(file.content, after.content);
+ try std.testing.expectEqual(@as(usize, 8), after.location_rows[5].source_column);
+ const restored_decoration = panes.Output.decorateRow(after.output, text, after.location_rows[5]);
+ try std.testing.expectEqual(decoration, restored_decoration);
+ try std.testing.expect(p.executeBuiltinLine(0, "CallstackLayout inline"));
+ try fillResults(p, 0, "/", .{ .query = .callstack }, "", try p.gpa.dupe(u8, "No callers reported\n"), null);
+ try std.testing.expectEqual(config.Runtime.CallstackLayout.@"inline", p.settings.callstack_layout);
+ }
+
+ test "Callstack signatures share unsaved tree context and keep guides out of Look selections" {
+ if (!syntax.enabled) return error.SkipZigTest;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 110, .rows = 30 });
+ defer p.deinit();
+ p.settings.callstack_layout = .@"inline";
+ const source = "const Box = struct {\n" ++
+ " pub fn caller(\n" ++
+ " value: u32,\n" ++
+ " ) void {\n" ++
+ " work(value);\n" ++
+ " }\n};\n";
+ const pane = try TreeContextTests.setZigFile(p, source);
+ const path = pane.file.?.path;
+ const input = try std.fmt.allocPrint(p.gpa, "├──┬ {s}:2:12-17 caller\n@callstack-match │ └─ {s}:5:9-12 work(value);\n└─── missing.zig:3:4-8 other ↻ recursion\n", .{ path, path });
+ try fillResults(p, 0, "/", .{ .query = .callstack }, "", input, null);
+ const result_id = pane.search_pane.?;
+ const result = p.panes[result_id].?;
+ const file = &result.file.?;
+ try std.testing.expect(std.mem.indexOf(u8, file.content, "pub fn caller(") != null);
+ try std.testing.expect(std.mem.indexOf(u8, file.content, "value: u32,") != null);
+ try std.testing.expect(std.mem.indexOf(u8, file.content, "const Box") == null);
+ try std.testing.expect(std.mem.indexOf(u8, file.content, "other ↻ recursion") != null);
+ try std.testing.expectEqual(@as(usize, 5), file.location_rows.len);
+ for (file.location_rows[0..3]) |row| {
+ try std.testing.expect(!row.declaration);
+ try std.testing.expect(!row.mark_occurrence);
+ try std.testing.expect(row.colors.len > 0);
+ }
+ for (1..3) |index| try std.testing.expect(std.mem.startsWith(u8, modal.lineSlice(file.content, index), "│ │ "));
+ const analysis = try syntax.analyzeSource(p.scratch.allocator(), path, source, true, true);
+ for (file.location_rows[0..3], 1..) |row, source_row| {
+ const offset = modal.lineStartOffset(source, source_row);
+ try std.testing.expectEqualSlices(u8, analysis.colors[offset..][0..row.colors.len], row.colors);
+ }
+ try std.testing.expect(file.location_rows[3].mark_occurrence);
+ try std.testing.expect(!file.location_rows[3].declaration);
+ try std.testing.expect(!panes.Output.isWalkRow(file, 1, modal.lineSlice(file.content, 1)));
+ p.active = result_id;
+ result.body.cur_row = 0;
+ result.body.cur_col = 0;
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = 'j' } });
+ p.update(.{ .key = .{ .cp = 'n' } });
+ try std.testing.expectEqual(@as(i32, 0), result.body.cur_row);
+ try std.testing.expectEqual(@as(i32, "├──┬ ".len), result.body.cur_col);
+ // Enter on the selected signature address must open source, not a path
+ // accidentally prefixed with tree glyphs.
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
+ p.settings.callstack_depth = 16;
+ try pardes.dump.dumpState(p);
+ const restored = try pardes.dump.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?);
+ defer restored.deinit();
+ try std.testing.expectEqual(@as(u8, 16), restored.settings.callstack_depth);
+ const restored_file = restored.panes[result_id].?.file.?;
+ try std.testing.expectEqualStrings(file.content, restored_file.content);
+ try std.testing.expectEqual(file.location_rows.len, restored_file.location_rows.len);
+ for (file.location_rows, restored_file.location_rows) |before, after| {
+ try std.testing.expectEqual(before.mark_occurrence, after.mark_occurrence);
+ try std.testing.expectEqual(before.at, after.at);
+ try std.testing.expectEqual(before.code_start, after.code_start);
+ try std.testing.expectEqualSlices(u8, before.colors, after.colors);
+ }
+ // Narrow enough that the location itself wraps. The repeated guide
+ // consumes cells, but neither changes the source address nor steals
+ // a click from the wrapped portion of that address.
+ p.active = result_id;
+ p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
+ p.update(.{ .resize = .{ .cols = 28, .rows = 40 } });
+ result.file.?.scroll = 0;
+ var frame = std.heap.ArenaAllocator.init(p.gpa);
+ defer frame.deinit();
+ _ = try p.render(frame.allocator());
+ const wrapped = for (0..result.wrap_n) |vr| {
+ const w = result.wrapAt(@intCast(vr));
+ 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_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];
+ const press: pardes.Mouse = .{ .button = .right, .kind = .press, .col = @intCast(rect.x + config.GUTTER + panes.File.gutterWidth(result) + w.pad + 1), .row = @intCast(p.bodyTop(result, rect) + wrapped) };
+
+ var release = press;
+ release.kind = .release;
+ p.update(.{ .mouse = press });
+ p.update(.{ .mouse = release });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
+ }
+
test "Locations context uses unsaved sources and navigation visits only matches" {
if (!syntax.enabled) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });