Skip to content

Failing test: CanShowChangesForAFileWithWin1250EncodingContent #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,5 +560,35 @@ public void CallingCompareWithAnUnsupportedGenericParamThrows()
Assert.Throws<LibGit2SharpException>(() => repo.Diff.Compare<string>());
}
}

[Fact]
public void CanShowChangesForAFileWithWin1250EncodingContent()
{
const string testFile = "windows1250.txt";

string repoPath = CloneStandardTestRepo();
using (var repo = new Repository(repoPath))
{
// Create the file in the workdir
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";
Touch(repo.Info.WorkingDirectory, testFile, testFileContent, win1250Encoding);

//compare changes
var changes = repo.Diff.Compare<Patch>(repo.Head.Tip.Tree,
DiffTargets.WorkingDirectory,
new[] { testFile })[testFile];

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);
}
}
}
}