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

Function TestDiffModesPreserveNonASCIIPaths

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

Source from the content-addressed store, hash-verified

332}
333
334func TestDiffModesPreserveNonASCIIPaths(t *testing.T) {
335 tests := []struct {
336 name string
337 provider func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider
338 }{
339 {
340 name: "workspace",
341 provider: func(_ *testing.T, repo string, runner *gitcmd.Runner) *Provider {
342 return NewWorkspaceProvider(repo, runner)
343 },
344 },
345 {
346 name: "commit",
347 provider: func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider {
348 runGitTest(t, repo, "add", "-A")
349 runGitTest(t, repo, "commit", "-q", "-m", "update non-ASCII file")
350 return NewCommitProvider(repo, "HEAD", runner)
351 },
352 },
353 {
354 name: "range",
355 provider: func(t *testing.T, repo string, runner *gitcmd.Runner) *Provider {
356 runGitTest(t, repo, "add", "-A")
357 runGitTest(t, repo, "commit", "-q", "-m", "update non-ASCII file")
358 return NewProvider(repo, "HEAD~1", "HEAD", runner)
359 },
360 },
361 }
362
363 for _, tt := range tests {
364 t.Run(tt.name, func(t *testing.T) {
365 repo, relPath := initRepoWithNonASCIIChange(t)
366 provider := tt.provider(t, repo, gitcmd.New(0))
367
368 diffs, err := provider.GetDiff(context.Background())
369 if err != nil {
370 t.Fatalf("GetDiff returned error: %v", err)
371 }
372 if len(diffs) != 1 {
373 t.Fatalf("got %d diffs, want 1: %+v", len(diffs), diffs)
374 }
375 if diffs[0].NewPath != relPath {
376 t.Errorf("NewPath = %q, want %q", diffs[0].NewPath, relPath)
377 }
378 if diffs[0].NewFileContent != "after\n" {
379 t.Errorf("NewFileContent = %q, want %q", diffs[0].NewFileContent, "after\n")
380 }
381 })
382 }
383}
384
385func TestWorkspaceDiffPreservesNonASCIIUntrackedPath(t *testing.T) {
386 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.65

Tested by

no test coverage detected