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

Function TestDiffModesPreserveNonASCIIPaths

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

Source from the content-addressed store, hash-verified

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