mirror of
https://github.com/spf13/cobra
synced 2025-04-27 09:07:19 +00:00
Apply code review feedback
The completion should be tested also in a mode that returns the description Co-authored-by: Marc Khouzam <marc.khouzam@gmail.com> Signed-off-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
This commit is contained in:
parent
8bcda5b137
commit
865cca0289
1 changed files with 35 additions and 14 deletions
|
@ -2883,22 +2883,43 @@ func TestFixedCompletionsWithCompletionHelpers(t *testing.T) {
|
|||
}
|
||||
rootCmd.AddCommand(childCmd)
|
||||
|
||||
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "child", "a")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
t.Run("completion with description", func(t *testing.T) {
|
||||
output, err := executeCommand(rootCmd, ShellCompRequestCmd, "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")
|
||||
expected := strings.Join([]string{
|
||||
"apple",
|
||||
"banana",
|
||||
"orange\torange are orange", // this one has the description as expected with [ShellCompRequestCmd] flag
|
||||
":4",
|
||||
"Completion ended with directive: ShellCompDirectiveNoFileComp", "",
|
||||
}, "\n")
|
||||
|
||||
if output != expected {
|
||||
t.Errorf("expected: %q, got: %q", expected, output)
|
||||
}
|
||||
if output != expected {
|
||||
t.Errorf("expected: %q, got: %q", expected, output)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("completion with no description", func(t *testing.T) {
|
||||
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "child", "a")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
expected := strings.Join([]string{
|
||||
"apple",
|
||||
"banana",
|
||||
"orange", // the description is absent as expected with [ShellCompNoDescRequestCmd] flag
|
||||
":4",
|
||||
"Completion ended with directive: ShellCompDirectiveNoFileComp", "",
|
||||
}, "\n")
|
||||
|
||||
if output != expected {
|
||||
t.Errorf("expected: %q, got: %q", expected, output)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCompletionForGroupedFlags(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue