Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Jun 29, 2024
1 parent 1b2854e commit a832345
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1635,3 +1635,68 @@ GLOBAL OPTIONS:
`, output.String())
}

func Test_checkShellCompleteFlag(t *testing.T) {
t.Parallel()
tests := []struct {
name string
cmd *Command
arguments []string
wantShellCompletion bool
wantArgs []string
}{
{
name: "disable-shell-completion",
arguments: []string{"--generate-shell-completion"},
cmd: &Command{},
wantShellCompletion: false,
wantArgs: []string{"--generate-shell-completion"},
},
{
name: "child-disable-shell-completion",
arguments: []string{"--generate-shell-completion"},
cmd: &Command{
parent: &Command{},
},
wantShellCompletion: false,
wantArgs: []string{"--generate-shell-completion"},
},
{
name: "last argument isn't --generate-shell-completion",
arguments: []string{"foo"},
cmd: &Command{
EnableShellCompletion: true,
},
wantShellCompletion: false,
wantArgs: []string{"foo"},
},
{
name: "arguments include double dash",
arguments: []string{"--", "foo", "--generate-shell-completion"},
cmd: &Command{
EnableShellCompletion: true,
},
wantShellCompletion: false,
wantArgs: []string{"--", "foo", "--generate-shell-completion"},
},
{
name: "shell completion",
arguments: []string{"foo", "--generate-shell-completion"},
cmd: &Command{
EnableShellCompletion: true,
},
wantShellCompletion: true,
wantArgs: []string{"foo"},
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
shellCompletion, args := checkShellCompleteFlag(tt.cmd, tt.arguments)
assert.Equal(t, tt.wantShellCompletion, shellCompletion)
assert.Equal(t, tt.wantArgs, args)
})
}
}

0 comments on commit a832345

Please sign in to comment.