summaryrefslogtreecommitdiff
path: root/test/output.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/output.zig')
-rw-r--r--test/output.zig26
1 files changed, 22 insertions, 4 deletions
diff --git a/test/output.zig b/test/output.zig
index fd4252e1..42b1ce7c 100644
--- a/test/output.zig
+++ b/test/output.zig
@@ -11,6 +11,24 @@ const platform = pardes.platform;
const font_picker = pardes.font_picker;
const fonts = if (font_picker) pardes.fonts else struct {};
+// Sorting tests compare original locations and source bytes independently of
+// alignment. Dedicated Locations tests verify the rendered column widths.
+fn expectResultRows(expected: []const u8, file: *const panes.File.State) !void {
+ if (file.location_rows.len == 0) return std.testing.expectEqualStrings(expected, file.content);
+ try std.testing.expectEqual(std.mem.endsWith(u8, expected, "\n"), std.mem.endsWith(u8, file.content, "\n"));
+ var source = std.mem.splitScalar(u8, expected, '\n');
+ var shown = std.mem.splitScalar(u8, file.content, '\n');
+ for (file.location_rows) |row| {
+ const want = source.next() orelse return error.MissingExpectedResult;
+ const actual = shown.next() orelse return error.MissingRenderedResult;
+ const target = panes.Output.location(want);
+ try std.testing.expectEqualStrings(want[0..target.end], actual[0..row.location_end]);
+ try std.testing.expectEqualStrings(want[@min(want.len, target.end + 1)..], actual[row.code_start..]);
+ }
+ try std.testing.expectEqualStrings("", source.next() orelse "");
+ try std.testing.expect(source.next() == null);
+}
+
test "search tint survives wrapping and theme changes while selections remain authoritative" {
const text = "nested/path/a.txt:1:5-7 let abc = 1;\n";
for ([_]u16{ 30, 80 }) |width| {
@@ -63,7 +81,7 @@ test "location results sort filenames and numeric positions while remapping thei
const source = try p.setTestFile("notes\n");
try panes.Output.fillResults(p, 0, "/tmp", origin, "", try p.gpa.dupe(u8, before), 2);
const results = p.panes[source.search_pane.?].?;
- try std.testing.expectEqualStrings(after, results.file.?.content);
+ try expectResultRows(after, &results.file.?);
try std.testing.expectEqual(@as(usize, 3), source.search_row.?);
}
}
@@ -106,7 +124,7 @@ test "reference Look selects the next sorted row from the captured request and k
p.lspResponse(request, response);
const rid = source.search_pane orelse return error.MissingResults;
const results = p.panes[rid].?;
- try std.testing.expectEqualStrings(sorted, results.file.?.content);
+ try expectResultRows(sorted, &results.file.?);
try std.testing.expectEqual(@as(usize, 0), p.active);
try std.testing.expectEqual(@as(i32, 3), source.cur_row);
try std.testing.expect(source.vsel.active);
@@ -159,7 +177,7 @@ test "location sorting leaves mixed prose alone and preserves newline shape" {
defer p.deinit();
const source = try p.setTestFile("notes\n");
try panes.Output.fillResults(p, 0, "/tmp", .search, "", try p.gpa.dupe(u8, case.before), 1);
- try std.testing.expectEqualStrings(case.after, p.panes[source.search_pane.?].?.file.?.content);
+ try expectResultRows(case.after, &p.panes[source.search_pane.?].?.file.?);
try std.testing.expectEqual(case.anchor, source.search_row.?);
}
}
@@ -218,7 +236,7 @@ test "reordered identical results preserve the selected row and warm line index"
result.select = true;
const selected = result.vsel;
try panes.Output.fillResults(p, 0, "/tmp", .{ .query = .references }, "new request", try p.gpa.dupe(u8, "a.zig:10:1 second\na.zig:2:1 first\n"), 0);
- try std.testing.expectEqualStrings(sorted, file.content);
+ try expectResultRows(sorted, file);
try std.testing.expectEqual(content, file.content.ptr);
try std.testing.expectEqual(index.ptr, file.line_starts.ptr);
try std.testing.expectEqual(revision, file.revision);