mirror of
https://github.com/spf13/cobra
synced 2025-04-28 09:37:17 +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,6 +2883,26 @@ func TestFixedCompletionsWithCompletionHelpers(t *testing.T) {
|
||||||
}
|
}
|
||||||
rootCmd.AddCommand(childCmd)
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
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\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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("completion with no description", func(t *testing.T) {
|
||||||
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "child", "a")
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "child", "a")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
@ -2891,7 +2911,7 @@ func TestFixedCompletionsWithCompletionHelpers(t *testing.T) {
|
||||||
expected := strings.Join([]string{
|
expected := strings.Join([]string{
|
||||||
"apple",
|
"apple",
|
||||||
"banana",
|
"banana",
|
||||||
"orange",
|
"orange", // the description is absent as expected with [ShellCompNoDescRequestCmd] flag
|
||||||
":4",
|
":4",
|
||||||
"Completion ended with directive: ShellCompDirectiveNoFileComp", "",
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", "",
|
||||||
}, "\n")
|
}, "\n")
|
||||||
|
@ -2899,6 +2919,7 @@ func TestFixedCompletionsWithCompletionHelpers(t *testing.T) {
|
||||||
if output != expected {
|
if output != expected {
|
||||||
t.Errorf("expected: %q, got: %q", expected, output)
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompletionForGroupedFlags(t *testing.T) {
|
func TestCompletionForGroupedFlags(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue