MCPcopy
hub / github.com/urfave/cli / TestCommand_Uint8Slice

Function TestCommand_Uint8Slice

flag_uint_slice_test.go:60–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

58}
59
60func TestCommand_Uint8Slice(t *testing.T) {
61 tests := []struct {
62 name string
63 flag Flag
64 arguments []string
65 expect []uint8
66 expectErr bool
67 }{
68 {
69 flag: &Uint8SliceFlag{
70 Name: "numbers",
71 },
72 arguments: []string{"--numbers", "1,2,3,4"},
73 expect: []uint8{1, 2, 3, 4},
74 },
75 {
76 flag: &Uint8SliceFlag{
77 Name: "numbers",
78 },
79 arguments: []string{"--numbers", "1,2", "--numbers", "3,4"},
80 expect: []uint8{1, 2, 3, 4},
81 },
82 }
83 for _, tt := range tests {
84 t.Run(tt.name, func(t *testing.T) {
85 cmd := &Command{
86 Name: "mock",
87 Flags: []Flag{tt.flag},
88 Writer: io.Discard,
89 ErrWriter: io.Discard,
90 }
91
92 err := cmd.Run(buildTestContext(t), append([]string{"mock"}, tt.arguments...))
93
94 if tt.expectErr {
95 require.Error(t, err)
96
97 return
98 }
99
100 require.NoError(t, err)
101
102 for _, name := range tt.flag.Names() {
103 assert.Equalf(t, tt.expect, cmd.Uint8Slice(name), "Uint8Slice(%v)", name)
104 }
105 })
106 }
107}
108
109func TestCommand_Uint16Slice(t *testing.T) {
110 tests := []struct {

Callers

nothing calls this directly

Calls 5

RunMethod · 0.95
Uint8SliceMethod · 0.95
buildTestContextFunction · 0.85
NamesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected