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

Function TestValidArgNames

cmd/opencodereview/arg_errors_test.go:283–310  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

281}
282
283func TestValidArgNames(t *testing.T) {
284 tests := []struct {
285 name string
286 valid []string
287 want []string
288 }{
289 {"plain values", []string{"bash", "zsh"}, []string{"bash", "zsh"}},
290 {"tab-separated descriptions are stripped", []string{"bash\tBourne again shell", "zsh\tZ shell"}, []string{"bash", "zsh"}},
291 // Values pass through as cobra.OnlyValidArgs sees them, so the listed
292 // values are exactly the accepted ones.
293 {"values are not otherwise altered", []string{"bash", " fish"}, []string{"bash", " fish"}},
294 {"none", nil, nil},
295 }
296
297 for _, tt := range tests {
298 t.Run(tt.name, func(t *testing.T) {
299 got := validArgNames(tt.valid)
300 if len(got) != len(tt.want) {
301 t.Fatalf("validArgNames(%v) = %v, want %v", tt.valid, got, tt.want)
302 }
303 for i := range got {
304 if got[i] != tt.want[i] {
305 t.Errorf("validArgNames(%v)[%d] = %q, want %q", tt.valid, i, got[i], tt.want[i])
306 }
307 }
308 })
309 }
310}

Callers

nothing calls this directly

Calls 2

validArgNamesFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected