Skip to content

Commit

Permalink
chore: add unit tests for completions helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoVeille committed Feb 8, 2025
1 parent 9d47599 commit 5345ce2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2872,6 +2872,35 @@ func TestFixedCompletions(t *testing.T) {
}
}

func TestFixedCompletionsWithCompletionChoiceHelpers(t *testing.T) {
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
// here we are mixing string, CompletionChoice and CompletionChoiceWithDescription
choices := []string{"apple", CompletionChoice("banana"), CompletionChoiceWithDescription("orange", "orange are orange")}
childCmd := &Command{
Use: "child",
ValidArgsFunction: FixedCompletions(choices, ShellCompDirectiveNoFileComp),
Run: emptyRun,
}
rootCmd.AddCommand(childCmd)

output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "child", "a")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}

expected := strings.Join([]string{
"apple",
"banana",
"orange",
":4",
"Completion ended with directive: ShellCompDirectiveNoFileComp", "",
}, "\n")

if output != expected {
t.Errorf("expected: %q, got: %q", expected, output)
}
}

func TestCompletionForGroupedFlags(t *testing.T) {
getCmd := func() *Command {
rootCmd := &Command{
Expand Down

0 comments on commit 5345ce2

Please # to comment.