2023-06-13 19:06:18 +03:00
|
|
|
package cobraz
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-11-20 04:06:36 +03:00
|
|
|
|
2024-01-15 04:45:34 +03:00
|
|
|
"github.com/neilotoole/sq/testh/tu"
|
2023-06-13 19:06:18 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestExtractDirectives(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
in cobra.ShellCompDirective
|
|
|
|
want []cobra.ShellCompDirective
|
|
|
|
wantStrings []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
cobra.ShellCompDirectiveError,
|
|
|
|
[]cobra.ShellCompDirective{cobra.ShellCompDirectiveError},
|
|
|
|
[]string{ShellCompDirectiveErrorText},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cobra.ShellCompDirectiveError | cobra.ShellCompDirectiveNoSpace,
|
|
|
|
[]cobra.ShellCompDirective{cobra.ShellCompDirectiveError, cobra.ShellCompDirectiveNoSpace},
|
|
|
|
[]string{ShellCompDirectiveErrorText, ShellCompDirectiveNoSpaceText},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cobra.ShellCompDirectiveDefault,
|
|
|
|
[]cobra.ShellCompDirective{cobra.ShellCompDirectiveDefault},
|
|
|
|
[]string{ShellCompDirectiveDefaultText},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
2024-01-15 04:45:34 +03:00
|
|
|
t.Run(tu.Name(i, tc.in), func(t *testing.T) {
|
2023-06-13 19:06:18 +03:00
|
|
|
gotDirectives := ExtractDirectives(tc.in)
|
|
|
|
require.Equal(t, tc.want, gotDirectives)
|
|
|
|
gotStrings := MarshalDirective(tc.in)
|
|
|
|
require.Equal(t, tc.wantStrings, gotStrings)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|