forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffBlobToBlobFixture.cs
More file actions
128 lines (102 loc) · 4.04 KB
/
DiffBlobToBlobFixture.cs
File metadata and controls
128 lines (102 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System.IO;
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.False(changes.IsBinaryComparison);
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);
}
}
Blob CreateBinaryBlob(Repository repo)
{
string fullpath = Path.Combine(repo.Info.WorkingDirectory, "binary.bin");
File.WriteAllBytes(fullpath, new byte[] { 17, 16, 0, 4, 65 });
return repo.ObjectDatabase.CreateBlob(fullpath);
}
[Fact]
public void CanCompareATextualBlobAgainstABinaryBlob()
{
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
using (var repo = new Repository(path.RepositoryPath))
{
Blob binBlob = CreateBinaryBlob(repo);
Blob blob = repo.Head.Tip.Tree.Blobs.First();
ContentChanges changes = repo.Diff.Compare(blob, binBlob);
Assert.True(changes.IsBinaryComparison);
Assert.Equal(0, changes.LinesAdded);
Assert.Equal(0, changes.LinesDeleted);
}
}
[Fact]
public void CanCompareABlobAgainstANullBlob()
{
using (var repo = new Repository(StandardTestRepoPath))
{
Blob blob = repo.Head.Tip.Tree.Blobs.First();
ContentChanges changes = repo.Diff.Compare(null, blob);
Assert.NotEqual(0, changes.LinesAdded);
Assert.Equal(0, changes.LinesDeleted);
Assert.NotEqual(string.Empty, changes.Patch);
changes = repo.Diff.Compare(blob, null);
Assert.Equal(0, changes.LinesAdded);
Assert.NotEqual(0, changes.LinesDeleted);
Assert.NotEqual(string.Empty, changes.Patch);
}
}
[Fact]
public void ComparingTwoNullBlobsReturnsAnEmptyContentChanges()
{
using (var repo = new Repository(StandardTestRepoPath))
{
ContentChanges changes = repo.Diff.Compare((Blob)null, (Blob)null);
Assert.False(changes.IsBinaryComparison);
Assert.Equal(0, changes.LinesAdded);
Assert.Equal(0, changes.LinesDeleted);
}
}
}
}