diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 15:11:14 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-09-15 17:24:42 -0300 |
| commit | 7d75f5d7f1394a09c6a2cc42c2a9a60e6aef7b12 (patch) | |
| tree | b3102012a030560431a9360840e80a5e7316cb1e /test | |
| parent | 40c19fd4f52d20df94c2dfa2d68102b89bd9d3f1 (diff) | |
| download | pardes-7d75f5d7f1394a09c6a2cc42c2a9a60e6aef7b12.tar.gz pardes-7d75f5d7f1394a09c6a2cc42c2a9a60e6aef7b12.zip | |
Mute result declaration context and show nesting after locations
Diffstat (limited to 'test')
| -rw-r--r-- | test/panes.zig | 86 |
1 files changed, 84 insertions, 2 deletions
diff --git a/test/panes.zig b/test/panes.zig index 16e40ee3..4ed8c1e1 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -2000,10 +2000,11 @@ const OutputTests = struct { matches[count] = i; count += 1; } else { - try std.testing.expect(std.mem.startsWith(u8, line, "| ")); + try std.testing.expect(std.mem.startsWith(u8, line, " ")); try std.testing.expect(!panes.Output.isResultRow(file, i)); try std.testing.expectEqualStrings(modal.lineSlice(source, expected_line - 1), line[row.code_start..]); } + try std.testing.expectEqual(expected_line <= 2, row.declaration); if (expected_line <= 2) try std.testing.expectEqual(@as(usize, 0), row.location_end); } try std.testing.expectEqual(@as(usize, 2), count); @@ -2028,7 +2029,13 @@ const OutputTests = struct { const styles = file.highlights[keyword..][0.."struct".len]; var colored = false; for (styles) |style| colored = colored or style != 0; - try std.testing.expect(colored); + try std.testing.expect(!colored); + const neighbor_row = file.location_rows[2]; + const neighbor_offset = @intFromPtr(modal.lineSlice(file.content, 2).ptr) - @intFromPtr(file.content.ptr); + var neighbor_colored = false; + for (file.highlights[neighbor_offset + neighbor_row.code_start .. neighbor_offset + modal.lineSlice(file.content, 2).len]) |style| + neighbor_colored = neighbor_colored or style != 0; + try std.testing.expect(neighbor_colored); try p.dumpState(); const restored = try Pardes.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?); @@ -2041,6 +2048,7 @@ const OutputTests = struct { 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.kind, after.kind); + try std.testing.expectEqual(before.declaration, after.declaration); try std.testing.expectEqualStrings(before.path, after.path); try std.testing.expectEqual(before.at, after.at); try std.testing.expectEqual(before.location_end, after.location_end); @@ -2071,6 +2079,80 @@ const OutputTests = struct { try std.testing.expectEqual(matches[1], pane.search_row.?); } + test "Locations visible declarations are muted and stars count scopes rather than signature lines" { + if (!syntax.enabled) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + const source = "const Outer = struct {\n" ++ + " const Inner = struct {\n" ++ + " pub fn run(\n" ++ + " value: usize,\n" ++ + " ) void {\n" ++ + " // nearby\n" ++ + "\t\tcall();\n" ++ + " }\n };\n};\n"; + const pane = try TreeContextTests.setZigFile(p, source); + p.locations_config = .{ .context = 1, .tscontext = true, .tslocations = true }; + const path = pane.file.?.path; + try fillResults(p, 0, "/", .search, "nesting", try std.fmt.allocPrint(p.gpa, "{s}:7:1 \t\tcall();\n{s}:2:5 const Inner = struct {{\n", .{ path, path }), 0); + const result = p.panes[pane.search_pane.?].?; + const file = &result.file.?; + var matches: usize = 0; + var alignment: ?usize = null; + for (file.location_rows, 0..) |row, index| { + const line = modal.lineSlice(file.content, index); + const width = panes.File.displayWidth(line[0..row.code_start]); + if (alignment) |previous| try std.testing.expectEqual(previous, width); + alignment = width; + try std.testing.expect(!std.mem.startsWith(u8, line, "| ")); + if (row.kind == .match) { + matches += 1; + try std.testing.expect(!row.declaration); + const location = panes.Output.location(line); + try std.testing.expectEqualStrings(path, location.path); + try std.testing.expectEqual(row.at, location.at); + try std.testing.expectEqual(row.location_end, location.end); + if (row.at.line == 7) { + try std.testing.expect(std.mem.startsWith(u8, line[row.location_end..], " ***")); + try std.testing.expectEqualStrings("\t\tcall();", line[row.code_start..]); + } + } else if (row.at.line <= 5) { + try std.testing.expect(row.declaration); + try std.testing.expect(row.location_end > 2); + try std.testing.expect(std.mem.startsWith(u8, line, " ")); + } + } + try std.testing.expectEqual(@as(usize, 2), matches); + var frame = std.heap.ArenaAllocator.init(p.gpa); + defer frame.deinit(); + result.scrollBy(-1000); + layout.compute(p); + const surface = try p.render(frame.allocator()); + const rect = p.rects[pane.search_pane.?]; + const body_y = if (p.settings.tag_bottom) rect.y else rect.y + pardes.BOX_H; + for (file.location_rows, 0..) |row, index| { + if (!row.declaration) continue; + const line = modal.lineSlice(file.content, index); + const start = @intFromPtr(line.ptr) - @intFromPtr(file.content.ptr); + for (file.highlights[start + row.code_start .. start + line.len]) |style| + try std.testing.expectEqual(@as(u8, 0), style); + const local = std.mem.indexOfNone(u8, line[row.code_start..], " \t") orelse continue; + const x = rect.x + config.GUTTER + panes.File.gutterWidth(result) + @as(u16, @intCast(panes.File.displayWidth(line[0 .. row.code_start + local]))); + const y = body_y + @as(u16, @intCast(index)); + const cell = surface.at(x, y); + try std.testing.expect(!cell.style.bold); + try std.testing.expectEqual(pardes.Color{ .rgb = pardes.ChromeTheme.fromTheme(p.theme()).lineno }, cell.style.fg); + } + // Old dumps and edited outputs still identify both context prefixes. + panes.File.setContent(p, file, try p.gpa.dupe(u8, "| old.zig:1 old\n new.zig:2 new\nmain.zig:42 ***\t\tmatch\n")); + try std.testing.expect(!panes.Output.isResultRow(file, 0)); + try std.testing.expect(!panes.Output.isResultRow(file, 1)); + try std.testing.expect(panes.Output.isResultRow(file, 2)); + const parsed = panes.Output.location(modal.lineSlice(file.content, 2)); + try std.testing.expectEqualStrings("main.zig", parsed.path); + try std.testing.expectEqual(@as(usize, 42), parsed.at.line); + } + test "replacing generated Help clears stale selection before executing a new row" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); defer p.deinit(); |
