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

Function TestReadDelegateExamples

internal/delegate/instructions_test.go:147–191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestReadDelegateExamples(t *testing.T) {
148 const diff = "git --no-pager diff --no-ext-diff --no-textconv --no-color HEAD -- \"<path>\""
149 const cat = "cat \"<path>\""
150 for _, tc := range []struct {
151 name string
152 contents []string
153 want []string
154 wantErr string
155 }{
156 {
157 name: "matching sets with duplicates and different order",
158 contents: []string{diff + "\n" + cat + "\n" + diff, cat + "\n" + diff},
159 want: []string{cat, diff},
160 },
161 {name: "empty first document", contents: []string{"# No examples", diff}, wantErr: "doc-0.md contains no review command examples"},
162 {name: "empty later document", contents: []string{diff, "# No examples"}, wantErr: "doc-1.md contains no review command examples"},
163 {name: "all documents empty", contents: []string{"", ""}, wantErr: "doc-0.md contains no review command examples"},
164 {name: "no documents", wantErr: "no delegate documents to check"},
165 {name: "no Git commands", contents: []string{cat, cat}, wantErr: "doc-0.md contains no Git command examples"},
166 {name: "different command sets", contents: []string{diff, diff + "\n" + cat}, wantErr: "doc-1.md examples differ from doc-0.md"},
167 } {
168 t.Run(tc.name, func(t *testing.T) {
169 root := fstest.MapFS{}
170 var docs []string
171 for i, content := range tc.contents {
172 name := fmt.Sprintf("doc-%d.md", i)
173 docs = append(docs, name)
174 root[name] = &fstest.MapFile{Data: []byte(content)}
175 }
176 got, err := readDelegateExamples(root, docs)
177 if tc.wantErr != "" {
178 if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
179 t.Fatalf("error = %v, want %q", err, tc.wantErr)
180 }
181 return
182 }
183 if err != nil {
184 t.Fatal(err)
185 }
186 if !slices.Equal(got, tc.want) {
187 t.Fatalf("examples = %q, want %q", got, tc.want)
188 }
189 })
190 }
191}
192
193func (r delegateRepo) args(example, patchPath string) []string {
194 // Split placeholders before inserting paths containing spaces as single arguments.

Callers

nothing calls this directly

Calls 3

readDelegateExamplesFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected