diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-05-02 23:00:08 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-05-20 15:50:56 +0400 |
commit | 2054391b299149f06fceadea357ffe8ceb395e87 (patch) | |
tree | 76a1160b2bf9dfc42d1c92e8f0504aa3fcec1d08 /LibGit2Sharp.Tests | |
parent | 40bf30eae534d803173217d98d317fef21969685 (diff) |
Make Diff.Compare able to handle a blob to blob comparison
Diffstat (limited to 'LibGit2Sharp.Tests')
-rw-r--r-- | LibGit2Sharp.Tests/DiffBlobToBlobFixture.cs | 61 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 1 |
2 files changed, 62 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/DiffBlobToBlobFixture.cs b/LibGit2Sharp.Tests/DiffBlobToBlobFixture.cs new file mode 100644 index 00000000..15f36460 --- /dev/null +++ b/LibGit2Sharp.Tests/DiffBlobToBlobFixture.cs @@ -0,0 +1,61 @@ +using System.Linq; +using System.Text; +using LibGit2Sharp.Tests.TestHelpers; +using Xunit; + +namespace LibGit2Sharp.Tests +{ + public class DiffBlobToBlobFixture : BaseFixture + { + [Fact] + public void ComparingABlobAgainstItselfReturnsNoDifference() + { + using (var repo = new Repository(StandardTestRepoPath)) + { + Blob blob = repo.Head.Tip.Tree.Blobs.First(); + + ContentChanges changes = repo.Diff.Compare(blob, blob); + + Assert.Equal(0, changes.LinesAdded); + Assert.Equal(0, changes.LinesDeleted); + Assert.Equal(string.Empty, changes.Patch); + } + } + + [Fact] + public void CanCompareTwoVersionsOfABlobWithADiffOfTwoHunks() + { + using (var repo = new Repository(StandardTestRepoPath)) + { + var oldblob = repo.Lookup<Blob>("7909961"); + var newblob = repo.Lookup<Blob>("4e935b7"); + + ContentChanges changes = repo.Diff.Compare(oldblob, newblob); + + Assert.Equal(3, changes.LinesAdded); + Assert.Equal(1, changes.LinesDeleted); + + var expected = new StringBuilder() + .Append("@@ -1,4 +1,5 @@\n") + .Append(" 1\n") + .Append("+2\n") + .Append(" 3\n") + .Append(" 4\n") + .Append(" 5\n") + .Append("@@ -8,8 +9,9 @@\n") + .Append(" 8\n") + .Append(" 9\n") + .Append(" 10\n") + .Append("-12\n") + .Append("+11\n") + .Append(" 12\n") + .Append(" 13\n") + .Append(" 14\n") + .Append(" 15\n") + .Append("+16\n"); + + Assert.Equal(expected.ToString(), changes.Patch); + } + } + } +} diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index 8187f89e..52b8cbe7 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -45,6 +45,7 @@ <ItemGroup> <Compile Include="ConfigurationFixture.cs" /> <Compile Include="AttributesFixture.cs" /> + <Compile Include="DiffBlobToBlobFixture.cs" /> <Compile Include="ObjectDatabaseFixture.cs" /> <Compile Include="DiffTreeToTreeFixture.cs" /> <Compile Include="RepositoryOptionsFixture.cs" /> |