(t *testing.T)
| 320 | } |
| 321 | |
| 322 | func TestValidArgsCompletionInGo(t *testing.T) { |
| 323 | rootCmd := &Command{ |
| 324 | Use: "root", |
| 325 | ValidArgs: []string{"one", "two", "three"}, |
| 326 | Args: MinimumNArgs(1), |
| 327 | } |
| 328 | |
| 329 | // Test that validArgs are completed |
| 330 | output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "") |
| 331 | if err != nil { |
| 332 | t.Errorf("Unexpected error: %v", err) |
| 333 | } |
| 334 | |
| 335 | expected := strings.Join([]string{ |
| 336 | "one", |
| 337 | "two", |
| 338 | "three", |
| 339 | ":4", |
| 340 | "Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n") |
| 341 | |
| 342 | if output != expected { |
| 343 | t.Errorf("expected: %q, got: %q", expected, output) |
| 344 | } |
| 345 | |
| 346 | // Test that validArgs are completed with prefix |
| 347 | output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "o") |
| 348 | if err != nil { |
| 349 | t.Errorf("Unexpected error: %v", err) |
| 350 | } |
| 351 | |
| 352 | expected = strings.Join([]string{ |
| 353 | "one", |
| 354 | ":4", |
| 355 | "Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n") |
| 356 | |
| 357 | if output != expected { |
| 358 | t.Errorf("expected: %q, got: %q", expected, output) |
| 359 | } |
| 360 | |
| 361 | // Test that validArgs don't repeat |
| 362 | output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "one", "") |
| 363 | if err != nil { |
| 364 | t.Errorf("Unexpected error: %v", err) |
| 365 | } |
| 366 | |
| 367 | expected = strings.Join([]string{ |
| 368 | ":0", |
| 369 | "Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n") |
| 370 | |
| 371 | if output != expected { |
| 372 | t.Errorf("expected: %q, got: %q", expected, output) |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | func TestValidArgsAndCmdCompletionInGo(t *testing.T) { |
| 377 | rootCmd := &Command{ |
nothing calls this directly
no test coverage detected