Skip to content

Commit

Permalink
test:(review) added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Mar 18, 2024
1 parent ae4bf66 commit 5538e47
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions print-help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func TestAddOpts_multipleOpts(t *testing.T) {
assert.False(t, more)
}

func TestAddOpts_hasAnyOption(t *testing.T) {
func TestAddOpts_StoreKeyIsAnyOption(t *testing.T) {
help := cliargs.NewHelp()
help.AddOpts([]cliargs.OptCfg{
cliargs.OptCfg{
Expand All @@ -587,7 +587,57 @@ func TestAddOpts_hasAnyOption(t *testing.T) {
assert.False(t, more)
}

func TestAddOpts_hasAnyOption_withIndent(t *testing.T) {
func TestAddOpts_FirstElementInNamesIsAnyOption(t *testing.T) {
help := cliargs.NewHelp()
help.AddOpts([]cliargs.OptCfg{
cliargs.OptCfg{
Names: []string{"foo-bar"},
Desc: "a12345678 b12345678",
},
cliargs.OptCfg{
Names: []string{"*"},
Desc: "c12345678 d12345678",
},
})
iter := help.Iter()

line, more := iter.Next()
assert.Equal(t, line, "--foo-bar a12345678 b12345678")
assert.False(t, more)

line, more = iter.Next()
assert.Equal(t, line, "")
assert.False(t, more)
}

func TestAddOpts_StoreKeyIsAnyOption_withIndent(t *testing.T) {
help := cliargs.NewHelp()
help.AddOpts([]cliargs.OptCfg{
cliargs.OptCfg{
StoreKey: "*",
Desc: "c12345678 d12345678",
},
cliargs.OptCfg{
Names: []string{"foo-bar"},
Desc: "a12345678 b12345678",
},
}, 5)
iter := help.Iter()

line, more := iter.Next()
assert.Equal(t, line, "--foo-bar")
assert.True(t, more)

line, more = iter.Next()
assert.Equal(t, line, " a12345678 b12345678")
assert.False(t, more)

line, more = iter.Next()
assert.Equal(t, line, "")
assert.False(t, more)
}

func TestAddOpts_FirstElementInNamesIsAnyOption_withIndent(t *testing.T) {
help := cliargs.NewHelp()
help.AddOpts([]cliargs.OptCfg{
cliargs.OptCfg{
Expand Down

0 comments on commit 5538e47

Please sign in to comment.