box-o-sand/argh/querier_test.go

46 lines
827 B
Go
Raw Normal View History

2022-05-19 00:15:31 +00:00
package argh_test
import (
"testing"
"git.meatballhat.com/x/box-o-sand/argh"
"github.com/stretchr/testify/require"
)
func TestQuerier_Program(t *testing.T) {
for _, tc := range []struct {
name string
args []string
cfg *argh.ParserConfig
2022-05-27 12:22:07 +00:00
exp string
2022-05-19 00:15:31 +00:00
expOK bool
}{
{
name: "typical",
args: []string{"pizzas", "ahoy", "--treatsa", "fun"},
2022-05-27 12:22:07 +00:00
exp: "pizzas",
2022-05-19 00:15:31 +00:00
expOK: true,
},
{
name: "minimal",
args: []string{"pizzas"},
2022-05-27 12:22:07 +00:00
exp: "pizzas",
2022-05-19 00:15:31 +00:00
expOK: true,
},
{
name: "invalid",
args: []string{},
expOK: false,
},
2022-05-19 00:15:31 +00:00
} {
t.Run(tc.name, func(ct *testing.T) {
2022-05-27 12:22:07 +00:00
pt, err := argh.ParseArgs2(tc.args, tc.cfg)
2022-05-19 00:15:31 +00:00
require.Nil(ct, err)
prog, ok := argh.NewQuerier(pt.Nodes).Program()
2022-05-19 00:15:31 +00:00
require.Equal(ct, tc.expOK, ok)
2022-05-27 12:22:07 +00:00
require.Equal(ct, tc.exp, prog.Name)
2022-05-19 00:15:31 +00:00
})
}
}