MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestDiffModesPreserveNonASCIIPaths

Function TestDiffModesPreserveNonASCIIPaths

internal/diff/git_test.go:98–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func TestDiffModesPreserveNonASCIIPaths(t *testing.T) {
99 tests := []struct {
100 name string
101 provider func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider
102 }{
103 {
104 name: "workspace",
105 provider: func(_ *testing.T, repo string, runner *gitcmd.Runner) *Provider {
106 return NewWorkspaceProvider(repo, runner)
107 },
108 },
109 {
110 name: "commit",
111 provider: func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider {
112 runGitTest(t, repo, "add", "-A")
113 runGitTest(t, repo, "commit", "-q", "-m", "update non-ASCII file")
114 return NewCommitProvider(repo, "HEAD", runner)
115 },
116 },
117 {
118 name: "range",
119 provider: func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider {
120 runGitTest(t, repo, "add", "-A")
121 runGitTest(t, repo, "commit", "-q", "-m", "update non-ASCII file")
122 return NewProvider(repo, "HEAD~1", "HEAD", runner)
123 },
124 },
125 }
126
127 for _, tt := range tests {
128 t.Run(tt.name, func(t *testing.T) {
129 repo, relPath := initRepoWithNonASCIIChange(t)
130 provider := tt.provider(t, repo, gitcmd.New(0))
131
132 diffs, err := provider.GetDiff(context.Background())
133 if err != nil {
134 t.Fatalf("GetDiff returned error: %v", err)
135 }
136 if len(diffs) != 1 {
137 t.Fatalf("got %d diffs, want 1: %+v", len(diffs), diffs)
138 }
139 if diffs[0].NewPath != relPath {
140 t.Errorf("NewPath = %q, want %q", diffs[0].NewPath, relPath)
141 }
142 if diffs[0].NewFileContent != "after\n" {
143 t.Errorf("NewFileContent = %q, want %q", diffs[0].NewFileContent, "after\n")
144 }
145 })
146 }
147}
148
149func TestWorkspaceDiffPreservesNonASCIIUntrackedPath(t *testing.T) {
150 repo, trackedPath := initRepoWithNonASCIIChange(t)

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
NewWorkspaceProviderFunction · 0.85
runGitTestFunction · 0.85
NewCommitProviderFunction · 0.85
GetDiffMethod · 0.80
NewProviderFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected