From 299c842f15d51efed30b73da3d0e1ea39082cd3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janusz=20Bia=C5=82obrzewski?= Date: Tue, 15 Oct 2013 22:03:47 +0200 Subject: [PATCH 1/3] Failing test: CanShowChangesForAFileWithWin1250EncodingContent --- LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs index 289650f70..1d962f7b2 100644 --- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs +++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs @@ -560,5 +560,36 @@ public void CallingCompareWithAnUnsupportedGenericParamThrows() Assert.Throws(() => repo.Diff.Compare()); } } + + [Fact] + public void CanShowChangesForAFileWithWin1250EncodingContent() + { + const string testFile = "windows1250.txt"; + + string repoPath = CloneStandardTestRepo(); + using (var repo = new Repository(repoPath)) + { + // Create the file in the workdir + string testFileFullPath = Path.Combine(repo.Info.WorkingDirectory, testFile); + Encoding win1250Encoding = Encoding.GetEncoding("windows-1250"); + Assert.NotNull(win1250Encoding); + const string testFileContent = "Content in windows-1250 encoding." + + "\u0105\u0119\u0107\u0142\u00F3\u015b\u017a\u017c" + + "\n"; + File.WriteAllText(testFileFullPath, testFileContent, win1250Encoding); + + //compare changes + var changes = repo.Diff.Compare(repo.Head.Tip.Tree, + DiffTargets.WorkingDirectory, + new[] { testFile }).FirstOrDefault(); + + Assert.NotNull(changes); + string expectedHunkHeader = "@@ -0,0 +1 @@\n+"; + int hunkHeaderIdx = changes.Patch.IndexOf(expectedHunkHeader); + Assert.True(hunkHeaderIdx > 0, "Hunk header expected: " + expectedHunkHeader); + string fileContentFromPatch = changes.Patch.Substring(hunkHeaderIdx + expectedHunkHeader.Length); + Assert.Equal(testFileContent, fileContentFromPatch); + } + } } } From 47d97b817b7bbb0c5c176679b7561fa986e50ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janusz=20Bia=C5=82obrzewski?= Date: Tue, 15 Oct 2013 22:47:50 +0200 Subject: [PATCH 2/3] Use Touch to create test file as per PR comment. --- LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs index 1d962f7b2..455cd630c 100644 --- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs +++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs @@ -570,13 +570,12 @@ public void CanShowChangesForAFileWithWin1250EncodingContent() using (var repo = new Repository(repoPath)) { // Create the file in the workdir - string testFileFullPath = Path.Combine(repo.Info.WorkingDirectory, testFile); Encoding win1250Encoding = Encoding.GetEncoding("windows-1250"); Assert.NotNull(win1250Encoding); const string testFileContent = "Content in windows-1250 encoding." + "\u0105\u0119\u0107\u0142\u00F3\u015b\u017a\u017c" + "\n"; - File.WriteAllText(testFileFullPath, testFileContent, win1250Encoding); + Touch(repo.Info.WorkingDirectory, testFile, testFileContent, win1250Encoding); //compare changes var changes = repo.Diff.Compare(repo.Head.Tip.Tree, From 7d1348b5ea4302c02ab5d081afa8346fb94f13bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janusz=20Bia=C5=82obrzewski?= Date: Tue, 15 Oct 2013 23:14:50 +0200 Subject: [PATCH 3/3] Expect changes for testFile --- LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs index 455cd630c..a00d44a77 100644 --- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs +++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs @@ -580,7 +580,7 @@ public void CanShowChangesForAFileWithWin1250EncodingContent() //compare changes var changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.WorkingDirectory, - new[] { testFile }).FirstOrDefault(); + new[] { testFile })[testFile]; Assert.NotNull(changes); string expectedHunkHeader = "@@ -0,0 +1 @@\n+";