From 865cca02896f7a5d1ecf098a0c05463a5f66d597 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Sun, 9 Feb 2025 09:21:55 +0100 Subject: [PATCH] Apply code review feedback The completion should be tested also in a mode that returns the description Co-authored-by: Marc Khouzam Signed-off-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- completions_test.go | 49 ++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/completions_test.go b/completions_test.go index 302a9129..62c203e1 100644 --- a/completions_test.go +++ b/completions_test.go @@ -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) {