Skip to content

Commit 6a6f134

Browse files
committed
Test for IndentHeuristic Diff option
This test is based on example from: https://github.com/git/git/blob/433860f3d0beb0c6f205290bd16cda413148f098/t/t4061-diff-indent.sh#L17
1 parent e34ae5b commit 6a6f134

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

LibGit2Sharp.Tests/DiffBlobToBlobFixture.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,44 @@ public void ComparingTwoNullBlobsReturnsAnEmptyContentChanges()
126126
Assert.Equal(0, changes.LinesDeleted);
127127
}
128128
}
129+
130+
[Fact]
131+
public void ComparingBlobsWithIndentHeuristicOptionMakesADifference()
132+
{
133+
var path = SandboxStandardTestRepoGitDir();
134+
using (var repo = new Repository(path))
135+
{
136+
// Based on test diff indent heuristic from:
137+
// https://github.com/git/git/blob/433860f3d0beb0c6f205290bd16cda413148f098/t/t4061-diff-indent.sh#L17
138+
var oldContent =
139+
@" 1
140+
2
141+
a
142+
143+
b
144+
3
145+
4";
146+
var newContent =
147+
@" 1
148+
2
149+
a
150+
151+
b
152+
a
153+
154+
b
155+
3
156+
4";
157+
var oldBlob = repo.ObjectDatabase.CreateBlob(new MemoryStream(Encoding.UTF8.GetBytes(oldContent)));
158+
var newBlob = repo.ObjectDatabase.CreateBlob(new MemoryStream(Encoding.UTF8.GetBytes(newContent)));
159+
var noIndentHeuristicOption = new CompareOptions { IndentHeuristic = false };
160+
var indentHeuristicOption = new CompareOptions { IndentHeuristic = true };
161+
162+
ContentChanges changes0 = repo.Diff.Compare(oldBlob, newBlob, noIndentHeuristicOption);
163+
ContentChanges changes1 = repo.Diff.Compare(oldBlob, newBlob, indentHeuristicOption);
164+
165+
Assert.NotEqual(changes0.Patch, changes1.Patch);
166+
}
167+
}
129168
}
130169
}

0 commit comments

Comments
 (0)