diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 16:44:18 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-09-15 17:24:42 -0300 |
| commit | 96725011b43d7bf56ac02e710ea4ef4a76f05351 (patch) | |
| tree | 3fb1dd233337a6023fe11a8e1ad777d6f44accec /test | |
| parent | 89b3c352378eb0284b521722a13c4245cab41b0c (diff) | |
| download | pardes-96725011b43d7bf56ac02e710ea4ef4a76f05351.tar.gz pardes-96725011b43d7bf56ac02e710ea4ef4a76f05351.zip | |
Make location highlighting an explicit output producer choice
Diffstat (limited to 'test')
| -rw-r--r-- | test/output.zig | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/output.zig b/test/output.zig index 2ccd951a..f1d9d4e0 100644 --- a/test/output.zig +++ b/test/output.zig @@ -72,6 +72,85 @@ test "search tint survives wrapping and theme changes while selections remain au } } +fn outputCell(p: *Pardes, surface: *pardes.Surface, id: usize, byte: usize) *pardes.Cell { + const pane = p.panes[id].?; + const line = modal.lineSlice(pane.file.?.content, 0); + const rect = p.rects[id]; + const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + @as(u16, @intCast(panes.File.displayWidth(line[0..byte]))); + const y = if (p.settings.tag_bottom) rect.y else rect.y + pardes.BOX_H; + return surface.at(x, y); +} + +fn resultId(p: *Pardes) !usize { + for (p.panes, 0..) |slot, id| if (slot) |pane| { + if (pane.file) |file| if (file.output != null) return id; + }; + return error.MissingOutput; +} + +test "output callers opt into location highlighting instead of matching prose colons" { + for ([_]panes.Output.Origin{ .{ .cmd = .LocationsConfig }, .{ .cmd = .Config }, .{ .query = .hover } }) |origin| { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 30 }); + defer p.deinit(); + _ = try p.setTestFile("ordinary\n"); + p.presentation.enabled = false; + if (origin == .cmd and origin.cmd == .LocationsConfig) { + p.locations_config.context = 5; + try std.testing.expect(p.executeBuiltinLine(0, "LocationsConfig")); + } else { + try panes.Output.fillResults(p, 0, "/", origin, "plain report", try p.gpa.dupe(u8, "source.zig:3:5-7 warning: context:5\n"), null); + } + const id = try resultId(p); + const file = &p.panes[id].?.file.?; + try std.testing.expectEqual(@as(usize, 0), file.location_rows.len); + pardes.layout.compute(p); + var frame = std.heap.ArenaAllocator.init(p.gpa); + defer frame.deinit(); + const surface = try p.render(frame.allocator()); + const line = modal.lineSlice(file.content, 0); + const before_colon = std.mem.indexOfScalar(u8, line, ':').?; + const normal: pardes.Color = if (p.theme().fg) |fg| .{ .rgb = fg } else .default; + for (0..before_colon + 2) |byte| { + const cell = outputCell(p, surface, id, byte); + try std.testing.expectEqual(normal, cell.style.fg); + try std.testing.expect(!cell.style.bold); + } + } +} + +test "location producers retain rendered location match and diagnostic styles" { + for ([_]panes.Output.Origin{ .search, .{ .cmd = .Grep }, .{ .query = .references }, .{ .query = .diagnostics } }) |origin| { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 30 }); + defer p.deinit(); + _ = try p.setTestFile("ordinary\n"); + p.presentation.enabled = false; + const diagnostic = origin == .query and origin.query == .diagnostics; + const code = if (diagnostic) "warning: unused value" else "const value = 42;"; + try panes.Output.fillResults(p, 0, "/", origin, "styles", try std.fmt.allocPrint(p.gpa, "source.zig:3:1-3 {s}\n", .{code}), null); + const id = try resultId(p); + const file = &p.panes[id].?.file.?; + try std.testing.expectEqual(@as(usize, 1), file.location_rows.len); + pardes.layout.compute(p); + var frame = std.heap.ArenaAllocator.init(p.gpa); + defer frame.deinit(); + const surface = try p.render(frame.allocator()); + const chrome = pardes.ChromeTheme.fromTheme(p.theme()); + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.lineno }, outputCell(p, surface, id, 0).style.fg); + const start = file.location_rows[0].code_start; + const first = outputCell(p, surface, id, start); + if (diagnostic) { + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.diagnostic_warning }, first.style.fg); + try std.testing.expect(first.style.bold); + } else if (origin == .search or origin == .cmd) { + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.search_bg }, first.style.bg); + } + if (!diagnostic and pardes.syntax.enabled) { + const number = start + std.mem.indexOf(u8, code, "42").?; + try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().num }, outputCell(p, surface, id, number).style.fg); + } + } +} + test "location results sort filenames and numeric positions while remapping their anchor" { const before = "z.zig:1:1 z\nb.zig:10:2-3 ten\nb.zig:2:10-12 two-b\nb.zig:2:2-3 two-a\na.zig:99:1 a\nb.zig:2:2-3 duplicate\n"; const after = "a.zig:99:1 a\nb.zig:2:2-3 two-a\nb.zig:2:2-3 duplicate\nb.zig:2:10-12 two-b\nb.zig:10:2-3 ten\nz.zig:1:1 z\n"; |
