(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func 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 | |
| 152 | func TestWorkspaceDiffPreservesNonASCIIUntrackedPath(t *testing.T) { |
| 153 | repo, trackedPath := initRepoWithNonASCIIChange(t) |
nothing calls this directly
no test coverage detected