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

Function TestSSAsSliceValue

string_slice_test.go:255–276  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

253}
254
255func TestSSAsSliceValue(t *testing.T) {
256 var ss []string
257 f := setUpSSFlagSet(&ss)
258
259 in := []string{"one", "two"}
260 argfmt := "--ss=%s"
261 arg1 := fmt.Sprintf(argfmt, in[0])
262 arg2 := fmt.Sprintf(argfmt, in[1])
263 err := f.Parse([]string{arg1, arg2})
264 if err != nil {
265 t.Fatal("expected no error; got", err)
266 }
267
268 f.VisitAll(func(f *Flag) {
269 if val, ok := f.Value.(SliceValue); ok {
270 _ = val.Replace([]string{"three"})
271 }
272 })
273 if len(ss) != 1 || ss[0] != "three" {
274 t.Fatalf("Expected ss to be overwritten with 'three', but got: %s", ss)
275 }
276}

Callers

nothing calls this directly

Calls 4

setUpSSFlagSetFunction · 0.85
VisitAllMethod · 0.80
ParseMethod · 0.65
ReplaceMethod · 0.65

Tested by

no test coverage detected