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

Function TestInt16Flag

flag_int_test.go:118–177  ·  flag_int_test.go::TestInt16Flag
(t *testing.T)

Source from the content-addressed store, hash-verified

116}
117
118func TestInt16Flag(t *testing.T) {
119 tests := []struct {
120 name string
121 flag Flag
122 arguments []string
123 expectedValue int16
124 expectErr bool
125 }{
126 {
127 name: "valid",
128 flag: &Int16Flag{
129 Name: "number",
130 Aliases: []string{"n"},
131 },
132 arguments: []string{"--number", "32767"},
133 expectedValue: 32767,
134 },
135 {
136 name: "invalid",
137 flag: &Int16Flag{
138 Name: "number",
139 },
140 arguments: []string{"--number", "gopher"},
141 expectErr: true,
142 },
143 {
144 name: "out of range",
145 flag: &Int16Flag{
146 Name: "number",
147 },
148 arguments: []string{"--number", "32768"},
149 expectErr: true,
150 },
151 }
152
153 for _, tt := range tests {
154 t.Run(tt.name, func(t *testing.T) {
155 cmd := &Command{
156 Name: "mock",
157 Flags: []Flag{tt.flag},
158 Writer: io.Discard,
159 ErrWriter: io.Discard,
160 }
161
162 err := cmd.Run(buildTestContext(t), append([]string{"mock"}, tt.arguments...))
163
164 if tt.expectErr {
165 require.Error(t, err)
166
167 return
168 }
169
170 require.NoError(t, err)
171
172 for _, name := range tt.flag.Names() {
173 assert.Equal(t, tt.expectedValue, cmd.Int16(name))
174 }
175 })

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected