From b292808d75078c6b121e4873b150574308bcdc6f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 15 Sep 2026 16:05:34 -0300 Subject: Use result metadata when walking output locations with n and N --- test/output.zig | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'test') diff --git a/test/output.zig b/test/output.zig index e835a474..86ea287a 100644 --- a/test/output.zig +++ b/test/output.zig @@ -620,6 +620,73 @@ fn selectedOutputText(pane: *const pardes.Pane) ?[]const u8 { return line[lo..@min(line.len, hi + 1)]; } +test "n/N skips formatted context and selects comment match locations" { + if (!pardes.syntax.enabled) return error.SkipZigTest; + for ([_]panes.Output.Origin{ .search, .{ .query = .references } }) |origin| { + for ([_]bool{ false, true }) |tslocations| { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); + defer p.deinit(); + const text = "const Box = struct {\n" ++ + " pub fn run() void {\n" ++ + " // /tmp neighboring path\n" ++ + " // actual match /tmp\n" ++ + " // / another neighbor\n" ++ + " call();\n" ++ + " // /tmp trailing context\n" ++ + " }\n};\n"; + const source = try p.setTestFile(text); + p.gpa.free(source.file.?.path); + source.file.?.path = try p.gpa.dupe(u8, "/look-walk-context.zig"); + p.presentation.enabled = false; + p.locations_config = .{ .context = 1, .tscontext = true, .tslocations = tslocations }; + const path = source.file.?.path; + const input = try std.fmt.allocPrint(p.gpa, "{s}:4:9 {s}\n{s}:6:9 {s}\n", .{ + path, modal.lineSlice(text, 3), path, modal.lineSlice(text, 5), + }); + try panes.Output.fillResults(p, 0, "/", origin, "walk", input, null); + const id = source.search_pane.?; + const result = p.panes[id].?; + const file = &result.file.?; + var matches: [2]usize = undefined; + var count: usize = 0; + for (file.location_rows, 0..) |row, index| { + if (row.kind != .match) continue; + matches[count] = index; + count += 1; + } + try std.testing.expectEqual(@as(usize, 2), count); + const available = p.freeSlot(); + for ([_]struct { key: u21, match: usize }{ + .{ .key = 'n', .match = 0 }, + .{ .key = 'n', .match = 1 }, + .{ .key = 'n', .match = 0 }, + .{ .key = 'N', .match = 1 }, + .{ .key = 'N', .match = 0 }, + }) |step| { + p.update(.{ .key = .{ .cp = step.key } }); + try std.testing.expectEqual(id, p.active); + const row = matches[step.match]; + try std.testing.expectEqual(@as(i32, @intCast(row)), result.cur_row); + const line = modal.lineSlice(file.content, row); + try std.testing.expectEqualStrings(line[0..file.location_rows[row].location_end], selectedOutputText(result) orelse ""); + try std.testing.expectEqual(available, p.freeSlot()); + } + try p.dumpState(); + const restored = try Pardes.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?); + defer restored.deinit(); + restored.armLookWalk(id); + const restored_result = restored.panes[id].?; + restored.update(.{ .key = .{ .cp = 'n' } }); + try std.testing.expectEqual(@as(i32, @intCast(matches[0])), restored_result.cur_row); + restored.update(.{ .key = .{ .cp = 'N' } }); + try std.testing.expectEqual(@as(i32, @intCast(matches[1])), restored_result.cur_row); + const restored_file = &restored_result.file.?; + const last = modal.lineSlice(restored_file.content, matches[1]); + try std.testing.expectEqualStrings(last[0..restored_file.location_rows[matches[1]].location_end], selectedOutputText(restored_result) orelse ""); + } + } +} + test "n/N selects one output location per row and opens nothing" { if (platform == .web) return; var cwd_buf: [4096]u8 = undefined; -- cgit v1.3