From 08be2cb98199b82b112f0fe7aaa86ab5fd8b3286 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Thu, 27 Jul 2023 23:52:11 +0900 Subject: [PATCH] add unit tests --- command_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/command_test.go b/command_test.go index 5c070ee8..540e2176 100644 --- a/command_test.go +++ b/command_test.go @@ -1887,6 +1887,47 @@ func TestRemoveSingleGroup(t *testing.T) { checkStringContains(t, output, "\nAdditional Commands:\n sub") } +func TestRemoveHelpCommandGroup(t *testing.T) { + rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun} + rootCmd.CompletionOptions.DisableDefaultCmd = true + + rootCmd.AddGroup(&Group{ID: "group", Title: "group"}) + rootCmd.AddCommand(&Command{Use: "child", Short: "c", GroupID: "group", Run: emptyRun}) + rootCmd.SetHelpCommandGroupID("group") + + rootCmd.RemoveGroup("group") + + output, err := executeCommand(rootCmd, "--help") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + checkStringOmits(t, output, "\ngroup\n child\n help") + checkStringContains(t, output, "\nAvailable Commands:\n child c\n help") +} + +func TestRemoveCompletionCommandGroup(t *testing.T) { + rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun} + + rootCmd.AddGroup( + &Group{ID: "group", Title: "group"}, + &Group{ID: "help", Title: "help"}, + ) + rootCmd.AddCommand(&Command{Use: "child", Short: "c", GroupID: "group", Run: emptyRun}) + rootCmd.SetHelpCommandGroupID("help") + rootCmd.SetCompletionCommandGroupID("group") + + rootCmd.RemoveGroup("group") + + output, err := executeCommand(rootCmd, "--help") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + checkStringOmits(t, output, "\ngroup\n child\n completion") + checkStringContains(t, output, "\nAdditional Commands:\n child c\n completion") +} + func TestRemoveMultipleGroups(t *testing.T) { var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}