Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/GitHub.Exports/Models/DiffUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ public static DiffLine Match(IEnumerable<DiffChunk> diff, IList<DiffLine> target
{
if (source.Lines[i].Content == target[j].Content)
{
if (++j == target.Count) return source.Lines[i + j - 1];
if (++j == target.Count || i == 0)
{
return source.Lines[i + j - 1];
}
}
else
{
Expand Down
10 changes: 8 additions & 2 deletions test/GitHub.InlineReviews.UnitTests/Models/DiffUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,20 @@ public class TheMatchMethod
{
[Theory]
[InlineData(" 1", " 1", 0)]
[InlineData(" 1\n 2", " 2", 1)]
[InlineData(" 1\n 1", " 1", 1)] // match the later line
[InlineData(" 1. 2", " 2", 1)]
[InlineData(" 1. 1", " 1", 1)] // match the later line
[InlineData("+x", "-x", -1)]
[InlineData("", " x", -1)]
[InlineData(" x", "", -1)]

[InlineData(" 1. 2.", " 2. 1.", 1)] // matched full context
[InlineData(" 1. 2.", " 2. 3.", -1)] // didn't match full context
[InlineData(" 2.", " 2. 1.", 0)] // match if we run out of context lines
public void MatchLine(string lines1, string lines2, int skip /* -1 for no match */)
{
var header = "@@ -1 +1 @@";
lines1 = lines1.Replace(".", "\r\n");
lines2 = lines2.Replace(".", "\r\n");
var chunks1 = DiffUtilities.ParseFragment(header + "\n" + lines1).ToList();
var chunks2 = DiffUtilities.ParseFragment(header + "\n" + lines2).ToList();
var expectLine = (skip != -1) ? chunks1.First().Lines.Skip(skip).First() : null;
Expand Down