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

Function TestDiffModesPreserveNonASCIIPaths

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

Source from the content-addressed store, hash-verified

234}
235
236func TestDiffModesPreserveNonASCIIPaths(t *testing.T) {
237 tests := []struct {
238 name string
239 provider func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider
240 }{
241 {
242 name: "workspace",
243 provider: func(_ *testing.T, repo string, runner *gitcmd.Runner) *Provider {
244 return NewWorkspaceProvider(repo, runner)
245 },
246 },
247 {
248 name: "commit",
249 provider: func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider {
250 runGitTest(t, repo, "add", "-A")
251 runGitTest(t, repo, "commit", "-q", "-m", "update non-ASCII file")
252 return NewCommitProvider(repo, "HEAD", runner)
253 },
254 },
255 {
256 name: "range",
257 provider: func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider {
258 runGitTest(t, repo, "add", "-A")
259 runGitTest(t, repo, "commit", "-q", "-m", "update non-ASCII file")
260 return NewProvider(repo, "HEAD~1", "HEAD", runner)
261 },
262 },
263 }
264
265 for _, tt := range tests {
266 t.Run(tt.name, func(t *testing.T) {
267 repo, relPath := initRepoWithNonASCIIChange(t)
268 provider := tt.provider(t, repo, gitcmd.New(0))
269
270 diffs, err := provider.GetDiff(context.Background())
271 if err != nil {
272 t.Fatalf("GetDiff returned error: %v", err)
273 }
274 if len(diffs) != 1 {
275 t.Fatalf("got %d diffs, want 1: %+v", len(diffs), diffs)
276 }
277 if diffs[0].NewPath != relPath {
278 t.Errorf("NewPath = %q, want %q", diffs[0].NewPath, relPath)
279 }
280 if diffs[0].NewFileContent != "after\n" {
281 t.Errorf("NewFileContent = %q, want %q", diffs[0].NewFileContent, "after\n")
282 }
283 })
284 }
285}
286
287func TestWorkspaceDiffPreservesNonASCIIUntrackedPath(t *testing.T) {
288 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