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

Function TestUISAsSliceValue

uint_slice_test.go:143–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

141}
142
143func TestUISAsSliceValue(t *testing.T) {
144 var uis []uint
145 f := setUpUISFlagSet(&uis)
146
147 in := []string{"1", "2"}
148 argfmt := "--uis=%s"
149 arg1 := fmt.Sprintf(argfmt, in[0])
150 arg2 := fmt.Sprintf(argfmt, in[1])
151 err := f.Parse([]string{arg1, arg2})
152 if err != nil {
153 t.Fatal("expected no error; got", err)
154 }
155
156 f.VisitAll(func(f *Flag) {
157 if val, ok := f.Value.(SliceValue); ok {
158 _ = val.Replace([]string{"3"})
159 }
160 })
161 if len(uis) != 1 || uis[0] != 3 {
162 t.Fatalf("Expected ss to be overwritten with '3.1', but got: %v", uis)
163 }
164}
165
166func TestUISCalledTwice(t *testing.T) {
167 var uis []uint

Callers

nothing calls this directly

Calls 4

setUpUISFlagSetFunction · 0.85
VisitAllMethod · 0.80
ParseMethod · 0.65
ReplaceMethod · 0.65

Tested by

no test coverage detected