diff options
Diffstat (limited to 'src/hunks.zig')
| -rw-r--r-- | src/hunks.zig | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/hunks.zig b/src/hunks.zig index 00fe265b..8f4b4233 100644 --- a/src/hunks.zig +++ b/src/hunks.zig @@ -804,3 +804,36 @@ test "a hunk edited since, beside siblings with its signature's tail, is found i defer locations.freeRows(p.gpa, result.rows); try testing.expect(std.mem.indexOf(u8, result.content, "a.rs:12\n fn three(\na.rs:15 *\n") != null); } + +test "patch panes keep different commits and reuse only the same commit" { + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + const Page = struct { + fn open(pp: *Pardes, hash: []const u8) !usize { + const id = try pardes.panes.Output.openPager(pp, 0, "/pardes-patch-test"); + var held: std.ArrayList(u8) = .empty; + defer held.deinit(pp.gpa); + try held.print(pp.gpa, "commit {s}\ndiff --git a/x b/x\n--- a/x\n+++ b/x\n@@ -1 +1 @@\n-old\n+new\n", .{hash}); + try @import("ninep/ctl.zig").fillPager(pp, pp.panes[id].?.serial, &held); + for (pp.panes, 0..) |slot, i| { + const f = (slot orelse continue).file orelse continue; + const output = f.output orelse continue; + if (std.meta.eql(output.from, pardes.panes.Output.Origin{ .cmd = .Diff }) and + std.mem.indexOf(u8, f.content, hash) != null) return i; + } + return error.MissingDiff; + } + }; + const a = "0123456789abcdef0123456789abcdef01234567"; + const b = "fedcba9876543210fedcba9876543210fedcba98"; + const first = try Page.open(p, a); + const original = try testing.allocator.dupe(u8, p.panes[first].?.file.?.content); + defer testing.allocator.free(original); + const second = try Page.open(p, b); + try testing.expect(first != second); + try testing.expectEqualStrings(original, p.panes[first].?.file.?.content); + try testing.expectEqualStrings("/pardes-patch-test/+Diff-0123456789ab", p.panes[first].?.file.?.path); + try testing.expectEqualStrings("/pardes-patch-test/+Diff-fedcba987654", p.panes[second].?.file.?.path); + try testing.expectEqual(first, try Page.open(p, a)); + try testing.expectEqualStrings(original, p.panes[first].?.file.?.content); +} |
