MCPcopy
hub / github.com/spf13/pflag / TestI32SAsSliceValue

Function TestI32SAsSliceValue

int32_slice_test.go:153–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

151}
152
153func TestI32SAsSliceValue(t *testing.T) {
154 var i32s []int32
155 f := setUpI32SFlagSet(&i32s)
156
157 in := []string{"1", "2"}
158 argfmt := "--is=%s"
159 arg1 := fmt.Sprintf(argfmt, in[0])
160 arg2 := fmt.Sprintf(argfmt, in[1])
161 err := f.Parse([]string{arg1, arg2})
162 if err != nil {
163 t.Fatal("expected no error; got", err)
164 }
165
166 f.VisitAll(func(f *Flag) {
167 if val, ok := f.Value.(SliceValue); ok {
168 _ = val.Replace([]string{"3"})
169 }
170 })
171 if len(i32s) != 1 || i32s[0] != 3 {
172 t.Fatalf("Expected ss to be overwritten with '3.1', but got: %v", i32s)
173 }
174}
175
176func TestI32SCalledTwice(t *testing.T) {
177 var is []int32

Callers

nothing calls this directly

Calls 4

setUpI32SFlagSetFunction · 0.85
VisitAllMethod · 0.80
ParseMethod · 0.65
ReplaceMethod · 0.65

Tested by

no test coverage detected