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:
ccoVeille 2025-02-09 09:21:55 +01:00
parent 8bcda5b137
commit 865cca0289
No known key found for this signature in database

View file

@ -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) {