Show the window before slow location probes and wrap git.exe for commit, diff, and merge.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
86
tests/Explorer.Application.Tests/GitDiffParserTests.cs
Normal file
86
tests/Explorer.Application.Tests/GitDiffParserTests.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using Explorer.Application;
|
||||
using Explorer.Domain;
|
||||
|
||||
namespace Explorer.Application.Tests;
|
||||
|
||||
public class GitDiffPlannerTests
|
||||
{
|
||||
[Fact]
|
||||
public void Staged_diff_does_not_read_the_working_tree()
|
||||
{
|
||||
var request = GitDiffPlanner.Create(new GitChange
|
||||
{
|
||||
Path = "src/App.cs",
|
||||
State = GitChangeState.Staged,
|
||||
Index = 'M',
|
||||
WorkTree = '.'
|
||||
});
|
||||
Assert.Null(request.Error);
|
||||
Assert.False(request.NeedsWorkingTree);
|
||||
Assert.Contains("--cached", request.Arguments);
|
||||
Assert.Contains("src/App.cs", request.Arguments);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Untracked_diff_uses_no_index_against_dev_null()
|
||||
{
|
||||
var request = GitDiffPlanner.Create(new GitChange
|
||||
{
|
||||
Path = "new.txt",
|
||||
State = GitChangeState.Untracked,
|
||||
Index = '?',
|
||||
WorkTree = '?'
|
||||
});
|
||||
Assert.True(request.NeedsWorkingTree);
|
||||
Assert.Contains("--no-index", request.Arguments);
|
||||
Assert.Contains("/dev/null", request.Arguments);
|
||||
Assert.Contains("new.txt", request.Arguments);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deleted_unstaged_diff_does_not_need_the_working_tree()
|
||||
{
|
||||
var request = GitDiffPlanner.Create(new GitChange
|
||||
{
|
||||
Path = "gone.cs",
|
||||
State = GitChangeState.Unstaged,
|
||||
Index = '.',
|
||||
WorkTree = 'D'
|
||||
});
|
||||
Assert.False(request.NeedsWorkingTree);
|
||||
Assert.DoesNotContain("--cached", request.Arguments);
|
||||
}
|
||||
}
|
||||
|
||||
public class GitDiffParserTests
|
||||
{
|
||||
[Fact]
|
||||
public void Classifies_unified_diff_lines()
|
||||
{
|
||||
var diff = GitDiffParser.Parse("""
|
||||
diff --git a/src/App.cs b/src/App.cs
|
||||
index 111..222 100644
|
||||
--- a/src/App.cs
|
||||
+++ b/src/App.cs
|
||||
@@ -1,3 +1,4 @@
|
||||
keep
|
||||
-old
|
||||
+new
|
||||
still
|
||||
""", "src/App.cs");
|
||||
Assert.Equal("src/App.cs", diff.Title);
|
||||
Assert.False(diff.IsBinary);
|
||||
Assert.Equal(GitDiffLineKind.Meta, diff.Lines[0].Kind);
|
||||
Assert.Equal(GitDiffLineKind.Hunk, diff.Lines[4].Kind);
|
||||
Assert.Equal(GitDiffLineKind.Context, diff.Lines[5].Kind);
|
||||
Assert.Equal(GitDiffLineKind.Removed, diff.Lines[6].Kind);
|
||||
Assert.Equal(GitDiffLineKind.Added, diff.Lines[7].Kind);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Marks_binary_and_empty()
|
||||
{
|
||||
Assert.True(GitDiffParser.Parse("Binary files a/x and b/x differ\n", "x").IsBinary);
|
||||
Assert.True(GitDiffParser.Parse("", "x").IsEmpty);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user