Skip to content

Commit d36e843

Browse files
committed
Enforce repo.Diff.Compare<TreeChanges> test coverage
1 parent df12a77 commit d36e843

File tree

1 file changed

+60
-38
lines changed

1 file changed

+60
-38
lines changed

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -904,14 +904,13 @@ public void CanCompareTwoVersionsOfAFileWithADiffOfTwoHunks(int contextLines, in
904904
}
905905
}
906906

907-
[Fact]
908-
public void CanHandleTwoTreeEntryChangesWithTheSamePath()
907+
private void CanHandleTwoTreeEntryChangesWithTheSamePath(SimilarityOptions similarity, Action<string, TreeChanges> verifier)
909908
{
910909
string repoPath = InitNewRepository();
911910

912911
using (var repo = new Repository(repoPath))
913912
{
914-
Blob mainContent = OdbHelper.CreateBlob(repo, "awesome content\n");
913+
Blob mainContent = OdbHelper.CreateBlob(repo, "awesome content\n" + new string('b', 4096));
915914
Blob linkContent = OdbHelper.CreateBlob(repo, "../../objc/Nu.h");
916915

917916
string path = string.Format("include{0}Nu{0}Nu.h", Path.DirectorySeparatorChar);
@@ -930,45 +929,68 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePath()
930929
var changes = repo.Diff.Compare<TreeChanges>(treeOld, treeNew,
931930
compareOptions: new CompareOptions
932931
{
933-
Similarity = SimilarityOptions.None,
932+
Similarity = similarity,
934933
});
934+
}
935+
}
935936

936-
/*
937-
* $ git diff-tree -p 5c87b67 d5278d0
938-
* diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
939-
* deleted file mode 120000
940-
* index 19bf568..0000000
941-
* --- a/include/Nu/Nu.h
942-
* +++ /dev/null
943-
* @@ -1 +0,0 @@
944-
* -../../objc/Nu.h
945-
* \ No newline at end of file
946-
* diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
947-
* new file mode 100644
948-
* index 0000000..f9e6561
949-
* --- /dev/null
950-
* +++ b/include/Nu/Nu.h
951-
* @@ -0,0 +1 @@
952-
* +awesome content
953-
* diff --git a/objc/Nu.h b/objc/Nu.h
954-
* deleted file mode 100644
955-
* index f9e6561..0000000
956-
* --- a/objc/Nu.h
957-
* +++ /dev/null
958-
* @@ -1 +0,0 @@
959-
* -awesome content
960-
*/
937+
[Fact]
938+
public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityNone()
939+
{
940+
/*
941+
* $ git diff-tree -p 5c87b67 d5278d0
942+
* diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
943+
* deleted file mode 120000
944+
* index 19bf568..0000000
945+
* --- a/include/Nu/Nu.h
946+
* +++ /dev/null
947+
* @@ -1 +0,0 @@
948+
* -../../objc/Nu.h
949+
* \ No newline at end of file
950+
* diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
951+
* new file mode 100644
952+
* index 0000000..f9e6561
953+
* --- /dev/null
954+
* +++ b/include/Nu/Nu.h
955+
* @@ -0,0 +1 @@
956+
* +awesome content
957+
* diff --git a/objc/Nu.h b/objc/Nu.h
958+
* deleted file mode 100644
959+
* index f9e6561..0000000
960+
* --- a/objc/Nu.h
961+
* +++ /dev/null
962+
* @@ -1 +0,0 @@
963+
* -awesome content
964+
*/
965+
966+
CanHandleTwoTreeEntryChangesWithTheSamePath(SimilarityOptions.None,
967+
(path, changes) =>
968+
{
969+
Assert.Equal(1, changes.Deleted.Count());
970+
Assert.Equal(0, changes.Modified.Count());
971+
Assert.Equal(1, changes.TypeChanged.Count());
972+
973+
TreeEntryChanges change = changes[path];
974+
Assert.Equal(Mode.SymbolicLink, change.OldMode);
975+
Assert.Equal(Mode.NonExecutableFile, change.Mode);
976+
Assert.Equal(ChangeKind.TypeChanged, change.Status);
977+
Assert.Equal(path, change.Path);
978+
});
979+
}
961980

962-
Assert.Equal(1, changes.Deleted.Count());
963-
Assert.Equal(0, changes.Modified.Count());
964-
Assert.Equal(1, changes.TypeChanged.Count());
981+
[Fact]
982+
public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityDefault()
983+
{
984+
/*
985+
* $ git diff-tree -p 5c87b67 d5278d0
986+
* To be done...
987+
*/
965988

966-
TreeEntryChanges change = changes[path];
967-
Assert.Equal(Mode.SymbolicLink, change.OldMode);
968-
Assert.Equal(Mode.NonExecutableFile, change.Mode);
969-
Assert.Equal(ChangeKind.TypeChanged, change.Status);
970-
Assert.Equal(path, change.Path);
971-
}
989+
CanHandleTwoTreeEntryChangesWithTheSamePath(SimilarityOptions.Default,
990+
(path, changes) =>
991+
{
992+
// TODO: What should we assert there?
993+
});
972994
}
973995

974996
[Fact]

0 commit comments

Comments
 (0)