Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jul 27, 2023
1 parent 8a27698 commit 08be2cb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down

0 comments on commit 08be2cb

Please sign in to comment.